Core and composer updates
This commit is contained in:
parent
a82634bb98
commit
62cac30480
1118 changed files with 21770 additions and 6306 deletions
|
@ -83,9 +83,13 @@ class Result extends AreaPluginBase {
|
|||
// Not every view has total_rows set, use view->result instead.
|
||||
$total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
|
||||
$label = Html::escape($this->view->storage->label());
|
||||
// If there is no result the "start" and "current_record_count" should be
|
||||
// equal to 0. To have the same calculation logic, we use a "start offset"
|
||||
// to handle all the cases.
|
||||
$start_offset = empty($total) ? 0 : 1;
|
||||
if ($per_page === 0) {
|
||||
$page_count = 1;
|
||||
$start = 1;
|
||||
$start = $start_offset;
|
||||
$end = $total;
|
||||
}
|
||||
else {
|
||||
|
@ -94,10 +98,10 @@ class Result extends AreaPluginBase {
|
|||
if ($total_count > $total) {
|
||||
$total_count = $total;
|
||||
}
|
||||
$start = ($current_page - 1) * $per_page + 1;
|
||||
$start = ($current_page - 1) * $per_page + $start_offset;
|
||||
$end = $total_count;
|
||||
}
|
||||
$current_record_count = ($end - $start) + 1;
|
||||
$current_record_count = ($end - $start) + $start_offset;
|
||||
// Get the search information.
|
||||
$replacements = [];
|
||||
$replacements['@start'] = $start;
|
||||
|
@ -109,7 +113,7 @@ class Result extends AreaPluginBase {
|
|||
$replacements['@current_record_count'] = $current_record_count;
|
||||
$replacements['@page_count'] = $page_count;
|
||||
// Send the output.
|
||||
if (!empty($total)) {
|
||||
if (!empty($total) || !empty($this->options['empty'])) {
|
||||
$output .= Xss::filterAdmin(str_replace(array_keys($replacements), array_values($replacements), $format));
|
||||
}
|
||||
// Return as render array.
|
||||
|
|
|
@ -149,24 +149,32 @@ class NumericField extends FieldPluginBase {
|
|||
*/
|
||||
public function render(ResultRow $values) {
|
||||
$value = $this->getValue($values);
|
||||
if (!empty($this->options['set_precision'])) {
|
||||
$value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
|
||||
}
|
||||
else {
|
||||
$remainder = abs($value) - intval(abs($value));
|
||||
$value = $value > 0 ? floor($value) : ceil($value);
|
||||
$value = number_format($value, 0, '', $this->options['separator']);
|
||||
if ($remainder) {
|
||||
// The substr may not be locale safe.
|
||||
$value .= $this->options['decimal'] . substr($remainder, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if hiding should happen before adding prefix and suffix.
|
||||
// Check to see if hiding should happen before adding prefix and suffix
|
||||
// and before rewriting.
|
||||
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!empty($this->options['set_precision'])) {
|
||||
$precision = $this->options['precision'];
|
||||
}
|
||||
elseif ($decimal_position = strpos($value, '.')) {
|
||||
$precision = strlen($value) - $decimal_position - 1;
|
||||
}
|
||||
else {
|
||||
$precision = 0;
|
||||
}
|
||||
|
||||
// Use round first to avoid negative zeros.
|
||||
$value = round($value, $precision);
|
||||
// Test against both integer zero and float zero.
|
||||
if ($this->options['empty_zero'] && ($value === 0 || $value === 0.0)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$value = number_format($value, $precision, $this->options['decimal'], $this->options['separator']);
|
||||
|
||||
// If we should format as plural, take the (possibly) translated plural
|
||||
// setting and format with the current language.
|
||||
if (!empty($this->options['format_plural'])) {
|
||||
|
|
|
@ -482,8 +482,8 @@ abstract class StylePluginBase extends PluginBase {
|
|||
* - level: The hierarchical level of the grouping.
|
||||
* - rows: The result rows to be rendered in this group..
|
||||
*
|
||||
* @return string
|
||||
* Rendered output of given grouping sets.
|
||||
* @return array
|
||||
* Render array of grouping sets.
|
||||
*/
|
||||
public function renderGroupingSets($sets) {
|
||||
$output = [];
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
|
|
@ -149,4 +149,24 @@ class DisplayFeedTest extends PluginTestBase {
|
|||
$this->assertResponse(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the feed display works when the linked display is disabled.
|
||||
*/
|
||||
public function testDisabledLinkedDisplay() {
|
||||
$view = Views::getView('test_attached_disabled');
|
||||
$view->setDisplay();
|
||||
// Disable the page and link the feed to the page.
|
||||
$view->displayHandlers->get('feed_1')->setOption('link_display', 'page_1');
|
||||
$view->displayHandlers->get('page_1')->setOption('enabled', FALSE);
|
||||
$view->save();
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
$this->drupalGet('test-attached-disabled');
|
||||
$this->assertResponse(404);
|
||||
// Ensure the feed can still be reached.
|
||||
$this->drupalGet('test-attached-disabled.xml');
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
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\simpletest\WebTestBase;
|
||||
|
@ -13,6 +14,9 @@ use Drupal\views\ViewExecutable;
|
|||
* When possible, ViewsKernelTestBase should be used instead. Both base classes
|
||||
* 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\simpletest\WebTestBase
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: test_area_result
|
||||
label: ''
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: views_test_data
|
||||
base_field: nid
|
||||
core: '8'
|
||||
display:
|
||||
default:
|
||||
display_options:
|
||||
defaults:
|
||||
fields: false
|
||||
pager: false
|
||||
sorts: false
|
||||
fields:
|
||||
id:
|
||||
field: id
|
||||
id: id
|
||||
relationship: none
|
||||
table: views_test_data
|
||||
plugin_id: numeric
|
||||
pager:
|
||||
options:
|
||||
offset: 0
|
||||
type: none
|
||||
sorts:
|
||||
id:
|
||||
field: id
|
||||
id: id
|
||||
order: ASC
|
||||
relationship: none
|
||||
table: views_test_data
|
||||
plugin_id: numeric
|
||||
empty:
|
||||
title:
|
||||
field: title
|
||||
id: title
|
||||
table: views
|
||||
plugin_id: title
|
||||
title: test_title_empty
|
||||
header:
|
||||
result:
|
||||
id: result
|
||||
table: views
|
||||
field: result
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
empty: true
|
||||
content: "start: @start | end: @end | total: @total | label: @label | per page: @per_page | current page: @current_page | current record count: @current_record_count | page count: @page_count"
|
||||
plugin_id: result
|
||||
display_plugin: default
|
||||
display_title: Master
|
||||
id: default
|
||||
position: 0
|
||||
page_1:
|
||||
display_options:
|
||||
path: test-area-result
|
||||
defaults:
|
||||
header: false
|
||||
header:
|
||||
result:
|
||||
id: result
|
||||
table: views
|
||||
field: result
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
empty: false
|
||||
content: "start: @start | end: @end | total: @total | label: @label | per page: @per_page | current page: @current_page | current record count: @current_record_count | page count: @page_count"
|
||||
plugin_id: result
|
||||
display_plugin: page
|
||||
display_title: 'Page 1'
|
||||
id: page_1
|
||||
position: 1
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
|
@ -42,8 +42,8 @@ class DefaultViewsTest extends ViewTestBase {
|
|||
'glossary' => ['all'],
|
||||
];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Entity;
|
||||
namespace Drupal\Tests\views\Functional\Entity;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
|
@ -32,8 +32,8 @@ class BaseFieldAccessTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
/** @var \Drupal\Core\Entity\EntityDefinitionUpdateManager $update_manager */
|
||||
$update_manager = $this->container->get('entity.definition_update_manager');
|
||||
\Drupal::entityManager()->clearCachedDefinitions();
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Entity;
|
||||
namespace Drupal\Tests\views\Functional\Entity;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\comment\Entity\Comment;
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Entity;
|
||||
namespace Drupal\Tests\views\Functional\Entity;
|
||||
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Symfony\Component\CssSelector\CssSelectorConverter;
|
||||
|
||||
/**
|
||||
|
@ -164,8 +164,8 @@ class FieldEntityTranslationTest extends ViewTestBase {
|
|||
$rows = $this->cssSelect('div.views-row');
|
||||
foreach ($rows as $row) {
|
||||
$actual[] = [
|
||||
'title' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))[0],
|
||||
'sticky' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))[0],
|
||||
'title' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))->getText(),
|
||||
'sticky' => $row->find('xpath', (new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))->getText(),
|
||||
];
|
||||
}
|
||||
$this->assertEqual($actual, $expected);
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Entity;
|
||||
namespace Drupal\Tests\views\Functional\Entity;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -42,7 +42,7 @@ class FilterEntityBundleTest extends ViewTestBase {
|
|||
*/
|
||||
protected $entities = [];
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp(FALSE);
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'test_bundle']);
|
|
@ -1,17 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Entity;
|
||||
namespace Drupal\Tests\views\Functional\Entity;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language_test\Entity\NoLanguageEntityTest;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the view creation of non-translatable entities.
|
||||
*
|
||||
* @group views
|
||||
*/
|
||||
class ViewNonTranslatableEntityTest extends WebTestBase {
|
||||
class ViewNonTranslatableEntityTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\Tests\AssertViewsCacheTagsTrait;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -97,8 +98,8 @@ class GlossaryTest extends ViewTestBase {
|
|||
'user_list',
|
||||
'http_response',
|
||||
'rendered',
|
||||
// FinishResponseSubscriber adds this cache tag to responses that have the
|
||||
// 'user.permissions' cache context for anonymous users.
|
||||
// FinishResponseSubscriber adds this cache tag to responses that have
|
||||
// the 'user.permissions' cache context for anonymous users.
|
||||
'config:user.role.anonymous',
|
||||
]
|
||||
);
|
||||
|
@ -113,8 +114,9 @@ class GlossaryTest extends ViewTestBase {
|
|||
// to ensure that both of them are correct.
|
||||
$result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', [':href' => $href, ':label' => $label]);
|
||||
$this->assertTrue(count($result));
|
||||
// The rendered output looks like "| (count)" so let's figure out the int.
|
||||
$result_count = trim(str_replace(['|', '(', ')'], '', (string) $result[0]));
|
||||
// The rendered output looks like "<a href=''>X</a> | (count)" so let's
|
||||
// figure out the int.
|
||||
$result_count = explode(' ', trim(str_replace(['|', '(', ')'], '', $result[0]->getText())))[1];
|
||||
$this->assertEqual($result_count, $count, 'The expected number got rendered.');
|
||||
}
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -10,7 +11,7 @@ use Drupal\views\Views;
|
|||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\area\HTTPStatusCode
|
||||
*/
|
||||
class AreaHTTPStatusCodeTest extends HandlerTestBase {
|
||||
class AreaHTTPStatusCodeTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -12,7 +13,7 @@ use Drupal\views\Views;
|
|||
* @see \Drupal\views\Plugin\views\area\AreaPluginBase
|
||||
* @see \Drupal\views_test\Plugin\views\area\TestExample
|
||||
*/
|
||||
class AreaTest extends HandlerTestBase {
|
||||
class AreaTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -28,8 +29,8 @@ class AreaTest extends HandlerTestBase {
|
|||
*/
|
||||
public static $modules = ['node', 'views_ui'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
@ -110,41 +111,6 @@ class AreaTest extends HandlerTestBase {
|
|||
$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.
|
||||
*/
|
|
@ -1,9 +1,9 @@
|
|||
<?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\Tests\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the title area handler with a web test.
|
||||
|
@ -23,8 +23,8 @@ class AreaTitleWebTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -9,7 +10,7 @@ use Drupal\views\Views;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class ArgumentStringTest extends HandlerTestBase {
|
||||
class ArgumentStringTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the dropbutton field handler.
|
||||
|
@ -8,7 +10,7 @@ namespace Drupal\views\Tests\Handler;
|
|||
* @group views
|
||||
* @see \Drupal\system\Plugin\views\field\Dropbutton
|
||||
*/
|
||||
class FieldDropButtonTest extends HandlerTestBase {
|
||||
class FieldDropButtonTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -27,8 +29,8 @@ class FieldDropButtonTest extends HandlerTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$admin_user = $this->drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
@ -48,7 +50,7 @@ class FieldDropButtonTest extends HandlerTestBase {
|
|||
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()]);
|
||||
$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.');
|
||||
}
|
||||
|
|
@ -1,17 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the core Drupal\views\Plugin\views\field\EntityOperations handler.
|
||||
*
|
||||
* @group views
|
||||
*/
|
||||
class FieldEntityOperationsTest extends HandlerTestBase {
|
||||
class FieldEntityOperationsTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -27,8 +28,8 @@ class FieldEntityOperationsTest extends HandlerTestBase {
|
|||
*/
|
||||
public static $modules = ['node', 'language', 'views_ui'];
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Create Article content type.
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
@ -72,7 +73,7 @@ class FieldEntityOperationsTest extends HandlerTestBase {
|
|||
$this->assertTrue(count($operations) > 0, 'There are operations.');
|
||||
foreach ($operations as $operation) {
|
||||
$expected_destination = Url::fromUri('internal:/test-entity-operations')->toString();
|
||||
$result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[@href=:path and text()=:title]', [':path' => $operation['url']->toString() . '?destination=' . $expected_destination, ':title' => $operation['title']]);
|
||||
$result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[@href=:path and text()=:title]', [':path' => $operation['url']->toString() . '?destination=' . $expected_destination, ':title' => (string) $operation['title']]);
|
||||
$this->assertEqual(count($result), 1, t('Found entity @operation link with destination parameter.', ['@operation' => $operation['title']]));
|
||||
// Entities which were created in Hungarian should link to the Hungarian
|
||||
// edit form, others to the English one (which has no path prefix here).
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Render\RenderContext;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
|
@ -15,7 +16,7 @@ use Drupal\field\Entity\FieldStorageConfig;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class FieldGroupRowsTest extends HandlerTestBase {
|
||||
class FieldGroupRowsTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -38,8 +39,8 @@ class FieldGroupRowsTest extends HandlerTestBase {
|
|||
*/
|
||||
private $fieldName = 'field_group_rows';
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Create content type with unlimited text field.
|
||||
$node_type = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the "Display all values in the same row" setting.
|
||||
|
@ -59,8 +59,8 @@ class FieldGroupRowsWebTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Create content type with unlimited text field.
|
||||
$this->nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
@ -98,7 +98,7 @@ class FieldGroupRowsWebTest extends ViewTestBase {
|
|||
|
||||
$rendered_value = [];
|
||||
foreach ($result as $row) {
|
||||
$rendered_value[] = (string) $row[0];
|
||||
$rendered_value[] = $row->getText();
|
||||
}
|
||||
$this->assertEqual(['a, b, c'], $rendered_value);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class FieldGroupRowsWebTest extends ViewTestBase {
|
|||
$result = $this->cssSelect('div.views-field-field-views-testing-group- div');
|
||||
$rendered_value = [];
|
||||
foreach ($result as $row) {
|
||||
$rendered_value[] = (string) $row[0];
|
||||
$rendered_value[] = $row->getText();
|
||||
}
|
||||
$this->assertEqual(['a', 'b', 'c'], $rendered_value);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
@ -8,6 +8,7 @@ use Drupal\Component\Utility\UrlHelper;
|
|||
use Drupal\Core\Render\RenderContext;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +17,7 @@ use Drupal\views\Views;
|
|||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\field\FieldPluginBase
|
||||
*/
|
||||
class FieldWebTest extends HandlerTestBase {
|
||||
class FieldWebTest extends ViewTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
|
@ -41,8 +42,8 @@ class FieldWebTest extends HandlerTestBase {
|
|||
'views_test_data_name' => 'name',
|
||||
];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ class FieldWebTest extends HandlerTestBase {
|
|||
$fields = $this->xpath("//td[contains(@class, 'views-field-id')]");
|
||||
$ids = [];
|
||||
foreach ($fields as $field) {
|
||||
$ids[] = (int) $field[0];
|
||||
$ids[] = (int) $field->getText();
|
||||
}
|
||||
return $ids;
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -13,7 +14,7 @@ use Drupal\views\Views;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class FilterDateTest extends HandlerTestBase {
|
||||
class FilterDateTest extends ViewTestBase {
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
|
@ -30,8 +31,8 @@ class FilterDateTest extends HandlerTestBase {
|
|||
*/
|
||||
public static $modules = ['node', 'views_ui', 'datetime'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Add a date field so we can test datetime handling.
|
||||
NodeType::create([
|
||||
|
@ -213,7 +214,7 @@ class FilterDateTest extends HandlerTestBase {
|
|||
$this->assertFieldByName($name, $value);
|
||||
if (strpos($name, '[value][type]')) {
|
||||
$radio = $this->cssSelect('input[name="' . $name . '"][checked="checked"][type="radio"]');
|
||||
$this->assertEqual((string) $radio[0]['value'], $value);
|
||||
$this->assertEqual($radio[0]->getAttribute('value'), $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,22 +222,27 @@ class FilterDateTest extends HandlerTestBase {
|
|||
$this->assertConfigSchemaByName('views.view.test_filter_date_between');
|
||||
|
||||
// Test that the exposed filter works as expected.
|
||||
$this->drupalGet('admin/structure/views/view/test_filter_date_between/edit');
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$path = 'test_filter_date_between-path';
|
||||
$this->drupalPostForm('admin/structure/views/view/test_filter_date_between/edit', [], 'Add Page');
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_filter_date_between/page_1/path', ['path' => $path], 'Apply');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
$this->drupalGet($path);
|
||||
$this->drupalPostForm(NULL, [], 'Apply');
|
||||
$results = $this->cssSelect('.view-content .field-content');
|
||||
$this->assertEqual(count($results), 4);
|
||||
$this->drupalPostForm(NULL, ['created' => '1'], t('Update preview'));
|
||||
$this->drupalPostForm(NULL, ['created' => '1'], 'Apply');
|
||||
$results = $this->cssSelect('.view-content .field-content');
|
||||
$this->assertEqual(count($results), 1);
|
||||
$this->assertEqual((string) $results[0], $this->nodes[3]->id());
|
||||
$this->drupalPostForm(NULL, ['created' => '2'], t('Update preview'));
|
||||
$this->assertEqual($results[0]->getText(), $this->nodes[3]->id());
|
||||
$this->drupalPostForm(NULL, ['created' => '2'], 'Apply');
|
||||
$results = $this->cssSelect('.view-content .field-content');
|
||||
$this->assertEqual(count($results), 1);
|
||||
$this->assertEqual((string) $results[0], $this->nodes[3]->id());
|
||||
$this->drupalPostForm(NULL, ['created' => '3'], t('Update preview'));
|
||||
$this->assertEqual($results[0]->getText(), $this->nodes[3]->id());
|
||||
$this->drupalPostForm(NULL, ['created' => '3'], 'Apply');
|
||||
$results = $this->cssSelect('.view-content .field-content');
|
||||
$this->assertEqual(count($results), 1);
|
||||
$this->assertEqual((string) $results[0], $this->nodes[1]->id());
|
||||
$this->assertEqual($results[0]->getText(), $this->nodes[1]->id());
|
||||
|
||||
// Change the filter to a single filter to test the schema when the operator
|
||||
// is not exposed.
|
||||
|
@ -250,15 +256,15 @@ class FilterDateTest extends HandlerTestBase {
|
|||
$this->assertConfigSchemaByName('views.view.test_filter_date_between');
|
||||
|
||||
// Test that the filter works as expected.
|
||||
$this->drupalPostForm(NULL, [], t('Update preview'));
|
||||
$this->drupalGet($path);
|
||||
$results = $this->cssSelect('.view-content .field-content');
|
||||
$this->assertEqual(count($results), 1);
|
||||
$this->assertEqual((string) $results[0], $this->nodes[3]->id());
|
||||
$this->drupalPostForm(NULL, ['created' => format_date(250000, 'custom', 'Y-m-d H:i:s')], t('Update preview'));
|
||||
$this->assertEqual($results[0]->getText(), $this->nodes[3]->id());
|
||||
$this->drupalPostForm(NULL, ['created' => format_date(250000, 'custom', 'Y-m-d H:i:s')], 'Apply');
|
||||
$results = $this->cssSelect('.view-content .field-content');
|
||||
$this->assertEqual(count($results), 2);
|
||||
$this->assertEqual((string) $results[0], $this->nodes[2]->id());
|
||||
$this->assertEqual((string) $results[1], $this->nodes[3]->id());
|
||||
$this->assertEqual($results[0]->getText(), $this->nodes[2]->id());
|
||||
$this->assertEqual($results[1]->getText(), $this->nodes[3]->id());
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Plugin\views\HandlerBase;
|
||||
use Drupal\views\Plugin\views\filter\InOperator;
|
||||
|
@ -13,7 +14,7 @@ use Drupal\views\Entity\View;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class HandlerAllTest extends HandlerTestBase {
|
||||
class HandlerAllTest extends ViewTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Handler;
|
||||
namespace Drupal\Tests\views\Functional\Handler;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\views\Plugin\views\HandlerBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -32,8 +32,8 @@ class HandlerTest extends ViewTestBase {
|
|||
*/
|
||||
public static $modules = ['views_ui', 'comment', 'node'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
$this->enableViewsTestModule();
|
||||
|
@ -260,13 +260,12 @@ class HandlerTest extends ViewTestBase {
|
|||
$this->assertFieldByName($relationship_name);
|
||||
|
||||
// Check for available options.
|
||||
$xpath = $this->constructFieldXpath('name', $relationship_name);
|
||||
$fields = $this->xpath($xpath);
|
||||
$fields = $this->getSession()->getPage()->findAll('named_exact', ['field', $relationship_name]);
|
||||
$options = [];
|
||||
foreach ($fields as $field) {
|
||||
$items = $this->getAllOptions($field);
|
||||
$items = $field->findAll('css', 'option');
|
||||
foreach ($items as $item) {
|
||||
$options[] = $item->attributes()->value;
|
||||
$options[] = $item->getAttribute('value');
|
||||
}
|
||||
}
|
||||
$expected_options = ['none', 'nid'];
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -12,7 +13,7 @@ use Drupal\views\Views;
|
|||
* @todo It probably make sense to split the test up by one for role/perm/none
|
||||
* and the two generic ones.
|
||||
*/
|
||||
class AccessTest extends PluginTestBase {
|
||||
class AccessTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -42,8 +43,8 @@ class AccessTest extends PluginTestBase {
|
|||
*/
|
||||
protected $normalUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest as ArgumentDefaultTestPlugin;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -15,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class ArgumentDefaultTest extends PluginTestBase {
|
||||
class ArgumentDefaultTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -37,8 +38,8 @@ class ArgumentDefaultTest extends PluginTestBase {
|
|||
*/
|
||||
public static $modules = ['node', 'views_ui', 'block'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
@ -161,9 +162,9 @@ class ArgumentDefaultTest extends PluginTestBase {
|
|||
$this->drupalPlaceBlock("views_block:test_argument_default_node-block_1", ['id' => $id]);
|
||||
$xpath = '//*[@id="block-' . $id . '"]';
|
||||
$this->drupalGet('node/' . $node1->id());
|
||||
$this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node1->getTitle()));
|
||||
$this->assertTrue(strpos($this->xpath($xpath)[0]->getText(), $node1->getTitle()));
|
||||
$this->drupalGet('node/' . $node2->id());
|
||||
$this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node2->getTitle()));
|
||||
$this->assertTrue(strpos($this->xpath($xpath)[0]->getText(), $node2->getTitle()));
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -12,7 +13,7 @@ use Drupal\views\Views;
|
|||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\cache\Tag
|
||||
*/
|
||||
class CacheTagTest extends PluginTestBase {
|
||||
class CacheTagTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -70,8 +71,8 @@ class CacheTagTest extends PluginTestBase {
|
|||
*/
|
||||
protected $user;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -12,7 +13,7 @@ use Drupal\views\Views;
|
|||
* @group views
|
||||
* @see views_plugin_cache
|
||||
*/
|
||||
class CacheWebTest extends PluginTestBase {
|
||||
class CacheWebTest extends ViewTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
|
@ -33,8 +34,8 @@ class CacheWebTest extends PluginTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Core\Plugin\Context\ContextDefinitionInterface;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
|
@ -47,8 +47,8 @@ class ContextualFiltersBlockContextTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['block_test_views']);
|
||||
$this->enableViewsTestModule();
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the ability to disable and enable view displays.
|
||||
|
@ -8,7 +10,7 @@ namespace Drupal\views\Tests\Plugin;
|
|||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\display\Feed
|
||||
*/
|
||||
class DisabledDisplayTest extends PluginTestBase {
|
||||
class DisabledDisplayTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -24,8 +26,8 @@ class DisabledDisplayTest extends PluginTestBase {
|
|||
*/
|
||||
public static $modules = ['block', 'node', 'views'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
|
@ -56,7 +58,7 @@ class DisabledDisplayTest extends PluginTestBase {
|
|||
// Enabled page display should return content.
|
||||
$this->drupalGet('test-disabled-display');
|
||||
$result = $this->xpath('//h1[@class="page-title"]');
|
||||
$this->assertEqual($result[0], 'test_disabled_display', 'The enabled page_1 display is accessible.');
|
||||
$this->assertEqual($result[0]->getText(), 'test_disabled_display', 'The enabled page_1 display is accessible.');
|
||||
|
||||
// Disabled page view should 404.
|
||||
$this->drupalGet('test-disabled-display-2');
|
||||
|
@ -75,7 +77,7 @@ class DisabledDisplayTest extends PluginTestBase {
|
|||
// Check that the originally disabled page_2 display is now enabled.
|
||||
$this->drupalGet('test-disabled-display-2');
|
||||
$result = $this->xpath('//h1[@class="page-title"]');
|
||||
$this->assertEqual($result[0], 'test_disabled_display', 'The enabled page_2 display is accessible.');
|
||||
$this->assertEqual($result[0]->getText(), 'test_disabled_display', 'The enabled page_2 display is accessible.');
|
||||
|
||||
// Disable each disabled display and save the view.
|
||||
foreach ($display_ids as $display_id) {
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -10,7 +11,7 @@ use Drupal\views\Views;
|
|||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\display\Attachment
|
||||
*/
|
||||
class DisplayAttachmentTest extends PluginTestBase {
|
||||
class DisplayAttachmentTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -26,8 +27,8 @@ class DisplayAttachmentTest extends PluginTestBase {
|
|||
*/
|
||||
public static $modules = ['node', 'views'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +16,7 @@ use Drupal\views\Views;
|
|||
*
|
||||
* @see \Drupal\views\Plugin\views\display\EntityReference
|
||||
*/
|
||||
class DisplayEntityReferenceTest extends PluginTestBase {
|
||||
class DisplayEntityReferenceTest extends ViewTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
|
@ -64,8 +65,8 @@ class DisplayEntityReferenceTest extends PluginTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer views']));
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -10,7 +11,7 @@ use Drupal\views\Views;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class DisplayPageWebTest extends PluginTestBase {
|
||||
class DisplayPageWebTest extends ViewTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
|
@ -31,8 +32,8 @@ class DisplayPageWebTest extends PluginTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
|
@ -55,13 +56,13 @@ class DisplayPageWebTest extends PluginTestBase {
|
|||
$this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url']);
|
||||
$result = $this->xpath('//span[@class="field-content"]');
|
||||
$this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
|
||||
$this->assertEqual((string) $result[0], 1, 'The passed ID was returned.');
|
||||
$this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
|
||||
|
||||
$this->drupalGet('test_route_with_suffix/1/suffix');
|
||||
$this->assertResponse(200);
|
||||
$result = $this->xpath('//span[@class="field-content"]');
|
||||
$this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
|
||||
$this->assertEqual((string) $result[0], 1, 'The passed ID was returned.');
|
||||
$this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
|
||||
|
||||
$this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2');
|
||||
$this->assertResponse(200);
|
||||
|
@ -72,13 +73,13 @@ class DisplayPageWebTest extends PluginTestBase {
|
|||
$this->assertResponse(200);
|
||||
$result = $this->xpath('//span[@class="field-content"]');
|
||||
$this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
|
||||
$this->assertEqual((string) $result[0], 1, 'The passed ID was returned.');
|
||||
$this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
|
||||
|
||||
$this->drupalGet('test_route_with_long_argument/1');
|
||||
$this->assertResponse(200);
|
||||
$result = $this->xpath('//span[@class="field-content"]');
|
||||
$this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
|
||||
$this->assertEqual((string) $result[0], 1, 'The passed ID was returned.');
|
||||
$this->assertEqual($result[0]->getText(), 1, 'The passed ID was returned.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,11 +89,11 @@ class DisplayPageWebTest extends PluginTestBase {
|
|||
// Check local tasks.
|
||||
$this->drupalGet('test_page_display_menu');
|
||||
$this->assertResponse(200);
|
||||
$element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]', [
|
||||
$element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]/child::text()', [
|
||||
':ul_class' => 'tabs primary',
|
||||
':a_class' => 'is-active',
|
||||
]);
|
||||
$this->assertEqual((string) $element[0], t('Test default tab'));
|
||||
$this->assertEqual($element[0]->getText(), t('Test default tab'));
|
||||
$this->assertTitle(t('Test default page | Drupal'));
|
||||
|
||||
$this->drupalGet('test_page_display_menu/default');
|
||||
|
@ -100,11 +101,11 @@ class DisplayPageWebTest extends PluginTestBase {
|
|||
|
||||
$this->drupalGet('test_page_display_menu/local');
|
||||
$this->assertResponse(200);
|
||||
$element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]', [
|
||||
$element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]/child::text()', [
|
||||
':ul_class' => 'tabs primary',
|
||||
':a_class' => 'is-active',
|
||||
]);
|
||||
$this->assertEqual((string) $element[0], t('Test local tab'));
|
||||
$this->assertEqual($element[0]->getText(), t('Test local tab'));
|
||||
$this->assertTitle(t('Test local page | Drupal'));
|
||||
|
||||
// Check an ordinary menu link.
|
||||
|
@ -114,7 +115,7 @@ class DisplayPageWebTest extends PluginTestBase {
|
|||
$this->drupalGet('<front>');
|
||||
|
||||
$menu_link = $this->cssSelect('nav.block-menu ul.menu a');
|
||||
$this->assertEqual((string) $menu_link[0], 'Test menu link');
|
||||
$this->assertEqual($menu_link[0]->getText(), 'Test menu link');
|
||||
|
||||
// Update the menu link.
|
||||
$this->drupalPostForm("admin/structure/menu/link/views_view:views.test_page_display_menu.page_3/edit", [
|
||||
|
@ -123,7 +124,7 @@ class DisplayPageWebTest extends PluginTestBase {
|
|||
|
||||
$this->drupalGet('<front>');
|
||||
$menu_link = $this->cssSelect('nav.block-menu ul.menu a');
|
||||
$this->assertEqual((string) $menu_link[0], 'New title');
|
||||
$this->assertEqual($menu_link[0]->getText(), 'New title');
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views_test_data\Plugin\views\display\DisplayTest as DisplayTestPlugin;
|
||||
|
||||
|
@ -12,7 +12,7 @@ use Drupal\views_test_data\Plugin\views\display\DisplayTest as DisplayTestPlugin
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class DisplayTest extends PluginTestBase {
|
||||
class DisplayTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -28,7 +28,7 @@ class DisplayTest extends PluginTestBase {
|
|||
*/
|
||||
public static $modules = ['views_ui', 'node', 'block'];
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
@ -94,6 +94,13 @@ class DisplayTest extends PluginTestBase {
|
|||
// Check the test option.
|
||||
$this->assertIdentical($view->display_handler->getOption('test_option'), '');
|
||||
|
||||
$style = $view->display_handler->getOption('style');
|
||||
$style['type'] = 'test_style';
|
||||
$view->display_handler->setOption('style', $style);
|
||||
$view->initDisplay();
|
||||
$view->initStyle();
|
||||
$view->style_plugin->setUsesRowPlugin(FALSE);
|
||||
|
||||
$output = $view->preview();
|
||||
$output = $renderer->renderRoot($output);
|
||||
|
||||
|
@ -113,9 +120,9 @@ class DisplayTest extends PluginTestBase {
|
|||
$this->drupalGet('admin/structure/views/view/test_view/edit/display_test_1');
|
||||
$this->assertText('Display test settings');
|
||||
// Ensure that the order is as expected.
|
||||
$result = $this->xpath('//ul[@id="views-display-menu-tabs"]/li');
|
||||
$this->assertEqual((string) $result[0]->a, 'Display test 2');
|
||||
$this->assertEqual((string) $result[1]->a, 'Display test');
|
||||
$result = $this->xpath('//ul[@id="views-display-menu-tabs"]/li/a/child::text()');
|
||||
$this->assertEqual($result[0]->getText(), 'Display test 2');
|
||||
$this->assertEqual($result[1]->getText(), 'Display test');
|
||||
|
||||
$this->clickLink('Test option title');
|
||||
|
||||
|
@ -160,76 +167,6 @@ class DisplayTest extends PluginTestBase {
|
|||
$this->assertEqual($view->display_handler->getAttachedDisplays(), []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the readmore functionality.
|
||||
*/
|
||||
public function testReadMore() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = $this->container->get('renderer');
|
||||
|
||||
if (!isset($this->options['validate']['type'])) {
|
||||
return;
|
||||
}
|
||||
$expected_more_text = 'custom more text';
|
||||
|
||||
$view = Views::getView('test_display_more');
|
||||
$this->executeView($view);
|
||||
|
||||
$output = $view->preview();
|
||||
$output = $renderer->renderRoot($output);
|
||||
|
||||
$this->setRawContent($output);
|
||||
$result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']);
|
||||
$this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.');
|
||||
$this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.');
|
||||
|
||||
// Test the renderMoreLink method directly. This could be directly unit
|
||||
// tested.
|
||||
$more_link = $view->display_handler->renderMoreLink();
|
||||
$more_link = $renderer->renderRoot($more_link);
|
||||
$this->setRawContent($more_link);
|
||||
$result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']);
|
||||
$this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.');
|
||||
$this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.');
|
||||
|
||||
// Test the useMoreText method directly. This could be directly unit
|
||||
// tested.
|
||||
$more_text = $view->display_handler->useMoreText();
|
||||
$this->assertEqual($more_text, $expected_more_text, 'The right more text is chosen.');
|
||||
|
||||
$view = Views::getView('test_display_more');
|
||||
$view->setDisplay();
|
||||
$view->display_handler->setOption('use_more', 0);
|
||||
$this->executeView($view);
|
||||
$output = $view->preview();
|
||||
$output = $renderer->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']);
|
||||
$this->assertTrue(empty($result), 'The more link is not shown.');
|
||||
|
||||
$view = Views::getView('test_display_more');
|
||||
$view->setDisplay();
|
||||
$view->display_handler->setOption('use_more', 0);
|
||||
$view->display_handler->setOption('use_more_always', 0);
|
||||
$view->display_handler->setOption('pager', [
|
||||
'type' => 'some',
|
||||
'options' => [
|
||||
'items_per_page' => 1,
|
||||
'offset' => 0,
|
||||
],
|
||||
]);
|
||||
$this->executeView($view);
|
||||
$output = $view->preview();
|
||||
$output = $renderer->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$result = $this->xpath('//a[@class=:class]', [':class' => 'more-link']);
|
||||
$this->assertTrue(empty($result), 'The more link is not shown when view has more records.');
|
||||
|
||||
// Test the default value of use_more_always.
|
||||
$view = View::create()->getExecutable();
|
||||
$this->assertTrue($view->getDisplay()->getOption('use_more_always'), 'Always display the more link by default.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the readmore validation.
|
||||
*/
|
||||
|
@ -290,7 +227,8 @@ class DisplayTest extends PluginTestBase {
|
|||
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertResponse(200);
|
||||
$this->assertBlockAppears($block);
|
||||
$result = $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]);
|
||||
$this->assertEquals(1, count($result));
|
||||
|
||||
// Change the block plugin ID to an invalid one.
|
||||
$config = $this->config('views.view.test_display_invalid');
|
||||
|
@ -302,7 +240,8 @@ class DisplayTest extends PluginTestBase {
|
|||
$this->drupalGet('<front>');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('The "invalid" plugin does not exist.');
|
||||
$this->assertNoBlockAppears($block);
|
||||
$result = $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]);
|
||||
$this->assertEquals(0, count($result));
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views\Entity\View;
|
||||
|
@ -33,8 +33,8 @@ class ExposedFormTest extends ViewTestBase {
|
|||
*/
|
||||
public static $modules = ['node', 'views_ui', 'block', 'entity_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
|
@ -191,26 +191,6 @@ class ExposedFormTest extends ViewTestBase {
|
|||
$this->helperButtonHasLabel('edit-reset', $expected_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the exposed form markup.
|
||||
*/
|
||||
public function testExposedFormRender() {
|
||||
$view = Views::getView('test_exposed_form_buttons');
|
||||
$this->executeView($view);
|
||||
$exposed_form = $view->display_handler->getPlugin('exposed_form');
|
||||
$output = $exposed_form->renderExposedForm();
|
||||
$this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
|
||||
|
||||
$this->assertFieldByXpath('//form/@id', $this->getExpectedExposedFormId($view), 'Expected form ID found.');
|
||||
|
||||
$view->setDisplay('page_1');
|
||||
$expected_action = $view->display_handler->getUrlInfo()->toString();
|
||||
$this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.');
|
||||
// Make sure the description is shown.
|
||||
$result = $this->xpath('//form//div[contains(@id, :id) and normalize-space(text())=:description]', [':id' => 'edit-type--description', ':description' => t('Exposed description')]);
|
||||
$this->assertEqual(count($result), 1, 'Filter description was found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests overriding the default render option with checkboxes.
|
||||
*/
|
||||
|
@ -265,7 +245,8 @@ class ExposedFormTest extends ViewTestBase {
|
|||
|
||||
// Test there is an exposed form in a block.
|
||||
$xpath = $this->buildXPathQuery('//div[@id=:id]/form/@id', [':id' => Html::getUniqueId('block-' . $block->id())]);
|
||||
$this->assertFieldByXpath($xpath, $this->getExpectedExposedFormId($view), 'Expected form found in views block.');
|
||||
$result = $this->xpath($xpath);
|
||||
$this->assertEquals(1, count($result));
|
||||
|
||||
// Test there is not an exposed form in the view page content area.
|
||||
$xpath = $this->buildXPathQuery('//div[@class="view-content"]/form/@id', [':id' => Html::getUniqueId('block-' . $block->id())]);
|
||||
|
@ -381,7 +362,7 @@ class ExposedFormTest extends ViewTestBase {
|
|||
$elements = $this->cssSelect('div.view-test-exposed-form-sort-items-per-page div.views-row span.field-content');
|
||||
$actual_ids = [];
|
||||
foreach ($elements as $element) {
|
||||
$actual_ids[] = (int) $element;
|
||||
$actual_ids[] = (int) $element->getText();
|
||||
}
|
||||
|
||||
return $this->assertIdentical($ids, $actual_ids);
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views_test_data\Plugin\views\filter\FilterTest as FilterPlugin;
|
||||
|
||||
|
@ -11,7 +12,7 @@ use Drupal\views_test_data\Plugin\views\filter\FilterTest as FilterPlugin;
|
|||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\filter\FilterPluginBase
|
||||
*/
|
||||
class FilterTest extends PluginTestBase {
|
||||
class FilterTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -27,8 +28,8 @@ class FilterTest extends PluginTestBase {
|
|||
*/
|
||||
public static $modules = ['views_ui', 'node'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the menu links created in views.
|
||||
|
@ -36,8 +36,8 @@ class MenuLinkTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -10,7 +11,7 @@ use Drupal\views\Views;
|
|||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\pager\Mini
|
||||
*/
|
||||
class MiniPagerTest extends PluginTestBase {
|
||||
class MiniPagerTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -33,8 +34,8 @@ class MiniPagerTest extends PluginTestBase {
|
|||
*/
|
||||
protected $nodes;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
// Create a bunch of test nodes.
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Component\Gettext\PoHeader;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the creation of numeric fields.
|
||||
|
@ -27,8 +27,8 @@ class NumericFormatPluralTest extends ViewTestBase {
|
|||
*/
|
||||
public static $testViews = ['numeric_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$web_user = $this->drupalCreateUser(['administer views', 'administer languages']);
|
||||
$this->drupalLogin($web_user);
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
|
@ -11,7 +12,7 @@ use Drupal\language\Entity\ConfigurableLanguage;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class PagerTest extends PluginTestBase {
|
||||
class PagerTest extends ViewTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the summary style plugin.
|
||||
|
@ -58,13 +58,13 @@ class StyleSummaryTest extends ViewTestBase {
|
|||
$this->assertEqual(4, count($summary_list));
|
||||
|
||||
foreach ($summary_list as $summary_list_item) {
|
||||
$this->assertEqual('(5)', trim((string) $summary_list_item));
|
||||
$this->assertEqual('(5)', trim(explode(' ', $summary_list_item->getText())[1]));
|
||||
}
|
||||
|
||||
$summary_links = $this->cssSelect('ul.views-summary a');
|
||||
$this->assertEqual(4, count($summary_links));
|
||||
foreach ($summary_links as $index => $summary_link) {
|
||||
$this->assertEqual('type' . $index, trim((string) $summary_link));
|
||||
$this->assertEqual('type' . $index, trim($summary_link->getText()));
|
||||
}
|
||||
|
||||
$this->clickLink('type1');
|
||||
|
@ -100,13 +100,13 @@ class StyleSummaryTest extends ViewTestBase {
|
|||
$this->assertEqual(3, count($summary_list));
|
||||
|
||||
foreach ($summary_list as $summary_list_item) {
|
||||
$this->assertEqual('(5)', trim((string) $summary_list_item));
|
||||
$this->assertEqual('(5)', trim(explode(' ', $summary_list_item->getText())[1]));
|
||||
}
|
||||
|
||||
$summary_links = $this->cssSelect('.views-summary-unformatted a');
|
||||
$this->assertEqual(3, count($summary_links));
|
||||
foreach ($summary_links as $index => $summary_link) {
|
||||
$this->assertEqual('type' . $index, trim((string) $summary_link));
|
||||
$this->assertEqual('type' . $index, trim($summary_link->getText()));
|
||||
}
|
||||
|
||||
$this->clickLink('type1');
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Entity\View;
|
||||
|
||||
/**
|
||||
|
@ -9,7 +10,7 @@ use Drupal\views\Entity\View;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class StyleTableTest extends PluginTestBase {
|
||||
class StyleTableTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -21,8 +22,8 @@ class StyleTableTest extends PluginTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
@ -33,17 +34,17 @@ class StyleTableTest extends PluginTestBase {
|
|||
public function testAccessibilitySettings() {
|
||||
$this->drupalGet('test-table');
|
||||
|
||||
$result = $this->xpath('//caption');
|
||||
$result = $this->xpath('//caption/child::text()');
|
||||
$this->assertTrue(count($result), 'The caption appears on the table.');
|
||||
$this->assertEqual(trim((string) $result[0]), 'caption-text');
|
||||
$this->assertEqual(trim($result[0]->getText()), 'caption-text');
|
||||
|
||||
$result = $this->xpath('//summary');
|
||||
$result = $this->xpath('//summary/child::text()');
|
||||
$this->assertTrue(count($result), 'The summary appears on the table.');
|
||||
$this->assertEqual(trim((string) $result[0]), 'summary-text');
|
||||
$this->assertEqual(trim($result[0]->getText()), 'summary-text');
|
||||
|
||||
$result = $this->xpath('//caption/details');
|
||||
$result = $this->xpath('//caption/details/child::text()');
|
||||
$this->assertTrue(count($result), 'The table description appears on the table.');
|
||||
$this->assertEqual(trim((string) $result[0]), 'description-text');
|
||||
$this->assertEqual(trim($result[0]->getText()), 'description-text');
|
||||
|
||||
// Remove the caption and ensure the caption is not displayed anymore.
|
||||
$view = View::load('test_table');
|
||||
|
@ -52,8 +53,8 @@ class StyleTableTest extends PluginTestBase {
|
|||
$view->save();
|
||||
|
||||
$this->drupalGet('test-table');
|
||||
$result = $this->xpath('//caption');
|
||||
$this->assertFalse(trim((string) $result[0]), 'Ensure that the caption disappears.');
|
||||
$result = $this->xpath('//caption/child::text()');
|
||||
$this->assertFalse(trim($result[0]->getText()), 'Ensure that the caption disappears.');
|
||||
|
||||
// Remove the table summary.
|
||||
$display = &$view->getDisplay('default');
|
||||
|
@ -61,7 +62,7 @@ class StyleTableTest extends PluginTestBase {
|
|||
$view->save();
|
||||
|
||||
$this->drupalGet('test-table');
|
||||
$result = $this->xpath('//summary');
|
||||
$result = $this->xpath('//summary/child::text()');
|
||||
$this->assertFalse(count($result), 'Ensure that the summary disappears.');
|
||||
|
||||
// Remove the table description.
|
||||
|
@ -70,7 +71,7 @@ class StyleTableTest extends PluginTestBase {
|
|||
$view->save();
|
||||
|
||||
$this->drupalGet('test-table');
|
||||
$result = $this->xpath('//caption/details');
|
||||
$result = $this->xpath('//caption/details/child::text()');
|
||||
$this->assertFalse(count($result), 'Ensure that the description disappears.');
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\views_test_data\Plugin\views\row\RowTest;
|
||||
use Drupal\views\Plugin\views\row\Fields;
|
||||
use Drupal\views\ResultRow;
|
||||
|
@ -31,8 +31,8 @@ class StyleTest extends ViewTestBase {
|
|||
*/
|
||||
protected $elements;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests views bulk operation selection.
|
||||
*
|
||||
* @group views
|
||||
*/
|
||||
class ViewsBulkTest extends WebTestBase {
|
||||
class ViewsBulkTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* An admin user
|
||||
|
@ -25,8 +25,8 @@ class ViewsBulkTest extends WebTestBase {
|
|||
*/
|
||||
public static $modules = ['node', 'views'];
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->admin_user = $this->createUser(['bypass node access', 'administer nodes', 'access content overview']);
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests Views forms functionality.
|
||||
*
|
||||
* @group views
|
||||
*/
|
||||
class ViewsFormTest extends WebTestBase {
|
||||
class ViewsFormTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\Core\Database\DatabaseExceptionWrapper;
|
||||
|
||||
|
@ -10,7 +11,7 @@ use Drupal\Core\Database\DatabaseExceptionWrapper;
|
|||
*
|
||||
* @group views
|
||||
*/
|
||||
class ViewsSqlExceptionTest extends PluginTestBase {
|
||||
class ViewsSqlExceptionTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -22,8 +23,8 @@ class ViewsSqlExceptionTest extends PluginTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
|
@ -60,15 +60,15 @@ class RenderCacheWebTest extends ViewTestBase {
|
|||
$this->assertEqual([], $this->cssSelect('div.region-header div.views-field-title'));
|
||||
|
||||
$this->drupalGet($this->nodes[0]->toUrl());
|
||||
$result = (string) $this->cssSelect('div.region-header div.views-field-title')[0]->span;
|
||||
$result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText();
|
||||
$this->assertEqual('test title 1', $result);
|
||||
|
||||
$this->drupalGet($this->nodes[1]->toUrl());
|
||||
$result = (string) $this->cssSelect('div.region-header div.views-field-title')[0]->span;
|
||||
$result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText();
|
||||
$this->assertEqual('test title 2', $result);
|
||||
|
||||
$this->drupalGet($this->nodes[0]->toUrl());
|
||||
$result = (string) $this->cssSelect('div.region-header div.views-field-title')[0]->span;
|
||||
$result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText();
|
||||
$this->assertEqual('test title 1', $result);
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Tests search integration filters.
|
||||
|
@ -11,6 +12,8 @@ use Drupal\Component\Utility\SafeMarkup;
|
|||
*/
|
||||
class SearchIntegrationTest extends ViewTestBase {
|
||||
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
|
@ -108,10 +111,10 @@ class SearchIntegrationTest extends ViewTestBase {
|
|||
$this->cronRun();
|
||||
$this->drupalGet('test-arg/rocks');
|
||||
$xpath = '//div[@class="views-row"]//a';
|
||||
/** @var \SimpleXMLElement[] $results */
|
||||
/** @var \Behat\Mink\Element\NodeElement[] $results */
|
||||
$results = $this->xpath($xpath);
|
||||
$this->assertEqual((string) $results[0], "Drupal's search rocks <em>really</em> rocks!");
|
||||
$this->assertEqual((string) $results[1], "Drupal's search rocks.");
|
||||
$this->assertEqual($results[0]->getText(), "Drupal's search rocks <em>really</em> rocks!");
|
||||
$this->assertEqual($results[1]->getText(), "Drupal's search rocks.");
|
||||
$this->assertEscaped("Drupal's search rocks <em>really</em> rocks!");
|
||||
|
||||
// Test sorting with another set of titles.
|
||||
|
@ -127,8 +130,8 @@ class SearchIntegrationTest extends ViewTestBase {
|
|||
$xpath = '//div[@class="views-row"]//a';
|
||||
/** @var \SimpleXMLElement[] $results */
|
||||
$results = $this->xpath($xpath);
|
||||
$this->assertEqual((string) $results[0], "Testing one one one");
|
||||
$this->assertEqual((string) $results[1], "Testing one two two two");
|
||||
$this->assertEqual($results[0]->getText(), "Testing one one one");
|
||||
$this->assertEqual($results[1]->getText(), "Testing one two two two");
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Tests search integration filters with multilingual nodes.
|
||||
|
@ -12,6 +13,8 @@ use Drupal\node\NodeInterface;
|
|||
*/
|
||||
class SearchMultilingualTest extends ViewTestBase {
|
||||
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
|
||||
|
||||
|
@ -34,8 +34,8 @@ class TaxonomyGlossaryTest extends ViewTestBase {
|
|||
*/
|
||||
protected $taxonomyTerms;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -18,8 +18,8 @@ class ViewRenderTest extends ViewTestBase {
|
|||
*/
|
||||
public static $testViews = ['test_view_render'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
158
web/core/modules/views/tests/src/Functional/ViewTestBase.php
Normal file
158
web/core/modules/views/tests/src/Functional/ViewTestBase.php
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Behat\Mink\Exception\ElementNotFoundException;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\views\Tests\ViewResultAssertionTrait;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
||||
/**
|
||||
* Defines a base class for Views testing in the full web test environment.
|
||||
*
|
||||
* Use this base test class if you need to emulate a full Drupal installation.
|
||||
* When possible, ViewsKernelTestBase should be used instead. Both base classes
|
||||
* include the same methods.
|
||||
*
|
||||
* @see \Drupal\Tests\views\Kernel\ViewsKernelTestBase
|
||||
* @see \Drupal\simpletest\WebTestBase
|
||||
*/
|
||||
abstract class ViewTestBase extends BrowserTestBase {
|
||||
|
||||
use ViewResultAssertionTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views', 'views_test_config'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
if ($import_test_views) {
|
||||
ViewTestData::createTestViews(get_class($this), ['views_test_config']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the views_test_data.module.
|
||||
*
|
||||
* Because the schema of views_test_data.module is dependent on the test
|
||||
* using it, it cannot be enabled normally.
|
||||
*/
|
||||
protected function enableViewsTestModule() {
|
||||
// Define the schema and views data variable before enabling the test module.
|
||||
\Drupal::state()->set('views_test_data_schema', $this->schemaDefinition());
|
||||
\Drupal::state()->set('views_test_data_views_data', $this->viewsData());
|
||||
|
||||
\Drupal::service('module_installer')->install(['views_test_data']);
|
||||
$this->resetAll();
|
||||
$this->rebuildContainer();
|
||||
$this->container->get('module_handler')->reload();
|
||||
|
||||
// Load the test dataset.
|
||||
$data_set = $this->dataSet();
|
||||
$query = db_insert('views_test_data')
|
||||
->fields(array_keys($data_set[0]));
|
||||
foreach ($data_set as $record) {
|
||||
$query->values($record);
|
||||
}
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders a nested array containing a result set based on a given column.
|
||||
*
|
||||
* @param array $result_set
|
||||
* An array of rows from a result set, with each row as an associative
|
||||
* array keyed by column name.
|
||||
* @param string $column
|
||||
* The column name by which to sort the result set.
|
||||
* @param bool $reverse
|
||||
* (optional) Boolean indicating whether to sort the result set in reverse
|
||||
* order. Defaults to FALSE.
|
||||
*
|
||||
* @return array
|
||||
* The sorted result set.
|
||||
*/
|
||||
protected function orderResultSet($result_set, $column, $reverse = FALSE) {
|
||||
$order = $reverse ? -1 : 1;
|
||||
usort($result_set, function ($a, $b) use ($column, $order) {
|
||||
if ($a[$column] == $b[$column]) {
|
||||
return 0;
|
||||
}
|
||||
return $order * (($a[$column] < $b[$column]) ? -1 : 1);
|
||||
});
|
||||
return $result_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the existence of a button with a certain ID and label.
|
||||
*
|
||||
* @param string $id
|
||||
* The HTML ID of the button
|
||||
* @param string $expected_label
|
||||
* The expected label for the button.
|
||||
* @param string $message
|
||||
* (optional) A custom message to display with the assertion. If no custom
|
||||
* message is provided, the message will indicate the button label.
|
||||
*
|
||||
* @throws \Behat\Mink\Exception\ElementNotFoundException
|
||||
*/
|
||||
protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') {
|
||||
$xpath = $this->assertSession()->buildXPathQuery('//button[@id=:value]|//input[@id=:value]', [':value' => $id]);
|
||||
$field = $this->getSession()->getPage()->find('xpath', $xpath);
|
||||
|
||||
if (empty($field)) {
|
||||
throw new ElementNotFoundException($this->getSession()->getDriver(), 'form field', 'id', $field);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected_label, $field->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a view with debugging.
|
||||
*
|
||||
* @param \Drupal\views\ViewExecutable $view
|
||||
* The view object.
|
||||
* @param array $args
|
||||
* (optional) An array of the view arguments to use for the view.
|
||||
*/
|
||||
protected function executeView(ViewExecutable $view, $args = []) {
|
||||
// A view does not really work outside of a request scope, due to many
|
||||
// dependencies like the current user.
|
||||
$view->setDisplay();
|
||||
$view->preExecute($args);
|
||||
$view->execute();
|
||||
$verbose_message = '<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>';
|
||||
if ($view->build_info['query'] instanceof SelectInterface) {
|
||||
$verbose_message .= '<pre>Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '</pre>';
|
||||
}
|
||||
$this->verbose($verbose_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the schema definition.
|
||||
*/
|
||||
protected function schemaDefinition() {
|
||||
return ViewTestData::schemaDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the views data definition.
|
||||
*/
|
||||
protected function viewsData() {
|
||||
return ViewTestData::viewsData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a very simple test dataset.
|
||||
*/
|
||||
protected function dataSet() {
|
||||
return ViewTestData::dataSet();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
/**
|
||||
* Tests output of Views.
|
||||
|
@ -30,8 +30,8 @@ class ViewsEscapingTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp(TRUE);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
/**
|
||||
* Tests a page with multiple Views forms.
|
||||
|
@ -19,8 +19,8 @@ class ViewsFormMultipleTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ class ViewsFormMultipleTest extends ViewTestBase {
|
|||
// Submit the forms, validate argument returned in message set by handler.
|
||||
// @note There is not a way to specify a specific index for a submit button. So
|
||||
// the row index returned is always the last occurrence.
|
||||
$this->drupalPostForm(NULL, [], t('Test Button'), [], [], 'views-form-test-form-multiple-default-arg2');
|
||||
$this->getSession()->getPage()->pressButton('edit-field-form-button-test-4--2');
|
||||
$this->assertText('The test button at row 4 for test_form_multiple (default) View with args: arg2 was submitted.');
|
||||
$this->drupalPostForm(NULL, [], t('Test Button'), [], [], 'views-form-test-form-multiple-default-arg1');
|
||||
$this->getSession()->getPage()->pressButton('edit-field-form-button-test-4');
|
||||
$this->assertText('The test button at row 4 for test_form_multiple (default) View with args: arg1 was submitted.');
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +23,7 @@ class ViewsTemplateTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp(FALSE);
|
||||
|
||||
$this->enableViewsTestModule();
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
/**
|
||||
* Tests the Views theme integration.
|
||||
|
@ -33,8 +33,8 @@ class ViewsThemeIntegrationTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Wizard;
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
@ -14,8 +14,8 @@ use Drupal\views\Views;
|
|||
*/
|
||||
class BasicTest extends WizardTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
@ -80,7 +80,9 @@ class BasicTest extends WizardTestBase {
|
|||
$elements = $this->cssSelect('link[href="' . Url::fromRoute('view.' . $view2['id'] . '.feed_1', [], ['absolute' => TRUE])->toString() . '"]');
|
||||
$this->assertEqual(count($elements), 1, 'Feed found.');
|
||||
$this->drupalGet($view2['page[feed_properties][path]']);
|
||||
$this->assertTrue(!empty($this->cssSelect('rss[version="2.0"]')));
|
||||
// Because the response is XML we can't use the page which depends on an
|
||||
// HTML tag being present.
|
||||
$this->assertEquals('2.0', $this->getSession()->getDriver()->getAttribute('//rss', 'version'));
|
||||
// The feed should have the same title and nodes as the page.
|
||||
$this->assertText($view2['page[title]']);
|
||||
$this->assertRaw($node1->url('canonical', ['absolute' => TRUE]));
|
||||
|
@ -134,7 +136,7 @@ class BasicTest extends WizardTestBase {
|
|||
|
||||
// Confirm that the block is available in the block administration UI.
|
||||
$this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default'));
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$this->clickLink('Place block');
|
||||
$this->assertText($view3['label']);
|
||||
|
||||
// Place the block.
|
||||
|
@ -164,7 +166,7 @@ class BasicTest extends WizardTestBase {
|
|||
// Check that the REST export path works.
|
||||
$this->drupalGet($view4['rest_export[path]']);
|
||||
$this->assertResponse(200);
|
||||
$data = Json::decode($this->content);
|
||||
$data = Json::decode($this->getSession()->getPage()->getContent());
|
||||
$this->assertEqual(count($data), 1, 'Only the node of type page is exported.');
|
||||
$node = reset($data);
|
||||
$this->assertEqual($node['nid'][0]['value'], $node1->id(), 'The node of type page is exported.');
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Wizard;
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to specify the number of items per
|
||||
|
@ -10,8 +10,8 @@ namespace Drupal\views\Tests\Wizard;
|
|||
*/
|
||||
class ItemsPerPageTest extends WizardTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class ItemsPerPageTest extends WizardTestBase {
|
|||
|
||||
// Confirm that the block is listed in the block administration UI.
|
||||
$this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default'));
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$this->clickLink('Place block');
|
||||
$this->assertText($view['label']);
|
||||
|
||||
// Place the block, visit a page that displays the block, and check that the
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Wizard;
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Url;
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Wizard;
|
||||
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
/**
|
||||
* Tests node wizard and generic entity integration.
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Wizard;
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to create views without a pager.
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Wizard;
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to create views with sorts.
|
||||
|
@ -9,8 +9,8 @@ namespace Drupal\views\Tests\Wizard;
|
|||
*/
|
||||
class SortingTest extends WizardTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Wizard;
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
@ -65,8 +65,8 @@ class TaggedWithTest extends WizardTestBase {
|
|||
*/
|
||||
protected $tagField;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Create two content types. One will have an autocomplete tagging field,
|
||||
// and one won't.
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Views UI wizard tests.
|
||||
*/
|
||||
abstract class WizardTestBase extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'views_ui', 'block', 'rest'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Create and log in a user with administer views permission.
|
||||
$views_admin = $this->drupalCreateUser(['administer views', 'administer blocks', 'bypass node access', 'access user profiles', 'view all revisions']);
|
||||
$this->drupalLogin($views_admin);
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Kernel\Handler;
|
||||
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the generic entity area handler.
|
||||
*
|
||||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\area\Entity
|
||||
*/
|
||||
class AreaEmptyTest extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('node');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views']['test_example'] = [
|
||||
'title' => 'Test Example area',
|
||||
'help' => 'A area handler which just exists for tests.',
|
||||
'area' => [
|
||||
'id' => 'test_example'
|
||||
]
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_example_area'];
|
||||
|
||||
/**
|
||||
* 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.
|
||||
$empty_text = $this->randomMachineName();
|
||||
$empty_header = $this->randomMachineName();
|
||||
$empty_footer = $this->randomMachineName();
|
||||
|
||||
// Set empty text.
|
||||
$view->empty['test_example']->options['string'] = '<p>' . $empty_text . '</p>';
|
||||
// Set example header text.
|
||||
$view->header['test_example']->options['string'] = '<p>' . $empty_header . '</p>';
|
||||
// Set example footer text.
|
||||
$view->footer['test_example']->options['string'] = '<p>' . $empty_footer . '</p>';
|
||||
|
||||
// Verify that the empty header and footer sections have not been rendered.
|
||||
$view->setDisplay('default');
|
||||
$this->executeView($view);
|
||||
$output = $view->render();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$this->assertText($empty_text);
|
||||
$this->assertNoText($empty_header);
|
||||
$this->assertNoText($empty_footer);
|
||||
|
||||
// Enable displaying the header and footer when the View is empty.
|
||||
$view->header['test_example']->options['empty'] = TRUE;
|
||||
$view->footer['test_example']->options['empty'] = TRUE;
|
||||
|
||||
// Verify that the header and footer sections have been rendered.
|
||||
$this->executeView($view);
|
||||
$output = $view->render();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$this->assertText($empty_header);
|
||||
$this->assertText($empty_footer);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Kernel\Handler;
|
||||
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the result area handler.
|
||||
*
|
||||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\area\Result
|
||||
*/
|
||||
class AreaResultTest extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $testViews = ['test_area_result'];
|
||||
|
||||
/**
|
||||
* Tests the results area handler.
|
||||
*/
|
||||
public function testResult() {
|
||||
$view = Views::getView('test_area_result');
|
||||
$view->setDisplay('default');
|
||||
$this->executeView($view);
|
||||
$output = $view->render();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$this->assertText('start: 1 | end: 5 | total: 5 | label: test_area_result | per page: 0 | current page: 1 | current record count: 5 | page count: 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the results area handler.
|
||||
*/
|
||||
public function testResultEmpty() {
|
||||
$view = Views::getView('test_area_result');
|
||||
|
||||
// Test that the area is displayed if we have checked the empty checkbox.
|
||||
$view->setDisplay('default');
|
||||
|
||||
// Add a filter that will make the result set empty.
|
||||
$view->displayHandlers->get('default')->overrideOption('filters', [
|
||||
'name' => [
|
||||
'id' => 'name',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => '=',
|
||||
'value' => 'non-existing-name',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->executeView($view);
|
||||
$output = $view->render();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$this->assertText('start: 0 | end: 0 | total: 0 | label: test_area_result | per page: 0 | current page: 1 | current record count: 0 | page count: 1');
|
||||
|
||||
// Test that the area is not displayed if we have not checked the empty
|
||||
// checkbox.
|
||||
$view->setDisplay('page_1');
|
||||
|
||||
$this->executeView($view);
|
||||
$output = $view->render();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$this->assertNoText('start: 0 | end: 0 | total: 0 | label: test_area_result | per page: 0 | current page: 1 | current record count: 0 | page count: 1');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Kernel\Handler;
|
||||
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the core Drupal\views\Plugin\views\field\Numeric handler.
|
||||
*
|
||||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\field\Numeric
|
||||
*/
|
||||
class FieldNumericTest extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the Numeric handler with different settings.
|
||||
*
|
||||
* @dataProvider providerTestFieldNumeric
|
||||
*/
|
||||
public function testFieldNumeric($field_settings, $values, $expected_values) {
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
|
||||
if (!empty($field_settings)) {
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', ['age' => $field_settings]);
|
||||
}
|
||||
$this->executeView($view);
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
$view->result[0]->views_test_data_age = $value;
|
||||
$this->assertSame($expected_values[$key], $view->field['age']->advancedRender($view->result[0]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testFieldNumeric.
|
||||
*
|
||||
* @return array
|
||||
* The data set containing field settings, values to set and expected
|
||||
* values.
|
||||
*/
|
||||
public function providerTestFieldNumeric() {
|
||||
return [
|
||||
'no-formating' => [
|
||||
[],
|
||||
[0, 0.1234, -0.1234, 1000.1234, -1000.1234],
|
||||
['0', '0.1234', '-0.1234', '1,000.1234', '-1,000.1234'],
|
||||
],
|
||||
'precision_2-hide_empty-hide_zero' => [
|
||||
[
|
||||
'hide_empty' => TRUE,
|
||||
'precision' => 2,
|
||||
'set_precision' => TRUE,
|
||||
'empty_zero' => TRUE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
],
|
||||
[0, 0.1234, -0.1234, 1000.1234, -1000.1234, 0.0001, -0.0001, NULL, ''],
|
||||
['', '0.12', '-0.12', '1,000.12', '-1,000.12', '', '', '', ''],
|
||||
],
|
||||
'decimal-separator' => [
|
||||
[
|
||||
'hide_empty' => TRUE,
|
||||
'decimal' => ',',
|
||||
'separator' => '.',
|
||||
'empty_zero' => TRUE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
],
|
||||
[0.1234, -0.1234, 1000.1234, -1000.1234],
|
||||
['0,1234', '-0,1234', '1.000,1234', '-1.000,1234'],
|
||||
],
|
||||
'precision_2-no_separator' => [
|
||||
[
|
||||
'hide_empty' => TRUE,
|
||||
'precision' => 2,
|
||||
'set_precision' => TRUE,
|
||||
'decimal' => ',',
|
||||
'separator' => '',
|
||||
'empty_zero' => TRUE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
],
|
||||
[1234, 1234.01, -1234, -1234.01],
|
||||
['1234,00', '1234,01', '-1234,00', '-1234,01'],
|
||||
],
|
||||
'precision_0-no_separator' => [
|
||||
[
|
||||
'hide_empty' => TRUE,
|
||||
'precision' => 0,
|
||||
'set_precision' => TRUE,
|
||||
'separator' => '',
|
||||
'empty_zero' => TRUE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
],
|
||||
[1234, 1234.01, -1234, -1234.01],
|
||||
['1234', '1234', '-1234', '-1234'],
|
||||
],
|
||||
'precision_0-hide_empty-zero_empty' => [
|
||||
[
|
||||
'hide_empty' => TRUE,
|
||||
'precision' => 0,
|
||||
'set_precision' => TRUE,
|
||||
'empty_zero' => TRUE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'prefix' => 'test: ',
|
||||
],
|
||||
[0, 0.1234, -0.1234, 1000.1234, -1000.1234],
|
||||
['', '', '', 'test: 1,000', 'test: -1,000'],
|
||||
],
|
||||
'precision_0-hide_empty-not_zero_empty' => [
|
||||
[
|
||||
'hide_empty' => TRUE,
|
||||
'precision' => 0,
|
||||
'set_precision' => TRUE,
|
||||
'empty_zero' => FALSE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'prefix' => '',
|
||||
],
|
||||
[0, 0.1234, -0.1234],
|
||||
['0', '0', '0'],
|
||||
],
|
||||
'precision_2-hide_empty-not_zero_empty' => [
|
||||
[
|
||||
'hide_empty' => TRUE,
|
||||
'precision' => 2,
|
||||
'set_precision' => TRUE,
|
||||
'empty_zero' => FALSE,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'prefix' => '',
|
||||
],
|
||||
[0, 0.001234, -0.001234, NULL],
|
||||
['0.00', '0.00', '0.00', ''],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\views\Tests\Plugin;
|
||||
namespace Drupal\Tests\views\Kernel\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest as DisplayExtenderTestData;
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -11,7 +12,7 @@ use Drupal\views\Views;
|
|||
* @group views
|
||||
* @see \Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest
|
||||
*/
|
||||
class DisplayExtenderTest extends PluginTestBase {
|
||||
class DisplayExtenderTest extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
|
@ -20,12 +21,6 @@ class DisplayExtenderTest extends PluginTestBase {
|
|||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test display extenders.
|
||||
*/
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\views\Kernel\Plugin;
|
|||
|
||||
use Drupal\Core\Menu\MenuTreeParameters;
|
||||
use Drupal\Core\Session\AnonymousUserSession;
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -22,7 +23,7 @@ class DisplayPageTest extends ViewsKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_page_display', 'test_page_display_route', 'test_page_display_menu'];
|
||||
public static $testViews = ['test_page_display', 'test_page_display_route', 'test_page_display_menu', 'test_display_more'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
|
@ -149,4 +150,71 @@ class DisplayPageTest extends ViewsKernelTestBase {
|
|||
$this->assertIdentical($expected, $view->getDependencies());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the readmore functionality.
|
||||
*/
|
||||
public function testReadMore() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = $this->container->get('renderer');
|
||||
|
||||
$expected_more_text = 'custom more text';
|
||||
|
||||
$view = Views::getView('test_display_more');
|
||||
$this->executeView($view);
|
||||
|
||||
$output = $view->preview();
|
||||
$output = $renderer->renderRoot($output);
|
||||
|
||||
$this->setRawContent($output);
|
||||
$result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
|
||||
$this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.');
|
||||
$this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.');
|
||||
|
||||
// Test the renderMoreLink method directly. This could be directly unit
|
||||
// tested.
|
||||
$more_link = $view->display_handler->renderMoreLink();
|
||||
$more_link = $renderer->renderRoot($more_link);
|
||||
$this->setRawContent($more_link);
|
||||
$result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
|
||||
$this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.');
|
||||
$this->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.');
|
||||
|
||||
// Test the useMoreText method directly. This could be directly unit
|
||||
// tested.
|
||||
$more_text = $view->display_handler->useMoreText();
|
||||
$this->assertEqual($more_text, $expected_more_text, 'The right more text is chosen.');
|
||||
|
||||
$view = Views::getView('test_display_more');
|
||||
$view->setDisplay();
|
||||
$view->display_handler->setOption('use_more', 0);
|
||||
$this->executeView($view);
|
||||
$output = $view->preview();
|
||||
$output = $renderer->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
|
||||
$this->assertTrue(empty($result), 'The more link is not shown.');
|
||||
|
||||
$view = Views::getView('test_display_more');
|
||||
$view->setDisplay();
|
||||
$view->display_handler->setOption('use_more', 0);
|
||||
$view->display_handler->setOption('use_more_always', 0);
|
||||
$view->display_handler->setOption('pager', [
|
||||
'type' => 'some',
|
||||
'options' => [
|
||||
'items_per_page' => 1,
|
||||
'offset' => 0,
|
||||
],
|
||||
]);
|
||||
$this->executeView($view);
|
||||
$output = $view->preview();
|
||||
$output = $renderer->renderRoot($output);
|
||||
$this->setRawContent($output);
|
||||
$result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
|
||||
$this->assertTrue(empty($result), 'The more link is not shown when view has more records.');
|
||||
|
||||
// Test the default value of use_more_always.
|
||||
$view = View::create()->getExecutable();
|
||||
$this->assertTrue($view->getDisplay()->getOption('use_more_always'), 'Always display the more link by default.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Kernel\Plugin;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the exposed form markup.
|
||||
*
|
||||
* @group views
|
||||
* @see \Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest
|
||||
*/
|
||||
class ExposedFormRenderTest extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $testViews = ['test_exposed_form_buttons'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('node');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the exposed form markup.
|
||||
*/
|
||||
public function testExposedFormRender() {
|
||||
$view = Views::getView('test_exposed_form_buttons');
|
||||
$this->executeView($view);
|
||||
$exposed_form = $view->display_handler->getPlugin('exposed_form');
|
||||
$output = $exposed_form->renderExposedForm();
|
||||
$this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
|
||||
|
||||
$this->assertFieldByXpath('//form/@id', Html::cleanCssIdentifier('views-exposed-form-' . $view->storage->id() . '-' . $view->current_display), 'Expected form ID found.');
|
||||
|
||||
$view->setDisplay('page_1');
|
||||
$expected_action = $view->display_handler->getUrlInfo()->toString();
|
||||
$this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.');
|
||||
// Make sure the description is shown.
|
||||
$result = $this->xpath('//form//div[contains(@id, :id) and normalize-space(text())=:description]', [':id' => 'edit-type--description', ':description' => t('Exposed description')]);
|
||||
$this->assertEqual(count($result), 1, 'Filter description was found.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Kernel\Plugin;
|
||||
|
||||
use Drupal\simpletest\UserCreationTrait;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the base relationship handler.
|
||||
*
|
||||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\relationship\RelationshipPluginBase
|
||||
*/
|
||||
class RelationshipJoinInTest extends RelationshipJoinTestBase {
|
||||
|
||||
use UserCreationTrait;
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Maps between the key in the expected result and the query result.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $columnMap = [
|
||||
'views_test_data_name' => 'name',
|
||||
'users_field_data_views_test_data_uid' => 'uid',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests the query result of a view with a relationship with an IN condition.
|
||||
*/
|
||||
public function testRelationshipInQuery() {
|
||||
// Update the first two Beatles to be authored by Kristiaan.
|
||||
$account_k = $this->createUser([], 'Kristiaan');
|
||||
db_query("UPDATE {views_test_data} SET uid = :uid WHERE id IN (1,2)", [':uid' => $account_k->id()]);
|
||||
|
||||
// Update the other two Beatles to be authored by Django.
|
||||
$account_d = $this->createUser([], 'Django');
|
||||
db_query("UPDATE {views_test_data} SET uid = :uid WHERE id IN (3,4)", [':uid' => $account_d->id()]);
|
||||
|
||||
// Update Meredith to be authored by Silvie.
|
||||
$account_s = $this->createUser([], 'Silvie');
|
||||
db_query("UPDATE {views_test_data} SET uid = :uid WHERE id = 5", [':uid' => $account_s->id()]);
|
||||
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
|
||||
$view->displayHandlers->get('default')->overrideOption('relationships', [
|
||||
'uid' => [
|
||||
'id' => 'uid',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'uid',
|
||||
'required' => TRUE,
|
||||
],
|
||||
]);
|
||||
|
||||
$view->displayHandlers->get('default')->overrideOption('filters', [
|
||||
'uid' => [
|
||||
'id' => 'uid',
|
||||
'table' => 'users_field_data',
|
||||
'field' => 'uid',
|
||||
'relationship' => 'uid',
|
||||
],
|
||||
]);
|
||||
|
||||
$fields = $view->displayHandlers->get('default')->getOption('fields');
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', $fields + [
|
||||
'uid' => [
|
||||
'id' => 'uid',
|
||||
'table' => 'users_field_data',
|
||||
'field' => 'uid',
|
||||
'relationship' => 'uid',
|
||||
],
|
||||
]);
|
||||
|
||||
// Check for all beatles created by Kristiaan.
|
||||
$view->initHandlers();
|
||||
$view->filter['uid']->value = [$account_k->id()];
|
||||
$this->executeView($view);
|
||||
|
||||
$expected_result = [
|
||||
['name' => 'John', 'uid' => $account_k->id()],
|
||||
['name' => 'George', 'uid' => $account_k->id()],
|
||||
];
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->columnMap);
|
||||
$view->destroy();
|
||||
|
||||
// Check for all beatles created by Django. This should not return anything
|
||||
// as the 'extra' option on the join prohibits relating to any authors but
|
||||
// Kristiaan or Silvie.
|
||||
$view->initHandlers();
|
||||
$view->filter['uid']->value = [$account_d->id()];
|
||||
$this->executeView($view);
|
||||
|
||||
$expected_result = [];
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->columnMap);
|
||||
$view->destroy();
|
||||
|
||||
// Check for all people created by anyone.
|
||||
$view->initHandlers();
|
||||
$this->executeView($view);
|
||||
$expected_result = [
|
||||
['name' => 'John', 'uid' => $account_k->id()],
|
||||
['name' => 'George', 'uid' => $account_k->id()],
|
||||
['name' => 'Meredith', 'uid' => $account_s->id()],
|
||||
];
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->columnMap);
|
||||
$view->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an IN condition for the user name.
|
||||
*/
|
||||
protected function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
// Only relate if the author's name is Kristiaan or Silvie.
|
||||
$data['views_test_data']['uid']['relationship']['extra'][] = [
|
||||
'field' => 'name',
|
||||
'value' => ['Kristiaan', 'Silvie'],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
|
@ -660,8 +660,17 @@ function views_query_views_alter(AlterableInterface $query) {
|
|||
// Replaces substitutions in tables.
|
||||
foreach ($tables as $table_name => $table_metadata) {
|
||||
foreach ($table_metadata['arguments'] as $replacement_key => $value) {
|
||||
if (isset($substitutions[$value])) {
|
||||
$tables[$table_name]['arguments'][$replacement_key] = $substitutions[$value];
|
||||
if (!is_array($value)) {
|
||||
if (isset($substitutions[$value])) {
|
||||
$tables[$table_name]['arguments'][$replacement_key] = $substitutions[$value];
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($value as $sub_key => $sub_value) {
|
||||
if (isset($substitutions[$sub_value])) {
|
||||
$tables[$table_name]['arguments'][$replacement_key][$sub_key] = $substitutions[$sub_value];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -858,12 +858,13 @@ function template_preprocess_views_view_rss(&$variables) {
|
|||
// Figure out which display which has a path we're using for this feed. If
|
||||
// there isn't one, use the global $base_url
|
||||
$link_display_id = $view->display_handler->getLinkDisplay();
|
||||
if ($link_display_id && $display = $view->displayHandlers->get($link_display_id)) {
|
||||
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase $display */
|
||||
if ($link_display_id && ($display = $view->displayHandlers->get($link_display_id)) && $display->isEnabled()) {
|
||||
$url = $view->getUrl(NULL, $link_display_id);
|
||||
}
|
||||
|
||||
/** @var \Drupal\Core\Url $url */
|
||||
if ($url) {
|
||||
if (!empty($url)) {
|
||||
$url_options = ['absolute' => TRUE];
|
||||
if (!empty($view->exposed_raw_input)) {
|
||||
$url_options['query'] = $view->exposed_raw_input;
|
||||
|
|
Reference in a new issue