3 namespace Drupal\entity_embed\Tests;
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\file\Entity\File;
8 use Drupal\filter\Entity\FilterFormat;
9 use Drupal\simpletest\WebTestBase;
12 * Base class for all entity_embed tests.
14 abstract class EntityEmbedTestBase extends WebTestBase {
21 public static $modules = ['entity_embed', 'entity_embed_test', 'node', 'ckeditor'];
26 * @var \Drupal\user\UserInterface
31 * A test node to be used for embedding.
33 * @var \Drupal\node\NodeInterface
40 protected function setUp() {
43 // Create a page content type.
44 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
46 // Create a text format and enable the entity_embed filter.
47 $format = FilterFormat::create([
48 'format' => 'custom_format',
49 'name' => 'Custom format',
59 'name' => 'Entity Embed',
64 $editor = Editor::create([
65 'format' => 'custom_format',
66 'editor' => 'ckeditor',
69 'rows' => [[$editor_group]],
75 // Create a user with required permissions.
76 $this->webUser = $this->drupalCreateUser([
78 'create page content',
79 'use text format custom_format',
81 $this->drupalLogin($this->webUser);
83 // Create a sample node to be embedded.
85 $settings['type'] = 'page';
86 $settings['title'] = 'Embed Test Node';
87 $settings['body'] = array('value' => 'This node is to be used for embedding in other nodes.', 'format' => 'custom_format');
88 $this->node = $this->drupalCreateNode($settings);
92 * Retrieves a sample file of the specified type.
94 * @return \Drupal\file\FileInterface
96 protected function getTestFile($type_name, $size = NULL) {
97 // Get a file to upload.
98 $file = current($this->drupalGetTestFiles($type_name, $size));
100 // Add a filesize property to files as would be read by
101 // \Drupal\file\Entity\File::load().
102 $file->filesize = filesize($file->uri);
104 $file = File::create((array) $file);
112 public function assertAvailableDisplayPlugins(EntityInterface $entity, array $expected_plugins, $message = '') {
113 $plugin_options = $this->container->get('plugin.manager.entity_embed.display')
114 ->getDefinitionOptionsForEntity($entity);
115 // @todo Remove the sorting so we can actually test return order.
116 ksort($plugin_options);
117 sort($expected_plugins);
118 $this->assertEqual(array_keys($plugin_options), $expected_plugins, $message);