class BlockTest
Tests Drupal\views\Plugin\views\display\Block.
Attributes
#[CoversClass(Block::class)]
#[Group('block')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of BlockTest
File
-
core/
modules/ views/ tests/ src/ Unit/ Plugin/ views/ display/ BlockTest.php, line 16
Namespace
Drupal\Tests\views\Unit\Plugin\views\displayView source
class BlockTest extends UnitTestCase {
/**
* The view executable.
*
* @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject
*/
protected $executable;
/**
* The views block plugin.
*
* @var \Drupal\views\Plugin\Block\ViewsBlock|\PHPUnit\Framework\MockObject\MockObject
*/
protected $blockPlugin;
/**
* The tested block display plugin.
*
* @var \Drupal\views\Plugin\views\display\Block|\PHPUnit\Framework\MockObject\MockObject
*/
protected $blockDisplay;
/**
* {@inheritdoc}
*/
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')
->willReturn(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();
}
/**
* Tests the build method with no overriding.
*
* @todo Delete the last two cases in https://www.drupal.org/project/drupal/issues/3521221. The last one is `intval('none')`.
*/
public function testBuildNoOverride($items_per_page_setting) : void {
$this->executable
->expects($this->never())
->method('setItemsPerPage');
$this->blockPlugin
->expects($this->once())
->method('getConfiguration')
->willReturn([
'items_per_page' => $items_per_page_setting,
]);
$this->blockDisplay
->preBlockBuild($this->blockPlugin);
}
/**
* Tests the build method with overriding items per page.
*/
public function testBuildOverride(mixed $input, int $expected) : void {
$this->executable
->expects($this->once())
->method('setItemsPerPage')
->with($expected);
$this->blockPlugin
->expects($this->once())
->method('getConfiguration')
->willReturn([
'items_per_page' => $input,
]);
$this->blockDisplay
->preBlockBuild($this->blockPlugin);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
BlockTest::$blockDisplay | protected | property | The tested block display plugin. | |
BlockTest::$blockPlugin | protected | property | The views block plugin. | |
BlockTest::$executable | protected | property | The view executable. | |
BlockTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
BlockTest::testBuildNoOverride | public | function | Tests the build method with no overriding. | |
BlockTest::testBuildOverride | public | function | Tests the build method with overriding items per page. | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.