You are here

class RolesRidTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php \Drupal\Tests\user\Unit\Views\Argument\RolesRidTest

@coversDefaultClass \Drupal\user\Plugin\views\argument\RolesRid @group user

Hierarchy

  • class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase

Expanded class hierarchy of RolesRidTest

File

core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php, line 19
Contains \Drupal\Tests\user\Unit\Views\Argument\RolesRidTest.

Namespace

Drupal\Tests\user\Unit\Views\Argument
View source
class RolesRidTest extends UnitTestCase {

  /**
   * Tests the titleQuery method.
   *
   * @covers ::titleQuery
   */
  public function testTitleQuery() {
    $role1 = new Role(array(
      'id' => 'test_rid_1',
      'label' => 'test rid 1',
    ), 'user_role');
    $role2 = new Role(array(
      'id' => 'test_rid_2',
      'label' => 'test <strong>rid 2</strong>',
    ), 'user_role');

    // Creates a stub entity storage;
    $role_storage = $this
      ->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityStorageInterface');
    $role_storage
      ->expects($this
      ->any())
      ->method('loadMultiple')
      ->will($this
      ->returnValueMap(array(
      array(
        array(),
        array(),
      ),
      array(
        array(
          'test_rid_1',
        ),
        array(
          'test_rid_1' => $role1,
        ),
      ),
      array(
        array(
          'test_rid_1',
          'test_rid_2',
        ),
        array(
          'test_rid_1' => $role1,
          'test_rid_2' => $role2,
        ),
      ),
    )));
    $entity_type = $this
      ->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
    $entity_type
      ->expects($this
      ->any())
      ->method('getKey')
      ->with('label')
      ->will($this
      ->returnValue('label'));
    $entity_manager = $this
      ->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
    $entity_manager
      ->expects($this
      ->any())
      ->method('getDefinition')
      ->with($this
      ->equalTo('user_role'))
      ->will($this
      ->returnValue($entity_type));
    $entity_manager
      ->expects($this
      ->once())
      ->method('getStorage')
      ->with($this
      ->equalTo('user_role'))
      ->will($this
      ->returnValue($role_storage));

    // @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to
    //   entity_get_info(), which in turn wraps \Drupal::entityManager(). Set
    //   the entity manager until this is fixed.
    $container = new ContainerBuilder();
    $container
      ->set('entity.manager', $entity_manager);
    \Drupal::setContainer($container);
    $roles_rid_argument = new RolesRid(array(), 'user__roles_rid', array(), $entity_manager);
    $roles_rid_argument->value = array();
    $titles = $roles_rid_argument
      ->titleQuery();
    $this
      ->assertEquals(array(), $titles);
    $roles_rid_argument->value = array(
      'test_rid_1',
    );
    $titles = $roles_rid_argument
      ->titleQuery();
    $this
      ->assertEquals(array(
      'test rid 1',
    ), $titles);
    $roles_rid_argument->value = array(
      'test_rid_1',
      'test_rid_2',
    );
    $titles = $roles_rid_argument
      ->titleQuery();
    $this
      ->assertEquals(array(
      'test rid 1',
      'test <strong>rid 2</strong>',
    ), $titles);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RolesRidTest::testTitleQuery public function Tests the titleQuery method.
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.
UnitTestCase::setUp protected function 259