ContentModerationPermissionsTest.php 2.4 KB

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