You are here

public function WizardTest::testCommentWizard in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/Views/WizardTest.php \Drupal\comment\Tests\Views\WizardTest::testCommentWizard()

Tests adding a view of comments.

File

core/modules/comment/src/Tests/Views/WizardTest.php, line 45
Contains \Drupal\comment\Tests\Views\WizardTest.

Class

WizardTest
Tests the comment module integration into the wizard.

Namespace

Drupal\comment\Tests\Views

Code

public function testCommentWizard() {
  $view = array();
  $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);

  // Just triggering the saving should automatically choose a proper row
  // plugin.
  $this
    ->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
  $this
    ->assertUrl('admin/structure/views/view/' . $view['id'], array(), 'Make sure the view saving was successful and the browser got redirected to the edit page.');

  // If we update the type first we should get a selection of comment valid
  // row plugins as the select field.
  $this
    ->drupalGet('admin/structure/views/add');
  $this
    ->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));

  // Check for available options of the row plugin.
  $xpath = $this
    ->constructFieldXpath('name', 'page[style][row_plugin]');
  $fields = $this
    ->xpath($xpath);
  $options = array();
  foreach ($fields as $field) {
    $items = $this
      ->getAllOptions($field);
    foreach ($items as $item) {
      $options[] = $item
        ->attributes()->value;
    }
  }
  $expected_options = array(
    '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'], array(), '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');

  // Check for the default filters.
  $this
    ->assertEqual($view->filter['status']->table, 'comment_field_data');
  $this
    ->assertEqual($view->filter['status']->field, 'status');
  $this
    ->assertTrue($view->filter['status']->value);
  $this
    ->assertEqual($view->filter['status_node']->table, 'node_field_data');
  $this
    ->assertEqual($view->filter['status_node']->field, 'status');
  $this
    ->assertTrue($view->filter['status_node']->value);

  // Check for the default fields.
  $this
    ->assertEqual($view->field['subject']->table, 'comment_field_data');
  $this
    ->assertEqual($view->field['subject']->field, 'subject');
}