Chris@0: enableViewsTestModule(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the rendered output and form output of a view element. Chris@0: */ Chris@0: public function testViewElement() { Chris@0: $view = Views::getView('test_view_embed'); Chris@0: $view->setDisplay(); Chris@0: // Test a form. Chris@0: $this->drupalGet('views_test_data_element_form'); Chris@0: Chris@0: $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); Chris@0: $this->assertTrue($xpath, 'The view container has been found on the form.'); Chris@0: Chris@0: $xpath = $this->xpath('//div[@class="view-content"]'); Chris@0: $this->assertTrue($xpath, 'The view content has been found on the form.'); Chris@0: // There should be 5 rows in the results. Chris@0: $xpath = $this->xpath('//div[@class="view-content"]/div'); Chris@0: $this->assertEqual(count($xpath), 5); Chris@0: Chris@0: // Add an argument and save the view. Chris@0: $view->displayHandlers->get('default')->overrideOption('arguments', [ Chris@0: 'age' => [ Chris@0: 'default_action' => 'ignore', Chris@0: 'title' => '', Chris@0: 'default_argument_type' => 'fixed', Chris@0: 'validate' => [ Chris@0: 'type' => 'none', Chris@0: 'fail' => 'not found', Chris@0: ], Chris@0: 'break_phrase' => FALSE, Chris@0: 'not' => FALSE, Chris@0: 'id' => 'age', Chris@0: 'table' => 'views_test_data', Chris@0: 'field' => 'age', Chris@0: 'plugin_id' => 'numeric', Chris@0: ], Chris@0: ]); Chris@0: $view->save(); Chris@0: Chris@0: // Test that the form has the expected result. Chris@0: $this->drupalGet('views_test_data_element_form'); Chris@0: $xpath = $this->xpath('//div[@class="view-content"]/div'); Chris@0: $this->assertEqual(count($xpath), 1); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the rendered output and form output of a view element, using the Chris@0: * embed display plugin. Chris@0: */ Chris@0: public function testViewElementEmbed() { Chris@0: $view = Views::getView('test_view_embed'); Chris@0: $view->setDisplay(); Chris@0: // Test a form. Chris@0: $this->drupalGet('views_test_data_element_embed_form'); Chris@0: Chris@0: $xpath = $this->xpath('//div[@class="views-element-container js-form-wrapper form-wrapper"]'); Chris@0: $this->assertTrue($xpath, 'The view container has been found on the form.'); Chris@0: Chris@0: $xpath = $this->xpath('//div[@class="view-content"]'); Chris@0: $this->assertTrue($xpath, 'The view content has been found on the form.'); Chris@0: // There should be 5 rows in the results. Chris@0: $xpath = $this->xpath('//div[@class="view-content"]/div'); Chris@0: $this->assertEqual(count($xpath), 5); Chris@0: Chris@0: // Add an argument and save the view. Chris@0: $view->displayHandlers->get('default')->overrideOption('arguments', [ Chris@0: 'age' => [ Chris@0: 'default_action' => 'ignore', Chris@0: 'title' => '', Chris@0: 'default_argument_type' => 'fixed', Chris@0: 'validate' => [ Chris@0: 'type' => 'none', Chris@0: 'fail' => 'not found', Chris@0: ], Chris@0: 'break_phrase' => FALSE, Chris@0: 'not' => FALSE, Chris@0: 'id' => 'age', Chris@0: 'table' => 'views_test_data', Chris@0: 'field' => 'age', Chris@0: 'plugin_id' => 'numeric', Chris@0: ], Chris@0: ]); Chris@0: $view->save(); Chris@0: Chris@0: // Test that the form has the same expected result. Chris@0: $this->drupalGet('views_test_data_element_embed_form'); Chris@0: $xpath = $this->xpath('//div[@class="view-content"]/div'); Chris@0: $this->assertEqual(count($xpath), 1); Chris@0: } Chris@0: Chris@0: }