BlockLocalTasksTest.php 2.16 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Tests\block\Unit\Menu\BlockLocalTasksTest.
6 7
 */

8
namespace Drupal\Tests\block\Unit\Menu;
9 10

use Drupal\Tests\Core\Menu\LocalTaskIntegrationTest;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12 13

/**
14
 * Tests block local tasks.
15
 *
16
 * @group block
17 18 19
 */
class BlockLocalTasksTest extends LocalTaskIntegrationTest {

20
  protected function setUp() {
21
    $this->directoryList = array('block' => 'core/modules/block');
22 23 24 25 26
    parent::setUp();

    $config_factory = $this->getConfigFactoryStub(array('system.theme' => array(
      'default' => 'test_c',
    )));
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

    $themes = array();
    $themes['test_a'] = (object) array(
      'status' => 0,
    );
    $themes['test_b'] = (object) array(
      'status' => 1,
      'info' => array(
        'name' => 'test_b',
      ),
    );
    $themes['test_c'] = (object) array(
      'status' => 1,
      'info' => array(
        'name' => 'test_c',
      ),
    );
    $theme_handler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
    $theme_handler->expects($this->any())
      ->method('listInfo')
      ->will($this->returnValue($themes));

    $container = new ContainerBuilder();
    $container->set('config.factory', $config_factory);
    $container->set('theme_handler', $theme_handler);
    \Drupal::setContainer($container);
53 54 55 56 57 58
  }

  /**
   * Tests the admin edit local task.
   */
  public function testBlockAdminLocalTasks() {
59
    $this->assertLocalTasks('entity.block.edit_form', array(array('entity.block.edit_form')));
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  }

  /**
   * Tests the block admin display local tasks.
   *
   * @dataProvider providerTestBlockAdminDisplay
   */
  public function testBlockAdminDisplay($route, $expected) {
    $this->assertLocalTasks($route, $expected);
  }

  /**
   * Provides a list of routes to test.
   */
  public function providerTestBlockAdminDisplay() {
    return array(
      array('block.admin_display', array(array('block.admin_display'), array('block.admin_display_theme:test_b', 'block.admin_display_theme:test_c'))),
      array('block.admin_display_theme', array(array('block.admin_display'), array('block.admin_display_theme:test_b', 'block.admin_display_theme:test_c'))),
    );
  }

}