class ContentModerationNotificationTest in Content Moderation Notifications 8.3
Same name and namespace in other branches
- 8.2 tests/src/Unit/Entity/ContentModerationNotificationTest.php \Drupal\Tests\content_moderation_notifications\Unit\Entity\ContentModerationNotificationTest
Tests for the notification entity.
@group content_moderation_notifications
@coversDefaultClass \Drupal\content_moderation_notifications\Entity\ContentModerationNotification
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\content_moderation_notifications\Unit\Entity\ContentModerationNotificationTest
Expanded class hierarchy of ContentModerationNotificationTest
File
- tests/
src/ Unit/ Entity/ ContentModerationNotificationTest.php, line 20
Namespace
Drupal\Tests\content_moderation_notifications\Unit\EntityView source
class ContentModerationNotificationTest extends UnitTestCase {
/**
* Test fixture.
*
* @var \Drupal\content_moderation_notifications\Entity\ContentModerationNotification
*/
protected $notification;
/**
* Test data for the fixture.
*
* @var array
*/
protected static $data = [
'id' => 'foo',
'roles' => [
'authenticated' => 'authenticated',
'biz' => 'biz',
],
'workflow' => 'foo_bar',
'transitions' => [
'foo_to_bar',
'bar_to_foo',
],
'subject' => 'A test notification',
'body' => [
'value' => 'Test message body',
'format' => 'test_format',
],
'author' => TRUE,
'emails' => 'foo@example.com',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->notification = new ContentModerationNotification(static::$data, 'content_moderation_notification');
}
/**
* @covers ::sendToAuthor
*/
public function testSendToAuthor() {
$this
->assertEquals(TRUE, $this->notification
->sendToAuthor());
}
/**
* @covers ::getEmails
*/
public function testGetEmails() {
$this
->assertEquals('foo@example.com', $this->notification
->getEmails());
}
/**
* @covers ::getWorkflowId
*/
public function testGetWorkflowId() {
$this
->assertEquals('foo_bar', $this->notification
->getWorkflowId());
}
/**
* @covers ::getRoleIds
*/
public function testGetRoleIds() {
$this
->assertEquals(static::$data['roles'], $this->notification
->getRoleIds());
}
/**
* @covers ::getTransitions
*/
public function testGetTransitions() {
$this
->assertEquals(static::$data['transitions'], $this->notification
->getTransitions());
}
/**
* @covers ::getSubject
*/
public function testGetSubject() {
$this
->assertEquals(static::$data['subject'], $this->notification
->getSubject());
}
/**
* @covers ::getMessage
*/
public function testGetMessage() {
$this
->assertEquals(static::$data['body']['value'], $this->notification
->getMessage());
}
/**
* @covers ::getMessageFormat
*/
public function getMessageFormat() {
$this
->assertEquals(static::$data['body']['format'], $this->notification
->getMessageFormat());
}
/**
* @covers ::preSave
*/
public function testPreSave() {
$data = static::$data;
$data['roles']['not_set'] = 0;
$data['transitions']['not_set'] = 0;
$notification = new ContentModerationNotification($data, 'content_moderation_notification');
// Mock out some necessary services.
$container = new ContainerBuilder();
$entity_type = $this
->prophesize(EntityTypeInterface::class)
->reveal();
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getDefinition('content_moderation_notification')
->willReturn($entity_type);
$container
->set('entity_type.manager', $entity_type_manager
->reveal());
\Drupal::setContainer($container);
$storage = $this
->prophesize(EntityStorageInterface::class);
$query = $this
->prophesize(QueryInterface::class);
$query
->execute()
->willReturn([]);
$query
->condition('uuid', NULL)
->willReturn($query
->reveal());
$storage
->getQuery()
->willReturn($query
->reveal());
$storage
->loadUnchanged('foo')
->willReturn($notification);
$notification
->preSave($storage
->reveal());
$this
->assertEquals(static::$data['roles'], $notification
->getRoleIds());
$this
->assertEquals(static::$data['transitions'], $notification
->getTransitions());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentModerationNotificationTest:: |
protected static | property | Test data for the fixture. | |
ContentModerationNotificationTest:: |
protected | property | Test fixture. | |
ContentModerationNotificationTest:: |
public | function | @covers ::getMessageFormat | |
ContentModerationNotificationTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ContentModerationNotificationTest:: |
public | function | @covers ::getEmails | |
ContentModerationNotificationTest:: |
public | function | @covers ::getMessage | |
ContentModerationNotificationTest:: |
public | function | @covers ::getRoleIds | |
ContentModerationNotificationTest:: |
public | function | @covers ::getSubject | |
ContentModerationNotificationTest:: |
public | function | @covers ::getTransitions | |
ContentModerationNotificationTest:: |
public | function | @covers ::getWorkflowId | |
ContentModerationNotificationTest:: |
public | function | @covers ::preSave | |
ContentModerationNotificationTest:: |
public | function | @covers ::sendToAuthor | |
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. |