function ViewElementTest::testViewElementEmbed

Same name in this branch
  1. 8.9.x core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest::testViewElementEmbed()
Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest::testViewElementEmbed()
  2. 9 core/modules/views/tests/src/Functional/ViewElementTest.php \Drupal\Tests\views\Functional\ViewElementTest::testViewElementEmbed()
  3. 10 core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest::testViewElementEmbed()
  4. 10 core/modules/views/tests/src/Functional/ViewElementTest.php \Drupal\Tests\views\Functional\ViewElementTest::testViewElementEmbed()
  5. 11.x core/modules/views/tests/src/Kernel/ViewElementTest.php \Drupal\Tests\views\Kernel\ViewElementTest::testViewElementEmbed()
  6. 11.x core/modules/views/tests/src/Functional/ViewElementTest.php \Drupal\Tests\views\Functional\ViewElementTest::testViewElementEmbed()

Tests the rendered output and form output of a view element, using the embed display plugin.

File

core/modules/views/tests/src/Functional/ViewElementTest.php, line 83

Class

ViewElementTest
Tests the view render element.

Namespace

Drupal\Tests\views\Functional

Code

public function testViewElementEmbed() {
    $view = Views::getView('test_view_embed');
    $view->setDisplay();
    // 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->assertNotEmpty($xpath, 'The view container has been found on the form.');
    $xpath = $this->xpath('//div[@class="view-content"]');
    $this->assertNotEmpty($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->assertCount(5, $xpath);
    // 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 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->assertCount(1, $xpath);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.