X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentity_embed%2Fsrc%2FTests%2FEntityEmbedTestBase.php;fp=web%2Fmodules%2Fcontrib%2Fentity_embed%2Fsrc%2FTests%2FEntityEmbedTestBase.php;h=4833947083fb026e9976a08a6056cc9cdf48d1d0;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/entity_embed/src/Tests/EntityEmbedTestBase.php b/web/modules/contrib/entity_embed/src/Tests/EntityEmbedTestBase.php new file mode 100644 index 000000000..483394708 --- /dev/null +++ b/web/modules/contrib/entity_embed/src/Tests/EntityEmbedTestBase.php @@ -0,0 +1,121 @@ +drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); + + // Create a text format and enable the entity_embed filter. + $format = FilterFormat::create([ + 'format' => 'custom_format', + 'name' => 'Custom format', + 'filters' => [ + 'entity_embed' => [ + 'status' => 1, + ], + ], + ]); + $format->save(); + + $editor_group = [ + 'name' => 'Entity Embed', + 'items' => [ + 'node', + ], + ]; + $editor = Editor::create([ + 'format' => 'custom_format', + 'editor' => 'ckeditor', + 'settings' => [ + 'toolbar' => [ + 'rows' => [[$editor_group]], + ], + ], + ]); + $editor->save(); + + // Create a user with required permissions. + $this->webUser = $this->drupalCreateUser([ + 'access content', + 'create page content', + 'use text format custom_format', + ]); + $this->drupalLogin($this->webUser); + + // Create a sample node to be embedded. + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'Embed Test Node'; + $settings['body'] = array('value' => 'This node is to be used for embedding in other nodes.', 'format' => 'custom_format'); + $this->node = $this->drupalCreateNode($settings); + } + + /** + * Retrieves a sample file of the specified type. + * + * @return \Drupal\file\FileInterface + */ + protected function getTestFile($type_name, $size = NULL) { + // Get a file to upload. + $file = current($this->drupalGetTestFiles($type_name, $size)); + + // Add a filesize property to files as would be read by + // \Drupal\file\Entity\File::load(). + $file->filesize = filesize($file->uri); + + $file = File::create((array) $file); + $file->save(); + return $file; + } + + /** + * + */ + public function assertAvailableDisplayPlugins(EntityInterface $entity, array $expected_plugins, $message = '') { + $plugin_options = $this->container->get('plugin.manager.entity_embed.display') + ->getDefinitionOptionsForEntity($entity); + // @todo Remove the sorting so we can actually test return order. + ksort($plugin_options); + sort($expected_plugins); + $this->assertEqual(array_keys($plugin_options), $expected_plugins, $message); + } + +}