Tests removing a block display.
protected 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(
'title' => 'test_view_block-block_1:1',
));
$block_2 = $this
->drupalPlaceBlock('views_block:test_view_block-block_1', array(
'title' => '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(
'title' => 'test_view_block2-block_1',
));
$block_4 = $this
->drupalPlaceBlock('views_block:test_view_block2-block_2', array(
'title' => '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_controller = $this->container
->get('plugin.manager.entity')
->getStorageController('block');
// Remove the block display, so both block entities from the first view
// should both dissapear.
$view = views_get_view('test_view_block');
$view
->initDisplay();
$view->displayHandlers
->remove('block_1');
$view->storage
->save();
$this
->assertFalse($block_storage_controller
->load(array(
$block_1
->id(),
)), 'The block for this display was removed.');
$this
->assertFalse($block_storage_controller
->load(array(
$block_2
->id(),
)), 'The block for this display was removed.');
$this
->assertTrue($block_storage_controller
->load(array(
$block_3
->id(),
)), 'A block from another view was unaffected.');
$this
->assertTrue($block_storage_controller
->load(array(
$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_get_view('test_view_block2');
$view
->initDisplay();
$view->displayHandlers
->remove('block_1');
$view->storage
->save();
$this
->assertFalse($block_storage_controller
->load(array(
$block_3
->id(),
)), 'The block for this display was removed.');
$this
->assertTrue($block_storage_controller
->load(array(
$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);
}