3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
7 class TagControllerTest
extends WallabagCoreTestCase
9 public $tagName = 'opensource';
11 public function testList()
13 $this->logInAs('admin');
14 $client = $this->getClient();
16 $client->request('GET', '/tag/list');
18 $this->assertEquals(200, $client->getResponse()->getStatusCode());
21 public function testAddTagToEntry()
23 $this->logInAs('admin');
24 $client = $this->getClient();
26 $entry = $client->getContainer()
27 ->get('doctrine.orm.entity_manager')
28 ->getRepository('WallabagCoreBundle:Entry')
29 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
31 $crawler = $client->request('GET', '/view/'.$entry->getId());
33 $form = $crawler->filter('form[name=tag]')->form();
36 'tag[label]' => $this->tagName
,
39 $client->submit($form, $data);
40 $this->assertEquals(302, $client->getResponse()->getStatusCode());
42 // be sure to reload the entry
43 $entry = $client->getContainer()
44 ->get('doctrine.orm.entity_manager')
45 ->getRepository('WallabagCoreBundle:Entry')
46 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
48 $this->assertEquals(3, count($entry->getTags()));
50 // tag already exists and already assigned
51 $client->submit($form, $data);
52 $this->assertEquals(302, $client->getResponse()->getStatusCode());
54 $newEntry = $client->getContainer()
55 ->get('doctrine.orm.entity_manager')
56 ->getRepository('WallabagCoreBundle:Entry')
57 ->find($entry->getId());
59 $this->assertEquals(3, count($newEntry->getTags()));
61 // tag already exists but still not assigned to this entry
63 'tag[label]' => 'foo',
66 $client->submit($form, $data);
67 $this->assertEquals(302, $client->getResponse()->getStatusCode());
69 $newEntry = $client->getContainer()
70 ->get('doctrine.orm.entity_manager')
71 ->getRepository('WallabagCoreBundle:Entry')
72 ->find($entry->getId());
74 $this->assertEquals(3, count($newEntry->getTags()));
77 public function testAddMultipleTagToEntry()
79 $this->logInAs('admin');
80 $client = $this->getClient();
82 $entry = $client->getContainer()
83 ->get('doctrine.orm.entity_manager')
84 ->getRepository('WallabagCoreBundle:Entry')
85 ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId());
87 $crawler = $client->request('GET', '/view/'.$entry->getId());
89 $form = $crawler->filter('form[name=tag]')->form();
92 'tag[label]' => 'foo2, bar2',
95 $client->submit($form, $data);
96 $this->assertEquals(302, $client->getResponse()->getStatusCode());
98 $newEntry = $client->getContainer()
99 ->get('doctrine.orm.entity_manager')
100 ->getRepository('WallabagCoreBundle:Entry')
101 ->find($entry->getId());
103 $tags = $newEntry->getTags()->toArray();
104 foreach ($tags as $key => $tag) {
105 $tags[$key] = $tag->getLabel();
108 $this->assertGreaterThanOrEqual(2, count($tags));
109 $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry');
110 $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry');
113 public function testRemoveTagFromEntry()
115 $this->logInAs('admin');
116 $client = $this->getClient();
118 $entry = $client->getContainer()
119 ->get('doctrine.orm.entity_manager')
120 ->getRepository('WallabagCoreBundle:Entry')
121 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
123 $tag = $client->getContainer()
124 ->get('doctrine.orm.entity_manager')
125 ->getRepository('WallabagCoreBundle:Tag')
126 ->findOneByEntryAndTagLabel($entry, $this->tagName
);
128 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
130 $this->assertEquals(302, $client->getResponse()->getStatusCode());
132 $this->assertNotContains($this->tagName
, $entry->getTags());
134 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
136 $this->assertEquals(404, $client->getResponse()->getStatusCode());
139 public function testShowEntriesForTagAction()
141 $this->logInAs('admin');
142 $client = $this->getClient();
144 $entry = $client->getContainer()
145 ->get('doctrine.orm.entity_manager')
146 ->getRepository('WallabagCoreBundle:Entry')
147 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
149 $tag = $client->getContainer()
150 ->get('doctrine.orm.entity_manager')
151 ->getRepository('WallabagCoreBundle:Tag')
152 ->findOneByEntryAndTagLabel($entry, 'foo');
154 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
156 $this->assertEquals(200, $client->getResponse()->getStatusCode());
157 $this->assertCount(2, $crawler->filter('div[class=entry]'));
159 $tag = $client->getContainer()
160 ->get('doctrine.orm.entity_manager')
161 ->getRepository('WallabagCoreBundle:Tag')
162 ->findOneByLabel('baz');
164 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
166 $this->assertEquals(200, $client->getResponse()->getStatusCode());
167 $this->assertCount(1, $crawler->filter('div[class=entry]'));