class ViewsBlockTest in Zircon Profile 8
Same name in this branch
- 8 core/modules/views/src/Tests/Plugin/ViewsBlockTest.php \Drupal\views\Tests\Plugin\ViewsBlockTest
 - 8 core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php \Drupal\Tests\views\Unit\Plugin\Block\ViewsBlockTest
 
Same name and namespace in other branches
- 8.0 core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php \Drupal\Tests\views\Unit\Plugin\Block\ViewsBlockTest
 
@coversDefaultClass \Drupal\views\Plugin\block\ViewsBlock @group views
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\views\Unit\Plugin\Block\ViewsBlockTest
 
 
Expanded class hierarchy of ViewsBlockTest
File
- core/
modules/ views/ tests/ src/ Unit/ Plugin/ Block/ ViewsBlockTest.php, line 23  - Contains \Drupal\Tests\views\Unit\Plugin\Block\ViewsBlockTest.
 
Namespace
Drupal\Tests\views\Unit\Plugin\BlockView source
class ViewsBlockTest extends UnitTestCase {
  /**
   * The view executable.
   *
   * @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $executable;
  /**
   * The view executable factory.
   *
   * @var \Drupal\views\ViewExecutableFactory|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $executableFactory;
  /**
   * The view entity.
   *
   * @var \Drupal\views\ViewEntityInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $view;
  /**
   * The view storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $storage;
  /**
   * The mocked user account.
   *
   * @var \Drupal\Core\Session\AccountInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $account;
  /**
   * The mocked display handler.
   *
   * @var \Drupal\views\Plugin\views\display\Block|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $displayHandler;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    // TODO: Change the autogenerated stub
    $condition_plugin_manager = $this
      ->getMock('Drupal\\Core\\Executable\\ExecutableManagerInterface');
    $condition_plugin_manager
      ->expects($this
      ->any())
      ->method('getDefinitions')
      ->will($this
      ->returnValue(array()));
    $container = new ContainerBuilder();
    $container
      ->set('plugin.manager.condition', $condition_plugin_manager);
    \Drupal::setContainer($container);
    $this->executable = $this
      ->getMockBuilder('Drupal\\views\\ViewExecutable')
      ->disableOriginalConstructor()
      ->setMethods([
      'buildRenderable',
      'setDisplay',
      'setItemsPerPage',
    ])
      ->getMock();
    $this->executable
      ->expects($this
      ->any())
      ->method('setDisplay')
      ->with('block_1')
      ->will($this
      ->returnValue(TRUE));
    $this->executable
      ->expects($this
      ->any())
      ->method('getShowAdminLinks')
      ->willReturn(FALSE);
    $this->executable->display_handler = $this
      ->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')
      ->disableOriginalConstructor()
      ->setMethods(NULL)
      ->getMock();
    $this->view = $this
      ->getMockBuilder('Drupal\\views\\Entity\\View')
      ->disableOriginalConstructor()
      ->getMock();
    $this->view
      ->expects($this
      ->any())
      ->method('id')
      ->willReturn('test_view');
    $this->executable->storage = $this->view;
    $this->executableFactory = $this
      ->getMockBuilder('Drupal\\views\\ViewExecutableFactory')
      ->disableOriginalConstructor()
      ->getMock();
    $this->executableFactory
      ->expects($this
      ->any())
      ->method('get')
      ->with($this->view)
      ->will($this
      ->returnValue($this->executable));
    $this->displayHandler = $this
      ->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')
      ->disableOriginalConstructor()
      ->getMock();
    $this->displayHandler
      ->expects($this
      ->any())
      ->method('blockSettings')
      ->willReturn([]);
    $this->displayHandler
      ->expects($this
      ->any())
      ->method('getPluginId')
      ->willReturn('block');
    $this->executable->display_handler = $this->displayHandler;
    $this->storage = $this
      ->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')
      ->disableOriginalConstructor()
      ->getMock();
    $this->storage
      ->expects($this
      ->any())
      ->method('load')
      ->with('test_view')
      ->will($this
      ->returnValue($this->view));
    $this->account = $this
      ->getMock('Drupal\\Core\\Session\\AccountInterface');
  }
  /**
   * Tests the build method.
   *
   * @see \Drupal\views\Plugin\block\ViewsBlock::build()
   */
  public function testBuild() {
    $output = $this
      ->randomMachineName(100);
    $build = array(
      'view_build' => $output,
      '#view_id' => 'test_view',
      '#view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Block',
      '#view_display_show_admin_links' => FALSE,
      '#view_display_plugin_id' => 'block',
      '#pre_rendered' => TRUE,
    );
    $this->executable
      ->expects($this
      ->once())
      ->method('buildRenderable')
      ->with('block_1', [])
      ->willReturn($build);
    $block_id = 'views_block:test_view-block_1';
    $config = array();
    $definition = array();
    $definition['provider'] = 'views';
    $plugin = new ViewsBlock($config, $block_id, $definition, $this->executableFactory, $this->storage, $this->account);
    $this
      ->assertEquals($build, $plugin
      ->build());
  }
  /**
   * Tests the build method.
   *
   * @covers ::build
   */
  public function testBuildEmpty() {
    $build = [
      'view_build' => [],
      '#view_id' => 'test_view',
      '#view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Block',
      '#view_display_show_admin_links' => FALSE,
      '#view_display_plugin_id' => 'block',
      '#pre_rendered' => TRUE,
      '#cache' => [
        'contexts' => [
          'user',
        ],
      ],
    ];
    $this->executable
      ->expects($this
      ->once())
      ->method('buildRenderable')
      ->with('block_1', [])
      ->willReturn($build);
    $block_id = 'views_block:test_view-block_1';
    $config = [];
    $definition = [];
    $definition['provider'] = 'views';
    $plugin = new ViewsBlock($config, $block_id, $definition, $this->executableFactory, $this->storage, $this->account);
    $this
      ->assertEquals(array_intersect_key($build, [
      '#cache' => TRUE,
    ]), $plugin
      ->build());
  }
  /**
   * Tests the build method with a failed execution.
   *
   * @see \Drupal\views\Plugin\block\ViewsBlock::build()
   */
  public function testBuildFailed() {
    $output = FALSE;
    $this->executable
      ->expects($this
      ->once())
      ->method('buildRenderable')
      ->with('block_1', [])
      ->willReturn($output);
    $block_id = 'views_block:test_view-block_1';
    $config = array();
    $definition = array();
    $definition['provider'] = 'views';
    $plugin = new ViewsBlock($config, $block_id, $definition, $this->executableFactory, $this->storage, $this->account);
    $this
      ->assertEquals(array(), $plugin
      ->build());
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            UnitTestCase:: | 
                  protected | property | The random generator. | |
| 
            UnitTestCase:: | 
                  protected | property | The app root. | |
| 
            UnitTestCase:: | 
                  protected | function | Asserts if two arrays are equal by sorting them first. | |
| 
            UnitTestCase:: | 
                  protected | function | Mocks a block with a block plugin. | |
| 
            UnitTestCase:: | 
                  protected | function | Returns a stub class resolver. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config factory that behaves according to the passed in array. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config storage that returns the supplied configuration. | |
| 
            UnitTestCase:: | 
                  protected | function | Sets up a container with a cache tags invalidator. | |
| 
            UnitTestCase:: | 
                  protected | function | Gets the random generator for the utility methods. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub translation manager that just returns the passed string. | |
| 
            UnitTestCase:: | 
                  public | function | Generates a unique random string containing letters and numbers. | |
| 
            ViewsBlockTest:: | 
                  protected | property | The mocked user account. | |
| 
            ViewsBlockTest:: | 
                  protected | property | The mocked display handler. | |
| 
            ViewsBlockTest:: | 
                  protected | property | The view executable. | |
| 
            ViewsBlockTest:: | 
                  protected | property | The view executable factory. | |
| 
            ViewsBlockTest:: | 
                  protected | property | The view storage. | |
| 
            ViewsBlockTest:: | 
                  protected | property | The view entity. | |
| 
            ViewsBlockTest:: | 
                  protected | function | 
            Overrides UnitTestCase:: | 
                  |
| 
            ViewsBlockTest:: | 
                  public | function | Tests the build method. | |
| 
            ViewsBlockTest:: | 
                  public | function | Tests the build method. | |
| 
            ViewsBlockTest:: | 
                  public | function | Tests the build method with a failed execution. |