View source
<?php
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\views\Views;
use Drupal\Tests\views\Functional\Wizard\WizardTestBase;
class WizardTest extends WizardTestBase {
use CommentTestTrait;
public static $modules = [
'node',
'comment',
];
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->drupalCreateContentType([
'type' => 'page',
'name' => t('Basic page'),
]);
$this
->addDefaultCommentField('node', 'page');
}
public function testCommentWizard() {
$view = [];
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['show[wizard_key]'] = 'comment';
$view['page[create]'] = TRUE;
$view['page[path]'] = $this
->randomMachineName(16);
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
$this
->drupalGet('admin/structure/views/add');
$this
->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
$xpath = $this
->constructFieldXpath('name', 'page[style][row_plugin]');
$fields = $this
->xpath($xpath);
$options = [];
foreach ($fields as $field) {
$items = $field
->findAll('xpath', 'option');
foreach ($items as $item) {
$options[] = $item
->getValue();
}
}
$expected_options = [
'entity:comment',
'fields',
];
$this
->assertEqual($options, $expected_options);
$view['id'] = strtolower($this
->randomMachineName(16));
$this
->drupalPostForm(NULL, $view, t('Save and edit'));
$this
->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
$user = $this
->drupalCreateUser([
'access comments',
]);
$this
->drupalLogin($user);
$view = Views::getView($view['id']);
$view
->initHandlers();
$row = $view->display_handler
->getOption('row');
$this
->assertEqual($row['type'], 'entity:comment');
$this
->assertEqual($view->filter['status']->table, 'comment_field_data');
$this
->assertEqual($view->filter['status']->field, 'status');
$this
->assertEquals('1', $view->filter['status']->value);
$this
->assertEqual($view->filter['status_node']->table, 'node_field_data');
$this
->assertEqual($view->filter['status_node']->field, 'status');
$this
->assertEquals('1', $view->filter['status_node']->value);
$this
->assertEqual($view->field['subject']->table, 'comment_field_data');
$this
->assertEqual($view->field['subject']->field, 'subject');
}
}