BlockTest.php in Drupal 10
File
core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php
View source
<?php
namespace Drupal\Tests\views\Unit\Plugin\views\display;
use Drupal\Tests\UnitTestCase;
class BlockTest extends UnitTestCase {
protected $executable;
protected $blockPlugin;
protected $blockDisplay;
protected function setUp() : void {
parent::setUp();
$this->executable = $this
->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->onlyMethods([
'executeDisplay',
'setDisplay',
'setItemsPerPage',
])
->getMock();
$this->executable
->expects($this
->any())
->method('setDisplay')
->with('block_1')
->will($this
->returnValue(TRUE));
$this->blockDisplay = $this->executable->display_handler = $this
->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')
->disableOriginalConstructor()
->onlyMethods([])
->getMock();
$this->blockDisplay->view = $this->executable;
$this->blockPlugin = $this
->getMockBuilder('Drupal\\views\\Plugin\\Block\\ViewsBlock')
->disableOriginalConstructor()
->getMock();
}
public function testBuildNoOverride() {
$this->executable
->expects($this
->never())
->method('setItemsPerPage');
$this->blockPlugin
->expects($this
->once())
->method('getConfiguration')
->will($this
->returnValue([
'items_per_page' => 'none',
]));
$this->blockDisplay
->preBlockBuild($this->blockPlugin);
}
public function testBuildOverride() {
$this->executable
->expects($this
->once())
->method('setItemsPerPage')
->with(5);
$this->blockPlugin
->expects($this
->once())
->method('getConfiguration')
->will($this
->returnValue([
'items_per_page' => 5,
]));
$this->blockDisplay
->preBlockBuild($this->blockPlugin);
}
}