View source
<?php
namespace Drupal\Tests\content_moderation_notifications\Functional\Form;
use Drupal\Component\Utility\Unicode;
use Drupal\content_moderation_notifications\Entity\ContentModerationNotification;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\Tests\BrowserTestBase;
class CrudFormTest extends BrowserTestBase {
use ContentTypeCreationTrait;
protected $adminUser;
public static $modules = [
'block',
'content_moderation_notifications',
'node',
'filter_test',
];
protected function setUp() {
parent::setUp();
$this
->createContentType([
'type' => 'article',
]);
$this
->drupalCreateUser();
$this->adminUser = $this
->createUser([
'administer content moderation notifications',
'use text format filtered_html',
'use text format full_html',
]);
$this
->placeBlock('local_actions_block');
}
public function testCrud() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/workflow/notifications');
$this
->clickLink(t('Add notification'));
$edit = [
'id' => Unicode::strtolower($this
->randomMachineName()),
'workflow' => 'editorial',
'transitions[create_new_draft]' => TRUE,
'transitions[archived_published]' => TRUE,
'roles[authenticated]' => TRUE,
'subject' => $this
->randomString(),
'body[value]' => $this->randomGenerator
->paragraphs(2),
];
$this
->drupalPostForm(NULL, $edit, t('Create Notification'));
$this
->assertSession()
->pageTextContains(t('Notification has been added.'));
$notification = ContentModerationNotification::load($edit['id']);
$this
->assertEquals($edit['id'], $notification
->id());
$this
->assertEquals($edit['workflow'], $notification
->getWorkflowId());
$this
->assertEquals([
'authenticated' => 'authenticated',
], $notification
->getRoleIds());
$this
->assertEquals([
'create_new_draft' => 'create_new_draft',
'archived_published' => 'archived_published',
], $notification
->getTransitions());
$edit = [
'subject' => $this
->randomString(),
'body[format]' => 'full_html',
'body[value]' => $this->randomGenerator
->paragraphs(3),
];
$this
->drupalGet($notification
->toUrl('edit-form'));
$this
->drupalPostForm(NULL, $edit, t('Update Notification'));
$this
->assertSession()
->pageTextContains(t('Notification has been updated'));
$notification = ContentModerationNotification::load($notification
->id());
$this
->assertEquals($edit['subject'], $notification
->getSubject());
$this
->assertEquals($edit['body[value]'], $notification
->getMessage());
$this
->assertEquals('full_html', $notification
->getMessageFormat());
$this
->drupalGet($notification
->toUrl('delete-form'));
$this
->drupalPostForm(NULL, [], t('Delete Notification'));
$this
->assertSession()
->pageTextContains(t('Notification was deleted'));
$this
->assertSession()
->pageTextContains(t('There is no Notification yet.'));
}
}