3 namespace Drupal\comment\Tests\Views;
5 use Drupal\comment\Tests\CommentTestTrait;
6 use Drupal\views\Views;
7 use Drupal\views\Tests\Wizard\WizardTestBase;
10 * Tests the comment module integration into the wizard.
13 * @see \Drupal\comment\Plugin\views\wizard\Comment
15 class WizardTest extends WizardTestBase {
24 public static $modules = ['node', 'comment'];
30 protected function setUp() {
32 $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
33 // Add comment field to page node type.
34 $this->addDefaultCommentField('node', 'page');
38 * Tests adding a view of comments.
40 public function testCommentWizard() {
42 $view['label'] = $this->randomMachineName(16);
43 $view['id'] = strtolower($this->randomMachineName(16));
44 $view['show[wizard_key]'] = 'comment';
45 $view['page[create]'] = TRUE;
46 $view['page[path]'] = $this->randomMachineName(16);
48 // Just triggering the saving should automatically choose a proper row
50 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
51 $this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
53 // If we update the type first we should get a selection of comment valid
54 // row plugins as the select field.
56 $this->drupalGet('admin/structure/views/add');
57 $this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
59 // Check for available options of the row plugin.
60 $xpath = $this->constructFieldXpath('name', 'page[style][row_plugin]');
61 $fields = $this->xpath($xpath);
63 foreach ($fields as $field) {
64 $items = $this->getAllOptions($field);
65 foreach ($items as $item) {
66 $options[] = $item->attributes()->value;
69 $expected_options = ['entity:comment', 'fields'];
70 $this->assertEqual($options, $expected_options);
72 $view['id'] = strtolower($this->randomMachineName(16));
73 $this->drupalPostForm(NULL, $view, t('Save and edit'));
74 $this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
76 $user = $this->drupalCreateUser(['access comments']);
77 $this->drupalLogin($user);
79 $view = Views::getView($view['id']);
80 $view->initHandlers();
81 $row = $view->display_handler->getOption('row');
82 $this->assertEqual($row['type'], 'entity:comment');
84 // Check for the default filters.
85 $this->assertEqual($view->filter['status']->table, 'comment_field_data');
86 $this->assertEqual($view->filter['status']->field, 'status');
87 $this->assertTrue($view->filter['status']->value);
88 $this->assertEqual($view->filter['status_node']->table, 'node_field_data');
89 $this->assertEqual($view->filter['status_node']->field, 'status');
90 $this->assertTrue($view->filter['status_node']->value);
92 // Check for the default fields.
93 $this->assertEqual($view->field['subject']->table, 'comment_field_data');
94 $this->assertEqual($view->field['subject']->field, 'subject');