9c02fccdac8556c4e34486c036871083b871b376
[yaffs-website] / web / core / modules / comment / tests / src / Functional / Views / WizardTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Functional\Views;
4
5 use Drupal\comment\Tests\CommentTestTrait;
6 use Drupal\views\Views;
7 use Drupal\Tests\views\Functional\Wizard\WizardTestBase;
8
9 /**
10  * Tests the comment module integration into the wizard.
11  *
12  * @group comment
13  * @see \Drupal\comment\Plugin\views\wizard\Comment
14  */
15 class WizardTest extends WizardTestBase {
16
17   use CommentTestTrait;
18
19   /**
20    * Modules to install.
21    *
22    * @var array
23    */
24   public static $modules = ['node', 'comment'];
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp($import_test_views = TRUE) {
30     parent::setUp($import_test_views);
31     $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
32     // Add comment field to page node type.
33     $this->addDefaultCommentField('node', 'page');
34   }
35
36   /**
37    * Tests adding a view of comments.
38    */
39   public function testCommentWizard() {
40     $view = [];
41     $view['label'] = $this->randomMachineName(16);
42     $view['id'] = strtolower($this->randomMachineName(16));
43     $view['show[wizard_key]'] = 'comment';
44     $view['page[create]'] = TRUE;
45     $view['page[path]'] = $this->randomMachineName(16);
46
47     // Just triggering the saving should automatically choose a proper row
48     // plugin.
49     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
50     $this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
51
52     // If we update the type first we should get a selection of comment valid
53     // row plugins as the select field.
54
55     $this->drupalGet('admin/structure/views/add');
56     $this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
57
58     // Check for available options of the row plugin.
59     $xpath = $this->constructFieldXpath('name', 'page[style][row_plugin]');
60     $fields = $this->xpath($xpath);
61     $options = [];
62     foreach ($fields as $field) {
63       $items = $this->getAllOptions($field);
64       foreach ($items as $item) {
65         $options[] = $item->getValue();
66       }
67     }
68     $expected_options = ['entity:comment', 'fields'];
69     $this->assertEqual($options, $expected_options);
70
71     $view['id'] = strtolower($this->randomMachineName(16));
72     $this->drupalPostForm(NULL, $view, t('Save and edit'));
73     $this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
74
75     $user = $this->drupalCreateUser(['access comments']);
76     $this->drupalLogin($user);
77
78     $view = Views::getView($view['id']);
79     $view->initHandlers();
80     $row = $view->display_handler->getOption('row');
81     $this->assertEqual($row['type'], 'entity:comment');
82
83     // Check for the default filters.
84     $this->assertEqual($view->filter['status']->table, 'comment_field_data');
85     $this->assertEqual($view->filter['status']->field, 'status');
86     $this->assertTrue($view->filter['status']->value);
87     $this->assertEqual($view->filter['status_node']->table, 'node_field_data');
88     $this->assertEqual($view->filter['status_node']->field, 'status');
89     $this->assertTrue($view->filter['status_node']->value);
90
91     // Check for the default fields.
92     $this->assertEqual($view->field['subject']->table, 'comment_field_data');
93     $this->assertEqual($view->field['subject']->field, 'subject');
94   }
95
96 }