ModerationSidebarTest.php in Moderation Sidebar 8        
                          
                  
                        
  
  
  
  
File
  tests/src/Functional/ModerationSidebarTest.php
  
    View source  
  <?php
namespace Drupal\Tests\moderation_sidebar\Functional;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTestMulRevPub;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class ModerationSidebarTest extends BrowserTestBase {
  use ContentModerationTestTrait;
  
  protected $defaultTheme = 'stark';
  
  protected static $modules = [
    'moderation_sidebar',
    'toolbar',
    'content_moderation',
    'workflows',
    'entity_test',
  ];
  
  protected function setUp() {
    parent::setUp();
    $workflow = $this
      ->createEditorialWorkflow();
    $this
      ->addEntityTypeAndBundleToWorkflow($workflow, 'entity_test_mulrevpub', 'entity_test_mulrevpub');
    $this
      ->drupalLogin($this
      ->createUser([
      'view test entity',
      'access toolbar',
      'access toolbar',
      'use ' . $workflow
        ->id() . ' transition create_new_draft',
      'use ' . $workflow
        ->id() . ' transition archive',
      'use ' . $workflow
        ->id() . ' transition publish',
      'use moderation sidebar',
    ]));
  }
  
  public function testToolbarItem() {
    $entity = EntityTestMulRevPub::create([
      'name' => $this
        ->randomMachineName(),
    ]);
    $entity
      ->save();
    $this
      ->drupalGet($entity
      ->toUrl());
    
    $toolbarItem = $this
      ->assertSession()
      ->elementExists('css', '.moderation-sidebar-toolbar-tab a');
    
    $url = Url::fromRoute('moderation_sidebar.sidebar_latest', [
      'entity_type' => $entity
        ->getEntityTypeId(),
      'entity' => $entity
        ->id(),
    ]);
    $this
      ->assertEquals($url
      ->toString(), $toolbarItem
      ->getAttribute('href'));
    $this
      ->assertEquals('Tasks', $toolbarItem
      ->getText());
  }
}