079fe99ee4af000269e8016acb21f2a5aef92d78
[yaffs-website] / web / core / modules / views / tests / src / FunctionalJavascript / Plugin / views / Handler / FieldTest.php
1 <?php
2
3 namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
4
5 use Drupal\Tests\SchemaCheckTestTrait;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\views\Tests\ViewTestData;
10
11 /**
12  * Tests the field field handler UI.
13  *
14  * @group views
15  */
16 class FieldTest extends WebDriverTestBase {
17   use SchemaCheckTestTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['node', 'views', 'views_ui', 'views_test_config'];
23
24   /**
25    * Views used by this test.
26    *
27    * @var array
28    */
29   public static $testViews = ['test_field_body'];
30
31   /**
32    * The account.
33    *
34    * @var \Drupal\user\UserInterface
35    */
36   protected $account;
37
38   /**
39    * {@inheritdoc}
40    */
41   protected function setUp() {
42     parent::setUp();
43
44     ViewTestData::createTestViews(get_class($this), ['views_test_config']);
45
46     // Disable automatic live preview to make the sequence of calls clearer.
47     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
48
49     $this->account = $this->drupalCreateUser(['administer views']);
50     $this->drupalLogin($this->account);
51
52     NodeType::create([
53       'type' => 'page',
54     ])->save();
55
56     FieldConfig::create([
57       'entity_type' => 'node',
58       'field_name' => 'body',
59       'bundle' => 'page',
60     ])->save();
61   }
62
63   public function testFormatterChanging() {
64     $web_assert = $this->assertSession();
65     $url = '/admin/structure/views/view/test_field_body';
66     $this->drupalGet($url);
67
68     $page = $this->getSession()->getPage();
69
70     $page->clickLink('Body field');
71     $web_assert->assertWaitOnAjaxRequest();
72
73     $page->fillField('options[type]', 'text_trimmed');
74     // Add a value to the trim_length setting.
75     $web_assert->assertWaitOnAjaxRequest();
76     $page->fillField('options[settings][trim_length]', '700');
77     $apply_button = $page->find('css', '.views-ui-dialog button.button--primary');
78     $this->assertTrue(!empty($apply_button));
79     $apply_button->press();
80     $web_assert->assertWaitOnAjaxRequest();
81
82     // Save the page.
83     $save_button = $page->find('css', '#edit-actions-submit');
84     $save_button->press();
85
86     // Set the body field back to 'default' and test that the trim_length
87     // settings are not in the config.
88     $this->drupalGet($url);
89     $page->clickLink('Body field');
90     $web_assert->assertWaitOnAjaxRequest();
91
92     $page->fillField('options[type]', 'text_default');
93     $web_assert->assertWaitOnAjaxRequest();
94     $apply_button = $page->find('css', '.views-ui-dialog button.button--primary');
95     $apply_button->press();
96     $web_assert->assertWaitOnAjaxRequest();
97
98     // Save the page.
99     $save_button = $page->find('css', '#edit-actions-submit');
100     $save_button->press();
101
102     $this->assertConfigSchemaByName('views.view.test_field_body');
103   }
104
105 }