X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FTests%2FViewElementTest.php;fp=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FTests%2FViewElementTest.php;h=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=ff11dc2c765d82131b43ff78a388e79cd1a7464a;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/views/src/Tests/ViewElementTest.php b/web/core/modules/views/src/Tests/ViewElementTest.php deleted file mode 100644 index ff11dc2c7..000000000 --- a/web/core/modules/views/src/Tests/ViewElementTest.php +++ /dev/null @@ -1,173 +0,0 @@ -enableViewsTestModule(); - } - - /** - * Tests the rendered output and form output of a view element. - */ - public function testViewElement() { - /** @var \Drupal\Core\Render\RendererInterface $renderer */ - $renderer = $this->container->get('renderer'); - $view = Views::getView('test_view_embed'); - - // Get the render array, #embed must be FALSE since this is the default - // display. - $render = $view->buildRenderable(); - $this->assertEqual($render['#embed'], FALSE); - $this->setRawContent($renderer->renderRoot($render)); - - $xpath = $this->xpath('//div[@class="views-element-container"]'); - $this->assertTrue($xpath, 'The view container has been found in the rendered output.'); - - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found in the rendered output.'); - // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 5); - - // Test a form. - $this->drupalGet('views_test_data_element_form'); - - $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); - $this->assertTrue($xpath, 'The view container has been found on the form.'); - - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found on the form.'); - // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 5); - - // Add an argument and save the view. - $view->displayHandlers->get('default')->overrideOption('arguments', [ - 'age' => [ - 'default_action' => 'ignore', - 'title' => '', - 'default_argument_type' => 'fixed', - 'validate' => [ - 'type' => 'none', - 'fail' => 'not found', - ], - 'break_phrase' => FALSE, - 'not' => FALSE, - 'id' => 'age', - 'table' => 'views_test_data', - 'field' => 'age', - 'plugin_id' => 'numeric', - ] - ]); - $view->save(); - - // Test the render array again. - $view = Views::getView('test_view_embed'); - $render = $view->buildRenderable(NULL, [25]); - $this->setRawContent($renderer->renderRoot($render)); - // There should be 1 row in the results, 'John' arg 25. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 1); - - // Test that the form has the same expected result. - $this->drupalGet('views_test_data_element_form'); - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 1); - } - - /** - * Tests the rendered output and form output of a view element, using the - * embed display plugin. - */ - public function testViewElementEmbed() { - /** @var \Drupal\Core\Render\RendererInterface $renderer */ - $renderer = $this->container->get('renderer'); - $view = Views::getView('test_view_embed'); - - // Get the render array, #embed must be TRUE since this is an embed display. - $render = $view->buildRenderable('embed_1'); - $this->assertEqual($render['#embed'], TRUE); - $this->setRawContent($renderer->renderRoot($render)); - - $xpath = $this->xpath('//div[@class="views-element-container"]'); - $this->assertTrue($xpath, 'The view container has been found in the rendered output.'); - - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found in the rendered output.'); - // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 5); - - // Test a form. - $this->drupalGet('views_test_data_element_embed_form'); - - $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); - $this->assertTrue($xpath, 'The view container has been found on the form.'); - - $xpath = $this->xpath('//div[@class="view-content"]'); - $this->assertTrue($xpath, 'The view content has been found on the form.'); - // There should be 5 rows in the results. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 5); - - // Add an argument and save the view. - $view->displayHandlers->get('default')->overrideOption('arguments', [ - 'age' => [ - 'default_action' => 'ignore', - 'title' => '', - 'default_argument_type' => 'fixed', - 'validate' => [ - 'type' => 'none', - 'fail' => 'not found', - ], - 'break_phrase' => FALSE, - 'not' => FALSE, - 'id' => 'age', - 'table' => 'views_test_data', - 'field' => 'age', - 'plugin_id' => 'numeric', - ] - ]); - $view->save(); - - // Test the render array again. - $view = Views::getView('test_view_embed'); - $render = $view->buildRenderable('embed_1', [25]); - $this->setRawContent($renderer->renderRoot($render)); - // There should be 1 row in the results, 'John' arg 25. - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 1); - - // Test that the form has the same expected result. - $this->drupalGet('views_test_data_element_embed_form'); - $xpath = $this->xpath('//div[@class="view-content"]/div'); - $this->assertEqual(count($xpath), 1); - - // Tests the render array with an exposed filter. - $view = Views::getView('test_view_embed'); - $render = $view->buildRenderable('embed_2'); - $this->setRawContent($renderer->renderRoot($render)); - - // Ensure that the exposed form is rendered. - $this->assertEqual(1, count($this->xpath('//form[@class="views-exposed-form"]'))); - } - -}