class UserSectionStorageUnitTest in Workbench Access 8
Unit tests for user section storage service.
@group workbench_access
@coversDefaultClass \Drupal\workbench_access\UserSectionStorage
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\workbench_access\Unit\UserSectionStorageUnitTest
Expanded class hierarchy of UserSectionStorageUnitTest
File
- tests/
src/ Unit/ UserSectionStorageUnitTest.php, line 21
Namespace
Drupal\Tests\workbench_access\UnitView source
class UserSectionStorageUnitTest extends UnitTestCase {
/**
* Tests that ::getUserSections is statically cached.
*
* @covers ::getUserSections
*/
public function testGetUserSectionsShouldBeStaticallyCached() {
$user = $this
->prophesize(UserInterface::class);
$testUserId = 37;
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$section_storage = $this
->prophesize(EntityStorageInterface::class);
$query = $this
->prophesize(QueryAggregateInterface::class);
$section_storage
->getAggregateQuery()
->willReturn($query
->reveal());
$query
->condition('access_scheme', 'editorial_section')
->willReturn($query
->reveal());
$query
->condition('user_id', 37)
->willReturn($query
->reveal());
$query
->groupBy('section_id')
->willReturn($query
->reveal());
$query
->execute()
->willReturn([
37 => [
'section_id' => 3,
],
])
->shouldBeCalledTimes(1);
$entity_type_manager
->getStorage('section_association')
->willReturn($section_storage
->reveal());
$scheme = $this
->prophesize(AccessSchemeInterface::class);
$scheme
->id()
->willReturn('editorial_section');
$user
->id()
->willReturn($testUserId);
$role_section_storage = $this
->prophesize(RoleSectionStorageInterface::class);
$role_section_storage
->getRoleSections($scheme
->reveal(), $user
->reveal())
->willReturn([]);
$user_section_storage = new UserSectionStorage($entity_type_manager
->reveal(), $user
->reveal(), $role_section_storage
->reveal());
// First time, prime the cache.
$first = $user_section_storage
->getUserSections($scheme
->reveal(), $user
->reveal());
// Second time, just return the result.
$second = $user_section_storage
->getUserSections($scheme
->reveal(), $user
->reveal());
$this
->assertEquals($first, $second);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed 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. | |
UnitTestCase:: |
protected | function | 340 | |
UserSectionStorageUnitTest:: |
public | function | Tests that ::getUserSections is statically cached. |