diff --git a/src/Tests/FlagResetTest.php b/src/Tests/FlagResetTest.php index 7ca12f0..146a588 100644 --- a/src/Tests/FlagResetTest.php +++ b/src/Tests/FlagResetTest.php @@ -6,7 +6,8 @@ namespace Drupal\flag\Tests; -use Drupal\flag\Entity\Flag; +use Drupal\flag\Tests\FlagTestBase; +use Drupal\node\Entity\Node; /** * Test resetting a flag. @@ -19,7 +20,6 @@ class FlagResetTest extends FlagTestBase { * The flag. * * @var \Drupal\flag\FlagInterface - * */ protected $flag; @@ -45,6 +45,13 @@ class FlagResetTest extends FlagTestBase { protected $adminUser; /** + * The node. + * + * @var \Drupal\node\Entity\Node + */ + protected $node; + + /** * {@inheritdoc} */ protected function setUp() { @@ -62,6 +69,9 @@ class FlagResetTest extends FlagTestBase { 'administer flags', ]); + // Login before setting up flag. + $this->drupalLogin($this->adminUser); + // Create a node to flag. $this->node = Node::create([ 'body' => [ @@ -79,34 +89,32 @@ class FlagResetTest extends FlagTestBase { /** * Tests that counts are kept in sync and can be retrieved. */ - public function testFlagResetUI() { + public function testFlagResetUi() { // Flag the node. $this->flagService->flag($this->flag, $this->node, $this->adminUser); - $this->entityQueryManager->get('flagging') + $ids_before = $this->entityQueryManager->get('flagging') ->condition('flag_id', $this->flag->id()) ->condition('entity_type', 'node') - ->condition('entity_id', $this->node->id()); + ->condition('entity_id', $this->node->id()) + ->execute(); - $ids = $query->execute(); - - $this->assertEqual(count($ids), 1, "The flag has one flagging."); + $this->assertEqual(count($ids_before), 1, "The flag has one flagging."); // Go to the reset form for the flag. $this->drupalGet('flag/reset/' . $this->flag->id()); - $this->assertText(t('Are you sure you want to reset the Flag test?')); + $this->assertText(t('Are you sure you want to reset the Flag')); $this->drupalPostForm(NULL, [], t('Reset')); - $this->entityQueryManager->get('flagging') + $ids_after = $this->entityQueryManager->get('flagging') ->condition('flag_id', $this->flag->id()) ->condition('entity_type', 'node') - ->condition('entity_id', $this->node->id()); - - $ids = $query->execute(); + ->condition('entity_id', $this->node->id()) + ->execute(); - $this->assertEqual(count($ids), 0, "The flag has no flaggings after being reset."); + $this->assertEqual(count($ids_after), 0, "The flag has no flaggings after being reset."); } // TODO: test the API directly too?