RevisionLogDefaultTest.php in Revision Log Default 8
File
tests/src/Kernel/RevisionLogDefaultTest.php
View source
<?php
namespace Drupal\Tests\revision_log_default\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\revision_log_entity_test\Entity\RevisionLogEntityTest;
class RevisionLogDefaultTest extends EntityKernelTestBase {
public static $modules = [
'node',
'language',
'revision_log_default',
'revision_log_entity_test',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'node',
]);
$this
->installSchema('node', 'node_access');
$type = NodeType::create([
'type' => 'page',
'name' => 'page',
]);
$type
->save();
node_add_body_field($type);
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this
->installEntitySchema('revision_log_default_test_entity');
$this
->installEntitySchema('revision_log_default_test_bundle');
}
public function testRevisionLogDefault() {
$this
->createUser();
$node = Node::create([
'type' => 'page',
'title' => $this
->randomMachineName(),
]);
$node
->save();
$this
->assertEquals($node->revision_log
->getString(), 'Created new page');
$french = $node
->addTranslation('fr');
$french->revision_log = '';
$french->title = $this
->randomMachineName();
$french
->save();
$this
->assertEquals($french->revision_log
->getString(), 'Created French translation');
$node->title = $this
->randomMachineName();
$node->revision_log = '';
$node
->save();
$this
->assertEquals($node->revision_log
->getString(), 'Updated the Title field');
$node->title = $this
->randomMachineName();
$node->body = $this
->randomMachineName();
$node->revision_log = '';
$node
->save();
$this
->assertEquals($node->revision_log
->getString(), 'Updated the Title and Body fields');
}
public function testRevisionLogBundleMissing() {
$entity = RevisionLogEntityTest::create([
'type' => $this
->randomMachineName(),
]);
$entity
->save();
$this
->assertEquals('Created new Revision log entity test', $entity
->getRevisionLogMessage());
}
}