Commit ff525f22 authored by phenaproxima's avatar phenaproxima Committed by Wim Leers

Issue #2328659 by phenaproxima, lokapujya, Dave Reid, Wim Leers, slashrsm,...

Issue #2328659 by phenaproxima, lokapujya, Dave Reid, Wim Leers, slashrsm, cs_shadow: Convert all existing entity_embed tests from WebTestBase to BrowserTestBase
parent 952b8155
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\editor\Entity\Editor;
......@@ -91,46 +91,6 @@ class EntityEmbedDialogTest extends EntityEmbedTestBase {
// Check that 'Next' is a primary button.
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Next', 'Next is a primary button');
$title = $this->node->getTitle() . ' (' . $this->node->id() . ')';
$edit = ['entity_id' => $title];
$response = $this->drupalPostAjaxForm(NULL, $edit, 'op');
$plugins = [
'entity_reference:entity_reference_label',
'entity_reference:entity_reference_entity_id',
'view_mode:node.full',
'view_mode:node.rss',
'view_mode:node.search_index',
'view_mode:node.search_result',
'view_mode:node.teaser',
];
foreach ($plugins as $plugin) {
$this->assertTrue(strpos($response[2]['data'], $plugin), 'Plugin ' . $plugin . ' is available in selection.');
}
$this->container->get('config.factory')->getEditable('entity_embed.settings')
->set('rendered_entity_mode', TRUE)->save();
$this->container->get('plugin.manager.entity_embed.display')->clearCachedDefinitions();
$this->getEmbedDialog('custom_format', 'node');
$title = $this->node->getTitle() . ' (' . $this->node->id() . ')';
$edit = ['entity_id' => $title];
$response = $this->drupalPostAjaxForm(NULL, $edit, 'op');
$plugins = [
'entity_reference:entity_reference_label',
'entity_reference:entity_reference_entity_id',
'entity_reference:entity_reference_entity_view',
];
foreach ($plugins as $plugin) {
$this->assertTrue(strpos($response[2]['data'], $plugin), 'Plugin ' . $plugin . ' is available in selection.');
}
/*$this->drupalPostForm(NULL, $edit, 'Next');
// Ensure form structure of the 'embed' step and submit form.
$this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.');
// Check that 'Embed' is a primary button.
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button');*/
}
/**
......
......@@ -4,6 +4,7 @@ namespace Drupal\entity_embed\Tests;
use Drupal\entity_browser\Entity\EntityBrowser;
use Drupal\embed\Entity\EmbedButton;
use Drupal\Tests\entity_embed\Functional\EntityEmbedDialogTest;
/**
* Tests the entity_embed entity_browser integration.
......@@ -55,6 +56,8 @@ class EntityEmbedEntityBrowserTest extends EntityEmbedDialogTest {
$embed_button->type_settings['entity_browser'] = 'entity_embed_entity_browser_test';
$embed_button->save();
$this->container->get('router.builder')->rebuild();
$this->getEmbedDialog('custom_format', 'node');
$this->assertResponse(200, 'Embed dialog is accessible with custom filter format and default embed button.');
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
/**
* Tests the entity_embed filter.
......@@ -14,7 +14,7 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'file',
'image',
'entity_embed',
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
/**
* Tests the hooks provided by entity_embed module.
......@@ -17,7 +17,7 @@ class EntityEmbedHooksTest extends EntityEmbedTestBase {
protected $state;
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\Core\Entity\EntityInterface;
use Drupal\editor\Entity\Editor;
use Drupal\file\Entity\File;
use Drupal\filter\Entity\FilterFormat;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait;
/**
* Base class for all entity_embed tests.
*/
abstract class EntityEmbedTestBase extends WebTestBase {
abstract class EntityEmbedTestBase extends BrowserTestBase {
use TestFileCreationTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['entity_embed', 'entity_embed_test', 'node', 'ckeditor'];
protected static $modules = ['entity_embed', 'entity_embed_test', 'node', 'ckeditor'];
/**
* The test user.
......@@ -35,7 +38,7 @@ abstract class EntityEmbedTestBase extends WebTestBase {
protected $node;
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......@@ -95,7 +98,7 @@ abstract class EntityEmbedTestBase extends WebTestBase {
*/
protected function getTestFile($type_name, $size = NULL) {
// Get a file to upload.
$file = current($this->drupalGetTestFiles($type_name, $size));
$file = current($this->getTestFiles($type_name, $size));
// Add a filesize property to files as would be read by
// \Drupal\file\Entity\File::load().
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
/**
* Tests Twig extension provided by entity_embed.
......@@ -10,7 +10,7 @@ namespace Drupal\entity_embed\Tests;
class EntityEmbedTwigTest extends EntityEmbedTestBase {
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\system\Tests\Update\UpdatePathTestBase;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the update hooks in entity_embed module.
......@@ -17,7 +17,7 @@ class EntityEmbedUpdateHookTest extends UpdatePathTestBase {
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
DRUPAL_ROOT . '/core/modules/system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../tests/fixtures/update/entity_embed.update-hook-test.php',
__DIR__ . '/../../fixtures/update/entity_embed.update-hook-test.php',
];
}
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\Core\Form\FormState;
......@@ -19,7 +19,7 @@ class EntityReferenceFieldFormatterTest extends EntityEmbedTestBase {
protected $menu;
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormState;
......@@ -27,7 +27,7 @@ class FileFieldFormatterTest extends EntityEmbedTestBase {
protected $file;
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......@@ -62,7 +62,7 @@ class FileFieldFormatterTest extends EntityEmbedTestBase {
->createInstance($plugin, []);
$display->setContextValue('entity', $this->file);
$conf_form = $display->buildConfigurationForm($form, $form_state);
$this->assertTrue(array_key_exists('description', $conf_form));
$this->assertArrayHasKey('description', $conf_form);
$this->assertIdentical($conf_form['description']['#type'], 'textfield');
$this->assertIdentical((string) $conf_form['description']['#title'], 'Description');
}
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormState;
......@@ -34,7 +34,7 @@ class ImageFieldFormatterTest extends EntityEmbedTestBase {
protected $file;
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......
<?php
namespace Drupal\entity_embed\Tests;
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\Core\Form\FormState;
......
<?php
namespace Drupal\Tests\entity_embed\FunctionalJavascript;
use Drupal\editor\Entity\Editor;
/**
* Tests the entity_embed dialog controller and route.
*
* @group entity_embed
*/
class EntityEmbedDialogTest extends EntityEmbedTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['image'];
/**
* Tests the entity embed button markup.
*/
public function testEntityEmbedButtonMarkup() {
// Ensure that the route is accessible with a valid embed button.
// 'Node' embed button is provided by default by the module and hence the
// request must be successful.
$this->getEmbedDialog('custom_format', 'node');
// Ensure form structure of the 'select' step and submit form.
$this->assertFieldByName('entity_id', '', 'Entity ID/UUID field is present.');
// Check that 'Next' is a primary button.
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Next', 'Next is a primary button');
$title = $this->node->getTitle() . ' (' . $this->node->id() . ')';
$this->assertSession()->fieldExists('entity_id')->setValue($title);
$this->assertSession()->buttonExists('Next')->press();
$this->assertSession()->assertWaitOnAjaxRequest();
$plugins = [
'entity_reference:entity_reference_label',
'entity_reference:entity_reference_entity_id',
'view_mode:node.full',
'view_mode:node.rss',
'view_mode:node.search_index',
'view_mode:node.search_result',
'view_mode:node.teaser',
];
foreach ($plugins as $plugin) {
$this->assertSession()->optionExists('Display as', $plugin);
}
$this->container->get('config.factory')->getEditable('entity_embed.settings')
->set('rendered_entity_mode', TRUE)->save();
$this->container->get('plugin.manager.entity_embed.display')->clearCachedDefinitions();
$this->getEmbedDialog('custom_format', 'node');
$title = $this->node->getTitle() . ' (' . $this->node->id() . ')';
$this->assertSession()->fieldExists('entity_id')->setValue($title);
$this->assertSession()->buttonExists('Next')->press();
$this->assertSession()->assertWaitOnAjaxRequest();
$plugins = [
'entity_reference:entity_reference_label',
'entity_reference:entity_reference_entity_id',
'entity_reference:entity_reference_entity_view',
];
foreach ($plugins as $plugin) {
$this->assertSession()->optionExists('Display as', $plugin);
}
/*$this->drupalPostForm(NULL, $edit, 'Next');
// Ensure form structure of the 'embed' step and submit form.
$this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.');
// Check that 'Embed' is a primary button.
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button');*/
}
/**
* Retrieves an embed dialog based on given parameters.
*
* @param string $filter_format_id
* ID of the filter format.
* @param string $embed_button_id
* ID of the embed button.
*
* @return string
* The retrieved HTML string.
*/
public function getEmbedDialog($filter_format_id = NULL, $embed_button_id = NULL) {
$url = 'entity-embed/dialog';
if (!empty($filter_format_id)) {
$url .= '/' . $filter_format_id;
if (!empty($embed_button_id)) {
$url .= '/' . $embed_button_id;
}
}
return $this->drupalGet($url);
}
}
<?php
namespace Drupal\Tests\entity_embed\FunctionalJavascript;
use Drupal\Core\Entity\EntityInterface;
use Drupal\editor\Entity\Editor;
use Drupal\file\Entity\File;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\TestFileCreationTrait;
/**
* Base class for all entity_embed tests.
*/
abstract class EntityEmbedTestBase extends WebDriverTestBase {
use TestFileCreationTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['entity_embed', 'entity_embed_test', 'node', 'ckeditor'];
/**
* The test user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* A test node to be used for embedding.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create a page content type.
$this->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->getTestFiles($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;
}
/**
* Assert that the expected display plugins are available for the entity.
*/
public function assertAvailableDisplayPlugins(EntityInterface $entity, array $expected_plugins, $message = '') {
$plugin_options = $this->container->get('plugin.manager.entity_embed.display')
->getDefinitionOptionsForEntity($entity);
$this->assertEqual([], array_diff($expected_plugins, array_keys($plugin_options)), $message);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment