RearrangeFieldsTest.php in Zircon Profile 8.0
File
core/modules/views_ui/src/Tests/RearrangeFieldsTest.php
View source
<?php
namespace Drupal\views_ui\Tests;
use Drupal\views\Views;
class RearrangeFieldsTest extends UITestBase {
public static $testViews = array(
'test_view',
);
protected function getViewFields($view_name = 'test_view', $display_id = 'default') {
$view = Views::getView($view_name);
$view
->setDisplay($display_id);
$fields = array();
foreach ($view->displayHandlers
->get('default')
->getHandlers('field') as $field => $handler) {
$fields[] = $field;
}
return $fields;
}
protected function assertFieldOrder($view_name, $fields) {
$this
->drupalGet('admin/structure/views/nojs/rearrange/' . $view_name . '/default/field');
foreach ($fields as $idx => $field) {
$this
->assertFieldById('edit-fields-' . $field . '-weight', $idx + 1);
}
}
public function testRearrangeFields() {
$view_name = 'test_view';
$this
->assertFieldOrder($view_name, $this
->getViewFields($view_name));
$fields = array();
$this
->drupalPostForm('admin/structure/views/nojs/rearrange/' . $view_name . '/default/field', $fields, t('Apply'));
$this
->assertFieldOrder($view_name, $this
->getViewFields($view_name));
$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);
$this
->assertEqual(count($this
->cssSelect('a.views-remove-link')), count($fields));
}
}