You are here

public function ViewsXMLBackendSortingTest::testSortingViewsXMLBackend in Views XML Backend 8

Tests Views XML Backend View sorting.

File

src/Tests/ViewsXMLBackendSortingTest.php, line 21
Contains \Drupal\views_xml_backend\Tests\ViewsXMLBackendSortingTest.

Class

ViewsXMLBackendSortingTest
Tests sorting functions from the Views XML Backend module.

Namespace

Drupal\views_xml_backend\Tests

Code

public function testSortingViewsXMLBackend() {
  $this
    ->addStandardXMLBackendView();

  // Check add sorting ability
  $this
    ->drupalPostForm("admin/structure/views/nojs/add-handler/{$this->viewsXMLBackendViewId}/default/sort", array(
    'name[views_xml_backend.text]' => 'views_xml_backend.text',
  ), t('Add and configure @handler', array(
    '@handler' => t('sort criteria'),
  )));
  $this
    ->assertField('options[xpath_selector]', "The XML input 'options[xpath_selector]' was found");
  $fields = [
    'options[xpath_selector]' => 'download_link',
    'options[order]' => 'DESC',
  ];
  $this
    ->drupalPostForm(NULL, $fields, t('Apply'));
  $this
    ->drupalGet("admin/structure/views/nojs/handler/{$this->viewsXMLBackendViewId}/default/sort/text");
  $this
    ->assertFieldByXPath("//input[@id='edit-options-xpath-selector']", 'download_link', "Value 'download_link' found in field 'edit-options-xpath-selector'");
  $field_id = $this
    ->xpath("//*[starts-with(@id, 'edit-options-order-desc')]/@id");
  $new_field_id = (string) $field_id[0]['id'];
  $this
    ->assertFieldByXPath("//input[@id='{$new_field_id}']", 'DESC', "Value 'DESC' found in field {$new_field_id}");
}