'Block storage', 'description' => 'Tests the storage of blocks.', 'group' => 'Block' ); } protected function setUp() { parent::setUp(); $this->controller = $this->container->get('plugin.manager.entity')->getStorageController('block'); } /** * Tests CRUD operations. */ public function testBlockCRUD() { $this->assertTrue($this->controller instanceof BlockStorageController, 'The block storage controller is loaded.'); // Run each test method in the same installation. $this->createTests(); $this->loadTests(); $this->renderTests(); $this->deleteTests(); } /** * Tests the creation of blocks. */ protected function createTests() { // Attempt to create a block without a plugin. try { $entity = $this->controller->create(array()); $this->fail('A block without a plugin was created with no exception thrown.'); } catch (PluginException $e) { $this->assertEqual('The block \'\' did not specify a plugin.', $e->getMessage(), 'An exception was thrown when a block was created without a plugin.'); } // Create a block with only required values. $entity = $this->controller->create(array( '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('block.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.test_block', 'label' => '', 'region' => '-1', 'weight' => '', 'module' => 'block_test', 'status' => '1', 'visibility' => array(), 'plugin' => 'test_html_id', 'settings' => array( 'cache' => '1', 'subject' => t('Test block html id'), ), ); $this->assertIdentical($actual_properties, $expected_properties, 'The block properties are exported correctly.'); $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.test_block')); $entity = reset($entities); $this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.'); // Verify several properties of the block. $this->assertEqual($entity->get('region'), '-1'); $this->assertTrue($entity->get('status')); $this->assertEqual($entity->get('theme'), 'stark'); $this->assertEqual($entity->get('module'), 'block_test'); $this->assertTrue($entity->uuid()); } /** * Tests the rendering of blocks. */ protected function renderTests() { $entity = $this->controller->create(array( 'id' => 'stark.test_block', 'plugin' => 'test_html_id', )); // Test the rendering of a block. $output = entity_view($entity, 'block'); $expected = array(); $expected[] = '