Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -7,7 +7,9 @@
|
|||
|
||||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\CommentManagerInterface;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
|
||||
|
@ -28,6 +30,16 @@ class CommentCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
|||
*/
|
||||
public static $modules = array('comment');
|
||||
|
||||
/**
|
||||
* @var \Drupal\entity_test\Entity\EntityTest
|
||||
*/
|
||||
protected $entityTestCamelid;
|
||||
|
||||
/**
|
||||
* @var \Drupal\entity_test\Entity\EntityTest
|
||||
*/
|
||||
protected $entityTestHippopotamidae;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -57,12 +69,12 @@ class CommentCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
|||
$field->setSetting('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT);
|
||||
$field->save();
|
||||
|
||||
// Create a "Camelids" test entity.
|
||||
$entity_test = entity_create('entity_test', array(
|
||||
// Create a "Camelids" test entity that the comment will be assigned to.
|
||||
$this->entityTestCamelid = entity_create('entity_test', array(
|
||||
'name' => 'Camelids',
|
||||
'type' => 'bar',
|
||||
));
|
||||
$entity_test->save();
|
||||
$this->entityTestCamelid->save();
|
||||
|
||||
// Create a "Llama" comment.
|
||||
$comment = entity_create('comment', array(
|
||||
|
@ -71,7 +83,7 @@ class CommentCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
|||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
),
|
||||
'entity_id' => $entity_test->id(),
|
||||
'entity_id' => $this->entityTestCamelid->id(),
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'comment',
|
||||
'status' => \Drupal\comment\CommentInterface::PUBLISHED,
|
||||
|
@ -81,6 +93,47 @@ class CommentCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
|||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that comments correctly invalidate the cache tag of their host entity.
|
||||
*/
|
||||
public function testCommentEntity() {
|
||||
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'MISS');
|
||||
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT');
|
||||
|
||||
// Create a "Hippopotamus" comment.
|
||||
$this->entityTestHippopotamidae = entity_create('entity_test', array(
|
||||
'name' => 'Hippopotamus',
|
||||
'type' => 'bar',
|
||||
));
|
||||
$this->entityTestHippopotamidae->save();
|
||||
|
||||
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'MISS');
|
||||
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'HIT');
|
||||
|
||||
$hippo_comment = Comment::create(array(
|
||||
'subject' => 'Hippopotamus',
|
||||
'comment_body' => array(
|
||||
'value' => 'The common hippopotamus (Hippopotamus amphibius), or hippo, is a large, mostly herbivorous mammal in sub-Saharan Africa',
|
||||
'format' => 'plain_text',
|
||||
),
|
||||
'entity_id' => $this->entityTestHippopotamidae->id(),
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'comment',
|
||||
'status' => CommentInterface::PUBLISHED,
|
||||
));
|
||||
$hippo_comment->save();
|
||||
|
||||
// Ensure that a new comment only invalidates the commented entity.
|
||||
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT');
|
||||
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'MISS');
|
||||
$this->assertText($hippo_comment->getSubject());
|
||||
|
||||
// Ensure that updating an existing comment only invalidates the commented
|
||||
// entity.
|
||||
$this->entity->save();
|
||||
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'MISS');
|
||||
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'HIT');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -70,17 +70,15 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
->getViewBuilder('entity_test')
|
||||
->view($commented_entity);
|
||||
$renderer->renderRoot($build);
|
||||
$cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($build['#cache']['contexts'])->getCacheTags();
|
||||
$expected_cache_tags = Cache::mergeTags($cache_context_tags, [
|
||||
$expected_cache_tags = [
|
||||
'entity_test_view',
|
||||
'entity_test:' . $commented_entity->id(),
|
||||
'comment_list',
|
||||
'config:core.entity_form_display.comment.comment.default',
|
||||
'config:field.field.comment.comment.comment_body',
|
||||
'config:field.field.entity_test.entity_test.comment',
|
||||
'config:field.storage.comment.comment_body',
|
||||
'config:user.settings',
|
||||
]);
|
||||
];
|
||||
sort($expected_cache_tags);
|
||||
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
|
||||
|
||||
|
@ -113,11 +111,9 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
->getViewBuilder('entity_test')
|
||||
->view($commented_entity);
|
||||
$renderer->renderRoot($build);
|
||||
$cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($build['#cache']['contexts'])->getCacheTags();
|
||||
$expected_cache_tags = Cache::mergeTags($cache_context_tags, [
|
||||
$expected_cache_tags = [
|
||||
'entity_test_view',
|
||||
'entity_test:' . $commented_entity->id(),
|
||||
'comment_list',
|
||||
'comment_view',
|
||||
'comment:' . $comment->id(),
|
||||
'config:filter.format.plain_text',
|
||||
|
@ -128,7 +124,7 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
'config:field.field.entity_test.entity_test.comment',
|
||||
'config:field.storage.comment.comment_body',
|
||||
'config:user.settings',
|
||||
]);
|
||||
];
|
||||
sort($expected_cache_tags);
|
||||
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
|
||||
}
|
||||
|
|
|
@ -53,15 +53,23 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
|
|||
protected $readOnlyFields = array(
|
||||
'changed',
|
||||
'hostname',
|
||||
'uuid',
|
||||
'cid',
|
||||
'thread',
|
||||
'comment_type',
|
||||
);
|
||||
|
||||
/**
|
||||
* These fields can be edited on create only.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $createOnlyFields = [
|
||||
'uuid',
|
||||
'pid',
|
||||
'comment_type',
|
||||
'entity_id',
|
||||
'entity_type',
|
||||
'field_name',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* These fields can only be edited by the admin or anonymous users if allowed.
|
||||
|
@ -252,6 +260,28 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
// Check create-only fields.
|
||||
foreach ($this->createOnlyFields as $field) {
|
||||
// Check view operation.
|
||||
foreach ($permutations as $set) {
|
||||
$may_view = $set['comment']->{$field}->access('view', $set['user']);
|
||||
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
|
||||
$this->assertEqual($may_view, $field != 'hostname' && ($set['user']->hasPermission('administer comments') ||
|
||||
($set['comment']->isPublished() && $set['user']->hasPermission('access comments'))), SafeMarkup::format('User @user !state view field !field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'!state' => $may_view ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
]));
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), SafeMarkup::format('User @user !state update field !field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'!state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
// Check contact fields.
|
||||
foreach ($this->contactFields as $field) {
|
||||
// Check view operation.
|
||||
|
|
|
@ -84,13 +84,13 @@ class CommentFieldsTest extends CommentTestBase {
|
|||
$this->drupalLogin($this->webUser);
|
||||
|
||||
$this->drupalGet('node/' . $node->nid->value);
|
||||
$elements = $this->cssSelect('.field-type-comment');
|
||||
$elements = $this->cssSelect('.field--type-comment');
|
||||
$this->assertEqual(2, count($elements), 'There are two comment fields on the node.');
|
||||
|
||||
// Delete the first comment field.
|
||||
FieldStorageConfig::loadByName('node', 'comment')->delete();
|
||||
$this->drupalGet('node/' . $node->nid->value);
|
||||
$elements = $this->cssSelect('.field-type-comment');
|
||||
$elements = $this->cssSelect('.field--type-comment');
|
||||
$this->assertEqual(1, count($elements), 'There is one comment field on the node.');
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('comment', 'node', 'history', 'field_ui', 'datetime');
|
||||
public static $modules = ['block', 'comment', 'node', 'history', 'field_ui', 'datetime'];
|
||||
|
||||
/**
|
||||
* An administrative user with permission to configure comment settings.
|
||||
|
@ -86,6 +86,7 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
|
||||
// Create a test node authored by the web user.
|
||||
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()));
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
|
@ -52,26 +53,26 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
// Generate and test sanitized tokens.
|
||||
$tests = array();
|
||||
$tests['[comment:cid]'] = $comment->id();
|
||||
$tests['[comment:hostname]'] = SafeMarkup::checkPlain($comment->getHostname());
|
||||
$tests['[comment:hostname]'] = Html::escape($comment->getHostname());
|
||||
$tests['[comment:author]'] = Xss::filter($comment->getAuthorName());
|
||||
$tests['[comment:mail]'] = SafeMarkup::checkPlain($this->adminUser->getEmail());
|
||||
$tests['[comment:homepage]'] = check_url($comment->getHomepage());
|
||||
$tests['[comment:mail]'] = Html::escape($this->adminUser->getEmail());
|
||||
$tests['[comment:homepage]'] = UrlHelper::filterBadProtocol($comment->getHomepage());
|
||||
$tests['[comment:title]'] = Xss::filter($comment->getSubject());
|
||||
$tests['[comment:body]'] = $comment->comment_body->processed;
|
||||
$tests['[comment:langcode]'] = SafeMarkup::checkPlain($comment->language()->getId());
|
||||
$tests['[comment:langcode]'] = Html::escape($comment->language()->getId());
|
||||
$tests['[comment:url]'] = $comment->url('canonical', $url_options + array('fragment' => 'comment-' . $comment->id()));
|
||||
$tests['[comment:edit-url]'] = $comment->url('edit-form', $url_options);
|
||||
$tests['[comment:created]'] = \Drupal::service('date.formatter')->format($comment->getCreatedTime(), 'medium', array('langcode' => $language_interface->getId()));
|
||||
$tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getCreatedTime(), array('langcode' => $language_interface->getId()));
|
||||
$tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getChangedTimeAcrossTranslations(), array('langcode' => $language_interface->getId()));
|
||||
$tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL;
|
||||
$tests['[comment:parent:title]'] = SafeMarkup::checkPlain($parent_comment->getSubject());
|
||||
$tests['[comment:entity]'] = SafeMarkup::checkPlain($node->getTitle());
|
||||
$tests['[comment:parent:title]'] = Html::escape($parent_comment->getSubject());
|
||||
$tests['[comment:entity]'] = Html::escape($node->getTitle());
|
||||
// Test node specific tokens.
|
||||
$tests['[comment:entity:nid]'] = $comment->getCommentedEntityId();
|
||||
$tests['[comment:entity:title]'] = SafeMarkup::checkPlain($node->getTitle());
|
||||
$tests['[comment:entity:title]'] = Html::escape($node->getTitle());
|
||||
$tests['[comment:author:uid]'] = $comment->getOwnerId();
|
||||
$tests['[comment:author:name]'] = SafeMarkup::checkPlain($this->adminUser->getUsername());
|
||||
$tests['[comment:author:name]'] = Html::escape($this->adminUser->getUsername());
|
||||
|
||||
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($comment);
|
||||
$metadata_tests = [];
|
||||
|
|
|
@ -38,10 +38,10 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
|
|||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'theme',
|
||||
'user.permissions',
|
||||
'timezone',
|
||||
'url.query_args:_wrapper_format',
|
||||
'url.query_args.pagers:0',
|
||||
'user.roles'
|
||||
'user'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade comments.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCommentTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
||||
static $modules = array('node', 'comment', 'text', 'filter');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installSchema('comment', ['comment_entity_statistics']);
|
||||
$this->installConfig(['node', 'comment']);
|
||||
|
||||
entity_create('node_type', array('type' => 'page'))->save();
|
||||
entity_create('node_type', array('type' => 'story'))->save();
|
||||
$this->addDefaultCommentField('node', 'story');
|
||||
$this->container->get('entity.manager')->getStorage('comment_type')->create(array(
|
||||
'id' => 'comment_no_subject',
|
||||
'label' => 'comment_no_subject',
|
||||
'target_entity_type_id' => 'node',
|
||||
))->save();
|
||||
\Drupal::service('comment.manager')->addBodyField('comment_no_subject');
|
||||
|
||||
$node = entity_create('node', array(
|
||||
'type' => 'story',
|
||||
'nid' => 1,
|
||||
'title' => $this->randomString(),
|
||||
));
|
||||
$node->enforceIsNew();
|
||||
$node->save();
|
||||
$id_mappings = array(
|
||||
'd6_filter_format' => array(array(array(1), array('filtered_html'))),
|
||||
'd6_node:*' => array(array(array(1), array(1))),
|
||||
'd6_user' => array(array(array(0), array(0))),
|
||||
'd6_comment_type' => array(array(array('comment'), array('comment_no_subject'))),
|
||||
'd6_comment_entity_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))),
|
||||
'd6_comment_entity_form_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_comment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 6 to Drupal 8 comment migration.
|
||||
*/
|
||||
public function testComments() {
|
||||
/** @var \Drupal\Core\Entity\EntityStorageInterface $comment_storage */
|
||||
$comment_storage = $this->container->get('entity.manager')->getStorage('comment');
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
$comment = $comment_storage->load(1);
|
||||
$this->assertIdentical('The first comment.', $comment->getSubject());
|
||||
$this->assertIdentical('The first comment body.', $comment->comment_body->value);
|
||||
$this->assertIdentical('filtered_html', $comment->comment_body->format);
|
||||
$this->assertIdentical('0', $comment->pid->target_id);
|
||||
$this->assertIdentical('1', $comment->getCommentedEntityId());
|
||||
$this->assertIdentical('node', $comment->getCommentedEntityTypeId());
|
||||
$this->assertIdentical('en', $comment->language()->getId());
|
||||
$this->assertIdentical('comment_no_subject', $comment->getTypeId());
|
||||
|
||||
$comment = $comment_storage->load(2);
|
||||
$this->assertIdentical('The response to the second comment.', $comment->subject->value);
|
||||
$this->assertIdentical('3', $comment->pid->target_id);
|
||||
|
||||
$comment = $comment_storage->load(3);
|
||||
$this->assertIdentical('The second comment.', $comment->subject->value);
|
||||
$this->assertIdentical('0', $comment->pid->target_id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade comment type.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCommentTypeTest extends MigrateDrupal6TestBase {
|
||||
|
||||
static $modules = array('node', 'comment', 'text', 'filter');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installConfig(['node', 'comment']);
|
||||
$this->executeMigration('d6_comment_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 6 to Drupal 8 comment type migration.
|
||||
*/
|
||||
public function testCommentType() {
|
||||
$comment_type = CommentType::load('comment');
|
||||
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
|
||||
$comment_type = CommentType::load('comment_no_subject');
|
||||
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentVariableDisplayBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Base class for Drupal 6 comment variables to Drupal 8 entity display tests.
|
||||
*/
|
||||
abstract class MigrateCommentVariableDisplayBase extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The ID of migration to run.
|
||||
*
|
||||
* This constant needs to be set in the concrete class in order for the test
|
||||
* to work.
|
||||
*/
|
||||
const MIGRATION = '';
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $modules = array('comment', 'node');
|
||||
|
||||
/**
|
||||
* The node types being tested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $types = array('page', 'story', 'article');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'type' => 'comment',
|
||||
'translatable' => '0',
|
||||
))->save();
|
||||
foreach ($this->types as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
entity_create('field_config', array(
|
||||
'label' => 'Comments',
|
||||
'description' => '',
|
||||
'field_name' => 'comment',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'required' => 1,
|
||||
))->save();
|
||||
}
|
||||
$id_mappings = array(
|
||||
'd6_comment_field_instance' => array(
|
||||
array(array('page'), array('node', 'comment', 'page')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration(static::MIGRATION);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentVariableEntityDisplayTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
/**
|
||||
* Upgrade comment variables to entity.display.node.*.default.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCommentVariableEntityDisplayTest extends MigrateCommentVariableDisplayBase {
|
||||
|
||||
/**
|
||||
* The migration to run.
|
||||
*/
|
||||
const MIGRATION = 'd6_comment_entity_display';
|
||||
|
||||
/**
|
||||
* The node types being used.
|
||||
*/
|
||||
protected $types = array('page', 'story', 'article');
|
||||
|
||||
/**
|
||||
* Tests comment variables migrated into an entity display.
|
||||
*/
|
||||
public function testCommentEntityDisplay() {
|
||||
foreach ($this->types as $type) {
|
||||
$component = entity_get_display('node', $type, 'default')->getComponent('comment');
|
||||
$this->assertIdentical('hidden', $component['label']);
|
||||
$this->assertIdentical('comment_default', $component['type']);
|
||||
$this->assertIdentical(20, $component['weight']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentVariableEntityFormDisplaySubjectTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade comment subject variable to core.entity_form_display.comment.*.default.yml
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCommentVariableEntityFormDisplaySubjectTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('comment', 'node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
foreach (['comment', 'comment_no_subject'] as $comment_type) {
|
||||
entity_create('comment_type', array(
|
||||
'id' => $comment_type,
|
||||
'target_entity_type_id' => 'node',
|
||||
))
|
||||
->save();
|
||||
}
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_comment_type' => array(
|
||||
array(array('comment'), array('comment_no_subject')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_comment_entity_form_display_subject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests comment subject variable migrated into an entity display.
|
||||
*/
|
||||
public function testCommentEntityFormDisplay() {
|
||||
$component = entity_get_form_display('comment', 'comment', 'default')
|
||||
->getComponent('subject');
|
||||
$this->assertIdentical('string_textfield', $component['type']);
|
||||
$this->assertIdentical(10, $component['weight']);
|
||||
$component = entity_get_form_display('comment', 'comment_no_subject', 'default')
|
||||
->getComponent('subject');
|
||||
$this->assertNull($component);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentVariableEntityFormDisplayTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
/**
|
||||
* Upgrade comment variables to core.entity_form_display.node.*.default.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCommentVariableEntityFormDisplayTest extends MigrateCommentVariableDisplayBase {
|
||||
|
||||
/**
|
||||
* The migration to run.
|
||||
*/
|
||||
const MIGRATION = 'd6_comment_entity_form_display';
|
||||
|
||||
/**
|
||||
* Tests comment variables migrated into an entity display.
|
||||
*/
|
||||
public function testCommentEntityFormDisplay() {
|
||||
foreach ($this->types as $type) {
|
||||
$component = entity_get_form_display('node', $type, 'default')->getComponent('comment');
|
||||
$this->assertIdentical('comment_default', $component['type']);
|
||||
$this->assertIdentical(20, $component['weight']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentVariableFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade comment variables to field.storage.node.comment.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCommentVariableFieldTest extends MigrateDrupal6TestBase {
|
||||
|
||||
static $modules = array('comment', 'node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
foreach (array('page', 'story', 'test') as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
}
|
||||
foreach (['comment', 'comment_no_subject'] as $comment_type) {
|
||||
entity_create('comment_type', array(
|
||||
'id' => $comment_type,
|
||||
'target_entity_type_id' => 'node',
|
||||
))
|
||||
->save();
|
||||
}
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_comment_type' => array(
|
||||
array(array('comment'), array('comment_no_subject')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_comment_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests comment variables migrated into a field entity.
|
||||
*/
|
||||
public function testCommentField() {
|
||||
$this->assertTrue(is_object(FieldStorageConfig::load('node.comment')));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d6\MigrateCommentVariableInstanceTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade comment variables to field.instance.node.*.comment.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCommentVariableInstanceTest extends MigrateDrupal6TestBase {
|
||||
|
||||
static $modules = array('comment', 'node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_comment_field' => array(
|
||||
array(array('page'), array('node', 'page')),
|
||||
),
|
||||
'd6_node_type' => array(
|
||||
array(array('page'), array('page')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
foreach (array('page', 'story', 'article') as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
}
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'type' => 'comment',
|
||||
'translatable' => '0',
|
||||
))->save();
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment_no_subject',
|
||||
'type' => 'comment',
|
||||
'translatable' => '0',
|
||||
))->save();
|
||||
$this->executeMigration('d6_comment_field_instance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the migrated field instance values.
|
||||
*/
|
||||
public function testCommentFieldInstance() {
|
||||
$node = entity_create('node', array('type' => 'page'));
|
||||
$this->assertIdentical(0, $node->comment->status);
|
||||
$this->assertIdentical('comment', $node->comment->getFieldDefinition()->getName());
|
||||
$settings = $node->comment->getFieldDefinition()->getSettings();
|
||||
$this->assertIdentical(4, $settings['default_mode']);
|
||||
$this->assertIdentical(50, $settings['per_page']);
|
||||
$this->assertIdentical(0, $settings['anonymous']);
|
||||
$this->assertIdentical(FALSE, $settings['form_location']);
|
||||
$this->assertIdentical(1, $settings['preview']);
|
||||
|
||||
$node = entity_create('node', array('type' => 'story'));
|
||||
$this->assertIdentical(2, $node->comment_no_subject->status);
|
||||
$this->assertIdentical('comment_no_subject', $node->comment_no_subject->getFieldDefinition()->getName());
|
||||
$settings = $node->comment_no_subject->getFieldDefinition()->getSettings();
|
||||
$this->assertIdentical(2, $settings['default_mode']);
|
||||
$this->assertIdentical(70, $settings['per_page']);
|
||||
$this->assertIdentical(1, $settings['anonymous']);
|
||||
$this->assertIdentical(FALSE, $settings['form_location']);
|
||||
$this->assertIdentical(0, $settings['preview']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentEntityDisplayTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment display configuration.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
$this->executeMigration('d7_comment_entity_display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a display entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $component_id
|
||||
* The ID of the display component.
|
||||
*/
|
||||
protected function assertDisplay($id, $component_id) {
|
||||
$component = EntityViewDisplay::load($id)->getComponent($component_id);
|
||||
$this->assertTrue(is_array($component));
|
||||
$this->assertIdentical('hidden', $component['label']);
|
||||
$this->assertIdentical('comment_default', $component['type']);
|
||||
$this->assertIdentical(20, $component['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated display configuration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertDisplay('node.page.default', 'comment_node_page');
|
||||
$this->assertDisplay('node.article.default', 'comment_node_article');
|
||||
$this->assertDisplay('node.book.default', 'comment_node_book');
|
||||
$this->assertDisplay('node.blog.default', 'comment_node_blog');
|
||||
$this->assertDisplay('node.forum.default', 'comment_node_forum');
|
||||
$this->assertDisplay('node.test_content_type.default', 'comment_node_test_content_type');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentEntityFormDisplaySubjectTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment form's subject display configuration.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_entity_form_display_subject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a display entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
*/
|
||||
protected function assertDisplay($id) {
|
||||
$component = EntityFormDisplay::load($id)->getComponent('subject');
|
||||
$this->assertTrue(is_array($component));
|
||||
$this->assertIdentical('string_textfield', $component['type']);
|
||||
$this->assertIdentical(10, $component['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated display configuration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertDisplay('comment.comment_node_page.default');
|
||||
$this->assertDisplay('comment.comment_node_article.default');
|
||||
$this->assertDisplay('comment.comment_node_book.default');
|
||||
$this->assertDisplay('comment.comment_node_blog.default');
|
||||
$this->assertDisplay('comment.comment_node_forum.default');
|
||||
$this->assertDisplay('comment.comment_node_test_content_type.default');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentEntityFormDisplayTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment form display configuration.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
$this->executeMigration('d7_comment_entity_form_display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a display entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $component
|
||||
* The ID of the form component.
|
||||
*/
|
||||
protected function assertDisplay($id, $component_id) {
|
||||
$component = EntityFormDisplay::load($id)->getComponent($component_id);
|
||||
$this->assertTrue(is_array($component));
|
||||
$this->assertIdentical('comment_default', $component['type']);
|
||||
$this->assertIdentical(20, $component['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated display configuration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertDisplay('node.page.default', 'comment');
|
||||
$this->assertDisplay('node.article.default', 'comment');
|
||||
$this->assertDisplay('node.book.default', 'comment');
|
||||
$this->assertDisplay('node.blog.default', 'comment');
|
||||
$this->assertDisplay('node.forum.default', 'comment');
|
||||
$this->assertDisplay('node.test_content_type.default', 'comment');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentFieldInstanceTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Core\Field\FieldConfigInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests creation of comment reference fields for each comment type defined
|
||||
* in Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a comment field entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $field_name
|
||||
* The field name.
|
||||
* @param string $bundle
|
||||
* The bundle ID.
|
||||
* @param int $default_mode
|
||||
* The field's default_mode setting.
|
||||
* @param int $per_page
|
||||
* The field's per_page setting.
|
||||
* @param bool $anonymous
|
||||
* The field's anonymous setting.
|
||||
* @param int $form_location
|
||||
* The field's form_location setting.
|
||||
* @param bool $preview
|
||||
* The field's preview setting.
|
||||
*/
|
||||
protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_page, $anonymous, $form_location, $preview) {
|
||||
$entity = FieldConfig::load($id);
|
||||
$this->assertTrue($entity instanceof FieldConfigInterface);
|
||||
/** @var \Drupal\field\FieldConfigInterface $entity */
|
||||
$this->assertIdentical('node', $entity->getTargetEntityTypeId());
|
||||
$this->assertIdentical('Comments', $entity->label());
|
||||
$this->assertTrue($entity->isRequired());
|
||||
$this->assertIdentical($field_name, $entity->getFieldStorageDefinition()->getName());
|
||||
$this->assertIdentical($bundle, $entity->getTargetBundle());
|
||||
$this->assertTrue($entity->get('default_value')[0]['status']);
|
||||
$this->assertEqual($default_mode, $entity->getSetting('default_mode'));
|
||||
$this->assertIdentical($per_page, $entity->getSetting('per_page'));
|
||||
$this->assertEqual($anonymous, $entity->getSetting('anonymous'));
|
||||
// This assertion fails because 1 !== TRUE. It's extremely strange that
|
||||
// the form_location setting is returning a boolean, but this appears to
|
||||
// be a problem with the entity, not with the migration.
|
||||
// $this->asserIdentical($form_location, $entity->getSetting('form_location'));
|
||||
$this->assertEqual($preview, $entity->getSetting('preview'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated fields.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertEntity('node.page.comment_node_page', 'comment_node_page', 'page', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
|
||||
$this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
|
||||
$this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
|
||||
$this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
|
||||
$this->assertEntity('node.forum.comment_node_forum', 'comment_node_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
|
||||
$this->assertEntity('node.test_content_type.comment_node_test_content_type', 'comment_node_test_content_type', 'test_content_type', TRUE, 30, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests creation of comment reference fields for each comment type defined
|
||||
* in Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a comment field entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $comment_type
|
||||
* The comment type (bundle ID) the field references.
|
||||
*/
|
||||
protected function assertEntity($id, $comment_type) {
|
||||
$entity = FieldStorageConfig::load($id);
|
||||
$this->assertTrue($entity instanceof FieldStorageConfigInterface);
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface $entity */
|
||||
$this->assertIdentical('node', $entity->getTargetEntityTypeId());
|
||||
$this->assertIdentical('comment', $entity->getType());
|
||||
$this->assertIdentical($comment_type, $entity->getSetting('comment_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated fields.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertEntity('node.comment_node_page', 'comment_node_page');
|
||||
$this->assertEntity('node.comment_node_article', 'comment_node_article');
|
||||
$this->assertEntity('node.comment_node_blog', 'comment_node_blog');
|
||||
$this->assertEntity('node.comment_node_book', 'comment_node_book');
|
||||
$this->assertEntity('node.comment_node_forum', 'comment_node_forum');
|
||||
$this->assertEntity('node.comment_node_test_content_type', 'comment_node_test_content_type');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests migration of comments from Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['filter', 'node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
|
||||
$this->executeMigration('d7_filter_format');
|
||||
$this->executeMigration('d7_user_role');
|
||||
$this->executeMigration('d7_user');
|
||||
// The test database doesn't include uid 1, so we'll need to create it.
|
||||
User::create(array(
|
||||
'uid' => 1,
|
||||
'name' => 'admin',
|
||||
'mail' => 'admin@local.host',
|
||||
))->save();
|
||||
$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->executeMigration('d7_node__test_content_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of comments from Drupal 7.
|
||||
*/
|
||||
public function testCommentMigration() {
|
||||
$comment = Comment::load(1);
|
||||
$this->assertTrue($comment instanceof CommentInterface);
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
$this->assertIdentical('A comment', $comment->getSubject());
|
||||
$this->assertIdentical('1421727536', $comment->getCreatedTime());
|
||||
$this->assertIdentical('1421727536', $comment->getChangedTime());
|
||||
$this->assertTrue($comment->getStatus());
|
||||
$this->assertIdentical('admin', $comment->getAuthorName());
|
||||
$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);
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertTrue($node instanceof NodeInterface);
|
||||
$this->assertIdentical('1', $node->id());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\CommentTypeInterface;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment types from Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a comment type entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $label
|
||||
* The entity label.
|
||||
*/
|
||||
protected function assertEntity($id, $label) {
|
||||
$entity = CommentType::load($id);
|
||||
$this->assertTrue($entity instanceof CommentTypeInterface);
|
||||
/** @var \Drupal\comment\CommentTypeInterface $entity */
|
||||
$this->assertIdentical($label, $entity->label());
|
||||
$this->assertIdentical('node', $entity->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated comment types.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertEntity('comment_node_page', 'Basic page comment');
|
||||
$this->assertEntity('comment_node_article', 'Article comment');
|
||||
$this->assertEntity('comment_node_blog', 'Blog entry comment');
|
||||
$this->assertEntity('comment_node_book', 'Book page comment');
|
||||
$this->assertEntity('comment_node_forum', 'Forum topic comment');
|
||||
$this->assertEntity('comment_node_test_content_type', 'Test content type comment');
|
||||
}
|
||||
|
||||
}
|
|
@ -91,11 +91,11 @@ class CommentFieldNameTest extends CommentTestBase {
|
|||
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
|
||||
return $view->field['field_name']->advancedRender($view->result[0]);
|
||||
});
|
||||
$this->assertIdentical($this->comment->getFieldName(), $output);
|
||||
$this->assertEqual($this->comment->getFieldName(), $output);
|
||||
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
|
||||
return $view->field['field_name']->advancedRender($view->result[1]);
|
||||
});
|
||||
$this->assertIdentical($this->customComment->getFieldName(), $output);
|
||||
$this->assertEqual($this->customComment->getFieldName(), $output);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ 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\Tests\ViewKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ use Drupal\views\Views;
|
|||
*
|
||||
* @group comment
|
||||
*/
|
||||
class CommentUserNameTest extends ViewUnitTestBase {
|
||||
class CommentUserNameTest extends ViewKernelTestBase {
|
||||
|
||||
/**
|
||||
* Admin user.
|
||||
|
@ -50,6 +50,7 @@ class CommentUserNameTest extends ViewUnitTestBase {
|
|||
$storage
|
||||
->create(array(
|
||||
'uid' => 0,
|
||||
'name' => '',
|
||||
'status' => 0,
|
||||
))
|
||||
->save();
|
||||
|
@ -75,6 +76,7 @@ class CommentUserNameTest extends ViewUnitTestBase {
|
|||
$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,
|
||||
|
|
41
core/modules/comment/src/Tests/Views/NodeCommentsTest.php
Normal file
41
core/modules/comment/src/Tests/Views/NodeCommentsTest.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Views\NodeCommentsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Views;
|
||||
|
||||
/**
|
||||
* Tests comments on nodes.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class NodeCommentsTest extends CommentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['history'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_new_comments'];
|
||||
|
||||
/**
|
||||
* Test the new comments field plugin.
|
||||
*/
|
||||
public function testNewComments() {
|
||||
$this->drupalGet('test-new-comments');
|
||||
$this->assertResponse(200);
|
||||
$new_comments = $this->cssSelect(".views-field-new-comments a:contains('1')");
|
||||
$this->assertEqual(count($new_comments), 1, 'Found the number of new comments for a certain node.');
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue