diff -u b/core/modules/views/tests/src/Functional/ViewTestBase.php b/core/modules/views/tests/src/Functional/ViewTestBase.php --- b/core/modules/views/tests/src/Functional/ViewTestBase.php +++ b/core/modules/views/tests/src/Functional/ViewTestBase.php @@ -2,6 +2,7 @@ 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; @@ -93,17 +94,23 @@ * * @param string $id * The HTML ID of the button - * @param string $label + * @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. * - * @return bool - * TRUE if the assertion was successful, or FALSE on failure. + * @throws \Behat\Mink\Exception\ElementNotFoundException */ protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') { - return $this->assertFieldById($id, $expected_label, t($message, ['%label' => $expected_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()); } /** only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/PluginTestBase.php +++ b/core/modules/views/src/Tests/Plugin/PluginTestBase.php @@ -1,11 +1,13 @@ enableViewsTestModule(); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/ArgumentDefaultTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } @@ -161,9 +161,9 @@ public function testArgumentDefaultNode() { $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())); } /** only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/CacheTagTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php @@ -1,6 +1,6 @@ drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/CacheWebTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/CacheWebTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/ContextualFiltersBlockContextTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ContextualFiltersBlockContextTest.php @@ -1,10 +1,9 @@ enableViewsTestModule(); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisabledDisplayTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); @@ -56,7 +56,7 @@ public function testDisabledDisplays() { // 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 +75,7 @@ public function testDisabledDisplays() { // 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) { only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/DisplayAttachmentTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayAttachmentTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php @@ -1,6 +1,6 @@ drupalLogin($this->drupalCreateUser(['administer views'])); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/DisplayFeedTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); $this->drupalPlaceBlock('local_tasks_block'); @@ -55,13 +55,13 @@ public function testArguments() { $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 +72,13 @@ public function testArguments() { $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 +88,11 @@ public function testPageDisplayMenu() { // 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 +100,11 @@ public function testPageDisplayMenu() { $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 +114,7 @@ public function testPageDisplayMenu() { $this->drupalGet(''); $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 +123,7 @@ public function testPageDisplayMenu() { $this->drupalGet(''); $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'); } /** only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php @@ -1,9 +1,8 @@ enableViewsTestModule(); @@ -94,6 +93,7 @@ public function testDisplayPlugin() { // Check the test option. $this->assertIdentical($view->display_handler->getOption('test_option'), ''); + $this->setExpectedException(\PHPUnit_Framework_Error::class); $output = $view->preview(); $output = $renderer->renderRoot($output); @@ -103,6 +103,7 @@ public function testDisplayPlugin() { $view->display_handler->overrideOption('test_option', 'Test option title'); $view->save(); + $this->setExpectedException(\PHPUnit_Framework_Error::class); $output = $view->preview(); $output = $renderer->renderRoot($output); @@ -161,76 +162,6 @@ public function testGetAttachedDisplays() { } /** - * 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. */ public function testReadMoreNoDisplay() { @@ -290,7 +221,8 @@ public function testInvalidDisplayPlugins() { $this->drupalGet(''); $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 +234,8 @@ public function testInvalidDisplayPlugins() { $this->drupalGet(''); $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)); } /** only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/ExposedFormTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); @@ -192,26 +192,6 @@ public function testResetButton() { } /** - * 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. */ public function testExposedFormRenderCheckboxes() { @@ -265,7 +245,8 @@ public function testExposedBlock() { // 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 @@ protected function assertIds(array $ids) { $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); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/FilterTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/MenuLinkTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php @@ -1,16 +1,15 @@ enableViewsTestModule(); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/MiniPagerTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/MiniPagerTest.php @@ -1,6 +1,6 @@ drupalCreateContentType(['type' => 'page']); // Create a bunch of test nodes. only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php @@ -1,17 +1,16 @@ drupalCreateUser(['administer views', 'administer languages']); $this->drupalLogin($web_user); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/PagerTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php @@ -1,6 +1,6 @@ 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 +99,13 @@ public function testSummaryView() { $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'); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/StyleTableTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/StyleTableTest.php @@ -1,6 +1,6 @@ enableViewsTestModule(); } @@ -33,17 +33,17 @@ protected function setUp() { 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 +52,8 @@ public function testAccessibilitySettings() { $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 +61,7 @@ public function testAccessibilitySettings() { $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 +70,7 @@ public function testAccessibilitySettings() { $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.'); } only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/StyleTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/StyleTest.php @@ -1,9 +1,8 @@ enableViewsTestModule(); } only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/ViewsBulkTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ViewsBulkTest.php @@ -1,15 +1,13 @@ drupalCreateContentType(['type' => 'page']); $this->admin_user = $this->createUser(['bypass node access', 'administer nodes', 'access content overview']); only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/ViewsFormTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ViewsFormTest.php @@ -1,15 +1,13 @@ enableViewsTestModule(); } only in patch2: unchanged: --- a/core/modules/views/src/Tests/Plugin/DisplayExtenderTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php @@ -1,7 +1,8 @@ enableViewsTestModule(); - } - /** * Test display extenders. */ only in patch2: unchanged: --- a/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php @@ -4,6 +4,7 @@ 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,74 @@ public function testDependencies() { $this->assertIdentical($expected, $view->getDependencies()); } + /** + * 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.'); + } + } only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php @@ -0,0 +1,55 @@ +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.'); + } + +}