DiffRevisionContentModerationTest.php in Diff 8        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Functional/DiffRevisionContentModerationTest.php
  
    View source  
  <?php
namespace Drupal\Tests\diff\Functional;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\workflows\Entity\Workflow;
class DiffRevisionContentModerationTest extends DiffRevisionTest {
  use ContentModerationTestTrait;
  
  protected static $modules = [
    'content_moderation',
  ];
  
  protected function setUp() {
    parent::setUp();
    
    $this
      ->createEditorialWorkflow();
    
    $workflow = Workflow::load('editorial');
    
    $plugin = $workflow
      ->getTypePlugin();
    $plugin
      ->addEntityTypeAndBundle('node', 'article');
    $workflow
      ->save();
    
    $this->adminPermissions = array_merge([
      'use editorial transition create_new_draft',
      'use editorial transition publish',
      'use editorial transition archive',
      'use editorial transition archived_draft',
      'use editorial transition archived_published',
      'view latest version',
      'view any unpublished content',
    ], $this->adminPermissions);
  }
  
  protected function drupalPostNodeForm($path, array $edit, $submit) {
    
    unset($edit['revision']);
    parent::drupalPostNodeForm($path, $edit, $submit);
  }
  
  public function testContentModeration() {
    $this
      ->loginAsAdmin();
    $title = $this
      ->randomString();
    $node = $this
      ->createNode([
      'type' => 'article',
      'title' => $title,
      'revision_log' => 'First revision',
    ]);
    
    $node->title = $title . ' change 1';
    $node->revision_log = 'Second revision';
    $node
      ->save();
    
    $node->moderation_state = 'published';
    $node->revision_log = 'Third revision';
    $node
      ->save();
    
    $node->title = $title . ' change 2';
    $node->moderation_state = 'draft';
    $node->revision_log = 'Fourth revision';
    $node
      ->save();
    
    $this
      ->drupalGet($node
      ->toUrl('version-history'));
    
    $diff_rows = $this
      ->xpath('//tbody/tr/td[1]/p');
    $this
      ->assertEqual('Fourth revision (Draft)', $diff_rows[0]
      ->getText());
    $this
      ->assertEqual('Third revision (Published)', $diff_rows[1]
      ->getText());
    $this
      ->assertEqual('Second revision (Draft)', $diff_rows[2]
      ->getText());
    $this
      ->assertEqual('First revision (Draft)', $diff_rows[3]
      ->getText());
  }
}