3a19d22d7a519893d8a17706a4148287fde258ef
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / ContentModerationPermissionsTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Kernel;
4
5 use Drupal\content_moderation\Permissions;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\workflows\Entity\Workflow;
8
9 /**
10  * Test to ensure content moderation permissions are generated correctly.
11  *
12  * @group content_moderation
13  */
14 class ContentModerationPermissionsTest extends KernelTestBase {
15
16   /**
17    * Modules to install.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'workflows',
23     'content_moderation',
24     'workflow_type_test',
25   ];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp() {
31     parent::setUp();
32     $this->installEntitySchema('workflow');
33   }
34
35   /**
36    * Test permissions generated by content moderation.
37    *
38    * @dataProvider permissionsTestCases
39    */
40   public function testPermissions($workflow, $permissions) {
41     Workflow::create($workflow)->save();
42     $this->assertEquals($permissions, (new Permissions())->transitionPermissions());
43   }
44
45   /**
46    * Test cases for ::testPermissions
47    *
48    * @return array
49    *   Content moderation permissions based test cases.
50    */
51   public function permissionsTestCases() {
52     return [
53       'Simple Content Moderation Workflow' => [
54         [
55           'id' => 'simple_workflow',
56           'label' => 'Simple Workflow',
57           'type' => 'content_moderation',
58           'transitions' => [
59             'publish' => [
60               'label' => 'Publish',
61               'from' => ['draft'],
62               'to' => 'published',
63               'weight' => 0,
64             ],
65             'unpublish' => [
66               'label' => 'Unpublish',
67               'from' => ['published'],
68               'to' => 'draft',
69               'weight' => 0,
70             ],
71           ],
72           'states' => [
73             'draft' => [
74               'label' => 'Draft',
75               'weight' => -5,
76             ],
77             'published' => [
78               'label' => 'Published',
79               'weight' => 0,
80             ],
81           ],
82         ],
83         [
84           'use simple_workflow transition publish' => [
85             'title' => 'Use <em class="placeholder">Publish</em> transition from <em class="placeholder">Simple Workflow</em> workflow.',
86           ],
87           'use simple_workflow transition unpublish' => [
88             'title' => 'Use <em class="placeholder">Unpublish</em> transition from <em class="placeholder">Simple Workflow</em> workflow.',
89           ],
90         ],
91       ],
92       'Non Content Moderation Workflow' => [
93         [
94           'id' => 'morning',
95           'label' => 'Morning',
96           'type' => 'workflow_type_test',
97           'transitions' => [
98             'drink_coffee' => [
99               'label' => 'Drink Coffee',
100               'from' => ['tired'],
101               'to' => 'awake',
102               'weight' => 0,
103             ],
104           ],
105           'states' => [
106             'awake' => [
107               'label' => 'Awake',
108               'weight' => -5,
109             ],
110             'tired' => [
111               'label' => 'Tired',
112               'weight' => -0,
113             ],
114           ],
115         ],
116         []
117       ],
118     ];
119   }
120
121 }