Commit 6b6ddee8 authored by catch's avatar catch

Issue #2863267 by Lendude, Jo Fitzgerald, michielnugter, dawehner, klausi:...

Issue #2863267 by Lendude, Jo Fitzgerald, michielnugter, dawehner, klausi: Convert web tests of views
parent 477fbfd2
<?php <?php
namespace Drupal\views\Tests\Handler; namespace Drupal\views\Tests\Handler;
@trigger_error('\Drupal\views\Tests\Handler\HandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestBase;
/** /**
* @todo. * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\views\Functional\ViewTestBase.
*/ */
abstract class HandlerTestBase extends ViewTestBase { abstract class HandlerTestBase extends ViewTestBase {
......
<?php <?php
namespace Drupal\views\Tests\Plugin; namespace Drupal\views\Tests\Plugin;
@trigger_error('\Drupal\views\Tests\Plugin\PluginTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestBase;
/** /**
* @todo. * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\views\Functional\ViewTestBase.
*/ */
abstract class PluginTestBase extends ViewTestBase { abstract class PluginTestBase extends ViewTestBase {
......
<?php <?php
namespace Drupal\views\Tests; namespace Drupal\views\Tests;
@trigger_error('\Drupal\views\Tests\ViewTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);
use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\SelectInterface;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
...@@ -13,6 +14,9 @@ ...@@ -13,6 +14,9 @@
* When possible, ViewsKernelTestBase should be used instead. Both base classes * When possible, ViewsKernelTestBase should be used instead. Both base classes
* include the same methods. * include the same methods.
* *
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\views\Functional\ViewTestBase.
*
* @see \Drupal\Tests\views\Kernel\ViewsKernelTestBase * @see \Drupal\Tests\views\Kernel\ViewsKernelTestBase
* @see \Drupal\simpletest\WebTestBase * @see \Drupal\simpletest\WebTestBase
*/ */
......
<?php <?php
namespace Drupal\views\Tests\Wizard; namespace Drupal\views\Tests\Wizard;
@trigger_error('\Drupal\views\Tests\Wizard\WizardTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\Wizard\WizardTestBase', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestBase;
/** /**
* Views UI wizard tests. * Views UI wizard tests.
*
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\views\Functional\Wizard\WizardTestBase.
*/ */
abstract class WizardTestBase extends ViewTestBase { abstract class WizardTestBase extends ViewTestBase {
......
<?php <?php
namespace Drupal\views\Tests; namespace Drupal\Tests\views\Functional;
use Drupal\comment\CommentInterface; use Drupal\comment\CommentInterface;
use Drupal\comment\Tests\CommentTestTrait; use Drupal\comment\Tests\CommentTestTrait;
...@@ -42,8 +42,8 @@ class DefaultViewsTest extends ViewTestBase { ...@@ -42,8 +42,8 @@ class DefaultViewsTest extends ViewTestBase {
'glossary' => ['all'], 'glossary' => ['all'],
]; ];
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
$this->drupalPlaceBlock('page_title_block'); $this->drupalPlaceBlock('page_title_block');
......
<?php <?php
namespace Drupal\views\Tests\Entity; namespace Drupal\Tests\views\Functional\Entity;
use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTest;
use Drupal\views\Tests\ViewTestBase; use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
/** /**
...@@ -32,8 +32,8 @@ class BaseFieldAccessTest extends ViewTestBase { ...@@ -32,8 +32,8 @@ class BaseFieldAccessTest extends ViewTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
/** @var \Drupal\Core\Entity\EntityDefinitionUpdateManager $update_manager */ /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManager $update_manager */
$update_manager = $this->container->get('entity.definition_update_manager'); $update_manager = $this->container->get('entity.definition_update_manager');
\Drupal::entityManager()->clearCachedDefinitions(); \Drupal::entityManager()->clearCachedDefinitions();
......
<?php <?php
namespace Drupal\views\Tests\Entity; namespace Drupal\Tests\views\Functional\Entity;
use Drupal\comment\Tests\CommentTestTrait; use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\views\Tests\ViewTestBase; use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\Comment;
......
<?php <?php
namespace Drupal\views\Tests\Entity; namespace Drupal\Tests\views\Functional\Entity;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType; use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestBase; use Drupal\Tests\views\Functional\ViewTestBase;
use Symfony\Component\CssSelector\CssSelectorConverter; use Symfony\Component\CssSelector\CssSelectorConverter;
/** /**
...@@ -164,8 +164,8 @@ protected function assertRows($expected = []) { ...@@ -164,8 +164,8 @@ protected function assertRows($expected = []) {
$rows = $this->cssSelect('div.views-row'); $rows = $this->cssSelect('div.views-row');
foreach ($rows as $row) { foreach ($rows as $row) {
$actual[] = [ $actual[] = [
'title' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))[0], 'title' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))->getText(),
'sticky' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))[0], 'sticky' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))->getText(),
]; ];
} }
$this->assertEqual($actual, $expected); $this->assertEqual($actual, $expected);
......
<?php <?php
namespace Drupal\views\Tests\Entity; namespace Drupal\Tests\views\Functional\Entity;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\views\Tests\ViewTestBase; use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views; use Drupal\views\Views;
...@@ -42,7 +42,7 @@ class FilterEntityBundleTest extends ViewTestBase { ...@@ -42,7 +42,7 @@ class FilterEntityBundleTest extends ViewTestBase {
*/ */
protected $entities = []; protected $entities = [];
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(FALSE); parent::setUp(FALSE);
$this->drupalCreateContentType(['type' => 'test_bundle']); $this->drupalCreateContentType(['type' => 'test_bundle']);
......
<?php <?php
namespace Drupal\views\Tests\Entity; namespace Drupal\Tests\views\Functional\Entity;
use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language_test\Entity\NoLanguageEntityTest; use Drupal\language_test\Entity\NoLanguageEntityTest;
use Drupal\simpletest\WebTestBase; use Drupal\Tests\BrowserTestBase;
/** /**
* Tests the view creation of non-translatable entities. * Tests the view creation of non-translatable entities.
* *
* @group views * @group views
*/ */
class ViewNonTranslatableEntityTest extends WebTestBase { class ViewNonTranslatableEntityTest extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.
......
<?php <?php
namespace Drupal\views\Tests; namespace Drupal\Tests\views\Functional;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\views\Tests\AssertViewsCacheTagsTrait;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -97,8 +98,8 @@ public function testGlossaryView() { ...@@ -97,8 +98,8 @@ public function testGlossaryView() {
'user_list', 'user_list',
'http_response', 'http_response',
'rendered', 'rendered',
// FinishResponseSubscriber adds this cache tag to responses that have the // FinishResponseSubscriber adds this cache tag to responses that have
// 'user.permissions' cache context for anonymous users. // the 'user.permissions' cache context for anonymous users.
'config:user.role.anonymous', 'config:user.role.anonymous',
] ]
); );
...@@ -113,8 +114,9 @@ public function testGlossaryView() { ...@@ -113,8 +114,9 @@ public function testGlossaryView() {
// to ensure that both of them are correct. // to ensure that both of them are correct.
$result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', [':href' => $href, ':label' => $label]); $result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', [':href' => $href, ':label' => $label]);
$this->assertTrue(count($result)); $this->assertTrue(count($result));
// The rendered output looks like "| (count)" so let's figure out the int. // The rendered output looks like "<a href=''>X</a> | (count)" so let's
$result_count = trim(str_replace(['|', '(', ')'], '', (string) $result[0])); // figure out the int.
$result_count = explode(' ', trim(str_replace(['|', '(', ')'], '', $result[0]->getText())))[1];
$this->assertEqual($result_count, $count, 'The expected number got rendered.'); $this->assertEqual($result_count, $count, 'The expected number got rendered.');
} }
} }
......
<?php <?php
namespace Drupal\views\Tests\Handler; namespace Drupal\Tests\views\Functional\Handler;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -10,7 +11,7 @@ ...@@ -10,7 +11,7 @@
* @group views * @group views
* @see \Drupal\views\Plugin\views\area\HTTPStatusCode * @see \Drupal\views\Plugin\views\area\HTTPStatusCode
*/ */
class AreaHTTPStatusCodeTest extends HandlerTestBase { class AreaHTTPStatusCodeTest extends ViewTestBase {
/** /**
* Views used by this test. * Views used by this test.
......
<?php <?php
namespace Drupal\views\Tests\Handler; namespace Drupal\Tests\views\Functional\Handler;
use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -12,7 +13,7 @@ ...@@ -12,7 +13,7 @@
* @see \Drupal\views\Plugin\views\area\AreaPluginBase * @see \Drupal\views\Plugin\views\area\AreaPluginBase
* @see \Drupal\views_test\Plugin\views\area\TestExample * @see \Drupal\views_test\Plugin\views\area\TestExample
*/ */
class AreaTest extends HandlerTestBase { class AreaTest extends ViewTestBase {
/** /**
* Views used by this test. * Views used by this test.
...@@ -28,8 +29,8 @@ class AreaTest extends HandlerTestBase { ...@@ -28,8 +29,8 @@ class AreaTest extends HandlerTestBase {
*/ */
public static $modules = ['node', 'views_ui']; public static $modules = ['node', 'views_ui'];
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
$this->enableViewsTestModule(); $this->enableViewsTestModule();
} }
...@@ -110,41 +111,6 @@ public function testRenderArea() { ...@@ -110,41 +111,6 @@ public function testRenderArea() {
$this->assertTrue(strpos($output, '<script') === FALSE, 'Script tags were escaped'); $this->assertTrue(strpos($output, '<script') === FALSE, 'Script tags were escaped');
} }
/**
* Tests that the header and footer areas are not rendered if empty.
*/
public function testRenderEmptyHeaderFooter() {
$view = Views::getView('test_example_area');
$view->initHandlers();
// Set example empty text.
$view->empty['test_example']->options['string'] = '<p>' . $this->randomMachineName() . '</p>';
$xpath = '//div[contains(@class, :class)]';
// Verify that the empty header and footer sections have not been rendered.
$output = $view->preview();
$html = $this->container->get('renderer')->renderRoot($output);
$this->setRawContent($html);
$this->assertEqual(0, count($this->xpath($xpath, [':class' => 'view-header'])));
$this->assertEqual(0, count($this->xpath($xpath, [':class' => 'view-footer'])));
// Set example header text.
$view->header['test_example']->options['string'] = '<p>' . $this->randomMachineName() . '</p>';
$view->header['test_example']->options['empty'] = TRUE;
// Set example footer text.
$view->footer['test_example']->options['string'] = '<p>' . $this->randomMachineName() . '</p>';
$view->footer['test_example']->options['empty'] = TRUE;
// Verify that the header and footer sections have been rendered.
$output = $view->preview();
$html = $this->container->get('renderer')->renderRoot($output);
$this->setRawContent($html);
$this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-header'])));
$this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-footer'])));
}
/** /**
* Tests the access for an area. * Tests the access for an area.
*/ */
......
<?php <?php
namespace Drupal\views\Tests\Handler; namespace Drupal\Tests\views\Functional\Handler;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Entity\View; use Drupal\views\Entity\View;
use Drupal\views\Tests\ViewTestBase;
/** /**
* Tests the title area handler with a web test. * Tests the title area handler with a web test.
...@@ -23,8 +23,8 @@ class AreaTitleWebTest extends ViewTestBase { ...@@ -23,8 +23,8 @@ class AreaTitleWebTest extends ViewTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
$this->enableViewsTestModule(); $this->enableViewsTestModule();
} }
......
<?php <?php
namespace Drupal\views\Tests\Handler; namespace Drupal\Tests\views\Functional\Handler;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -9,7 +10,7 @@ ...@@ -9,7 +10,7 @@
* *
* @group views * @group views
*/ */
class ArgumentStringTest extends HandlerTestBase { class ArgumentStringTest extends ViewTestBase {
/** /**
* Views used by this test. * Views used by this test.
......
<?php <?php
namespace Drupal\views\Tests\Handler; namespace Drupal\Tests\views\Functional\Handler;
use Drupal\Tests\views\Functional\ViewTestBase;
/** /**
* Tests the dropbutton field handler. * Tests the dropbutton field handler.
...@@ -8,7 +10,7 @@ ...@@ -8,7 +10,7 @@
* @group views * @group views
* @see \Drupal\system\Plugin\views\field\Dropbutton * @see \Drupal\system\Plugin\views\field\Dropbutton
*/ */
class FieldDropButtonTest extends HandlerTestBase { class FieldDropButtonTest extends ViewTestBase {
/** /**
* Views used by this test. * Views used by this test.
...@@ -27,8 +29,8 @@ class FieldDropButtonTest extends HandlerTestBase { ...@@ -27,8 +29,8 @@ class FieldDropButtonTest extends HandlerTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
$admin_user = $this->drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']); $admin_user = $this->drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']);
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
...@@ -48,7 +50,7 @@ public function testDropbutton() { ...@@ -48,7 +50,7 @@ public function testDropbutton() {
foreach ($nodes as $node) { foreach ($nodes as $node) {
$result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => $node->label()]); $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => $node->label()]);
$this->assertEqual(count($result), 1, 'Just one node title link was found.'); $this->assertEqual(count($result), 1, 'Just one node title link was found.');
$result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => t('Custom Text')]); $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => 'Custom Text']);
$this->assertEqual(count($result), 1, 'Just one custom link was found.'); $this->assertEqual(count($result), 1, 'Just one custom link was found.');
} }
......
<?php <?php
namespace Drupal\views\Tests\Handler; namespace Drupal\Tests\views\Functional\Handler;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\Tests\views\Functional\ViewTestBase;
/** /**
* Tests the core Drupal\views\Plugin\views\field\EntityOperations handler. * Tests the core Drupal\views\Plugin\views\field\EntityOperations handler.
* *
* @group views * @group views
*/ */
class FieldEntityOperationsTest extends HandlerTestBase { class FieldEntityOperationsTest extends ViewTestBase {