updated core and modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-09-09 16:27:51 +02:00
parent 027aa99b32
commit 41863f872c
7810 changed files with 318922 additions and 83631 deletions
@@ -7,8 +7,8 @@ package: Testing
dependencies:
- comment
# Information added by Drupal.org packaging script on 2016-08-03
version: '8.1.8'
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
core: '8.x'
project: 'drupal'
datestamp: 1470233792
datestamp: 1502903957
@@ -7,8 +7,8 @@ package: Testing
dependencies:
- comment
# Information added by Drupal.org packaging script on 2016-08-03
version: '8.1.8'
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
core: '8.x'
project: 'drupal'
datestamp: 1470233792
datestamp: 1502903957
@@ -31,14 +31,14 @@ function comment_test_comment_links_alter(array &$links, CommentInterface &$enti
return;
}
$links['comment_test'] = array(
$links['comment_test'] = [
'#theme' => 'links__comment__comment_test',
'#attributes' => array('class' => array('links', 'inline')),
'#links' => array(
'comment-report' => array(
'#attributes' => ['class' => ['links', 'inline']],
'#links' => [
'comment-report' => [
'title' => t('Report'),
'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")]]),
),
),
);
],
],
];
}
@@ -8,8 +8,8 @@ dependencies:
- comment
- views
# Information added by Drupal.org packaging script on 2016-08-03
version: '8.1.8'
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
core: '8.x'
project: 'drupal'
datestamp: 1470233792
datestamp: 1502903957
@@ -120,7 +120,7 @@ display:
entity_field: subject
filters:
status:
value: true
value: '1'
table: comment_field_data
field: status
id: status
@@ -131,7 +131,7 @@ display:
entity_type: comment
entity_field: status
status_node:
value: true
value: '1'
table: node_field_data
field: status
relationship: node
@@ -0,0 +1,100 @@
<?php
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
/**
* Tests comment status field access.
*
* @group comment
*/
class CommentStatusFieldAccessTest extends BrowserTestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
public $profile = 'testing';
/**
* Comment admin.
*
* @var \Drupal\user\UserInterface
*/
protected $commentAdmin;
/**
* Node author.
*
* @var \Drupal\user\UserInterface
*/
protected $nodeAuthor;
/**
* {@inheritdoc}
*/
public static $modules = [
'node',
'comment',
'user',
'system',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$node_type = NodeType::create([
'type' => 'article',
'name' => t('Article'),
]);
$node_type->save();
$this->nodeAuthor = $this->drupalCreateUser([
'create article content',
'skip comment approval',
'post comments',
'edit own comments',
'access comments',
'administer nodes',
]);
$this->commentAdmin = $this->drupalCreateUser([
'administer comments',
'create article content',
'edit own comments',
'skip comment approval',
'post comments',
'access comments',
'administer nodes',
]);
$this->addDefaultCommentField('node', 'article');
}
/**
* Tests comment status field access.
*/
public function testCommentStatusFieldAccessStatus() {
$this->drupalLogin($this->nodeAuthor);
$this->drupalGet('node/add/article');
$assert = $this->assertSession();
$assert->fieldNotExists('comment[0][status]');
$this->submitForm([
'title[0][value]' => 'Node 1',
], t('Save and publish'));
$assert->fieldExists('subject[0][value]');
$this->drupalLogin($this->commentAdmin);
$this->drupalGet('node/add/article');
$assert->fieldExists('comment[0][status]');
$this->submitForm([
'title[0][value]' => 'Node 2',
], t('Save and publish'));
$assert->fieldExists('subject[0][value]');
}
}
@@ -26,7 +26,7 @@ class CommentDefaultFormatterCacheTagsTest extends EntityKernelTestBase {
*
* @var array
*/
public static $modules = array('entity_test', 'comment');
public static $modules = ['entity_test', 'comment'];
/**
* {@inheritdoc}
@@ -48,11 +48,11 @@ class CommentDefaultFormatterCacheTagsTest extends EntityKernelTestBase {
// user does not have access to the 'administer comments' permission, to
// ensure only published comments are visible to the end user.
$current_user = $this->container->get('current_user');
$current_user->setAccount($this->createUser(array(), array('access comments')));
$current_user->setAccount($this->createUser([], ['access comments']));
// Install tables and config needed to render comments.
$this->installSchema('comment', array('comment_entity_statistics'));
$this->installConfig(array('system', 'filter', 'comment'));
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installConfig(['system', 'filter', 'comment']);
// Comment rendering generates links, so build the router.
$this->container->get('router.builder')->rebuild();
@@ -70,7 +70,7 @@ class CommentDefaultFormatterCacheTagsTest extends EntityKernelTestBase {
$renderer = $this->container->get('renderer');
// Create the entity that will be commented upon.
$commented_entity = EntityTest::create(array('name' => $this->randomMachineName()));
$commented_entity = EntityTest::create(['name' => $this->randomMachineName()]);
$commented_entity->save();
// Verify cache tags on the rendered entity before it has comments.
@@ -94,25 +94,27 @@ class CommentDefaultFormatterCacheTagsTest extends EntityKernelTestBase {
// also exists in the {users} table.
$user = $this->createUser();
$user->save();
$comment = Comment::create(array(
$comment = Comment::create([
'subject' => 'Llama',
'comment_body' => array(
'comment_body' => [
'value' => 'Llamas are cool!',
'format' => 'plain_text',
),
],
'entity_id' => $commented_entity->id(),
'entity_type' => 'entity_test',
'field_name' => 'comment',
'comment_type' => 'comment',
'status' => CommentInterface::PUBLISHED,
'uid' => $user->id(),
));
]);
$comment->save();
// Load commented entity so comment_count gets computed.
// @todo Remove the $reset = TRUE parameter after
// https://www.drupal.org/node/597236 lands. It's a temporary work-around.
$commented_entity = entity_load('entity_test', $commented_entity->id(), TRUE);
$storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
$storage->resetCache([$commented_entity->id()]);
$commented_entity = $storage->load($commented_entity->id());
// Verify cache tags on the rendered entity when it has comments.
$build = \Drupal::entityManager()
@@ -10,7 +10,7 @@ use Drupal\Core\Session\AnonymousUserSession;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\simpletest\TestBase;
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
@@ -23,36 +23,37 @@ use Drupal\user\RoleInterface;
class CommentFieldAccessTest extends EntityKernelTestBase {
use CommentTestTrait;
use GeneratePermutationsTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('comment', 'entity_test', 'user');
public static $modules = ['comment', 'entity_test', 'user'];
/**
* Fields that only users with administer comments permissions can change.
*
* @var array
*/
protected $administrativeFields = array(
protected $administrativeFields = [
'uid',
'status',
'created',
);
];
/**
* These fields are automatically managed and can not be changed by any user.
*
* @var array
*/
protected $readOnlyFields = array(
protected $readOnlyFields = [
'changed',
'hostname',
'cid',
'thread',
);
];
/**
* These fields can be edited on create only.
@@ -73,19 +74,19 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
*
* @var array
*/
protected $contactFields = array(
protected $contactFields = [
'name',
'mail',
'homepage',
);
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(array('user', 'comment'));
$this->installSchema('comment', array('comment_entity_statistics'));
$this->installConfig(['user', 'comment']);
$this->installSchema('comment', ['comment_entity_statistics']);
}
/**
@@ -203,7 +204,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
'comment' => [$comment1, $comment2, $comment3, $comment4],
'user' => [$comment_admin_user, $comment_enabled_user, $comment_no_edit_user, $comment_disabled_user, $anonymous_user]
];
$permutations = TestBase::generatePermutations($combinations);
$permutations = $this->generatePermutations($combinations);
// Check access to administrative fields.
foreach ($this->administrativeFields as $field) {
@@ -0,0 +1,138 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Entity\CommentType;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests integration of comment with other components.
*
* @group comment
*/
class CommentIntegrationTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'field', 'entity_test', 'user', 'system', 'dblog'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
$this->installSchema('dblog', ['watchdog']);
// Create a new 'comment' comment-type.
CommentType::create([
'id' => 'comment',
'label' => $this->randomString(),
])->save();
}
/**
* Tests view mode setting integration.
*
* @see comment_entity_view_display_presave()
* @see CommentDefaultFormatter::calculateDependencies()
*/
public function testViewMode() {
$mode = Unicode::strtolower($this->randomMachineName());
// Create a new comment view mode and a view display entity.
EntityViewMode::create([
'id' => "comment.$mode",
'targetEntityType' => 'comment',
'settings' => ['comment_type' => 'comment'],
])->save();
EntityViewDisplay::create([
'targetEntityType' => 'comment',
'bundle' => 'comment',
'mode' => $mode,
])->setStatus(TRUE)->save();
// Create a comment field attached to a host 'entity_test' entity.
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'type' => 'comment',
'field_name' => $field_name = Unicode::strtolower($this->randomMachineName()),
'settings' => [
'comment_type' => 'comment',
],
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'field_name' => $field_name,
])->save();
$component = [
'type' => 'comment_default',
'settings' => ['view_mode' => $mode, 'pager_id' => 0],
];
// Create a new 'entity_test' view display on host entity that uses the
// custom comment display in field formatter to show the field.
EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
])->setComponent($field_name, $component)->setStatus(TRUE)->save();
$host_display_id = 'entity_test.entity_test.default';
$comment_display_id = "comment.comment.$mode";
// Disable the "comment.comment.$mode" display.
EntityViewDisplay::load($comment_display_id)->setStatus(FALSE)->save();
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $host_display */
$host_display = EntityViewDisplay::load($host_display_id);
// Check that the field formatter has been disabled on host view display.
$this->assertNull($host_display->getComponent($field_name));
$this->assertTrue($host_display->get('hidden')[$field_name]);
// Check that the proper warning has been logged.
$arguments = [
'@id' => $host_display_id,
'@name' => $field_name,
'@display' => EntityViewMode::load("comment.$mode")->label(),
'@mode' => $mode,
];
$logged = (bool) Database::getConnection()->select('watchdog')
->fields('watchdog', ['wid'])
->condition('type', 'system')
->condition('message', "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.")
->condition('variables', serialize($arguments))
->execute()
->fetchField();
$this->assertTrue($logged);
// Re-enable the comment view display.
EntityViewDisplay::load($comment_display_id)->setStatus(TRUE)->save();
// Re-enable the comment field formatter on host entity view display.
EntityViewDisplay::load($host_display_id)->setComponent($field_name, $component)->save();
// Delete the "comment.$mode" view mode.
EntityViewMode::load("comment.$mode")->delete();
// Check that the comment view display entity has been deleted too.
$this->assertNull(EntityViewDisplay::load($comment_display_id));
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
$host_display = EntityViewDisplay::load($host_display_id);
// Check that the field formatter has been disabled on host view display.
$this->assertNull($host_display->getComponent($field_name));
$this->assertTrue($host_display->get('hidden')[$field_name]);
}
}
@@ -43,7 +43,9 @@ class CommentItemTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id, TRUE);
$storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
$storage->resetCache([$id]);
$entity = $storage->load($id);
$this->assertTrue($entity->comment instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->comment[0] instanceof CommentItemInterface, 'Field item implements interface.');
@@ -18,21 +18,21 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'comment',
'user',
'field',
'field_ui',
'entity_test',
'text',
);
];
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
$this->installSchema('comment', array('comment_entity_statistics'));
$this->installSchema('comment', ['comment_entity_statistics']);
// Create the comment body field storage.
$this->installConfig(array('field'));
$this->installConfig(['field']);
}
/**
@@ -40,21 +40,21 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
*/
public function testCommentFieldNonStringId() {
try {
$bundle = CommentType::create(array(
$bundle = CommentType::create([
'id' => 'foo',
'label' => 'foo',
'description' => '',
'target_entity_type_id' => 'entity_test_string_id',
));
]);
$bundle->save();
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => 'foo',
'entity_type' => 'entity_test_string_id',
'settings' => array(
'settings' => [
'comment_type' => 'entity_test_string_id',
),
],
'type' => 'comment',
));
]);
$field_storage->save();
$this->fail('Did not throw an exception as expected.');
}
@@ -19,14 +19,14 @@ class CommentValidationTest extends EntityKernelTestBase {
*
* @var array
*/
public static $modules = array('comment', 'node');
public static $modules = ['comment', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('comment', array('comment_entity_statistics'));
$this->installSchema('comment', ['comment_entity_statistics']);
}
/**
@@ -34,54 +34,54 @@ class CommentValidationTest extends EntityKernelTestBase {
*/
public function testValidation() {
// Add a user.
$user = User::create(array('name' => 'test', 'status' => TRUE));
$user = User::create(['name' => 'test', 'status' => TRUE]);
$user->save();
// Add comment type.
$this->entityManager->getStorage('comment_type')->create(array(
$this->entityManager->getStorage('comment_type')->create([
'id' => 'comment',
'label' => 'comment',
'target_entity_type_id' => 'node',
))->save();
])->save();
// Add comment field to content.
$this->entityManager->getStorage('field_storage_config')->create(array(
$this->entityManager->getStorage('field_storage_config')->create([
'entity_type' => 'node',
'field_name' => 'comment',
'type' => 'comment',
'settings' => array(
'settings' => [
'comment_type' => 'comment',
)
))->save();
]
])->save();
// Create a page node type.
$this->entityManager->getStorage('node_type')->create(array(
$this->entityManager->getStorage('node_type')->create([
'type' => 'page',
'name' => 'page',
))->save();
])->save();
// Add comment field to page content.
/** @var \Drupal\field\FieldConfigInterface $field */
$field = $this->entityManager->getStorage('field_config')->create(array(
$field = $this->entityManager->getStorage('field_config')->create([
'field_name' => 'comment',
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'Comment settings',
));
]);
$field->save();
$node = $this->entityManager->getStorage('node')->create(array(
$node = $this->entityManager->getStorage('node')->create([
'type' => 'page',
'title' => 'test',
));
]);
$node->save();
$comment = $this->entityManager->getStorage('comment')->create(array(
$comment = $this->entityManager->getStorage('comment')->create([
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
));
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default comment.');
@@ -101,7 +101,7 @@ class CommentValidationTest extends EntityKernelTestBase {
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, "Violation found on author name collision");
$this->assertEqual($violations[0]->getPropertyPath(), "name");
$this->assertEqual($violations[0]->getMessage(), t('The name you used (%name) belongs to a registered user.', array('%name' => 'test')));
$this->assertEqual($violations[0]->getMessage(), t('The name you used (%name) belongs to a registered user.', ['%name' => 'test']));
// Make the name valid.
$comment->set('name', 'valid unused name');
@@ -141,39 +141,39 @@ class CommentValidationTest extends EntityKernelTestBase {
\Drupal::entityManager()->getStorage('node')->resetCache([$node->id()]);
$node = Node::load($node->id());
// Create a new comment with the new field.
$comment = $this->entityManager->getStorage('comment')->create(array(
$comment = $this->entityManager->getStorage('comment')->create([
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
'uid' => 0,
'name' => '',
));
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when name is required, but empty and UID is anonymous.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name');
$this->assertEqual($violations[0]->getMessage(), t('You have to specify a valid author.'));
// Test creating a default comment with a given user id works.
$comment = $this->entityManager->getStorage('comment')->create(array(
$comment = $this->entityManager->getStorage('comment')->create([
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
'uid' => $user->id(),
));
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default comment with an author.');
// Test specifying a wrong author name does not work.
$comment = $this->entityManager->getStorage('comment')->create(array(
$comment = $this->entityManager->getStorage('comment')->create([
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
'uid' => $user->id(),
'name' => 'not-test',
));
]);
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when author name and comment author do not match.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name');
@@ -195,7 +195,7 @@ class CommentValidationTest extends EntityKernelTestBase {
$this->assertEqual(count($violations), 1, "Violation found when $field_name is too long.");
$this->assertEqual($violations[0]->getPropertyPath(), "$field_name.0.value");
$field_label = $comment->get($field_name)->getFieldDefinition()->getLabel();
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', array('%name' => $field_label, '@max' => $length)));
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', ['%name' => $field_label, '@max' => $length]));
}
}
@@ -33,11 +33,11 @@ class MigrateCommentStubTest extends MigrateDrupalTestBase {
$storage = \Drupal::entityManager()->getStorage('user');
// Insert a row for the anonymous user.
$storage
->create(array(
->create([
'uid' => 0,
'status' => 0,
'name' => '',
))
])
->save();
// Need at least one node type and comment type present.
NodeType::create([
@@ -17,7 +17,7 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
public static $modules = ['comment', 'menu_ui'];
/**
* {@inheritdoc}
@@ -61,14 +61,17 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
$this->assertIdentical('node', $comment->getCommentedEntityTypeId());
$this->assertIdentical('en', $comment->language()->getId());
$this->assertIdentical('comment_no_subject', $comment->getTypeId());
$this->assertEquals('203.0.113.1', $comment->getHostname());
$comment = $comment_storage->load(2);
$this->assertIdentical('The response to the second comment.', $comment->subject->value);
$this->assertIdentical('3', $comment->pid->target_id);
$this->assertEquals('203.0.113.2', $comment->getHostname());
$comment = $comment_storage->load(3);
$this->assertIdentical('The second comment.', $comment->subject->value);
$this->assertIdentical(NULL, $comment->pid->target_id);
$this->assertEquals('203.0.113.3', $comment->getHostname());
}
}
@@ -11,6 +11,11 @@ use Drupal\Core\Entity\Entity\EntityViewDisplay;
*/
class MigrateCommentVariableEntityDisplayTest extends MigrateCommentVariableDisplayBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_ui'];
/**
* {@inheritdoc}
*/
@@ -11,6 +11,11 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay;
*/
class MigrateCommentVariableEntityFormDisplayTest extends MigrateCommentVariableDisplayBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_ui'];
/**
* {@inheritdoc}
*/
@@ -15,7 +15,7 @@ class MigrateCommentVariableFieldTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
public static $modules = ['comment', 'menu_ui'];
/**
* {@inheritdoc}
@@ -16,7 +16,7 @@ class MigrateCommentVariableInstanceTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
public static $modules = ['comment', 'menu_ui'];
/**
* {@inheritdoc}
@@ -12,7 +12,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
*/
class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
public static $modules = ['node', 'comment', 'text', 'menu_ui'];
/**
* {@inheritdoc}
@@ -12,7 +12,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
*/
class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
public static $modules = ['node', 'comment', 'text', 'menu_ui'];
/**
* {@inheritdoc}
@@ -12,7 +12,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
*/
class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
public static $modules = ['node', 'comment', 'text', 'menu_ui'];
/**
* {@inheritdoc}
@@ -15,7 +15,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
*/
class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
public static $modules = ['node', 'comment', 'text', 'menu_ui'];
/**
* {@inheritdoc}
@@ -14,7 +14,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
*/
class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
public static $modules = ['node', 'comment', 'text', 'menu_ui'];
/**
* {@inheritdoc}
@@ -14,7 +14,7 @@ use Drupal\node\NodeInterface;
*/
class MigrateCommentTest extends MigrateDrupal7TestBase {
public static $modules = ['filter', 'node', 'comment', 'text'];
public static $modules = ['filter', 'node', 'comment', 'text', 'menu_ui'];
/**
* {@inheritdoc}
@@ -34,13 +34,13 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
$this->executeMigration('d7_node_type');
// We only need the test_content_type node migration to run for real, so
// mock all the others.
$this->prepareMigrations(array(
'd7_node' => array(
array(array(0), array(0)),
),
));
$this->prepareMigrations([
'd7_node' => [
[[0], [0]],
],
]);
$this->executeMigrations([
'd7_node:test_content_type',
'd7_node',
'd7_comment_type',
'd7_comment',
]);
@@ -61,6 +61,7 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
$this->assertIdentical('admin@local.host', $comment->getAuthorEmail());
$this->assertIdentical('This is a comment', $comment->comment_body->value);
$this->assertIdentical('filtered_html', $comment->comment_body->format);
$this->assertEquals('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname());
$node = $comment->getCommentedEntity();
$this->assertTrue($node instanceof NodeInterface);
@@ -13,7 +13,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
*/
class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
public static $modules = ['node', 'comment', 'text', 'menu_ui'];
/**
* {@inheritdoc}
@@ -0,0 +1,106 @@
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests the Drupal 6 comment source w/ high water handling.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\Comment
*
* @group comment
*/
class CommentSourceWithHighWaterTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['comments'] = [
[
'cid' => 1,
'pid' => 0,
'nid' => 2,
'uid' => 3,
'subject' => 'subject value 1',
'comment' => 'comment value 1',
'hostname' => 'hostname value 1',
'timestamp' => 1382255613,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
],
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => 2,
'type' => 'story',
],
[
'nid' => 3,
'type' => 'page',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
// The expected count is the count returned by the query before the query
// is modified by SqlBase::initializeIterator().
$tests[0]['expected_count'] = 2;
$tests[0]['configuration']['high_water_property']['name'] = 'timestamp';
$tests[0]['high_water'] = $tests[0]['source_data']['comments'][0]['timestamp'];
return $tests;
}
}
@@ -0,0 +1,116 @@
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D6 comment source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\Comment
* @group comment
*/
class CommentTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['comments'] = [
[
'cid' => 1,
'pid' => 0,
'nid' => 2,
'uid' => 3,
'subject' => 'subject value 1',
'comment' => 'comment value 1',
'hostname' => 'hostname value 1',
'timestamp' => 1382255613,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
],
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => 2,
'type' => 'story',
],
[
'nid' => 3,
'type' => 'page',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'cid' => 1,
'pid' => 0,
'nid' => 2,
'uid' => 3,
'subject' => 'subject value 1',
'comment' => 'comment value 1',
'hostname' => 'hostname value 1',
'timestamp' => 1382255613,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
],
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
return $tests;
}
}
@@ -0,0 +1,62 @@
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests comment variable per comment type source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\CommentVariablePerCommentType
* @group comment
*/
class CommentVariablePerCommentTypeTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['node_type'] = [
[
'type' => 'page',
],
[
'type' => 'story',
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'comment_subject_field_page',
'value' => serialize(1),
],
[
'name' => 'comment_subject_field_story',
'value' => serialize(0),
],
];
// The expected results.
// Each result will also include a label and description, but those are
// static values set by the source plugin and don't need to be asserted.
$tests[0]['expected_data'] = [
[
'comment_type' => 'comment',
],
[
'comment_type' => 'comment_no_subject',
],
];
return $tests;
}
}
@@ -0,0 +1,92 @@
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests d6_comment_variable source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\CommentVariable
* @group comment
*/
class CommentVariableTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['node_type'] = [
[
'type' => 'page',
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'comment_page',
'value' => serialize(1),
],
[
'name' => 'comment_default_mode_page',
'value' => serialize(1),
],
[
'name' => 'comment_default_order_page',
'value' => serialize(1),
],
[
'name' => 'comment_default_per_page_page',
'value' => serialize(50),
],
[
'name' => 'comment_controls_page',
'value' => serialize(1),
],
[
'name' => 'comment_anonymous_page',
'value' => serialize(1),
],
[
'name' => 'comment_subject_field_page',
'value' => serialize(1),
],
[
'name' => 'comment_preview_page',
'value' => serialize(1),
],
[
'name' => 'comment_form_location_page',
'value' => serialize(1),
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'comment' => '1',
'comment_default_mode' => '1',
'comment_default_order' => '1',
'comment_default_per_page' => '50',
'comment_controls' => '1',
'comment_anonymous' => '1',
'comment_subject_field' => '1',
'comment_preview' => '1',
'comment_form_location' => '1',
'node_type' => 'page',
'comment_type' => 'comment',
],
];
return $tests;
}
}
@@ -0,0 +1,117 @@
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D7 comment source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d7\Comment
* @group comment
*/
class CommentTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['comment'] = [
[
'cid' => '1',
'pid' => '0',
'nid' => '1',
'uid' => '1',
'subject' => 'A comment',
'hostname' => '::1',
'created' => '1421727536',
'changed' => '1421727536',
'status' => '1',
'thread' => '01/',
'name' => 'admin',
'mail' => '',
'homepage' => '',
'language' => 'und',
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => '1',
'vid' => '1',
'type' => 'test_content_type',
'language' => 'en',
'title' => 'A Node',
'uid' => '1',
'status' => '1',
'created' => '1421727515',
'changed' => '1421727515',
'comment' => '2',
'promote' => '1',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
'id' => '14',
'field_id' => '1',
'field_name' => 'comment_body',
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$tests[0]['source_data']['field_data_comment_body'] = [
[
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'This is a comment',
'comment_body_format' => 'filtered_html',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'cid' => '1',
'pid' => '0',
'nid' => '1',
'uid' => '1',
'subject' => 'A comment',
'hostname' => '::1',
'created' => '1421727536',
'changed' => '1421727536',
'status' => '1',
'thread' => '01/',
'name' => 'admin',
'mail' => '',
'homepage' => '',
'language' => 'und',
'comment_body' => [
[
'value' => 'This is a comment',
'format' => 'filtered_html',
],
],
],
];
return $tests;
}
}
@@ -0,0 +1,99 @@
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D7 comment type source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d7\CommentType
* @group comment
*/
class CommentTypeTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['node_type'] = [
[
'type' => 'article',
'name' => 'Article',
'base' => 'node_content',
'module' => 'node',
'description' => 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.',
'help' => 'Help text for articles',
'has_title' => '1',
'title_label' => 'Title',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'disabled' => '0',
'orig_type' => 'article',
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
'id' => '14',
'field_id' => '1',
'field_name' => 'comment_body',
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'comment_default_mode_article',
'value' => serialize(1),
],
[
'name' => 'comment_per_page_article',
'value' => serialize(50),
],
[
'name' => 'comment_anonymous_article',
'value' => serialize(0),
],
[
'name' => 'comment_form_location_article',
'value' => serialize(1),
],
[
'name' => 'comment_preview_article',
'value' => serialize(0),
],
[
'name' => 'comment_subject_article',
'value' => serialize(1),
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'bundle' => 'comment_node_article',
'node_type' => 'article',
'default_mode' => '1',
'per_page' => '50',
'anonymous' => '0',
'form_location' => '1',
'preview' => '0',
'subject' => '1',
'label' => 'Article comment',
],
];
return $tests;
}
}
@@ -43,11 +43,11 @@ class CommentUserNameTest extends ViewsKernelTestBase {
$storage = \Drupal::entityManager()->getStorage('user');
// Insert a row for the anonymous user.
$storage
->create(array(
->create([
'uid' => 0,
'name' => '',
'status' => 0,
))
])
->save();
$admin_role = Role::create([
@@ -1,12 +1,12 @@
<?php
namespace Drupal\Tests\comment\Unit {
namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentLinkBuilder;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\simpletest\TestBase;
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
use Drupal\Tests\UnitTestCase;
/**
@@ -15,6 +15,8 @@ use Drupal\Tests\UnitTestCase;
*/
class CommentLinkBuilderTest extends UnitTestCase {
use GeneratePermutationsTrait;
/**
* Comment manager mock.
*
@@ -75,9 +77,9 @@ class CommentLinkBuilderTest extends UnitTestCase {
$this->commentManager->expects($this->any())
->method('getFields')
->with('node')
->willReturn(array(
'comment' => array(),
));
->willReturn([
'comment' => [],
]);
$this->commentManager->expects($this->any())
->method('forbiddenMessage')
->willReturn("Can't let you do that Dave.");
@@ -116,10 +118,10 @@ class CommentLinkBuilderTest extends UnitTestCase {
->willReturn($history_exists);
$this->currentUser->expects($this->any())
->method('hasPermission')
->willReturnMap(array(
array('access comments', $has_access_comments),
array('post comments', $has_post_comments),
));
->willReturnMap([
['access comments', $has_access_comments],
['post comments', $has_post_comments],
]);
$this->currentUser->expects($this->any())
->method('isAuthenticated')
->willReturn(!$is_anonymous);
@@ -155,57 +157,57 @@ class CommentLinkBuilderTest extends UnitTestCase {
* Data provider for ::testCommentLinkBuilder.
*/
public function getLinkCombinations() {
$cases = array();
$cases = [];
// No links should be created if the entity doesn't have the field.
$cases[] = array(
$cases[] = [
$this->getMockNode(FALSE, CommentItemInterface::OPEN, CommentItemInterface::FORM_BELOW, 1),
array('view_mode' => 'teaser'),
['view_mode' => 'teaser'],
TRUE,
TRUE,
TRUE,
TRUE,
array(),
);
foreach (array('search_result', 'search_index', 'print') as $view_mode) {
[],
];
foreach (['search_result', 'search_index', 'print'] as $view_mode) {
// Nothing should be output in these view modes.
$cases[] = array(
$cases[] = [
$this->getMockNode(TRUE, CommentItemInterface::OPEN, CommentItemInterface::FORM_BELOW, 1),
array('view_mode' => $view_mode),
['view_mode' => $view_mode],
TRUE,
TRUE,
TRUE,
TRUE,
array(),
);
[],
];
}
// All other combinations.
$combinations = array(
'is_anonymous' => array(FALSE, TRUE),
'comment_count' => array(0, 1),
'has_access_comments' => array(0, 1),
'history_exists' => array(FALSE, TRUE),
'has_post_comments' => array(0, 1),
'form_location' => array(CommentItemInterface::FORM_BELOW, CommentItemInterface::FORM_SEPARATE_PAGE),
'comments' => array(
$combinations = [
'is_anonymous' => [FALSE, TRUE],
'comment_count' => [0, 1],
'has_access_comments' => [0, 1],
'history_exists' => [FALSE, TRUE],
'has_post_comments' => [0, 1],
'form_location' => [CommentItemInterface::FORM_BELOW, CommentItemInterface::FORM_SEPARATE_PAGE],
'comments' => [
CommentItemInterface::OPEN,
CommentItemInterface::CLOSED,
CommentItemInterface::HIDDEN,
),
'view_mode' => array(
],
'view_mode' => [
'teaser', 'rss', 'full',
),
);
$permutations = TestBase::generatePermutations($combinations);
],
];
$permutations = $this->generatePermutations($combinations);
foreach ($permutations as $combination) {
$case = array(
$case = [
$this->getMockNode(TRUE, $combination['comments'], $combination['form_location'], $combination['comment_count']),
array('view_mode' => $combination['view_mode']),
['view_mode' => $combination['view_mode']],
$combination['has_access_comments'],
$combination['history_exists'],
$combination['has_post_comments'],
$combination['is_anonymous'],
);
$expected = array();
];
$expected = [];
// When comments are enabled in teaser mode, and comments exist, and the
// user has access - we can output the comment count.
if ($combination['comments'] && $combination['view_mode'] == 'teaser' && $combination['comment_count'] && $combination['has_access_comments']) {
@@ -225,7 +227,7 @@ class CommentLinkBuilderTest extends UnitTestCase {
// comments exist or the form is on a separate page.
if ($combination['view_mode'] == 'teaser' || ($combination['has_access_comments'] && $combination['comment_count']) || $combination['form_location'] == CommentItemInterface::FORM_SEPARATE_PAGE) {
// There should be a add comment link.
$expected['comment-add'] = array('title' => 'Add new comment');
$expected['comment-add'] = ['title' => 'Add new comment'];
if ($combination['form_location'] == CommentItemInterface::FORM_BELOW) {
// On the same page.
$expected['comment-add']['url'] = Url::fromRoute('node.view');
@@ -274,11 +276,11 @@ class CommentLinkBuilderTest extends UnitTestCase {
if (empty($this->timestamp)) {
$this->timestamp = time();
}
$field_item = (object) array(
$field_item = (object) [
'status' => $comment_status,
'comment_count' => $comment_count,
'last_comment_timestamp' => $this->timestamp,
);
];
$node->expects($this->any())
->method('get')
->with('comment')
@@ -312,19 +314,17 @@ class CommentLinkBuilderTest extends UnitTestCase {
->willReturn($url);
$node->expects($this->any())
->method('url')
->willReturn(array('route_name' => 'node.view'));
->willReturn(['route_name' => 'node.view']);
return $node;
}
}
}
namespace Drupal\comment;
namespace {
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
}
@@ -3,6 +3,7 @@
namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentManager;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Tests\UnitTestCase;
/**
@@ -23,21 +24,21 @@ class CommentManagerTest extends UnitTestCase {
->method('getClass')
->will($this->returnValue('Node'));
$entity_type->expects($this->any())
->method('isSubclassOf')
->with('\Drupal\Core\Entity\FieldableEntityInterface')
->method('entityClassImplements')
->with(FieldableEntityInterface::class)
->will($this->returnValue(TRUE));
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$entity_manager->expects($this->once())
->method('getFieldMapByFieldType')
->will($this->returnValue(array(
'node' => array(
'field_foobar' => array(
->will($this->returnValue([
'node' => [
'field_foobar' => [
'type' => 'comment',
),
),
)));
],
],
]));
$entity_manager->expects($this->any())
->method('getDefinition')
@@ -45,7 +46,6 @@ class CommentManagerTest extends UnitTestCase {
$comment_manager = new CommentManager(
$entity_manager,
$this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory')->disableOriginalConstructor()->getMock(),
$this->getMock('Drupal\Core\Config\ConfigFactoryInterface'),
$this->getMock('Drupal\Core\StringTranslation\TranslationInterface'),
$this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'),
@@ -56,7 +56,7 @@ class CommentStatisticsUnitTest extends UnitTestCase {
$this->statement->expects($this->any())
->method('fetchObject')
->will($this->returnCallback(array($this, 'fetchObjectCallback')));
->will($this->returnCallback([$this, 'fetchObjectCallback']));
$this->select = $this->getMockBuilder('Drupal\Core\Database\Query\Select')
->disableOriginalConstructor()
@@ -95,8 +95,8 @@ class CommentStatisticsUnitTest extends UnitTestCase {
*/
public function testRead() {
$this->calls_to_fetch = 0;
$results = $this->commentStatistics->read(array('1' => 'boo', '2' => 'foo'), 'snafoos');
$this->assertEquals($results, array('something', 'something-else'));
$results = $this->commentStatistics->read(['1' => 'boo', '2' => 'foo'], 'snafoos');
$this->assertEquals($results, ['something', 'something-else']);
}
/**
@@ -111,13 +111,12 @@ class CommentStatisticsUnitTest extends UnitTestCase {
switch ($this->calls_to_fetch) {
case 1:
return 'something';
break;
case 2:
return 'something-else';
break;
default:
return FALSE;
break;
}
}
@@ -26,7 +26,7 @@ class CommentLockTest extends UnitTestCase {
$request_stack = new RequestStack();
$request_stack->push(Request::create('/'));
$container->set('request_stack', $request_stack);
$container->setParameter('cache_bins', array('cache.test' => 'test'));
$container->setParameter('cache_bins', ['cache.test' => 'test']);
$lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface');
$cid = 2;
$lock_name = "comment:$cid:.00/";
@@ -81,10 +81,6 @@ class CommentLockTest extends UnitTestCase {
$comment->expects($this->any())
->method('getEntityType')
->will($this->returnValue($entity_type));
$comment->expects($this->at(1))
->method('get')
->with('status')
->will($this->returnValue((object) array('value' => NULL)));
$storage = $this->getMock('Drupal\comment\CommentStorageInterface');
// preSave() should acquire the lock. (This is what's really being tested.)