class EntityListBuilderTest in Zircon Profile 8
Same name in this branch
- 8 core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest
- 8 core/modules/system/src/Tests/Entity/EntityListBuilderTest.php \Drupal\system\Tests\Entity\EntityListBuilderTest
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest
@coversDefaultClass \Drupal\entity_test\EntityTestListBuilder @group Entity
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase- class \Drupal\Tests\Core\Entity\EntityListBuilderTest
 
Expanded class hierarchy of EntityListBuilderTest
File
- core/tests/ Drupal/ Tests/ Core/ Entity/ EntityListBuilderTest.php, line 21 
- Contains \Drupal\Tests\Core\Entity\EntityListBuilderTest.
Namespace
Drupal\Tests\Core\EntityView source
class EntityListBuilderTest extends UnitTestCase {
  /**
   * The entity type used for testing.
   *
   * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $entityType;
  /**
   * The module handler used for testing.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $moduleHandler;
  /**
   * The translation manager used for testing.
   *
   * @var \Drupal\Core\StringTranslation\TranslationInterface
   */
  protected $translationManager;
  /**
   * The role storage used for testing.
   *
   * @var \Drupal\user\RoleStorageInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $roleStorage;
  /**
   * The service container used for testing.
   *
   * @var \Drupal\Core\DependencyInjection\ContainerBuilder
   */
  protected $container;
  /**
   * The entity used to construct the EntityListBuilder.
   *
   * @var \Drupal\user\RoleInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $role;
  /**
   * The EntityListBuilder object to test.
   *
   * @var \Drupal\Core\Entity\EntityListBuilder
   */
  protected $entityListBuilder;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->role = $this
      ->getMock('Drupal\\user\\RoleInterface');
    $this->roleStorage = $this
      ->getMock('\\Drupal\\user\\RoleStorageInterface');
    $this->moduleHandler = $this
      ->getMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $this->entityType = $this
      ->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
    $this->translationManager = $this
      ->getMock('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
    $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
    $this->container = new ContainerBuilder();
    \Drupal::setContainer($this->container);
  }
  /**
   * @covers ::getOperations
   */
  public function testGetOperations() {
    $operation_name = $this
      ->randomMachineName();
    $operations = array(
      $operation_name => array(
        'title' => $this
          ->randomMachineName(),
      ),
    );
    $this->moduleHandler
      ->expects($this
      ->once())
      ->method('invokeAll')
      ->with('entity_operation', array(
      $this->role,
    ))
      ->will($this
      ->returnValue($operations));
    $this->moduleHandler
      ->expects($this
      ->once())
      ->method('alter')
      ->with('entity_operation');
    $this->container
      ->set('module_handler', $this->moduleHandler);
    $this->role
      ->expects($this
      ->any())
      ->method('access')
      ->will($this
      ->returnValue(AccessResult::allowed()));
    $this->role
      ->expects($this
      ->any())
      ->method('hasLinkTemplate')
      ->will($this
      ->returnValue(TRUE));
    $url = $this
      ->getMockBuilder('\\Drupal\\Core\\Url')
      ->disableOriginalConstructor()
      ->getMock();
    $url
      ->expects($this
      ->any())
      ->method('toArray')
      ->will($this
      ->returnValue(array()));
    $this->role
      ->expects($this
      ->any())
      ->method('urlInfo')
      ->will($this
      ->returnValue($url));
    $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
    $list
      ->setStringTranslation($this->translationManager);
    $operations = $list
      ->getOperations($this->role);
    $this
      ->assertInternalType('array', $operations);
    $this
      ->assertArrayHasKey('edit', $operations);
    $this
      ->assertInternalType('array', $operations['edit']);
    $this
      ->assertArrayHasKey('title', $operations['edit']);
    $this
      ->assertArrayHasKey('delete', $operations);
    $this
      ->assertInternalType('array', $operations['delete']);
    $this
      ->assertArrayHasKey('title', $operations['delete']);
    $this
      ->assertArrayHasKey($operation_name, $operations);
    $this
      ->assertInternalType('array', $operations[$operation_name]);
    $this
      ->assertArrayHasKey('title', $operations[$operation_name]);
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| EntityListBuilderTest:: | protected | property | The service container used for testing. | |
| EntityListBuilderTest:: | protected | property | The EntityListBuilder object to test. | |
| EntityListBuilderTest:: | protected | property | The entity type used for testing. | |
| EntityListBuilderTest:: | protected | property | The module handler used for testing. | |
| EntityListBuilderTest:: | protected | property | The entity used to construct the EntityListBuilder. | |
| EntityListBuilderTest:: | protected | property | The role storage used for testing. | |
| EntityListBuilderTest:: | protected | property | The translation manager used for testing. | |
| EntityListBuilderTest:: | protected | function | Overrides UnitTestCase:: | |
| EntityListBuilderTest:: | public | function | @covers ::getOperations | |
| 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. | 
