You are here

public function RearrangeFieldsTest::testRearrangeFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/Tests/RearrangeFieldsTest.php \Drupal\views_ui\Tests\RearrangeFieldsTest::testRearrangeFields()

Tests field sorting.

File

core/modules/views_ui/src/Tests/RearrangeFieldsTest.php, line 59
Contains \Drupal\views_ui\Tests\RearrangeFieldsTest.

Class

RearrangeFieldsTest
Tests the reordering of fields via AJAX.

Namespace

Drupal\views_ui\Tests

Code

public function testRearrangeFields() {
  $view_name = 'test_view';

  // Checks that the order on the rearrange form matches the creation order.
  $this
    ->assertFieldOrder($view_name, $this
    ->getViewFields($view_name));

  // Checks that a field is not deleted if a value is not passed back.
  $fields = array();
  $this
    ->drupalPostForm('admin/structure/views/nojs/rearrange/' . $view_name . '/default/field', $fields, t('Apply'));
  $this
    ->assertFieldOrder($view_name, $this
    ->getViewFields($view_name));

  // Checks that revers the new field order is respected.
  $reversedFields = array_reverse($this
    ->getViewFields($view_name));
  $fields = array();
  foreach ($reversedFields as $delta => $field) {
    $fields['fields[' . $field . '][weight]'] = $delta;
  }
  $this
    ->drupalPostForm('admin/structure/views/nojs/rearrange/' . $view_name . '/default/field', $fields, t('Apply'));
  $this
    ->assertFieldOrder($view_name, $reversedFields);

  // Checks that there is a remove link for each field.
  $this
    ->assertEqual(count($this
    ->cssSelect('a.views-remove-link')), count($fields));
}