BlockTest.php

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

Namespace

Drupal\Tests\views\Unit\Plugin\views\display

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;

/**
 * @coversDefaultClass \Drupal\views\Plugin\views\display\Block
 * @group block
 */
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() {
        $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() {
        $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);
    }

}

Classes

Title Deprecated Summary
BlockTest @coversDefaultClass \Drupal\views\Plugin\views\display\Block @group block

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