CommentUpdateTest.php in Drupal 8
File
core/modules/comment/tests/src/Functional/Update/CommentUpdateTest.php
View source
<?php
namespace Drupal\Tests\comment\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
class CommentUpdateTest extends UpdatePathTestBase {
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8-rc1.filled.standard.php.gz',
];
}
public function testCommentUpdate8101() {
$config = $this
->config('core.entity_view_display.node.article.default');
$this
->assertNull($config
->get('content.comment.settings.view_mode'));
$config = $this
->config('core.entity_view_display.node.forum.default');
$this
->assertNull($config
->get('content.comment_forum.settings.view_mode'));
$this
->runUpdates();
$config = $this
->config('core.entity_view_display.node.article.default');
$this
->assertIdentical($config
->get('content.comment.settings.view_mode'), 'default');
$config = $this
->config('core.entity_view_display.node.forum.default');
$this
->assertIdentical($config
->get('content.comment_forum.settings.view_mode'), 'default');
}
public function testPublishedEntityKey() {
$entity_type = \Drupal::entityDefinitionUpdateManager()
->getEntityType('comment');
$this
->assertFalse($entity_type
->getKey('published'));
$this
->runUpdates();
$entity_type = \Drupal::entityDefinitionUpdateManager()
->getEntityType('comment');
$this
->assertEqual('status', $entity_type
->getKey('published'));
$this
->assertTrue(\Drupal::database()
->schema()
->indexExists('comment_field_data', 'comment__status_comment_type'));
}
public function testOwnerEntityKey() {
$entity_type = \Drupal::entityDefinitionUpdateManager()
->getEntityType('comment');
$this
->assertFalse($entity_type
->getKey('owner'));
$this
->runUpdates();
$entity_type = \Drupal::entityDefinitionUpdateManager()
->getEntityType('comment');
$this
->assertEquals('uid', $entity_type
->getKey('owner'));
}
public function testCommentEntityTypeAndFieldNameRequired() {
$database = \Drupal::database();
$this
->assertEquals(2, $database
->query('SELECT count(*) FROM {comment_field_data}')
->fetchField());
if ($database
->driver() === 'mysql') {
$table_description = $database
->query('DESCRIBE {comment_field_data}')
->fetchAllAssoc('Field');
$this
->assertEquals('YES', $table_description['entity_type']->Null);
$this
->assertEquals('YES', $table_description['field_name']->Null);
}
$this
->runUpdates();
$this
->assertEquals(2, $database
->query('SELECT count(*) FROM {comment_field_data}')
->fetchField());
if ($database
->driver() === 'mysql') {
$table_description = $database
->query('DESCRIBE {comment_field_data}')
->fetchAllAssoc('Field');
$this
->assertEquals('NO', $table_description['entity_type']->Null);
$this
->assertEquals('NO', $table_description['field_name']->Null);
}
}
public function testCommentEntityTypeAndFieldUpdateRequirementsCheck() {
require_once __DIR__ . '/../../../fixtures/update/drupal-8.empty-comment-fields.3052147.php';
$this
->writeSettings([
'settings' => [
'update_free_access' => (object) [
'value' => TRUE,
'required' => TRUE,
],
],
]);
$this
->drupalGet($this->updateUrl);
$this
->assertSession()
->pageTextContains('Errors found');
$this
->assertSession()
->elementContains('css', '.system-status-report__entry--error', 'The comment_update_8701() function requires that the <em class="placeholder">entity_type</em> and <em class="placeholder">field_name</em> fields have values for all comment entities.');
}
}
Classes
Name |
Description |
CommentUpdateTest |
Tests that comment settings are properly updated during database updates. |