LinkTypeReloadTest.php in Flag 8.4
File
tests/src/Functional/LinkTypeReloadTest.php
View source
<?php
namespace Drupal\Tests\flag\Functional;
class LinkTypeReloadTest extends FlagTestBase {
protected $flag;
public function testFlagReloadLink() {
$this->adminUser = $this
->drupalCreateUser([
'administer flags',
]);
$this
->drupalLogin($this->adminUser);
$this
->doCreateFlag();
$this
->doFlagNode();
}
public function doCreateFlag() {
$this->flag = $this
->createFlag('node', [
$this->nodeType,
], 'reload');
}
public function doFlagNode() {
$node = $this
->drupalCreateNode([
'type' => $this->nodeType,
]);
$node_id = $node
->id();
$flag_id = $this->flag
->id();
$this
->grantFlagPermissions($this->flag);
$user_1 = $this
->drupalCreateUser();
$this
->drupalLogin($user_1);
$flag_count_pre = \Drupal::database()
->query('SELECT count FROM {flag_counts}
WHERE flag_id = :flag_id AND entity_type = :entity_type AND entity_id = :entity_id', [
':flag_id' => $flag_id,
':entity_type' => 'node',
':entity_id' => $node_id,
])
->fetchField();
$this
->drupalGet("flag/flag/{$flag_id}/{$node_id}");
$this
->assertResponse(403, "Access to the flag reload link is denied when no token is supplied.");
$this
->drupalGet('node/' . $node_id);
$this
->clickLink($this->flag
->getShortText('flag'));
$this
->drupalGet('node/' . $node_id);
$this
->assertLink($this->flag
->getShortText('unflag'));
$flag_count_flagged = \Drupal::database()
->query('SELECT count FROM {flag_counts}
WHERE flag_id = :flag_id AND entity_type = :entity_type AND entity_id = :entity_id', [
':flag_id' => $flag_id,
':entity_type' => 'node',
':entity_id' => $node_id,
])
->fetchField();
$this
->assertEqual($flag_count_flagged, $flag_count_pre + 1, "The flag count was incremented.");
$this
->drupalGet("flag/unflag/{$flag_id}/{$node_id}");
$this
->assertResponse(403, "Access to the unflag reload link is denied when no token is supplied.");
$this
->drupalGet('node/' . $node_id);
$this
->clickLink($this->flag
->getShortText('unflag'));
$this
->drupalGet('node/' . $node_id);
$this
->assertLink($this->flag
->getShortText('flag'));
$flag_count_unflagged = \Drupal::database()
->query('SELECT count FROM {flag_counts}
WHERE flag_id = :flag_id AND entity_type = :entity_type AND entity_id = :entity_id', [
':flag_id' => $flag_id,
':entity_type' => 'node',
':entity_id' => $node_id,
])
->fetchField();
$this
->assertEqual($flag_count_unflagged, $flag_count_flagged - 1, "The flag count was decremented.");
}
}