public function testConstructor()
 {
     $tagging = new Tagging();
     $this->assertNull($tagging->getId());
     $this->assertEquals(new \DateTime('now'), $tagging->getCreatedAt());
     $this->assertEquals(new \DateTime('now'), $tagging->getUpdatedAt());
     $tag = new Tag('Smallville');
     $article = new Article();
     $article->setTitle('Hello World!');
     $article->id = 123;
     $tagging = new Tagging($tag, $article);
     $this->assertEquals($article->getTaggableType(), $tagging->getResourceType());
     $this->assertEquals($article->getTaggableId(), $tagging->getResourceId());
     $this->assertEquals($tag, $tagging->getTag());
 }
 /**
  * @covers DoctrineExtensions\Taggable\TagManager::getTagNames
  */
 public function testGetTagNames()
 {
     $article = new Article();
     $article->setTitle('Unit Test');
     $this->assertEquals(array(), $this->manager->getTagNames($article));
     $tag1 = new Tag('Smallville');
     $this->manager->addTag($tag1, $article);
     $this->assertEquals(array('Smallville'), $this->manager->getTagNames($article));
     $tag2 = new Tag('Superman');
     $tag3 = new Tag('TV');
     $this->manager->addTags(array($tag2, $tag3), $article);
     $this->assertEquals(array('Smallville', 'Superman', 'TV'), $this->manager->getTagNames($article));
 }
 /**
  * Loads in some dummy articles with tags so we can test against it.
  *
  * Articles:
  *
  *  My 1 article => array(tag1, alltag)
  *  My 2 article => array(tag2, alltag)
  *  My 3 article => array(tag3, alltag)
  *  My 4 article => array(tag3)
  *
  *
  * @return void
  */
 private function loadFixtures()
 {
     $tagAll = $this->manager->loadOrCreateTag('alltag');
     $tags = array();
     $allArticles = array();
     for ($i = 1; $i <= 4; $i++) {
         $article = new Article();
         $article->setTitle('My ' . $i . ' article');
         $allArticles[] = $article;
         $this->em->persist($article);
         $tags[$i] = $this->manager->loadOrCreateTag('tag' . $i);
         $tags[$i]->setName('tag' . $i);
         if ($i != 4) {
             // give them their own tag and the all tag
             $this->manager->addTag($tags[$i], $article);
             $this->manager->addTag($tagAll, $article);
         } else {
             // does't get its own tag, but get's 3's tag
             $this->manager->addTag($tags[3], $article);
         }
     }
     $this->em->flush();
     // save the tagging after everything's been flushed
     foreach ($allArticles as $article) {
         $this->manager->saveTagging($article);
     }
 }