public function testDeleteTagsByLabel()
 {
     $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
     $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')->getRepository('WallabagCoreBundle:Entry')->findOneWithTags($this->user->getId());
     $entry = $entry[0];
     $tag = new Tag();
     $tag->setLabel('Awesome tag for tagsLabel');
     $em->persist($tag);
     $tag2 = new Tag();
     $tag2->setLabel('Awesome tag for tagsLabel 2');
     $em->persist($tag2);
     $entry->addTag($tag);
     $entry->addTag($tag2);
     $em->persist($entry);
     $em->flush();
     $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel() . ',' . $tag2->getLabel()]);
     $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
     $content = json_decode($this->client->getResponse()->getContent(), true);
     $this->assertCount(2, $content);
     $this->assertArrayHasKey('label', $content[0]);
     $this->assertEquals($tag->getLabel(), $content[0]['label']);
     $this->assertEquals($tag->getSlug(), $content[0]['slug']);
     $this->assertArrayHasKey('label', $content[1]);
     $this->assertEquals($tag2->getLabel(), $content[1]['label']);
     $this->assertEquals($tag2->getSlug(), $content[1]['slug']);
     $entries = $this->client->getContainer()->get('doctrine.orm.entity_manager')->getRepository('WallabagCoreBundle:Entry')->findAllByTagId($this->user->getId(), $tag->getId());
     $this->assertCount(0, $entries);
     $entries = $this->client->getContainer()->get('doctrine.orm.entity_manager')->getRepository('WallabagCoreBundle:Entry')->findAllByTagId($this->user->getId(), $tag2->getId());
     $this->assertCount(0, $entries);
 }
 /**
  * Fetch a tag.
  *
  * @param string $label The tag's label
  *
  * @return Tag
  */
 private function getTag($label)
 {
     $tag = $this->tagRepository->findOneByLabel($label);
     if (!$tag) {
         $tag = new Tag();
         $tag->setLabel($label);
     }
     return $tag;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $tag1 = new Tag();
     $tag1->setLabel('foo');
     $manager->persist($tag1);
     $this->addReference('foo-tag', $tag1);
     $tag2 = new Tag();
     $tag2->setLabel('bar');
     $manager->persist($tag2);
     $this->addReference('bar-tag', $tag2);
     $manager->flush();
 }
 public function testShowEntriesForTagAction()
 {
     $this->logInAs('admin');
     $client = $this->getClient();
     $em = $client->getContainer()->get('doctrine.orm.entity_manager');
     $tag = new Tag();
     $tag->setLabel($this->tagName);
     $entry = $client->getContainer()->get('doctrine.orm.entity_manager')->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
     $tag->addEntry($entry);
     $em->persist($entry);
     $em->persist($tag);
     $em->flush();
     $tag = $client->getContainer()->get('doctrine.orm.entity_manager')->getRepository('WallabagCoreBundle:Tag')->findOneByEntryAndTagLabel($entry, $this->tagName);
     $crawler = $client->request('GET', '/tag/list/' . $tag->getSlug());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $this->assertCount(1, $crawler->filter('[id*="entry-"]'));
     $entry->removeTag($tag);
     $em->remove($tag);
     $em->flush();
 }
Exemple #5
0
 /**
  * Assign some tags to an entry.
  *
  * @param Entry        $entry
  * @param array|string $tags          An array of tag or a string coma separated of tag
  * @param array        $entitiesReady Entities from the EntityManager which are persisted but not yet flushed
  *                                    It is mostly to fix duplicate tag on import @see http://stackoverflow.com/a/7879164/569101
  */
 public function assignTagsToEntry(Entry $entry, $tags, array $entitiesReady = [])
 {
     if (!is_array($tags)) {
         $tags = explode(',', $tags);
     }
     // keeps only Tag entity from the "not yet flushed entities"
     $tagsNotYetFlushed = [];
     foreach ($entitiesReady as $entity) {
         if ($entity instanceof Tag) {
             $tagsNotYetFlushed[$entity->getLabel()] = $entity;
         }
     }
     foreach ($tags as $label) {
         $label = trim($label);
         // avoid empty tag
         if (0 === strlen($label)) {
             continue;
         }
         if (isset($tagsNotYetFlushed[$label])) {
             $tagEntity = $tagsNotYetFlushed[$label];
         } else {
             $tagEntity = $this->tagRepository->findOneByLabel($label);
             if (is_null($tagEntity)) {
                 $tagEntity = new Tag();
                 $tagEntity->setLabel($label);
             }
         }
         // only add the tag on the entry if the relation doesn't exist
         if (false === $entry->getTags()->contains($tagEntity)) {
             $entry->addTag($tagEntity);
         }
     }
 }
 public function testAssignTagsNotFlushed()
 {
     $graby = $this->getMockBuilder('Graby\\Graby')->disableOriginalConstructor()->getMock();
     $tagRepo = $this->getTagRepositoryMock();
     $tagRepo->expects($this->never())->method('__call');
     $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
     $tagEntity = new Tag();
     $tagEntity->setLabel('tag1');
     $entry = new Entry(new User());
     $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]);
     $this->assertCount(1, $entry->getTags());
     $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
 }
Exemple #7
0
 /**
  * Assign some tags to an entry.
  *
  * @param Entry        $entry
  * @param array|string $tags  An array of tag or a string coma separated of tag
  */
 public function assignTagsToEntry(Entry $entry, $tags)
 {
     if (!is_array($tags)) {
         $tags = explode(',', $tags);
     }
     foreach ($tags as $label) {
         $label = trim($label);
         // avoid empty tag
         if (0 === strlen($label)) {
             continue;
         }
         $tagEntity = $this->tagRepository->findOneByLabel($label);
         if (is_null($tagEntity)) {
             $tagEntity = new Tag();
             $tagEntity->setLabel($label);
         }
         // only add the tag on the entry if the relation doesn't exist
         if (false === $entry->getTags()->contains($tagEntity)) {
             $entry->addTag($tagEntity);
         }
     }
 }
 public function testAssignTagsAlreadyAssigned()
 {
     $graby = $this->getMockBuilder('Graby\\Graby')->disableOriginalConstructor()->getMock();
     $tagRepo = $this->getTagRepositoryMock();
     $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
     $tagEntity = new Tag();
     $tagEntity->setLabel('tag1');
     $entry = new Entry(new User());
     $entry->addTag($tagEntity);
     $proxy->assignTagsToEntry($entry, 'tag1, tag2');
     $this->assertCount(2, $entry->getTags());
     $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
     $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
 }