GroupByTest.php 1.66 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\views_ui\Functional;
4 5 6

/**
 * Tests UI of aggregate functionality..
7 8
 *
 * @group views_ui
9
 */
10
class GroupByTest extends UITestBase {
11

12 13 14 15 16
  /**
   * Views used by this test.
   *
   * @var array
   */
17
  public static $testViews = ['test_views_groupby_save'];
18

19 20 21
  /**
   * Tests whether basic saving works.
   *
22
   * @todo This should check the change of the settings as well.
23
   */
24
  public function testGroupBySave() {
25 26
    $this->drupalGet('admin/structure/views/view/test_views_groupby_save/edit');

27 28
    $edit_groupby_url = 'admin/structure/views/nojs/handler-group/test_views_groupby_save/default/field/id';
    $this->assertNoLinkByHref($edit_groupby_url, 0, 'No aggregation link found.');
29 30

    // Enable aggregation on the view.
31
    $edit = [
32
      'group_by' => TRUE,
33
    ];
34
    $this->drupalPostForm('admin/structure/views/nojs/display/test_views_groupby_save/default/group_by', $edit, t('Apply'));
35

36
    $this->assertLinkByHref($edit_groupby_url, 0, 'Aggregation link found.');
37 38

    // Change the groupby type in the UI.
39
    $this->drupalPostForm($edit_groupby_url, ['options[group_type]' => 'count'], t('Apply'));
40
    $this->assertLink('COUNT(Views test: ID)', 0, 'The count setting is displayed in the UI');
41

42
    $this->drupalPostForm(NULL, [], t('Save'));
43

44
    $view = $this->container->get('entity.manager')->getStorage('view')->load('test_views_groupby_save');
45 46 47
    $display = $view->getDisplay('default');
    $this->assertTrue($display['display_options']['group_by'], 'The groupby setting was saved on the view.');
    $this->assertEqual($display['display_options']['fields']['id']['group_type'], 'count', 'Count groupby_type was saved on the view.');
48
  }
49

50
}