9a9b2da4a8d154f36096ea0e9c6c2f46544f0304
[yaffs-website] / web / core / modules / views / tests / src / FunctionalJavascript / Plugin / views / Handler / GroupedExposedFilterTest.php
1 <?php
2
3 namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\views\Tests\ViewTestData;
9
10 /**
11  * Tests the grouped exposed filter admin UI.
12  *
13  * @group views
14  */
15 class GroupedExposedFilterTest extends JavascriptTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['node', 'views', 'views_ui', 'user', 'views_test_config'];
21
22   /**
23    * Views used by this test.
24    *
25    * @var array
26    */
27   public static $testViews = ['test_exposed_admin_ui'];
28
29   /**
30    * The account.
31    *
32    * @var \Drupal\user\UserInterface
33    */
34   protected $account;
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function setUp() {
40     parent::setUp();
41
42     ViewTestData::createTestViews(get_class($this), ['views_test_config']);
43
44     // Disable automatic live preview to make the sequence of calls clearer.
45     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
46
47     $this->account = $this->drupalCreateUser(['administer views']);
48     $this->drupalLogin($this->account);
49
50     // Setup a node type that has the right fields for the test view.
51     NodeType::create([
52       'type' => 'page',
53     ])->save();
54
55     FieldConfig::create([
56       'entity_type' => 'node',
57       'field_name' => 'body',
58       'bundle' => 'page',
59     ])->save();
60   }
61
62   /**
63    * Test if the right fields are shown and the right values set.
64    */
65   public function testGroupedFilterValuesUI() {
66     $web_assert = $this->assertSession();
67
68     $this->drupalGet('/admin/structure/views/view/test_exposed_admin_ui');
69     $page = $this->getSession()->getPage();
70
71     // Open the dialog for the grouped filter.
72     $page->clickLink('Content: Authored on (grouped)');
73     $web_assert->assertWaitOnAjaxRequest();
74
75     // Test that the 'min' field is shown and that it contains the right value.
76     $between_from = $page->findField('options[group_info][group_items][1][value][min]');
77     $this->assertNotEmpty($between_from->isVisible());
78     $this->assertEquals('2015-01-01', $between_from->getValue());
79
80     // Test that the 'max' field is shown and that it contains the right value.
81     $between_to = $page->findField('options[group_info][group_items][1][value][max]');
82     $this->assertNotEmpty($between_to->isVisible());
83     $this->assertEquals('2016-01-01', $between_to->getValue());
84
85     $weight = $page->findField('options[group_info][group_items][1][weight]');
86
87     // If there are 3 items, values from -3 to 3 should be available.
88     $this->assertFalse($weight->find('named', ['option', -4]));
89     foreach (range(-3, 3) as $value) {
90       $this->assertTrue($weight->find('named', ['option', $value]));
91     }
92     $this->assertFalse($weight->find('named', ['option', 4]));
93
94     $page->pressButton("Add another item");
95     $web_assert->waitForField('options[group_info][group_items][4][title]');
96
97     // A new items was added, weight options should now be -4 to 4.
98     $this->assertFalse($weight->find('named', ['option', -5]));
99     foreach (range(-4, 4) as $value) {
100       $this->assertTrue($weight->find('named', ['option', $value]));
101     }
102     $this->assertFalse($weight->find('named', ['option', 5]));
103   }
104
105 }