You are here

class BlockTest in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/block/src/Tests/BlockTest.php \Drupal\block\Tests\BlockTest
  2. 8 core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest
  3. 8 core/modules/block/tests/src/Unit/Plugin/migrate/source/BlockTest.php \Drupal\Tests\block\Unit\Plugin\migrate\source\BlockTest
Same name and namespace in other branches
  1. 8.0 core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest

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

Hierarchy

  • class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
    • class \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest

Expanded class hierarchy of BlockTest

File

core/modules/views/tests/src/Unit/Plugin/views/display/BlockTest.php, line 16
Contains \Drupal\Tests\views\Unit\Plugin\views\display\BlockTest.

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() {
    parent::setUp();
    $this->executable = $this
      ->getMockBuilder('Drupal\\views\\ViewExecutable')
      ->disableOriginalConstructor()
      ->setMethods(array(
      '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()
      ->setMethods(NULL)
      ->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')
      ->will($this
      ->returnValue(array(
      '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')
      ->will($this
      ->returnValue(array(
      'items_per_page' => 5,
    )));
    $this->blockDisplay
      ->preBlockBuild($this->blockPlugin);
  }

}

Members

Namesort descending Modifiers Type Description 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.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in 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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.