Namespace
  Drupal\Tests\rules\Functional
File
  - 
              tests/src/Functional/TempStorageTest.php
    
   
  
    View source
  
  <?php
namespace Drupal\Tests\rules\Functional;
class TempStorageTest extends RulesBrowserTestBase {
  
  protected static $modules = [
    'rules',
  ];
  
  protected $profile = 'minimal';
  
  public function testLocking() {
    
    $account_1 = $this->drupalCreateUser([
      'administer rules',
    ]);
    $this->drupalLogin($account_1);
    $this->drupalGet('admin/config/workflow/rules');
    $this->clickLink('Add reaction rule');
    $this->fillField('Label', 'Test rule');
    $this->fillField('Machine-readable name', 'test_rule');
    $this->fillField('React on event', 'rules_entity_insert:node');
    $this->pressButton('Save');
    $this->clickLink('Add condition');
    $this->fillField('Condition', 'rules_node_is_promoted');
    $this->pressButton('Continue');
    $this->fillField('context_definitions[node][setting]', 'node');
    $this->pressButton('Save');
    
    $assert = $this->assertSession();
    $assert->pageTextContains('You have unsaved changes.');
    
    $account_2 = $this->drupalCreateUser([
      'administer rules',
    ]);
    $this->drupalLogin($account_2);
    $this->drupalGet('admin/config/workflow/rules/reactions/edit/test_rule');
    $assert->pageTextContains('This rule is being edited by user ' . $account_1->getDisplayName() . ', and is therefore locked from editing by others.');
    $this->pressButton('Cancel');
    $assert->pageTextNotContains('Canceled.');
    $assert->pageTextContains('This rule is being edited by user ' . $account_1->getDisplayName() . ', and is therefore locked from editing by others.');
    $this->pressButton('Save');
    $assert->pageTextNotContains('Reaction rule Test rule has been updated.');
    $assert->pageTextContains('This rule is being edited by user ' . $account_1->getDisplayName() . ', and is therefore locked from editing by others.');
    $this->clickLink('Edit');
    $current_url = $this->getSession()
      ->getCurrentUrl();
    $this->pressButton('Save');
    $this->assertEquals($current_url, $this->getSession()
      ->getCurrentUrl());
    $assert->pageTextContains('This rule is being edited by user ' . $account_1->getDisplayName() . ', and is therefore locked from editing by others.');
    
    $this->clickLink('break this lock');
    $assert->pageTextContains('By breaking this lock, any unsaved changes made by ' . $account_1->getDisplayName() . ' will be lost.');
    $this->pressButton('Break lock');
    $assert->pageTextContains('The lock has been broken and you may now edit this rule.');
    
    
    $this->assertFalse($this->getSession()
      ->getPage()
      ->hasLink('Edit'));
  }
}
 
Classes
  
  
  
  
  
  
  
        
      
                                                  | Title | Deprecated | Summary | 
    
    
          
                                                                                        | TempStorageTest |  | Tests that editing a rule locks it for another user. |