Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes

This commit is contained in:
Pantheon Automation 2016-04-20 09:56:34 -07:00 committed by Greg Anderson
parent b11a755ba8
commit c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\ArgumentUserUIDTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;

View file

@ -1,13 +1,9 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentFieldFilterTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\comment\Entity\Comment;
/**
* Tests comment field filters with translations.
@ -61,7 +57,7 @@ class CommentFieldFilterTest extends CommentTestBase {
'pid' => '',
'node_type' => '',
);
$this->comment = entity_create('comment', $comment);
$this->comment = Comment::create($comment);
// Add field values and translate the comment.
$this->comment->subject->value = $this->commentTitles['en'];

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentFieldNameTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;

View file

@ -1,180 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentLinksTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\CommentInterface;
use Drupal\comment\CommentManagerInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\Views;
/**
* Tests the comment link field handlers.
*
* @group comment
*/
class CommentLinksTest extends CommentViewKernelTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_comment'];
/**
* Test the comment approve link.
*/
public function testLinkApprove() {
// Create an unapproved comment.
$comment = $this->commentStorage->create([
'uid' => $this->adminUser->id(),
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'status' => 0,
]);
$comment->save();
$view = Views::getView('test_comment');
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('fields', [
'approve_comment' => [
'table' => 'comment',
'field' => 'approve_comment',
'id' => 'approve_comment',
'plugin_id' => 'comment_link_approve',
],
]);
$view->save();
/* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher = \Drupal::service('account_switcher');
$account_switcher->switchTo($this->adminUser);
$view->preview();
// Check if I can see the comment approve link on an unapproved comment.
$approve_comment = $view->style_plugin->getField(0, 'approve_comment');
$options = ['query' => ['destination' => '/']];
$url = Url::fromRoute('comment.approve', ['comment' => $comment->id()], $options);
$this->assertEqual(\Drupal::l('Approve', $url), (string) $approve_comment, 'Found a comment approve link for an unapproved comment.');
// Approve the comment.
$comment->setPublished(CommentInterface::PUBLISHED);
$comment->save();
$view = Views::getView('test_comment');
$view->preview();
// Check if I can see the comment approve link on an approved comment.
$approve_comment = $view->style_plugin->getField(1, 'approve_comment');
$this->assertFalse((string) $approve_comment, "Didn't find a comment approve link for an already approved comment.");
// Check if I can see the comment approve link on an approved comment as an
// anonymous user.
$account_switcher->switchTo(new AnonymousUserSession());
// Set the comment as unpublished again.
$comment->setPublished(CommentInterface::NOT_PUBLISHED);
$comment->save();
$view = Views::getView('test_comment');
$view->preview();
$replyto_comment = $view->style_plugin->getField(0, 'approve_comment');
$this->assertFalse((string) $replyto_comment, "I can't approve the comment as an anonymous user.");
}
/**
* Test the comment reply link.
*/
public function testLinkReply() {
$this->enableModules(['field', 'entity_test']);
$this->installEntitySchema('entity_test');
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installConfig(['field']);
$field_storage_comment = FieldStorageConfig::create([
'field_name' => 'comment',
'type' => 'comment',
'entity_type' => 'entity_test',
]);
$field_storage_comment->save();
// Create a comment field which allows threading.
$field_comment = FieldConfig::create([
'field_name' => 'comment',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'settings' => [
'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED,
],
]);
$field_comment->save();
$host = EntityTest::create(['name' => $this->randomString()]);
$host->save();
// Attach an unapproved comment to the test entity.
$comment = $this->commentStorage->create([
'uid' => $this->adminUser->id(),
'entity_type' => 'entity_test',
'entity_id' => $host->id(),
'comment_type' => 'entity_test',
'field_name' => $field_storage_comment->getName(),
'status' => 0,
]);
$comment->save();
$view = Views::getView('test_comment');
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('fields', [
'replyto_comment' => [
'table' => 'comment',
'field' => 'replyto_comment',
'id' => 'replyto_comment',
'plugin_id' => 'comment_link_reply',
'entity_type' => 'comment',
],
]);
$view->save();
/* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher = \Drupal::service('account_switcher');
$account_switcher->switchTo($this->adminUser);
$view->preview();
// Check if I can see the reply link on an unapproved comment.
$replyto_comment = $view->style_plugin->getField(0, 'replyto_comment');
$this->assertFalse((string) $replyto_comment, "I can't reply to an unapproved comment.");
// Approve the comment.
$comment->setPublished(CommentInterface::PUBLISHED);
$comment->save();
$view = Views::getView('test_comment');
$view->preview();
// Check if I can see the reply link on an approved comment.
$replyto_comment = $view->style_plugin->getField(0, 'replyto_comment');
$url = Url::fromRoute('comment.reply', [
'entity_type' => 'entity_test',
'entity' => $host->id(),
'field_name' => 'comment',
'pid' => $comment->id(),
]);
$this->assertEqual(\Drupal::l('Reply', $url), (string) $replyto_comment, 'Found the comment reply link as an admin user.');
// Check if I can see the reply link as an anonymous user.
$account_switcher->switchTo(new AnonymousUserSession());
$view = Views::getView('test_comment');
$view->preview();
$replyto_comment = $view->style_plugin->getField(0, 'replyto_comment');
$this->assertFalse((string) $replyto_comment, "Didn't find the comment reply link as an anonymous user.");
}
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentOperationsTest.
*/
namespace Drupal\comment\Tests\Views;
/**

View file

@ -1,13 +1,9 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentRestExportTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\Component\Serialization\Json;
use Drupal\comment\Entity\Comment;
/**
* Tests a comment rest export view.
@ -43,7 +39,7 @@ class CommentRestExportTest extends CommentTestBase {
'name' => 'bobby tables',
'hostname' => 'public.example.com',
);
$this->comment = entity_create('comment', $comment);
$this->comment = Comment::create($comment);
$this->comment->save();
$user = $this->drupalCreateUser(['access comments']);

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentRowTest.
*/
namespace Drupal\comment\Tests\Views;
/**

View file

@ -1,15 +1,11 @@
<?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;
use Drupal\comment\Entity\Comment;
/**
* Tests the argument_comment_user_uid handler.
@ -87,7 +83,7 @@ abstract class CommentTestBase extends ViewTestBase {
'pid' => '',
'mail' => 'someone@example.com',
);
$this->comment = entity_create('comment', $comment);
$this->comment = Comment::create($comment);
$this->comment->save();
}

View file

@ -1,171 +0,0 @@
<?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\ViewKernelTestBase;
use Drupal\views\Views;
/**
* Tests comment user name field
*
* @group comment
*/
class CommentUserNameTest extends ViewKernelTestBase {
/**
* 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,
'name' => '',
'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(),
'name' => $this->adminUser->label(),
'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

@ -1,83 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentViewKernelTestBase.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\user\Entity\Role;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Provides a common test base for comment views tests.
*/
abstract class CommentViewKernelTestBase extends ViewKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['comment_test_views', 'user', 'comment'];
/**
* Admin user.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* The entity storage for comments.
*
* @var \Drupal\comment\CommentStorageInterface
*/
protected $commentStorage;
/**
* The entity storage for users.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
$this->installConfig(['user']);
$entity_manager = $this->container->get('entity.manager');
$this->commentStorage = $entity_manager->getStorage('comment');
$this->userStorage = $entity_manager->getStorage('user');
// Insert a row for the anonymous user.
$this->userStorage
->create([
'uid' => 0,
'name' => '',
'status' => 0,
])
->save();
$admin_role = Role::create(['id' => 'admin']);
$admin_role->grantPermission('administer comments');
$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 = $this->userStorage->create(['name' => $this->randomMachineName()]);
$this->adminUser->addRole('admin');
$this->adminUser->save();
}
}

View file

@ -1,81 +0,0 @@
<?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

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\DefaultViewRecentCommentsTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\CommentInterface;
@ -84,7 +79,7 @@ class DefaultViewRecentCommentsTest extends ViewTestBase {
// 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(
$comment = Comment::create(array(
'status' => CommentInterface::PUBLISHED,
'field_name' => 'comment',
'entity_type' => 'node',

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\FilterUserUIDTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\NodeCommentsTest.
*/
namespace Drupal\comment\Tests\Views;
/**

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\RowRssTest.
*/
namespace Drupal\comment\Tests\Views;
/**

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\WizardTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Tests\CommentTestTrait;