class BlockTest

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/BlockTest.php \Drupal\Tests\jsonapi\Functional\BlockTest
  2. 10 core/modules/block/tests/src/Kernel/Plugin/migrate/source/BlockTest.php \Drupal\Tests\block\Kernel\Plugin\migrate\source\BlockTest
  3. 10 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest
Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/BlockTest.php \Drupal\Tests\jsonapi\Functional\BlockTest
  2. 9 core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest
  3. 9 core/modules/block/tests/src/Kernel/Plugin/migrate/source/BlockTest.php \Drupal\Tests\block\Kernel\Plugin\migrate\source\BlockTest
  4. 9 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest
  5. 8.9.x core/modules/jsonapi/tests/src/Functional/BlockTest.php \Drupal\Tests\jsonapi\Functional\BlockTest
  6. 8.9.x core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest
  7. 8.9.x core/modules/block/tests/src/Kernel/Plugin/migrate/source/BlockTest.php \Drupal\Tests\block\Kernel\Plugin\migrate\source\BlockTest
  8. 8.9.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest
  9. 11.x core/modules/jsonapi/tests/src/Functional/BlockTest.php \Drupal\Tests\jsonapi\Functional\BlockTest
  10. 11.x core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest
  11. 11.x core/modules/block/tests/src/Kernel/Plugin/migrate/source/BlockTest.php \Drupal\Tests\block\Kernel\Plugin\migrate\source\BlockTest
  12. 11.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest

@coversDefaultClass \Drupal\views\Plugin\views\display\Block @group block

Hierarchy

Expanded class hierarchy of BlockTest

File

core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php, line 13

Namespace

Drupal\Tests\views\Unit\Plugin\views\display
View 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.
     */
    public function testBuildNoOverride() : void {
        $this->executable
            ->expects($this->never())
            ->method('setItemsPerPage');
        $this->blockPlugin
            ->expects($this->once())
            ->method('getConfiguration')
            ->willReturn([
            'items_per_page' => 'none',
        ]);
        $this->blockDisplay
            ->preBlockBuild($this->blockPlugin);
    }
    
    /**
     * Tests the build method with overriding items per page.
     */
    public function testBuildOverride() : void {
        $this->executable
            ->expects($this->once())
            ->method('setItemsPerPage')
            ->with(5);
        $this->blockPlugin
            ->expects($this->once())
            ->method('getConfiguration')
            ->willReturn([
            'items_per_page' => 5,
        ]);
        $this->blockDisplay
            ->preBlockBuild($this->blockPlugin);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
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.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
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.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
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::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
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::setUpBeforeClass public static function
UnitTestCase::__get public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.