annotate core/modules/views_ui/src/Tests/RowUITest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\views_ui\Tests;
Chris@0 4
Chris@0 5 use Drupal\Core\Entity\Entity\EntityViewMode;
Chris@0 6 use Drupal\views\Views;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Tests the UI of row plugins.
Chris@0 10 *
Chris@0 11 * @group views_ui
Chris@0 12 * @see \Drupal\views_test_data\Plugin\views\row\RowTest.
Chris@0 13 */
Chris@0 14 class RowUITest extends UITestBase {
Chris@0 15
Chris@0 16 /**
Chris@0 17 * Views used by this test.
Chris@0 18 *
Chris@0 19 * @var array
Chris@0 20 */
Chris@0 21 public static $testViews = ['test_view'];
Chris@0 22
Chris@0 23 /**
Chris@0 24 * Tests changing the row plugin and changing some options of a row.
Chris@0 25 */
Chris@0 26 public function testRowUI() {
Chris@0 27 $view_name = 'test_view';
Chris@0 28 $view_edit_url = "admin/structure/views/view/$view_name/edit";
Chris@0 29
Chris@0 30 $row_plugin_url = "admin/structure/views/nojs/display/$view_name/default/row";
Chris@0 31 $row_options_url = "admin/structure/views/nojs/display/$view_name/default/row_options";
Chris@0 32
Chris@0 33 $this->drupalGet($row_plugin_url);
Chris@0 34 $this->assertFieldByName('row[type]', 'fields', 'The default row plugin selected in the UI should be fields.');
Chris@0 35
Chris@0 36 $edit = [
Chris@0 37 'row[type]' => 'test_row'
Chris@0 38 ];
Chris@0 39 $this->drupalPostForm(NULL, $edit, t('Apply'));
Chris@0 40 $this->assertFieldByName('row_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
Chris@0 41 $random_name = $this->randomMachineName();
Chris@0 42 $edit = [
Chris@0 43 'row_options[test_option]' => $random_name
Chris@0 44 ];
Chris@0 45 $this->drupalPostForm(NULL, $edit, t('Apply'));
Chris@0 46 $this->drupalGet($row_options_url);
Chris@0 47 $this->assertFieldByName('row_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
Chris@0 48
Chris@0 49 $this->drupalPostForm($view_edit_url, [], t('Save'));
Chris@0 50 $this->assertLink(t('Test row plugin'), 0, 'Make sure the test row plugin is shown in the UI');
Chris@0 51
Chris@0 52 $view = Views::getView($view_name);
Chris@0 53 $view->initDisplay();
Chris@0 54 $row = $view->display_handler->getOption('row');
Chris@0 55 $this->assertEqual($row['type'], 'test_row', 'Make sure that the test_row got saved as used row plugin.');
Chris@0 56 $this->assertEqual($row['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
Chris@0 57
Chris@0 58 // Change the row plugin to fields using ajax.
Chris@0 59 // Note: this is the best approximation we can achieve, because we cannot
Chris@0 60 // simulate the 'openDialog' command in
Chris@0 61 // WebTestBase::drupalProcessAjaxResponse(), hence we have to make do.
Chris@0 62 $row_plugin_url_ajax = str_replace('/nojs/', '/ajax/', $row_plugin_url);
Chris@0 63 $ajax_settings = [
Chris@0 64 'accepts' => 'application/vnd.drupal-ajax',
Chris@0 65 'submit' => [
Chris@0 66 '_triggering_element_name' => 'op',
Chris@0 67 '_triggering_element_value' => 'Apply',
Chris@0 68 ],
Chris@0 69 'url' => $row_plugin_url_ajax,
Chris@0 70 ];
Chris@0 71 $this->drupalPostAjaxForm($row_plugin_url, ['row[type]' => 'fields'], NULL, $row_plugin_url_ajax, [], [], NULL, $ajax_settings);
Chris@0 72 $this->drupalGet($row_plugin_url);
Chris@0 73 $this->assertResponse(200);
Chris@0 74 $this->assertFieldByName('row[type]', 'fields', 'Make sure that the fields got saved as used row plugin.');
Chris@0 75
Chris@0 76 // Ensure that entity row plugins appear.
Chris@0 77 $view_name = 'content';
Chris@0 78 $row_plugin_url = "admin/structure/views/nojs/display/$view_name/default/row";
Chris@0 79 $row_options_url = "admin/structure/views/nojs/display/$view_name/default/row_options";
Chris@0 80
Chris@0 81 $this->drupalGet($row_plugin_url);
Chris@0 82 $this->assertFieldByName('row[type]', 'entity:node');
Chris@0 83 $this->drupalPostForm(NULL, ['row[type]' => 'entity:node'], t('Apply'));
Chris@0 84 $this->assertUrl($row_options_url);
Chris@0 85 $this->assertFieldByName('row_options[view_mode]', 'teaser');
Chris@0 86
Chris@0 87 // Change the teaser label to have markup so we can test escaping.
Chris@0 88 $teaser = EntityViewMode::load('node.teaser');
Chris@0 89 $teaser->set('label', 'Teaser <em>markup</em>');
Chris@0 90 $teaser->save();
Chris@0 91 $this->drupalGet('admin/structure/views/view/frontpage/edit/default');
Chris@0 92 $this->assertEscaped('Teaser <em>markup</em>');
Chris@0 93 }
Chris@0 94
Chris@0 95 }