AutosaveTest.php in Lightning Workflow 8.3        
                          
                  
                        
  
  
  
  
  
File
  tests/src/FunctionalJavascript/AutosaveTest.php
  
    View source  
  <?php
namespace Drupal\Tests\lightning_workflow\FunctionalJavascript;
use Behat\Mink\Element\NodeElement;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class AutosaveTest extends WebDriverTestBase {
  
  protected $defaultTheme = 'stark';
  
  protected static $modules = [
    'block',
    'autosave_form',
    'lightning_workflow',
  ];
  
  protected function setUp() {
    parent::setUp();
    $this
      ->drupalCreateContentType([
      'type' => 'moderated',
      'third_party_settings' => [
        'lightning_workflow' => [
          'autosave' => TRUE,
          'workflow' => 'editorial',
        ],
      ],
    ]);
    $this
      ->drupalPlaceBlock('local_tasks_block');
  }
  
  public function testAutosaveIntegration() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $account = $this
      ->drupalCreateUser([
      'access content overview',
      'edit any moderated content',
      'use editorial transition create_new_draft',
    ]);
    $this
      ->drupalLogin($account);
    $node = $this
      ->drupalCreateNode([
      'type' => 'moderated',
      'moderation_state' => 'published',
    ]);
    $this
      ->drupalGet('/admin/content');
    $page
      ->clickLink($node
      ->getTitle());
    $assert_session
      ->elementExists('named', [
      'link',
      'edit-form',
    ])
      ->click();
    
    $this
      ->waitForAutosave();
    $page
      ->fillField('Title', 'Testing');
    $this
      ->waitForAutosave();
    $page
      ->clickLink('View');
    $assert_session
      ->elementExists('named', [
      'link',
      'edit-form',
    ])
      ->click();
    $button = $assert_session
      ->waitForButton('Resume editing');
    $this
      ->assertNotEmpty($button);
    $button
      ->press();
    $assert_session
      ->fieldValueEquals('Title', 'Testing');
  }
  
  private function waitForAutosave() {
    $element = $this
      ->assertSession()
      ->elementExists('css', '#autosave-notification');
    $is_visible = $element
      ->waitFor(20, function (NodeElement $element) {
      return $element
        ->isVisible();
    });
    $this
      ->assertTrue($is_visible);
    $is_hidden = $element
      ->waitFor(10, function (NodeElement $element) {
      return $element
        ->isVisible() === FALSE;
    });
    $this
      ->assertTrue($is_hidden);
  }
}
 
Classes
        
  
  
      
      
         
      
                  | Name   | Description | 
    
    
          
                  | AutosaveTest | Tests Lightning Workflow's integration with Autosave Form. |