summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2017-09-05 21:08:28 (GMT)
committerLee Rowlands2017-09-05 21:08:28 (GMT)
commit7ba77154a04250e6707f1dff2dbe596c1ba582f5 (patch)
tree17ec1b1c07a42de30e287866848555e700c8168a
parent69edc2a364e328ffc0f8a5fa4e0accc236195ceb (diff)
Issue #2863644 by Lendude, zviryatko, Manuel Garcia, Jo Fitzgerald: Convert web tests of block
-rw-r--r--core/modules/block/src/Tests/BlockTestBase.php7
-rw-r--r--core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php50
-rw-r--r--core/modules/block/tests/src/Functional/BlockAdminThemeTest.php (renamed from core/modules/block/src/Tests/BlockAdminThemeTest.php)6
-rw-r--r--core/modules/block/tests/src/Functional/BlockFormInBlockTest.php (renamed from core/modules/block/src/Tests/BlockFormInBlockTest.php)6
-rw-r--r--core/modules/block/tests/src/Functional/BlockInstallTest.php (renamed from core/modules/block/src/Tests/BlockInstallTest.php)6
-rw-r--r--core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php (renamed from core/modules/block/src/Tests/BlockLanguageCacheTest.php)10
-rw-r--r--core/modules/block/tests/src/Functional/BlockRenderOrderTest.php (renamed from core/modules/block/src/Tests/BlockRenderOrderTest.php)6
-rw-r--r--core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php (renamed from core/modules/block/src/Tests/BlockSystemBrandingTest.php)4
-rw-r--r--core/modules/block/tests/src/Functional/BlockTest.php (renamed from core/modules/block/src/Tests/BlockTest.php)8
-rw-r--r--core/modules/block/tests/src/Functional/BlockTestBase.php74
-rw-r--r--core/modules/block/tests/src/Functional/BlockUiTest.php (renamed from core/modules/block/src/Tests/BlockUiTest.php)16
-rw-r--r--core/modules/block/tests/src/Functional/BlockXssTest.php (renamed from core/modules/block/src/Tests/BlockXssTest.php)18
-rw-r--r--core/modules/block/tests/src/Functional/NonDefaultBlockAdminTest.php (renamed from core/modules/block/src/Tests/NonDefaultBlockAdminTest.php)6
-rw-r--r--core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php (renamed from core/modules/block/src/Tests/Views/DisplayBlockTest.php)34
-rw-r--r--core/modules/simpletest/src/TestDiscovery.php4
15 files changed, 196 insertions, 59 deletions
diff --git a/core/modules/block/src/Tests/BlockTestBase.php b/core/modules/block/src/Tests/BlockTestBase.php
index 71f0ae6..7397a47 100644
--- a/core/modules/block/src/Tests/BlockTestBase.php
+++ b/core/modules/block/src/Tests/BlockTestBase.php
@@ -2,11 +2,18 @@
namespace Drupal\block\Tests;
+@trigger_error(__NAMESPACE__ . '\BlockTestBase is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\block\Functional\BlockTestBase, see https://www.drupal.org/node/2901823.', E_USER_DEPRECATED);
+
use Drupal\simpletest\WebTestBase;
use Drupal\filter\Entity\FilterFormat;
/**
* Provides setup and helper methods for block module tests.
+ *
+ * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
+ * Use \Drupal\Tests\block\Functional\BlockTestBase.
+ *
+ * @see https://www.drupal.org/node/2901823
*/
abstract class BlockTestBase extends WebTestBase {
diff --git a/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php b/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php
new file mode 100644
index 0000000..17244ff
--- /dev/null
+++ b/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Drupal\Tests\block\Functional;
+
+use Drupal\block\Entity\Block;
+use Drupal\Component\Render\FormattableMarkup;
+
+/**
+ * Provides test assertions for testing block appearance.
+ *
+ * Can be used by test classes that extend \Drupal\Tests\BrowserTestBase.
+ */
+trait AssertBlockAppearsTrait {
+
+ /**
+ * Checks to see whether a block appears on the page.
+ *
+ * @param \Drupal\block\Entity\Block $block
+ * The block entity to find on the page.
+ */
+ protected function assertBlockAppears(Block $block) {
+ $result = $this->findBlockInstance($block);
+ $this->assertTrue(!empty($result), new FormattableMarkup('Ensure the block @id appears on the page', ['@id' => $block->id()]));
+ }
+
+ /**
+ * Checks to see whether a block does not appears on the page.
+ *
+ * @param \Drupal\block\Entity\Block $block
+ * The block entity to find on the page.
+ */
+ protected function assertNoBlockAppears(Block $block) {
+ $result = $this->findBlockInstance($block);
+ $this->assertFalse(!empty($result), new FormattableMarkup('Ensure the block @id does not appear on the page', ['@id' => $block->id()]));
+ }
+
+ /**
+ * Find a block instance on the page.
+ *
+ * @param \Drupal\block\Entity\Block $block
+ * The block entity to find on the page.
+ *
+ * @return array
+ * The result from the xpath query.
+ */
+ protected function findBlockInstance(Block $block) {
+ return $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]);
+ }
+
+}
diff --git a/core/modules/block/src/Tests/BlockAdminThemeTest.php b/core/modules/block/tests/src/Functional/BlockAdminThemeTest.php
index 8773f03..88f35e4 100644
--- a/core/modules/block/src/Tests/BlockAdminThemeTest.php
+++ b/core/modules/block/tests/src/Functional/BlockAdminThemeTest.php
@@ -1,15 +1,15 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Tests the block system with admin themes.
*
* @group block
*/
-class BlockAdminThemeTest extends WebTestBase {
+class BlockAdminThemeTest extends BrowserTestBase {
/**
* Modules to install.
diff --git a/core/modules/block/src/Tests/BlockFormInBlockTest.php b/core/modules/block/tests/src/Functional/BlockFormInBlockTest.php
index ebe43c8..3b46aee 100644
--- a/core/modules/block/src/Tests/BlockFormInBlockTest.php
+++ b/core/modules/block/tests/src/Functional/BlockFormInBlockTest.php
@@ -1,9 +1,9 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
use Drupal\Component\Utility\Crypt;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
@@ -11,7 +11,7 @@ use Drupal\simpletest\WebTestBase;
*
* @group block
*/
-class BlockFormInBlockTest extends WebTestBase {
+class BlockFormInBlockTest extends BrowserTestBase {
/**
* Modules to install.
diff --git a/core/modules/block/src/Tests/BlockInstallTest.php b/core/modules/block/tests/src/Functional/BlockInstallTest.php
index 55f4b8a..c6fd1eb 100644
--- a/core/modules/block/src/Tests/BlockInstallTest.php
+++ b/core/modules/block/tests/src/Functional/BlockInstallTest.php
@@ -1,15 +1,15 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Tests block module's installation.
*
* @group block
*/
-class BlockInstallTest extends WebTestBase {
+class BlockInstallTest extends BrowserTestBase {
public function testCacheTagInvalidationUponInstallation() {
// Warm the page cache.
diff --git a/core/modules/block/src/Tests/BlockLanguageCacheTest.php b/core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php
index 269536d..b9c7c90 100644
--- a/core/modules/block/src/Tests/BlockLanguageCacheTest.php
+++ b/core/modules/block/tests/src/Functional/BlockLanguageCacheTest.php
@@ -1,17 +1,17 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\language\Entity\ConfigurableLanguage;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Tests display of menu blocks with multiple languages.
*
* @group block
*/
-class BlockLanguageCacheTest extends WebTestBase {
+class BlockLanguageCacheTest extends BrowserTestBase {
/**
* Modules to install.
@@ -57,7 +57,7 @@ class BlockLanguageCacheTest extends WebTestBase {
// Create the block cache for all languages.
foreach ($this->langcodes as $langcode) {
$this->drupalGet('admin/structure/block', ['language' => $langcode]);
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
}
// Create a menu in the default language.
@@ -69,7 +69,7 @@ class BlockLanguageCacheTest extends WebTestBase {
// Check that the block is listed for all languages.
foreach ($this->langcodes as $langcode) {
$this->drupalGet('admin/structure/block', ['language' => $langcode]);
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$this->assertText($edit['label']);
}
}
diff --git a/core/modules/block/src/Tests/BlockRenderOrderTest.php b/core/modules/block/tests/src/Functional/BlockRenderOrderTest.php
index a7e26de..2fd1ab8 100644
--- a/core/modules/block/src/Tests/BlockRenderOrderTest.php
+++ b/core/modules/block/tests/src/Functional/BlockRenderOrderTest.php
@@ -1,16 +1,16 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
use Drupal\Component\Utility\Html;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Tests blocks are being rendered in order by weight.
*
* @group block
*/
-class BlockRenderOrderTest extends WebTestBase {
+class BlockRenderOrderTest extends BrowserTestBase {
/**
* Modules to install.
diff --git a/core/modules/block/src/Tests/BlockSystemBrandingTest.php b/core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php
index b5025e8..89ce0c4 100644
--- a/core/modules/block/src/Tests/BlockSystemBrandingTest.php
+++ b/core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
/**
* Tests branding block display.
@@ -54,7 +54,7 @@ class BlockSystemBrandingTest extends BlockTestBase {
->save();
$this->drupalGet('');
$site_slogan_element = $this->xpath($site_slogan_xpath);
- $this->assertEqual($site_slogan_element[0], 'alert("Community carpentry");', 'The site slogan was XSS-filtered.');
+ $this->assertEqual($site_slogan_element[0]->getText(), 'alert("Community carpentry");', 'The site slogan was XSS-filtered.');
// Turn just the logo off.
$this->config('block.block.site-branding')
diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/tests/src/Functional/BlockTest.php
index 4b9deb4..3002052 100644
--- a/core/modules/block/src/Tests/BlockTest.php
+++ b/core/modules/block/tests/src/Functional/BlockTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
use Drupal\Component\Utility\Html;
use Drupal\block\Entity\Block;
@@ -150,9 +150,9 @@ class BlockTest extends BlockTestBase {
]);
$links = $this->xpath('//a[contains(@href, :href)]', [':href' => $add_url->toString()]);
$this->assertEqual(1, count($links), 'Found one matching link.');
- $this->assertEqual(t('Place block'), (string) $links[0], 'Found the expected link text.');
+ $this->assertEqual(t('Place block'), $links[0]->getText(), 'Found the expected link text.');
- list($path, $query_string) = explode('?', $links[0]['href'], 2);
+ list($path, $query_string) = explode('?', $links[0]->getAttribute('href'), 2);
parse_str($query_string, $query_parts);
$this->assertEqual($weight, $query_parts['weight'], 'Found the expected weight query string.');
@@ -164,7 +164,7 @@ class BlockTest extends BlockTestBase {
'settings[label]' => $title,
];
// Create the block using the link parsed from the library page.
- $this->drupalPostForm($this->getAbsoluteUrl($links[0]['href']), $edit, t('Save block'));
+ $this->drupalPostForm($this->getAbsoluteUrl($links[0]->getAttribute('href')), $edit, t('Save block'));
// Ensure that the block was created with the expected weight.
/** @var \Drupal\block\BlockInterface $block */
diff --git a/core/modules/block/tests/src/Functional/BlockTestBase.php b/core/modules/block/tests/src/Functional/BlockTestBase.php
new file mode 100644
index 0000000..e1ccd1a
--- /dev/null
+++ b/core/modules/block/tests/src/Functional/BlockTestBase.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Drupal\Tests\block\Functional;
+
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Provides setup and helper methods for block module tests.
+ */
+abstract class BlockTestBase extends BrowserTestBase {
+
+ /**
+ * Modules to install.
+ *
+ * @var array
+ */
+ public static $modules = ['block', 'filter', 'test_page_test', 'help', 'block_test'];
+
+ /**
+ * A list of theme regions to test.
+ *
+ * @var array
+ */
+ protected $regions;
+
+ /**
+ * A test user with administrative privileges.
+ *
+ * @var \Drupal\user\UserInterface
+ */
+ protected $adminUser;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ // Use the test page as the front page.
+ $this->config('system.site')->set('page.front', '/test-page')->save();
+
+ // Create Full HTML text format.
+ $full_html_format = FilterFormat::create([
+ 'format' => 'full_html',
+ 'name' => 'Full HTML',
+ ]);
+ $full_html_format->save();
+
+ // Create and log in an administrative user having access to the Full HTML
+ // text format.
+ $this->adminUser = $this->drupalCreateUser([
+ 'administer blocks',
+ $full_html_format->getPermissionName(),
+ 'access administration pages',
+ ]);
+ $this->drupalLogin($this->adminUser);
+
+ // Define the existing regions.
+ $this->regions = [
+ 'header',
+ 'sidebar_first',
+ 'content',
+ 'sidebar_second',
+ 'footer',
+ ];
+ $block_storage = $this->container->get('entity_type.manager')->getStorage('block');
+ $blocks = $block_storage->loadByProperties(['theme' => $this->config('system.theme')->get('default')]);
+ foreach ($blocks as $block) {
+ $block->delete();
+ }
+ }
+
+}
diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/tests/src/Functional/BlockUiTest.php
index d4ebda4..e6c1875 100644
--- a/core/modules/block/src/Tests/BlockUiTest.php
+++ b/core/modules/block/tests/src/Functional/BlockUiTest.php
@@ -1,16 +1,16 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
use Drupal\Component\Utility\Html;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Tests that the block configuration UI exists and stores data correctly.
*
* @group block
*/
-class BlockUiTest extends WebTestBase {
+class BlockUiTest extends BrowserTestBase {
/**
* Modules to install.
@@ -105,7 +105,7 @@ class BlockUiTest extends WebTestBase {
$block = $this->blocks[$delta];
$label = $block->label();
$element = $this->xpath('//*[@id="blocks"]/tbody/tr[' . $values['tr'] . ']/td[1]/text()');
- $this->assertTrue((string) $element[0] == $label, 'The "' . $label . '" block title is set inside the ' . $values['settings']['region'] . ' region.');
+ $this->assertEquals($element[0]->getText(), $label, 'The "' . $label . '" block title is set inside the ' . $values['settings']['region'] . ' region.');
// Look for a test block region select form element.
$this->assertField('blocks[' . $values['settings']['id'] . '][region]', 'The block "' . $values['label'] . '" has a region assignment field.');
// Move the test block to the header region.
@@ -171,7 +171,7 @@ class BlockUiTest extends WebTestBase {
$pattern = '//tr[.//td/div[text()=:title] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]';
$this->drupalGet('admin/structure/block');
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue(!empty($elements), 'The test block appears in the category for its module.');
@@ -180,7 +180,7 @@ class BlockUiTest extends WebTestBase {
$this->container->get('plugin.manager.block')->clearCachedDefinitions();
$this->drupalGet('admin/structure/block');
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$arguments[':category'] = 'Custom category';
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue(!empty($elements), 'The test block appears in a custom category controlled by block_test_block_alter().');
@@ -197,7 +197,7 @@ class BlockUiTest extends WebTestBase {
];
$this->drupalGet('admin/structure/block');
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$elements = $this->xpath('//tr[.//td/div[text()=:text] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]', $arguments);
$this->assertTrue(empty($elements), 'The context-aware test block does not appear.');
@@ -223,7 +223,7 @@ class BlockUiTest extends WebTestBase {
$pattern = '//tr[.//td/div[text()=:title] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]';
$this->drupalGet('admin/structure/block');
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue(!empty($elements), 'The context-aware test block appears.');
$definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware');
diff --git a/core/modules/block/src/Tests/BlockXssTest.php b/core/modules/block/tests/src/Functional/BlockXssTest.php
index b37f4cd..3e661d7 100644
--- a/core/modules/block/src/Tests/BlockXssTest.php
+++ b/core/modules/block/tests/src/Functional/BlockXssTest.php
@@ -1,12 +1,12 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Core\Url;
-use Drupal\simpletest\WebTestBase;
use Drupal\system\Entity\Menu;
+use Drupal\Tests\BrowserTestBase;
use Drupal\views\Entity\View;
/**
@@ -14,7 +14,7 @@ use Drupal\views\Entity\View;
*
* @group block
*/
-class BlockXssTest extends WebTestBase {
+class BlockXssTest extends BrowserTestBase {
/**
* Modules to install.
@@ -29,7 +29,7 @@ class BlockXssTest extends WebTestBase {
public function testNoUnexpectedEscaping() {
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'access administration pages']));
$this->drupalGet(Url::fromRoute('block.admin_display'));
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$this->assertNoEscaped('<');
}
@@ -58,7 +58,7 @@ class BlockXssTest extends WebTestBase {
$this->drupalPlaceBlock('test_xss_title');
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'access administration pages']));
$this->drupalGet(Url::fromRoute('block.admin_display'));
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$this->assertNoRaw("<script>alert('XSS category');</script>");
}
@@ -73,7 +73,7 @@ class BlockXssTest extends WebTestBase {
$this->doBlockContentTest();
$this->drupalGet(Url::fromRoute('block.admin_display'));
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$this->assertNoRaw('&amp;lt;', 'The page does not have double escaped HTML tags.');
}
@@ -101,7 +101,7 @@ class BlockXssTest extends WebTestBase {
$view->save();
$this->drupalGet(Url::fromRoute('block.admin_display'));
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
// \Drupal\views\Plugin\Derivative\ViewsBlock::getDerivativeDefinitions()
// has a different code path for an admin label based only on the View
@@ -137,7 +137,7 @@ class BlockXssTest extends WebTestBase {
])->save();
$this->drupalGet(Url::fromRoute('block.admin_display'));
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$this->assertEscaped('<script>alert("menu");</script>');
$this->assertNoRaw('<script>alert("menu");</script>');
@@ -158,7 +158,7 @@ class BlockXssTest extends WebTestBase {
])->save();
$this->drupalGet(Url::fromRoute('block.admin_display'));
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$this->assertEscaped('<script>alert("block_content");</script>');
$this->assertNoRaw('<script>alert("block_content");</script>');
diff --git a/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php b/core/modules/block/tests/src/Functional/NonDefaultBlockAdminTest.php
index fc2f33c..7b7927d 100644
--- a/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php
+++ b/core/modules/block/tests/src/Functional/NonDefaultBlockAdminTest.php
@@ -1,15 +1,15 @@
<?php
-namespace Drupal\block\Tests;
+namespace Drupal\Tests\block\Functional;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Tests the block administration page for a non-default theme.
*
* @group block
*/
-class NonDefaultBlockAdminTest extends WebTestBase {
+class NonDefaultBlockAdminTest extends BrowserTestBase {
/**
* Modules to install.
diff --git a/core/modules/block/src/Tests/Views/DisplayBlockTest.php b/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php
index 3d35845..d122099 100644
--- a/core/modules/block/src/Tests/Views/DisplayBlockTest.php
+++ b/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php
@@ -1,13 +1,14 @@
<?php
-namespace Drupal\block\Tests\Views;
+namespace Drupal\Tests\block\Functional\Views;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Url;
-use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
+use Drupal\Tests\block\Functional\AssertBlockAppearsTrait;
+use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
+use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Entity\View;
use Drupal\views\Views;
-use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\Core\Template\Attribute;
@@ -15,11 +16,12 @@ use Drupal\Core\Template\Attribute;
* Tests the block display plugin.
*
* @group block
- * @see \Drupal\block\Plugin\views\display\Block
+ * @see \Drupal\views\Plugin\views\display\Block
*/
class DisplayBlockTest extends ViewTestBase {
use AssertPageCacheContextsAndTagsTrait;
+ use AssertBlockAppearsTrait;
/**
* Modules to install.
@@ -35,8 +37,11 @@ class DisplayBlockTest extends ViewTestBase {
*/
public static $testViews = ['test_view_block', 'test_view_block2'];
- protected function setUp() {
- parent::setUp();
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp($import_test_views = TRUE) {
+ parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['block_test_views']);
$this->enableViewsTestModule();
@@ -67,10 +72,10 @@ class DisplayBlockTest extends ViewTestBase {
'plugin_id' => 'views_block:' . $edit['id'] . '-block_1',
'theme' => 'classy',
]),
- ':category' => t('Lists (Views)'),
+ ':category' => 'Lists (Views)',
];
$this->drupalGet('admin/structure/block');
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue(!empty($elements), 'The test block appears in the category for its base table.');
@@ -95,7 +100,7 @@ class DisplayBlockTest extends ViewTestBase {
// Test that the blocks are listed under the correct categories.
$arguments[':category'] = $category;
$this->drupalGet('admin/structure/block');
- $this->clickLinkPartialName('Place block');
+ $this->clickLink('Place block');
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue(!empty($elements), 'The test block appears in the custom category.');
@@ -104,7 +109,7 @@ class DisplayBlockTest extends ViewTestBase {
'plugin_id' => 'views_block:' . $edit['id'] . '-block_2',
'theme' => 'classy',
]),
- ':category' => t('Lists (Views)'),
+ ':category' => 'Lists (Views)',
];
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.');
@@ -243,7 +248,7 @@ class DisplayBlockTest extends ViewTestBase {
$this->drupalGet('');
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2');
- $this->assertEqual((string) $result[0], 'Custom title');
+ $this->assertEqual($result[0]->getText(), 'Custom title');
// Don't override the title anymore.
$plugin = $block->getPlugin();
@@ -252,7 +257,7 @@ class DisplayBlockTest extends ViewTestBase {
$this->drupalGet('');
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2');
- $this->assertEqual((string) $result[0], 'test_view_block');
+ $this->assertEqual($result[0]->getText(), 'test_view_block');
// Hide the title.
$block->getPlugin()->setConfigurationValue('label_display', FALSE);
@@ -363,9 +368,10 @@ class DisplayBlockTest extends ViewTestBase {
// Get server-rendered contextual links.
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
$post = ['ids[0]' => $id, 'ids[1]' => $cached_id];
- $response = $this->drupalPostWithFormat('contextual/render', 'json', $post, ['query' => ['destination' => 'test-page']]);
+ $url = 'contextual/render?_format=json,destination=test-page';
+ $this->getSession()->getDriver()->getClient()->request('POST', $url, $post);
$this->assertResponse(200);
- $json = Json::decode($response);
+ $json = Json::decode($this->getSession()->getPage()->getContent());
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
$this->assertIdentical($json[$cached_id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
}
diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php
index 8850717..b3844d1 100644
--- a/core/modules/simpletest/src/TestDiscovery.php
+++ b/core/modules/simpletest/src/TestDiscovery.php
@@ -144,8 +144,8 @@ class TestDiscovery {
* An array of tests keyed by the the group name.
* @code
* $groups['block'] => array(
- * 'Drupal\block\Tests\BlockTest' => array(
- * 'name' => 'Drupal\block\Tests\BlockTest',
+ * 'Drupal\Tests\block\Functional\BlockTest' => array(
+ * 'name' => 'Drupal\Tests\block\Functional\BlockTest',
* 'description' => 'Tests block UI CRUD functionality.',
* 'group' => 'block',
* ),