ModerationStateNodeTypeTest.php in Workbench Moderation 8.2        
                          
                  
                        
  
  
  
  
  
File
  src/Tests/ModerationStateNodeTypeTest.php
  
    View source  
  <?php
namespace Drupal\workbench_moderation\Tests;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
class ModerationStateNodeTypeTest extends ModerationStateTestBase {
  
  public function testNotModerated() {
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->createContentTypeFromUI('Not moderated', 'not_moderated');
    $this
      ->assertText('The content type Not moderated has been added.');
    $this
      ->grantUserPermissionToCreateContentOfType($this->adminUser, 'not_moderated');
    $this
      ->drupalGet('node/add/not_moderated');
    $this
      ->assertRaw('Save as unpublished');
    $this
      ->drupalPostForm(NULL, [
      'title[0][value]' => 'Test',
    ], t('Save and publish'));
    $this
      ->assertText('Not moderated Test has been created.');
  }
  
  
  public function testEnablingOnExistingContent() {
    
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->createContentTypeFromUI('Not moderated', 'not_moderated');
    $this
      ->grantUserPermissionToCreateContentOfType($this->adminUser, 'not_moderated');
    
    $this
      ->drupalGet('node/add/not_moderated');
    $this
      ->drupalPostForm(NULL, [
      'title[0][value]' => 'Test',
    ], t('Save and publish'));
    $this
      ->assertText('Not moderated Test has been created.');
    
    $this
      ->enableModerationThroughUI('not_moderated', [
      'draft',
      'needs_review',
      'published',
    ], 'draft');
    
    $nodes = \Drupal::entityTypeManager()
      ->getStorage('node')
      ->loadByProperties([
      'title' => 'Test',
    ]);
    if (empty($nodes)) {
      $this
        ->fail('Could not load node with title Test');
      return;
    }
    $node = reset($nodes);
    $this
      ->drupalGet('node/' . $node
      ->id());
    $this
      ->assertResponse(200);
    $this
      ->assertLinkByHref('node/' . $node
      ->id() . '/edit');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->assertResponse(200);
    $this
      ->assertRaw('Save and Create New Draft');
    $this
      ->assertNoRaw('Save and publish');
  }
}