You are here

protected function ViewsXMLBackendBase::addStandardXMLBackendView in Views XML Backend 8

Adds and verifies that a new Views XML Backend View can be created and specific basic Views XML Backend settings can be set.

4 calls to ViewsXMLBackendBase::addStandardXMLBackendView()
ViewsXMLBackendAddTest::testAddStandardViewsXMLBackend in src/Tests/ViewsXMLBackendAddTest.php
Tests Views XML Backend View can set Query Settings for XML source and set existing/new XML fields.
ViewsXMLBackendFilteringTest::testFilteringViewsXMLBackend in src/Tests/ViewsXMLBackendFilteringTest.php
Tests Views XML Backend View filtering.
ViewsXMLBackendPagingTest::testPagingViewsXMLBackend in src/Tests/ViewsXMLBackendPagingTest.php
Tests Views XML Backend View paging.
ViewsXMLBackendSortingTest::testSortingViewsXMLBackend in src/Tests/ViewsXMLBackendSortingTest.php
Tests Views XML Backend View sorting.

File

src/Tests/ViewsXMLBackendBase.php, line 215
Contains \Drupal\views_xml_backend\Tests\ViewsXMLBackendBase.

Class

ViewsXMLBackendBase
Provides supporting functions for testing the Views XML Backend module.

Namespace

Drupal\views_xml_backend\Tests

Code

protected function addStandardXMLBackendView() {
  $this
    ->addMinimalXMLBackendView();

  // Update the Query Settings
  $this
    ->drupalGet($this->viewsXMLBackendViewQueryPath);
  $this
    ->assertField('query[options][xml_file]', "The XML select option 'query[options][xml_file]' was found");
  $this
    ->assertField('query[options][row_xpath]', "The XML select option 'query[options][row_xpath]' was found");

  // Update the Query settings on the new View to use an XML file as source.
  $xml_setting = [
    'query[options][xml_file]' => $this->viewsXMLBackendFile,
    'query[options][row_xpath]' => "/project/releases/release",
  ];
  $this
    ->drupalPostForm($this->viewsXMLBackendViewQueryPath, $xml_setting, t('Apply'));
  $this
    ->drupalPostForm($this->viewsXMLBackendViewEditPath, array(), t('Save'));

  // Check that the Query Settings are saved into the view itself.
  $view = Views::getView($this->viewsXMLBackendViewId);
  $view
    ->initDisplay();
  $view
    ->initQuery();
  $this
    ->assertEqual($this->viewsXMLBackendFile, $view->query->options['xml_file'], 'Query settings were saved');

  // Update and confirm the default XML field on the new View.
  $this
    ->drupalGet("admin/structure/views/view/{$this->viewsXMLBackendViewId}/edit");
  $this
    ->assertResponse(200);
  $this
    ->drupalPostForm(NULL, $edit = array(), t('Update preview'));
  $edit_handler_url = "admin/structure/views/nojs/handler/{$this->viewsXMLBackendViewId}/default/field/text";
  $this
    ->drupalGet($edit_handler_url);
  $fields = [
    'options[xpath_selector]' => 'version_major',
  ];
  $this
    ->drupalPostForm(NULL, $fields, t('Apply'));
  $this
    ->drupalPostForm(NULL, $edit = array(), t('Update preview'));
  $edit_handler_url = "admin/structure/views/nojs/handler/{$this->viewsXMLBackendViewId}/default/field/text";
  $this
    ->drupalGet($edit_handler_url);
  $field_id = $this
    ->xpath("//*[starts-with(@id, 'edit-options-xpath-selector')]/@id");
  $new_field_id = (string) $field_id[0]['id'];
  $this
    ->assertFieldByXPath("//input[@id='{$new_field_id}']", 'version_major', "Value 'version_major' found in field {$new_field_id}");

  // Add and confirm a new XML field on the new View.
  $field_add = "/admin/structure/views/nojs/add-handler/{$this->viewsXMLBackendViewId}/default/field";
  $this
    ->drupalGet($field_add);
  $this
    ->assertField('name[views_xml_backend.text]', "The XML check field 'name[views_xml_backend.text]' was found");
  $fields = [
    'name[views_xml_backend.text]' => 'views_xml_backend.text',
  ];
  $this
    ->drupalPostForm(NULL, $fields, t('Add and configure fields'));
  $this
    ->assertField('options[xpath_selector]', "The XML input 'options[xpath_selector]' was found");
  $fields = [
    'options[xpath_selector]' => 'download_link',
  ];
  $this
    ->drupalPostForm(NULL, $fields, t('Apply'));
  $this
    ->drupalPostForm(NULL, $edit = array(), t('Update preview'));
  $edit_handler_url = "admin/structure/views/nojs/handler/{$this->viewsXMLBackendViewId}/default/field/text_1";
  $this
    ->drupalGet($edit_handler_url);
  $field_id = $this
    ->xpath("//*[starts-with(@id, 'edit-options-xpath-selector')]/@id");
  $new_field_id = (string) $field_id[0]['id'];
  $this
    ->assertFieldByXPath("//input[@id='{$new_field_id}']", 'download_link', "Value 'download_link' found in field {$new_field_id}");
}