BlockContentSaveTest.php in Zircon Profile 8.0
File
core/modules/block_content/src/Tests/BlockContentSaveTest.php
View source
<?php
namespace Drupal\block_content\Tests;
use Drupal\block_content\Entity\BlockContent;
class BlockContentSaveTest extends BlockContentTestBase {
public static $modules = array(
'block_content_test',
);
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
}
public function testImport() {
$max_id = db_query('SELECT MAX(id) FROM {block_content}')
->fetchField();
$test_id = $max_id + mt_rand(1000, 1000000);
$info = $this
->randomMachineName(8);
$block_array = array(
'info' => $info,
'body' => array(
'value' => $this
->randomMachineName(32),
),
'type' => 'basic',
'id' => $test_id,
);
$block = entity_create('block_content', $block_array);
$block
->enforceIsNew(TRUE);
$block
->save();
$this
->assertEqual($block
->id(), $test_id, 'Block imported using provide id');
$block_by_id = BlockContent::load($test_id);
$this
->assertTrue($block_by_id, 'Custom block load by block ID.');
$this
->assertIdentical($block_by_id->body->value, $block_array['body']['value']);
}
public function testDeterminingChanges() {
$block = $this
->createBlockContent('test_changes');
$this
->assertEqual($block
->getChangedTime(), REQUEST_TIME, 'Creating a block sets default "changed" timestamp.');
$block
->save();
$this
->assertEqual($block
->label(), 'test_changes', 'No changes have been determined.');
$block
->setInfo('updated');
$block
->save();
$this
->assertEqual($block
->label(), 'updated_presave_update', 'Changes have been determined.');
$this
->assertEqual($block
->getChangedTime(), 979534800, 'Saving a custom block uses "changed" timestamp set in presave hook.');
$block = BlockContent::load($block
->id());
$this
->assertEqual($block
->label(), 'updated_presave', 'Static cache has been cleared.');
}
public function testBlockContentSaveOnInsert() {
$block = $this
->createBlockContent('new');
$this
->assertEqual($block
->label(), 'BlockContent ' . $block
->id(), 'Custom block saved on block insert.');
}
}