Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,56 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\ArgumentUserUIDTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User;
use Drupal\views\Views;
/**
* Tests the user posted or commented argument handler.
*
* @group comment
*/
class ArgumentUserUIDTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_comment_user_uid');
function testCommentUserUIDTest() {
// Add an additional comment which is not created by the user.
$new_user = User::create(['name' => 'new user']);
$new_user->save();
$comment = Comment::create([
'uid' => $new_user->uid->value,
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => 'if a woodchuck could chuck wood.',
]);
$comment->save();
$view = Views::getView('test_comment_user_uid');
$this->executeView($view, array($this->account->id()));
$result_set = array(
array(
'nid' => $this->nodeUserPosted->id(),
),
array(
'nid' => $this->nodeUserCommented->id(),
),
);
$column_map = array('nid' => 'nid');
$this->assertIdenticalResultset($view, $result_set, $column_map);
}
}

View file

@ -0,0 +1,123 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentFieldFilterTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Tests comment field filters with translations.
*
* @group comment
*/
class CommentFieldFilterTest extends CommentTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('language');
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_field_filters');
/**
* List of comment titles by language.
*
* @var array
*/
public $commentTitles = array();
function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['access comments']));
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Set up comment titles.
$this->commentTitles = array(
'en' => 'Food in Paris',
'es' => 'Comida en Paris',
'fr' => 'Nouriture en Paris',
);
// Create a new comment. Using the one created earlier will not work,
// as it predates the language set-up.
$comment = array(
'uid' => $this->loggedInUser->id(),
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'cid' => '',
'pid' => '',
'node_type' => '',
);
$this->comment = entity_create('comment', $comment);
// Add field values and translate the comment.
$this->comment->subject->value = $this->commentTitles['en'];
$this->comment->comment_body->value = $this->commentTitles['en'];
$this->comment->langcode = 'en';
$this->comment->save();
foreach (array('es', 'fr') as $langcode) {
$translation = $this->comment->addTranslation($langcode, array());
$translation->comment_body->value = $this->commentTitles[$langcode];
$translation->subject->value = $this->commentTitles[$langcode];
}
$this->comment->save();
}
/**
* Tests body and title filters.
*/
public function testFilters() {
// Test the title filter page, which filters for title contains 'Comida'.
// Should show just the Spanish translation, once.
$this->assertPageCounts('test-title-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida title filter');
// Test the body filter page, which filters for body contains 'Comida'.
// Should show just the Spanish translation, once.
$this->assertPageCounts('test-body-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida body filter');
// Test the title Paris filter page, which filters for title contains
// 'Paris'. Should show each translation once.
$this->assertPageCounts('test-title-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris title filter');
// Test the body Paris filter page, which filters for body contains
// 'Paris'. Should show each translation once.
$this->assertPageCounts('test-body-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris body filter');
}
/**
* Asserts that the given comment translation counts are correct.
*
* @param string $path
* Path of the page to test.
* @param array $counts
* Array whose keys are languages, and values are the number of times
* that translation should be shown on the given page.
* @param string $message
* Message suffix to display.
*/
protected function assertPageCounts($path, $counts, $message) {
// Get the text of the page.
$this->drupalGet($path);
$text = $this->getTextContent();
// Check the counts. Note that the title and body are both shown on the
// page, and they are the same. So the title/body string should appear on
// the page twice as many times as the input count.
foreach ($counts as $langcode => $count) {
$this->assertEqual(substr_count($text, $this->commentTitles[$langcode]), 2 * $count, 'Translation ' . $langcode . ' has count ' . $count . ' with ' . $message);
}
}
}

View file

@ -0,0 +1,92 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentFieldNameTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\user\RoleInterface;
use Drupal\views\Views;
/**
* Tests the comment field name field.
*
* @group comment
*/
class CommentFieldNameTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_comment_field_name'];
/**
* The second comment entity used by this test.
*
* @var \Drupal\comment\CommentInterface
*/
protected $customComment;
/**
* The comment field name used by this test.
*
* @var string
*/
protected $fieldName = 'comment_custom';
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->addDefaultCommentField('node', 'page', $this->fieldName);
$this->customComment = Comment::create([
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => $this->fieldName,
]);
$this->customComment->save();
}
/**
* Test comment field name.
*/
public function testCommentFieldName() {
$view = Views::getView('test_comment_field_name');
$this->executeView($view);
$expected_result = [
[
'cid' => $this->comment->id(),
'field_name' => $this->comment->getFieldName(),
],
[
'cid' => $this->customComment->id(),
'field_name' => $this->customComment->getFieldName(),
],
];
$column_map = [
'cid' => 'cid',
'comment_field_data_field_name' => 'field_name',
];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
// Test that no data can be rendered.
$this->assertIdentical(FALSE, isset($view->field['field_name']));
// Grant permission to properly check view access on render.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
$this->container->get('account_switcher')->switchTo(new AnonymousUserSession());
$view = Views::getView('test_comment_field_name');
$this->executeView($view);
// Test that data rendered.
$this->assertIdentical($this->comment->getFieldName(), $view->field['field_name']->advancedRender($view->result[0]));
$this->assertIdentical($this->customComment->getFieldName(), $view->field['field_name']->advancedRender($view->result[1]));
}
}

View file

@ -0,0 +1,71 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentRestExportTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\Component\Serialization\Json;
/**
* Tests a comment rest export view.
*
* @group comment
*/
class CommentRestExportTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_comment_rest'];
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'comment', 'comment_test_views', 'rest', 'hal'];
protected function setUp() {
parent::setUp();
// Add another anonymous comment.
$comment = array(
'uid' => 0,
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => 'A lot, apparently',
'cid' => '',
'pid' => $this->comment->id(),
'mail' => 'someone@example.com',
'name' => 'bobby tables',
'hostname' => 'public.example.com',
);
$this->comment = entity_create('comment', $comment);
$this->comment->save();
$user = $this->drupalCreateUser(['access comments']);
$this->drupalLogin($user);
}
/**
* Test comment row.
*/
public function testCommentRestExport() {
$this->drupalGetWithFormat(sprintf('node/%d/comments', $this->nodeUserCommented->id()), 'hal_json');
$this->assertResponse(200);
$contents = Json::decode($this->getRawContent());
$this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck');
$this->assertEqual($contents[1]['subject'], 'A lot, apparently');
$this->assertEqual(count($contents), 2);
// Ensure field-level access is respected - user shouldn't be able to see
// mail or hostname fields.
$this->assertNoText('someone@example.com');
$this->assertNoText('public.example.com');
}
}

View file

@ -0,0 +1,34 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentRowTest.
*/
namespace Drupal\comment\Tests\Views;
/**
* Tests the comment row plugin.
*
* @group comment
*/
class CommentRowTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_comment_row');
/**
* Test comment row.
*/
public function testCommentRow() {
$this->drupalGet('test-comment-row');
$result = $this->xpath('//article[contains(@class, "comment")]');
$this->assertEqual(1, count($result), 'One rendered comment found.');
}
}

View file

@ -0,0 +1,94 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentTestBase.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the argument_comment_user_uid handler.
*/
abstract class CommentTestBase extends ViewTestBase {
use CommentTestTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('node', 'comment', 'comment_test_views');
/**
* A normal user with permission to post comments (without approval).
*
* @var \Drupal\user\UserInterface
*/
protected $account;
/**
* A second normal user that will author a node for $account to comment on.
*
* @var \Drupal\user\UserInterface
*/
protected $account2;
/**
* Stores a node posted by the user created as $account.
*
* @var \Drupal\node\NodeInterface
*/
protected $nodeUserPosted;
/**
* Stores a node posted by the user created as $account2.
*
* @var \Drupal\node\NodeInterface
*/
protected $nodeUserCommented;
/**
* Stores a comment used by the tests.
*
* @var \Drupal\comment\Entity\Comment
*/
protected $comment;
protected function setUp() {
parent::setUp();
ViewTestData::createTestViews(get_class($this), array('comment_test_views'));
// Add two users, create a node with the user1 as author and another node
// with user2 as author. For the second node add a comment from user1.
$this->account = $this->drupalCreateUser(array('skip comment approval'));
$this->account2 = $this->drupalCreateUser();
$this->drupalLogin($this->account);
$this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
$this->addDefaultCommentField('node', 'page');
$this->nodeUserPosted = $this->drupalCreateNode();
$this->nodeUserCommented = $this->drupalCreateNode(array('uid' => $this->account2->id()));
$comment = array(
'uid' => $this->loggedInUser->id(),
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => 'How much wood would a woodchuck chuck',
'cid' => '',
'pid' => '',
'mail' => 'someone@example.com',
);
$this->comment = entity_create('comment', $comment);
$this->comment->save();
}
}

View file

@ -0,0 +1,169 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentUserNameTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\views\Entity\View;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\Views;
/**
* Tests comment user name field
*
* @group comment
*/
class CommentUserNameTest extends ViewUnitTestBase {
/**
* Admin user.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
public static $modules = ['user', 'comment', 'entity_test'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
// Create the anonymous role.
$this->installConfig(['user']);
// Create an anonymous user.
$storage = \Drupal::entityManager()->getStorage('user');
// Insert a row for the anonymous user.
$storage
->create(array(
'uid' => 0,
'status' => 0,
))
->save();
$admin_role = Role::create([
'id' => 'admin',
'permissions' => ['administer comments', 'access user profiles'],
]);
$admin_role->save();
/* @var \Drupal\user\RoleInterface $anonymous_role */
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
$anonymous_role->grantPermission('access comments');
$anonymous_role->save();
$this->adminUser = User::create([
'name' => $this->randomMachineName(),
'roles' => [$admin_role->id()],
]);
$this->adminUser->save();
// Create some comments.
$comment = Comment::create([
'subject' => 'My comment title',
'uid' => $this->adminUser->id(),
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'status' => 1,
]);
$comment->save();
$comment_anonymous = Comment::create([
'subject' => 'Anonymous comment title',
'uid' => 0,
'name' => 'barry',
'mail' => 'test@example.com',
'homepage' => 'https://example.com',
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'created' => 123456,
'status' => 1,
]);
$comment_anonymous->save();
}
/**
* Test the username formatter.
*/
public function testUsername() {
$view_id = $this->randomMachineName();
$view = View::create([
'id' => $view_id,
'base_table' => 'comment_field_data',
'display' => [
'default' => [
'display_plugin' => 'default',
'id' => 'default',
'display_options' => [
'fields' => [
'name' => [
'table' => 'comment_field_data',
'field' => 'name',
'id' => 'name',
'plugin_id' => 'field',
'type' => 'comment_username'
],
'subject' => [
'table' => 'comment_field_data',
'field' => 'subject',
'id' => 'subject',
'plugin_id' => 'field',
'type' => 'string',
'settings' => [
'link_to_entity' => TRUE,
],
],
],
],
],
],
]);
$view->save();
/* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher = \Drupal::service('account_switcher');
/* @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$account_switcher->switchTo($this->adminUser);
$executable = Views::getView($view_id);
$build = $executable->preview();
$this->setRawContent($renderer->renderRoot($build));
$this->verbose($this->getRawContent());
$this->assertLink('My comment title');
$this->assertLink('Anonymous comment title');
$this->assertLink($this->adminUser->label());
$this->assertLink('barry (not verified)');
$account_switcher->switchTo(new AnonymousUserSession());
$executable = Views::getView($view_id);
$executable->storage->invalidateCaches();
$build = $executable->preview();
$this->setRawContent($renderer->renderRoot($build));
// No access to user-profiles, so shouldn't be able to see links.
$this->assertNoLink($this->adminUser->label());
// Note: External users aren't pointing to drupal user profiles.
$this->assertLink('barry (not verified)');
$this->verbose($this->getRawContent());
$this->assertLink('My comment title');
$this->assertLink('Anonymous comment title');
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentViewsFieldAccessTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User;
use Drupal\views\Tests\Handler\FieldFieldAccessTestBase;
/**
* Tests base field access in Views for the comment entity.
*
* @group comment
*/
class CommentViewsFieldAccessTest extends FieldFieldAccessTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'entity_test'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('comment');
}
/**
* Check access for comment fields.
*/
public function testCommentFields() {
$user = User::create([
'name' => 'test user',
]);
$user->save();
$comment = Comment::create([
'subject' => 'My comment title',
'uid' => $user->id(),
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
]);
$comment->save();
$comment_anonymous = Comment::create([
'subject' => 'Anonymous comment title',
'uid' => 0,
'name' => 'anonymous',
'mail' => 'test@example.com',
'homepage' => 'https://example.com',
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'created' => 123456,
'status' => 1,
]);
$comment_anonymous->save();
// @todo Expand the test coverage in https://www.drupal.org/node/2464635
$this->assertFieldAccess('comment', 'cid', $comment->id());
$this->assertFieldAccess('comment', 'cid', $comment_anonymous->id());
$this->assertFieldAccess('comment', 'uuid', $comment->uuid());
$this->assertFieldAccess('comment', 'subject', 'My comment title');
$this->assertFieldAccess('comment', 'subject', 'Anonymous comment title');
$this->assertFieldAccess('comment', 'name', 'anonymous');
$this->assertFieldAccess('comment', 'mail', 'test@example.com');
$this->assertFieldAccess('comment', 'homepage', 'https://example.com');
$this->assertFieldAccess('comment', 'uid', $user->getUsername());
// $this->assertFieldAccess('comment', 'created', \Drupal::service('date.formatter')->format(123456));
// $this->assertFieldAccess('comment', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));
$this->assertFieldAccess('comment', 'status', 'On');
}
}

View file

@ -0,0 +1,145 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\DefaultViewRecentCommentsTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestBase;
/**
* Tests results for the Recent Comments view shipped with the module.
*
* @group comment
*/
class DefaultViewRecentCommentsTest extends ViewTestBase {
use CommentTestTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('node', 'comment', 'block');
/**
* Number of results for the Master display.
*
* @var int
*/
protected $masterDisplayResults = 5;
/**
* Number of results for the Block display.
*
* @var int
*/
protected $blockDisplayResults = 5;
/**
* Number of results for the Page display.
*
* @var int
*/
protected $pageDisplayResults = 5;
/**
* Will hold the comments created for testing.
*
* @var array
*/
protected $commentsCreated = array();
/**
* Contains the node object used for comments of this test.
*
* @var \Drupal\node\Node
*/
public $node;
protected function setUp() {
parent::setUp();
// Create a new content type
$content_type = $this->drupalCreateContentType();
// Add a node of the new content type.
$node_data = array(
'type' => $content_type->id(),
);
$this->addDefaultCommentField('node', $content_type->id());
$this->node = $this->drupalCreateNode($node_data);
// Force a flush of the in-memory storage.
$this->container->get('views.views_data')->clear();
// Create some comments and attach them to the created node.
for ($i = 0; $i < $this->masterDisplayResults; $i++) {
/** @var \Drupal\comment\CommentInterface $comment */
$comment = entity_create('comment', array(
'status' => CommentInterface::PUBLISHED,
'field_name' => 'comment',
'entity_type' => 'node',
'entity_id' => $this->node->id(),
));
$comment->setOwnerId(0);
$comment->setSubject('Test comment ' . $i);
$comment->comment_body->value = 'Test body ' . $i;
$comment->comment_body->format = 'full_html';
// Ensure comments are sorted in ascending order.
$time = REQUEST_TIME + ($this->masterDisplayResults - $i);
$comment->setCreatedTime($time);
$comment->changed->value = $time;
$comment->save();
}
// Store all the nodes just created to access their properties on the tests.
$this->commentsCreated = Comment::loadMultiple();
// Sort created comments in descending order.
ksort($this->commentsCreated, SORT_NUMERIC);
}
/**
* Tests the block defined by the comments_recent view.
*/
public function testBlockDisplay() {
$user = $this->drupalCreateUser(['access comments']);
$this->drupalLogin($user);
$view = Views::getView('comments_recent');
$view->setDisplay('block_1');
$this->executeView($view);
$map = array(
'subject' => 'subject',
'cid' => 'cid',
'comment_field_data_created' => 'created'
);
$expected_result = array();
foreach (array_values($this->commentsCreated) as $key => $comment) {
$expected_result[$key]['subject'] = $comment->getSubject();
$expected_result[$key]['cid'] = $comment->id();
$expected_result[$key]['created'] = $comment->getCreatedTime();
}
$this->assertIdenticalResultset($view, $expected_result, $map);
// Check the number of results given by the display is the expected.
$this->assertEqual(sizeof($view->result), $this->blockDisplayResults,
format_string('There are exactly @results comments. Expected @expected',
array('@results' => count($view->result), '@expected' => $this->blockDisplayResults)
)
);
}
}

View file

@ -0,0 +1,68 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\FilterUserUIDTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User;
use Drupal\views\Views;
/**
* Tests the user posted or commented filter handler.
*
* The actual stuff is done in the parent class.
*
* @group comment
*/
class FilterUserUIDTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_comment_user_uid');
function testCommentUserUIDTest() {
$view = Views::getView('test_comment_user_uid');
$view->setDisplay();
$view->removeHandler('default', 'argument', 'uid_touch');
// Add an additional comment which is not created by the user.
$new_user = User::create(['name' => 'new user']);
$new_user->save();
$comment = Comment::create([
'uid' => $new_user->uid->value,
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => 'if a woodchuck could chuck wood.',
]);
$comment->save();
$options = array(
'id' => 'uid_touch',
'table' => 'node_field_data',
'field' => 'uid_touch',
'value' => array($this->loggedInUser->id()),
);
$view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options);
$this->executeView($view, array($this->account->id()));
$result_set = array(
array(
'nid' => $this->nodeUserPosted->id(),
),
array(
'nid' => $this->nodeUserCommented->id(),
),
);
$column_map = array('nid' => 'nid');
$this->assertIdenticalResultset($view, $result_set, $column_map);
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\RowRssTest.
*/
namespace Drupal\comment\Tests\Views;
/**
* Tests the comment rss row plugin.
*
* @group comment
* @see \Drupal\comment\Plugin\views\row\Rss
*/
class RowRssTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_comment_rss');
/**
* Test comment rss output.
*/
public function testRssRow() {
$this->drupalGet('test-comment-rss');
$result = $this->xpath('//item');
$this->assertEqual(count($result), 1, 'Just one comment was found in the rss output.');
$this->assertEqual($result[0]->pubdate, gmdate('r', $this->comment->getCreatedTime()), 'The right pubDate appears in the rss output.');
}
}

View file

@ -0,0 +1,102 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\WizardTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\views\Views;
use Drupal\views\Tests\Wizard\WizardTestBase;
/**
* Tests the comment module integration into the wizard.
*
* @group comment
* @see \Drupal\comment\Plugin\views\wizard\Comment
*/
class WizardTest extends WizardTestBase {
use CommentTestTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('node', 'comment');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
// Add comment field to page node type.
$this->addDefaultCommentField('node', 'page');
}
/**
* Tests adding a view of comments.
*/
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');
}
}