class ModerationInformationTest in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/ModerationInformationTest.php \Drupal\Tests\workbench_moderation\Unit\ModerationInformationTest
@coversDefaultClass \Drupal\workbench_moderation\ModerationInformation @group workbench_moderation
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\workbench_moderation\Unit\ModerationInformationTest
Expanded class hierarchy of ModerationInformationTest
File
- tests/
src/ Unit/ ModerationInformationTest.php, line 20
Namespace
Drupal\Tests\workbench_moderation\UnitView source
class ModerationInformationTest extends UnitTestCase {
/**
* Builds a mock user.
*
* @return \Drupal\Core\Session\AccountInterface
* Returns account interface.
*/
protected function getUser() {
return $this
->prophesize(AccountInterface::class)
->reveal();
}
/**
* Returns a mock Entity Type Manager.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_bundle_storage
* Entity bundle storage.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* Returns entity type manager.
*/
protected function getEntityTypeManager(EntityStorageInterface $entity_bundle_storage) {
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getStorage('entity_test_bundle')
->willReturn($entity_bundle_storage);
return $entity_type_manager
->reveal();
}
/**
* Setup moderation entity manager.
*/
public function setupModerationEntityManager($status) {
$bundle = $this
->prophesize(ConfigEntityInterface::class);
$bundle
->getThirdPartySetting('workbench_moderation', 'enabled', FALSE)
->willReturn($status);
$entity_storage = $this
->prophesize(EntityStorageInterface::class);
$entity_storage
->load('test_bundle')
->willReturn($bundle
->reveal());
return $this
->getEntityTypeManager($entity_storage
->reveal());
}
/**
* Test moderatable entity.
*
* @dataProvider providerBoolean
* @covers ::isModeratableEntity
*/
public function testIsModeratableEntity($status) {
$moderation_information = new ModerationInformation($this
->setupModerationEntityManager($status), $this
->getUser());
$entity_type = new ContentEntityType([
'id' => 'test_entity_type',
'bundle_entity_type' => 'entity_test_bundle',
]);
$entity = $this
->prophesize(ContentEntityInterface::class);
$entity
->getEntityType()
->willReturn($entity_type);
$entity
->bundle()
->willReturn('test_bundle');
$this
->assertEquals($status, $moderation_information
->isModeratableEntity($entity
->reveal()));
}
/**
* @covers ::isModeratableEntity
*/
public function testIsModeratableEntityForNonBundleEntityType() {
$entity_type = new ContentEntityType([
'id' => 'test_entity_type',
]);
$entity = $this
->prophesize(ContentEntityInterface::class);
$entity
->getEntityType()
->willReturn($entity_type);
$entity
->bundle()
->willReturn('test_entity_type');
$entity_storage = $this
->prophesize(EntityStorageInterface::class);
$entity_type_manager = $this
->getEntityTypeManager($entity_storage
->reveal());
$moderation_information = new ModerationInformation($entity_type_manager, $this
->getUser());
$this
->assertEquals(FALSE, $moderation_information
->isModeratableEntity($entity
->reveal()));
}
/**
* Test moderatable bundle.
*
* @dataProvider providerBoolean
* @covers ::isModeratableBundle
*/
public function testIsModeratableBundle($status) {
$entity_type = new ContentEntityType([
'id' => 'test_entity_type',
'bundle_entity_type' => 'entity_test_bundle',
]);
$moderation_information = new ModerationInformation($this
->setupModerationEntityManager($status), $this
->getUser());
$this
->assertEquals($status, $moderation_information
->isModeratableBundle($entity_type, 'test_bundle'));
}
/**
* Test moderated entity form.
*
* @dataProvider providerBoolean
* @covers ::isModeratedEntityForm
*/
public function testIsModeratedEntityForm($status) {
$entity_type = new ContentEntityType([
'id' => 'test_entity_type',
'bundle_entity_type' => 'entity_test_bundle',
]);
$entity = $this
->prophesize(ContentEntityInterface::class);
$entity
->getEntityType()
->willReturn($entity_type);
$entity
->bundle()
->willReturn('test_bundle');
$form = $this
->prophesize(ContentEntityFormInterface::class);
$form
->getEntity()
->willReturn($entity);
$moderation_information = new ModerationInformation($this
->setupModerationEntityManager($status), $this
->getUser());
$this
->assertEquals($status, $moderation_information
->isModeratedEntityForm($form
->reveal()));
}
/**
* Test if moderated entity form is with non content entity form.
*/
public function testIsModeratedEntityFormWithNonContentEntityForm() {
$form = $this
->prophesize(EntityFormInterface::class);
$moderation_information = new ModerationInformation($this
->setupModerationEntityManager(TRUE), $this
->getUser());
$this
->assertFalse($moderation_information
->isModeratedEntityForm($form
->reveal()));
}
/**
* Provides array with boolean values.
*/
public function providerBoolean() {
return [
[
FALSE,
],
[
TRUE,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ModerationInformationTest:: |
protected | function | Returns a mock Entity Type Manager. | |
ModerationInformationTest:: |
protected | function | Builds a mock user. | |
ModerationInformationTest:: |
public | function | Provides array with boolean values. | |
ModerationInformationTest:: |
public | function | Setup moderation entity manager. | |
ModerationInformationTest:: |
public | function | Test moderatable bundle. | |
ModerationInformationTest:: |
public | function | Test moderatable entity. | |
ModerationInformationTest:: |
public | function | @covers ::isModeratableEntity | |
ModerationInformationTest:: |
public | function | Test moderated entity form. | |
ModerationInformationTest:: |
public | function | Test if moderated entity form is with non content entity form. | |
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 |