public function DisplayBlockTest::testDeleteBlockDisplay in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/block/src/Tests/Views/DisplayBlockTest.php \Drupal\block\Tests\Views\DisplayBlockTest::testDeleteBlockDisplay()
Tests removing a block display.
File
- core/
modules/ block/ src/ Tests/ Views/ DisplayBlockTest.php, line 131 - Contains \Drupal\block\Tests\Views\DisplayBlockTest.
Class
- DisplayBlockTest
- Tests the block display plugin.
Namespace
Drupal\block\Tests\ViewsCode
public function testDeleteBlockDisplay() {
// To test all combinations possible we first place create two instances
// of the block display of the first view.
$block_1 = $this
->drupalPlaceBlock('views_block:test_view_block-block_1', array(
'label' => 'test_view_block-block_1:1',
));
$block_2 = $this
->drupalPlaceBlock('views_block:test_view_block-block_1', array(
'label' => 'test_view_block-block_1:2',
));
// Then we add one instance of blocks for each of the two displays of the
// second view.
$block_3 = $this
->drupalPlaceBlock('views_block:test_view_block2-block_1', array(
'label' => 'test_view_block2-block_1',
));
$block_4 = $this
->drupalPlaceBlock('views_block:test_view_block2-block_2', array(
'label' => 'test_view_block2-block_2',
));
$this
->drupalGet('test-page');
$this
->assertBlockAppears($block_1);
$this
->assertBlockAppears($block_2);
$this
->assertBlockAppears($block_3);
$this
->assertBlockAppears($block_4);
$block_storage = $this->container
->get('entity.manager')
->getStorage('block');
// Remove the block display, so both block entities from the first view
// should both disappear.
$view = Views::getView('test_view_block');
$view
->initDisplay();
$view->displayHandlers
->remove('block_1');
$view->storage
->save();
$this
->assertFalse($block_storage
->load($block_1
->id()), 'The block for this display was removed.');
$this
->assertFalse($block_storage
->load($block_2
->id()), 'The block for this display was removed.');
$this
->assertTrue($block_storage
->load($block_3
->id()), 'A block from another view was unaffected.');
$this
->assertTrue($block_storage
->load($block_4
->id()), 'A block from another view was unaffected.');
$this
->drupalGet('test-page');
$this
->assertNoBlockAppears($block_1);
$this
->assertNoBlockAppears($block_2);
$this
->assertBlockAppears($block_3);
$this
->assertBlockAppears($block_4);
// Remove the first block display of the second view and ensure the block
// instance of the second block display still exists.
$view = Views::getView('test_view_block2');
$view
->initDisplay();
$view->displayHandlers
->remove('block_1');
$view->storage
->save();
$this
->assertFalse($block_storage
->load($block_3
->id()), 'The block for this display was removed.');
$this
->assertTrue($block_storage
->load($block_4
->id()), 'A block from another display on the same view was unaffected.');
$this
->drupalGet('test-page');
$this
->assertNoBlockAppears($block_3);
$this
->assertBlockAppears($block_4);
}