diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index b1cc516..8f0a532 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -8,7 +8,7 @@ namespace Drupal\block\Tests; use Drupal\simpletest\DrupalUnitTestBase; -use Drupal\system\Plugin\block\block\SystemPoweredByBlock; +use Drupal\block_test\Plugin\block\block\TestHtmlIdBlock; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\block\BlockStorageController; use Drupal\Core\Entity\EntityMalformedException; @@ -26,7 +26,7 @@ class BlockStorageUnitTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('system'); + public static $modules = array('block_test'); /** * The block storage controller. @@ -78,44 +78,44 @@ protected function createTests() { // Create a block with only required values. $entity = $this->controller->create(array( - 'id' => 'stark.powered', - 'plugin' => 'system_powered_by_block', + 'id' => 'stark.test_block', + 'plugin' => 'test_html_id', )); $entity->save(); $this->assertTrue($entity instanceof Block, 'The newly created entity is a Block.'); // Verify all of the block properties. - $actual_properties = config('plugin.core.block.stark.powered')->get(); + $actual_properties = config('plugin.core.block.stark.test_block')->get(); $this->assertTrue(!empty($actual_properties['uuid']), 'The block UUID is set.'); unset($actual_properties['uuid']); // Ensure that default values are filled in. $expected_properties = array( - 'id' => 'stark.powered', + 'id' => 'stark.test_block', 'label' => '', 'region' => '-1', 'weight' => '', - 'cache' => '-1', - 'module' => 'system', + 'cache' => '1', + 'module' => 'block_test', 'theme' => 'stark', 'status' => '1', 'visibility' => array(), - 'plugin' => 'system_powered_by_block', + 'plugin' => 'test_html_id', 'configuration' => array( - 'subject' => t('Powered by Drupal'), + 'subject' => t('Test block html id'), ), ); $this->assertIdentical($actual_properties, $expected_properties, 'The block properties are exported correctly.'); - $this->assertTrue($entity->getPlugin() instanceof SystemPoweredByBlock, 'The entity has an instance of the correct block plugin.'); + $this->assertTrue($entity->getPlugin() instanceof TestHtmlIdBlock, 'The entity has an instance of the correct block plugin.'); } /** * Tests the rendering of blocks. */ protected function loadTests() { - $entities = $this->controller->load(array('stark.powered')); + $entities = $this->controller->load(array('stark.test_block')); $entity = reset($entities); $this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.'); @@ -124,7 +124,7 @@ protected function loadTests() { $this->assertEqual($entity->get('region'), '-1'); $this->assertTrue($entity->get('status')); $this->assertEqual($entity->get('theme'), 'stark'); - $this->assertEqual($entity->get('module'), 'system'); + $this->assertEqual($entity->get('module'), 'block_test'); $this->assertTrue($entity->uuid()); } @@ -133,23 +133,23 @@ protected function loadTests() { */ protected function renderTests() { $entity = $this->controller->create(array( - 'id' => 'stark.powered', - 'plugin' => 'system_powered_by_block', + 'id' => 'stark.test_block', + 'plugin' => 'test_html_id', )); // Test the rendering of a block. $output = entity_view($entity, 'block'); $expected = array(); - $expected[] = '
'; + $expected[] = '
'; $expected[] = ''; - $expected[] = '

Powered by Drupal

'; + $expected[] = '

Test block html id

'; $expected[] = ' '; $expected[] = '
'; - $expected[] = ' Powered by Drupal
'; + $expected[] = '
'; $expected[] = '
'; $expected[] = ''; $expected_output = implode("\n", $expected); - $this->assertEqual(render($output), $expected_output, 'The block rendered correctly.'); + $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.'); // Reset the HTML IDs so that the next render is not affected. drupal_static_reset('drupal_html_id'); @@ -158,23 +158,23 @@ protected function renderTests() { $entity->set('label', 'Powered by Bananas'); $output = entity_view($entity, 'block'); $expected = array(); - $expected[] = '
'; + $expected[] = '
'; $expected[] = ''; $expected[] = '

Powered by Bananas

'; $expected[] = ' '; $expected[] = '
'; - $expected[] = ' Powered by Drupal
'; + $expected[] = '
'; $expected[] = '
'; $expected[] = ''; $expected_output = implode("\n", $expected); - $this->assertEqual(render($output), $expected_output, 'The block rendered correctly.'); + $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.'); } /** * Tests the deleting of blocks. */ protected function deleteTests() { - $entities = $this->controller->load(array('stark.powered')); + $entities = $this->controller->load(array('stark.test_block')); $entity = reset($entities); // Ensure that the storage isn't currently empty. @@ -198,7 +198,7 @@ public function testDefaultBlocks() { $this->assertTrue(empty($entities), 'There are no blocks initially.'); // Enable the Help module, which provides a default block. - $this->enableModules(array('help')); + $this->enableModules(array('system', 'help')); $entities = $this->controller->load(); $entity = reset($entities); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index db722bb..22e6cb9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -29,7 +29,7 @@ class EntityCrudHookTest extends WebTestBase { * * @var array */ - public static $modules = array('entity_crud_hook_test', 'taxonomy', 'comment', 'file', 'entity_test'); + public static $modules = array('entity_crud_hook_test', 'taxonomy', 'block_test', 'block', 'comment', 'file', 'entity_test'); protected $ids = array(); @@ -67,6 +67,54 @@ protected function assertHookMessageOrder($messages) { } /** + * Tests hook invocations for CRUD operations on blocks. + */ + public function testBlockHooks() { + $entity = entity_create('block', array( + 'id' => 'stark.test_block', + 'plugin' => 'test_html_id', + )); + $_SESSION['entity_crud_hook_test'] = array(); + $entity->save(); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_block_presave called', + 'entity_crud_hook_test_entity_presave called for type block', + 'entity_crud_hook_test_block_insert called', + 'entity_crud_hook_test_entity_insert called for type block', + )); + + $_SESSION['entity_crud_hook_test'] = array(); + $entity = entity_load('block', $entity->id()); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_entity_load called for type block', + 'entity_crud_hook_test_block_load called', + )); + + $_SESSION['entity_crud_hook_test'] = array(); + $entity->label = 'New label'; + $entity->save(); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_block_presave called', + 'entity_crud_hook_test_entity_presave called for type block', + 'entity_crud_hook_test_block_update called', + 'entity_crud_hook_test_entity_update called for type block', + )); + + $_SESSION['entity_crud_hook_test'] = array(); + $entity->delete(); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_block_predelete called', + 'entity_crud_hook_test_entity_predelete called for type block', + 'entity_crud_hook_test_block_delete called', + 'entity_crud_hook_test_entity_delete called for type block', + )); + } + + /** * Tests hook invocations for CRUD operations on comments. */ public function testCommentHooks() { diff --git a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module index 8a1e43c..f2bb297 100644 --- a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module +++ b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module @@ -15,6 +15,13 @@ function entity_crud_hook_test_entity_presave(EntityInterface $entity) { } /** + * Implements hook_block_presave(). + */ +function entity_crud_hook_test_block_presave() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_presave(). */ function entity_crud_hook_test_comment_presave() { @@ -64,6 +71,13 @@ function entity_crud_hook_test_entity_insert(EntityInterface $entity) { } /** + * Implements hook_block_insert(). + */ +function entity_crud_hook_test_block_insert() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_insert(). */ function entity_crud_hook_test_comment_insert() { @@ -113,6 +127,13 @@ function entity_crud_hook_test_entity_load(array $entities, $type) { } /** + * Implements hook_block_load(). + */ +function entity_crud_hook_test_block_load() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_load(). */ function entity_crud_hook_test_comment_load() { @@ -162,6 +183,13 @@ function entity_crud_hook_test_entity_update(EntityInterface $entity) { } /** + * Implements hook_block_update(). + */ +function entity_crud_hook_test_block_update() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_update(). */ function entity_crud_hook_test_comment_update() { @@ -211,6 +239,13 @@ function entity_crud_hook_test_entity_predelete(EntityInterface $entity) { } /** + * Implements hook_block_predelete(). + */ +function entity_crud_hook_test_block_predelete() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_predelete(). */ function entity_crud_hook_test_comment_predelete() { @@ -260,6 +295,13 @@ function entity_crud_hook_test_entity_delete(EntityInterface $entity) { } /** + * Implements hook_block_delete(). + */ +function entity_crud_hook_test_block_delete() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_delete(). */ function entity_crud_hook_test_comment_delete() {