3 namespace Drupal\Tests\content_moderation\Kernel;
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\workflows\Entity\Workflow;
9 * Tests the API of the ContentModeration workflow type plugin.
11 * @group content_moderation
13 * @coversDefaultClass \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration
15 class ContentModerationWorkflowTypeApiTest extends KernelTestBase {
18 * A workflow for testing.
20 * @var \Drupal\workflows\Entity\Workflow;
29 public static $modules = [
37 protected function setUp() {
39 $this->workflow = Workflow::create(['id' => 'test', 'type' => 'content_moderation']);
41 ->addState('draft', 'Draft')
42 ->addState('published', 'Published');
46 * @covers ::getBundlesForEntityType
47 * @covers ::addEntityTypeAndBundle
48 * @covers ::removeEntityTypeAndBundle
50 public function testGetBundlesForEntityType() {
51 /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $workflow_plugin */
52 $workflow_plugin = $this->workflow->getTypePlugin();
53 // The content moderation plugin does not validate the existence of the
54 // entity type or bundle.
55 $this->assertEquals([], $workflow_plugin->getBundlesForEntityType('fake_node'));
56 $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_page');
57 $this->assertEquals(['fake_page'], $workflow_plugin->getBundlesForEntityType('fake_node'));
58 $this->assertEquals([], $workflow_plugin->getBundlesForEntityType('fake_block'));
59 $workflow_plugin->removeEntityTypeAndBundle('fake_node', 'fake_page');
60 $this->assertEquals([], $workflow_plugin->getBundlesForEntityType('fake_node'));
64 * @covers ::appliesToEntityTypeAndBundle
65 * @covers ::addEntityTypeAndBundle
66 * @covers ::removeEntityTypeAndBundle
68 public function testAppliesToEntityTypeAndBundle() {
69 /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $workflow_plugin */
70 $workflow_plugin = $this->workflow->getTypePlugin();
71 // The content moderation plugin does not validate the existence of the
72 // entity type or bundle.
73 $this->assertFalse($workflow_plugin->appliesToEntityTypeAndBundle('fake_node', 'fake_page'));
74 $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_page');
75 $this->assertTrue($workflow_plugin->appliesToEntityTypeAndBundle('fake_node', 'fake_page'));
76 $this->assertFalse($workflow_plugin->appliesToEntityTypeAndBundle('fake_block', 'fake_custom'));
77 $workflow_plugin->removeEntityTypeAndBundle('fake_node', 'fake_page');
78 $this->assertFalse($workflow_plugin->appliesToEntityTypeAndBundle('fake_node', 'fake_page'));
82 * @covers ::addEntityTypeAndBundle
84 public function testAddEntityTypeAndBundle() {
85 /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $workflow_plugin */
86 $workflow_plugin = $this->workflow->getTypePlugin();
88 // The bundles are intentionally added in reverse alphabetical order.
89 $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_page');
90 $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_article');
92 // Add another entity type that comes alphabetically before 'fake_node'.
93 $workflow_plugin->addEntityTypeAndBundle('fake_block', 'fake_custom');
95 // The entity type keys and bundle values should be sorted alphabetically.
96 // The bundle array index should not reflect the order in which they are
99 ['fake_block' => ['fake_custom'], 'fake_node' => ['fake_article', 'fake_page']],
100 $workflow_plugin->getConfiguration()['entity_types']