-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from Gizra/58-ajax-unflag-error
Fix double unsubscribe on ajax
- Loading branch information
Showing
2 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
message_subscribe_email/tests/src/FunctionalJavascript/MessageSubscribeEmailTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\message_subscribe_email\FunctionalJavascript; | ||
|
||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase; | ||
|
||
/** | ||
* Javascript tests for message subscribe email. | ||
* | ||
* @group message_subscribe_email | ||
*/ | ||
class MessageSubscribeEmailTest extends JavascriptTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static $modules = ['message_subscribe_email', 'node']; | ||
|
||
/** | ||
* Flag service. | ||
* | ||
* @var \Drupal\flag\FlagServiceInterface | ||
*/ | ||
protected $flagService; | ||
|
||
/** | ||
* Nodes to test with. | ||
* | ||
* @var \Drupal\node\NodeInterface[] | ||
*/ | ||
protected $nodes; | ||
|
||
/** | ||
* Users to test with. | ||
* | ||
* @var \Drupal\user\UserInterface[] | ||
*/ | ||
protected $users; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
|
||
// Add some nodes. | ||
$type = $this->createContentType(); | ||
foreach (range(1, 3) as $i) { | ||
$this->nodes[$i] = $this->drupalCreateNode(['type' => $type->id()]); | ||
} | ||
|
||
// Add some users. | ||
$permissions = [ | ||
'flag subscribe_node', | ||
'unflag subscribe_node', | ||
'flag email_node', | ||
'unflag email_node', | ||
]; | ||
|
||
$this->users[1] = $this->createUser($permissions); | ||
$this->users[2] = $this->createUser($permissions); | ||
$this->users[3] = $this->createUser($permissions); | ||
|
||
$this->flagService = $this->container->get('flag'); | ||
} | ||
|
||
/** | ||
* Tests the flag/unflag UI. | ||
*/ | ||
public function testUi() { | ||
$flag = $this->flagService->getFlagById('subscribe_node'); | ||
$this->drupalLogin($this->users[2]); | ||
$this->drupalGet($this->nodes[2]->toUrl()); | ||
|
||
// Subscribe to the node. | ||
$this->clickLink(t('Subscribe')); | ||
$this->assertSession()->assertWaitOnAjaxRequest(); | ||
$this->assertTrue($this->flagService->getFlagging($flag, $this->nodes[2], $this->users[2])); | ||
|
||
// Unsubscribe from the node. | ||
$this->clickLink(t('Unsubscribe')); | ||
$this->assertSession()->assertWaitOnAjaxRequest(); | ||
$this->assertFalse($this->flagService->getFlagging($flag, $this->nodes[2], $this->users[2])); | ||
|
||
// Subscribe again! | ||
$this->clickLink(t('Subscribe')); | ||
$this->assertSession()->assertWaitOnAjaxRequest(); | ||
$this->assertTrue($this->flagService->getFlagging($flag, $this->nodes[2], $this->users[2])); | ||
} | ||
|
||
} |