2015-08-07 18:29:03 +00:00
|
|
|
<?php
|
|
|
|
|
2016-06-01 19:27:35 +00:00
|
|
|
namespace Tests\Wallabag\CoreBundle\Controller;
|
2015-08-07 18:29:03 +00:00
|
|
|
|
2016-06-01 19:27:35 +00:00
|
|
|
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
|
2017-05-15 18:47:59 +00:00
|
|
|
use Wallabag\CoreBundle\Entity\Entry;
|
2016-10-07 21:31:53 +00:00
|
|
|
use Wallabag\CoreBundle\Entity\Tag;
|
2015-08-07 18:29:03 +00:00
|
|
|
|
|
|
|
class TagControllerTest extends WallabagCoreTestCase
|
|
|
|
{
|
2016-02-10 16:41:28 +00:00
|
|
|
public $tagName = 'opensource';
|
2017-05-21 15:01:59 +00:00
|
|
|
public $caseTagName = 'OpenSource';
|
2016-02-10 16:41:28 +00:00
|
|
|
|
2015-08-07 18:29:03 +00:00
|
|
|
public function testList()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$client->request('GET', '/tag/list');
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
2015-08-07 18:29:03 +00:00
|
|
|
}
|
2015-08-19 09:46:21 +00:00
|
|
|
|
|
|
|
public function testAddTagToEntry()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
2017-05-15 18:47:59 +00:00
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl('http://0.0.0.0/foo');
|
|
|
|
$this->getEntityManager()->persist($entry);
|
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$crawler = $client->request('GET', '/view/' . $entry->getId());
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2016-03-09 07:59:08 +00:00
|
|
|
$form = $crawler->filter('form[name=tag]')->form();
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
$data = [
|
2017-05-21 15:01:59 +00:00
|
|
|
'tag[label]' => $this->caseTagName,
|
2016-04-12 09:36:01 +00:00
|
|
|
];
|
2015-08-19 09:46:21 +00:00
|
|
|
|
|
|
|
$client->submit($form, $data);
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2016-06-24 09:55:45 +00:00
|
|
|
// be sure to reload the entry
|
2017-05-15 18:47:59 +00:00
|
|
|
$entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
|
|
|
|
$this->assertCount(1, $entry->getTags());
|
2022-01-31 08:27:20 +00:00
|
|
|
$this->assertContains($this->tagName, $entry->getTagsLabel());
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2016-09-28 08:02:31 +00:00
|
|
|
// tag already exists and already assigned
|
2015-08-19 09:46:21 +00:00
|
|
|
$client->submit($form, $data);
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2017-05-15 18:47:59 +00:00
|
|
|
$entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
|
|
|
|
$this->assertCount(1, $entry->getTags());
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2016-09-28 08:02:31 +00:00
|
|
|
// tag already exists but still not assigned to this entry
|
2016-04-12 09:36:01 +00:00
|
|
|
$data = [
|
2016-12-27 20:26:53 +00:00
|
|
|
'tag[label]' => 'foo bar',
|
2016-04-12 09:36:01 +00:00
|
|
|
];
|
2015-08-19 09:46:21 +00:00
|
|
|
|
|
|
|
$client->submit($form, $data);
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2015-08-19 09:46:21 +00:00
|
|
|
|
2017-05-15 18:47:59 +00:00
|
|
|
$entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
|
|
|
|
$this->assertCount(2, $entry->getTags());
|
2015-08-19 09:46:21 +00:00
|
|
|
}
|
2016-02-10 16:41:28 +00:00
|
|
|
|
2016-03-27 15:09:33 +00:00
|
|
|
public function testAddMultipleTagToEntry()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$entry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
2016-10-02 14:53:52 +00:00
|
|
|
->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId());
|
2016-03-27 15:09:33 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$crawler = $client->request('GET', '/view/' . $entry->getId());
|
2016-03-27 15:09:33 +00:00
|
|
|
|
|
|
|
$form = $crawler->filter('form[name=tag]')->form();
|
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
$data = [
|
2017-05-21 15:01:59 +00:00
|
|
|
'tag[label]' => 'foo2, Bar2',
|
2016-04-12 09:36:01 +00:00
|
|
|
];
|
2016-03-27 15:09:33 +00:00
|
|
|
|
|
|
|
$client->submit($form, $data);
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2016-03-27 15:09:33 +00:00
|
|
|
|
|
|
|
$newEntry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry->getId());
|
|
|
|
|
|
|
|
$tags = $newEntry->getTags()->toArray();
|
2016-10-02 14:53:52 +00:00
|
|
|
foreach ($tags as $key => $tag) {
|
|
|
|
$tags[$key] = $tag->getLabel();
|
|
|
|
}
|
|
|
|
|
2018-09-05 12:25:32 +00:00
|
|
|
$this->assertGreaterThanOrEqual(2, \count($tags));
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertNotFalse(array_search('foo2', $tags, true), 'Tag foo2 is assigned to the entry');
|
|
|
|
$this->assertNotFalse(array_search('bar2', $tags, true), 'Tag bar2 is assigned to the entry');
|
2016-03-27 15:09:33 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 16:41:28 +00:00
|
|
|
public function testRemoveTagFromEntry()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
2017-05-15 18:47:59 +00:00
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($this->tagName);
|
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl('http://0.0.0.0/foo');
|
|
|
|
$entry->addTag($tag);
|
|
|
|
$this->getEntityManager()->persist($entry);
|
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
2016-02-10 16:41:28 +00:00
|
|
|
|
2017-05-21 14:35:06 +00:00
|
|
|
// We make a first request to set an history and test redirection after tag deletion
|
2017-07-01 07:52:38 +00:00
|
|
|
$client->request('GET', '/view/' . $entry->getId());
|
2017-05-21 14:35:06 +00:00
|
|
|
$entryUri = $client->getRequest()->getUri();
|
2017-07-01 07:52:38 +00:00
|
|
|
$client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId());
|
2016-02-10 16:41:28 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
|
|
|
$this->assertSame($entryUri, $client->getResponse()->getTargetUrl());
|
2016-02-10 16:41:28 +00:00
|
|
|
|
2017-06-01 09:31:45 +00:00
|
|
|
// re-retrieve the entry to be sure to get fresh data from database (mostly for tags)
|
2017-05-15 18:47:59 +00:00
|
|
|
$entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
|
2022-01-31 08:27:20 +00:00
|
|
|
$this->assertNotContains($this->tagName, $entry->getTagsLabel());
|
2016-02-10 17:40:15 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId());
|
2016-02-10 16:41:28 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(404, $client->getResponse()->getStatusCode());
|
2016-10-07 21:31:53 +00:00
|
|
|
|
|
|
|
$tag = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
|
|
|
->findOneByLabel($this->tagName);
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertNull($tag, $this->tagName . ' was removed because it begun an orphan tag');
|
2016-02-10 16:41:28 +00:00
|
|
|
}
|
2016-04-30 13:03:22 +00:00
|
|
|
|
2022-06-14 14:45:02 +00:00
|
|
|
public function testRemoveTag()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($this->tagName);
|
|
|
|
|
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl('http://0.0.0.0/foo');
|
|
|
|
$entry->addTag($tag);
|
|
|
|
$this->getEntityManager()->persist($entry);
|
|
|
|
|
|
|
|
$entry2 = new Entry($this->getLoggedInUser());
|
|
|
|
$entry2->setUrl('http://0.0.0.0/bar');
|
|
|
|
$entry2->addTag($tag);
|
|
|
|
$this->getEntityManager()->persist($entry2);
|
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
|
|
|
|
|
|
|
$client->request('GET', '/tag/delete/' . $tag->getSlug());
|
|
|
|
|
|
|
|
$tag = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
|
|
|
->findOneByLabel($this->tagName);
|
|
|
|
|
|
|
|
$this->assertNull($tag, $this->tagName . ' was removed because it begun an orphan tag');
|
|
|
|
|
|
|
|
$user = $this->getEntityManager()
|
|
|
|
->getRepository('WallabagUserBundle:User')
|
|
|
|
->findOneByUserName('admin');
|
|
|
|
|
|
|
|
$entry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->findByUrlAndUserId('http://0.0.0.0/foo', $user->getId());
|
|
|
|
|
|
|
|
$entry2 = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->findByUrlAndUserId('http://0.0.0.0/bar', $user->getId());
|
|
|
|
|
|
|
|
$this->assertEmpty($entry->getTagsLabel());
|
|
|
|
$this->assertEmpty($entry2->getTagsLabel());
|
|
|
|
}
|
|
|
|
|
2016-04-30 13:03:22 +00:00
|
|
|
public function testShowEntriesForTagAction()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
2016-10-07 21:31:53 +00:00
|
|
|
$em = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager');
|
|
|
|
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($this->tagName);
|
2016-04-30 13:03:22 +00:00
|
|
|
|
|
|
|
$entry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
2016-10-02 14:53:52 +00:00
|
|
|
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
|
2016-04-30 13:03:22 +00:00
|
|
|
|
2016-10-07 21:31:53 +00:00
|
|
|
$tag->addEntry($entry);
|
2016-04-30 13:03:22 +00:00
|
|
|
|
2016-10-07 21:31:53 +00:00
|
|
|
$em->persist($entry);
|
|
|
|
$em->persist($tag);
|
|
|
|
$em->flush();
|
2016-04-30 13:03:22 +00:00
|
|
|
|
|
|
|
$tag = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
2016-10-07 21:31:53 +00:00
|
|
|
->findOneByEntryAndTagLabel($entry, $this->tagName);
|
2016-04-30 13:03:22 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$crawler = $client->request('GET', '/tag/list/' . $tag->getSlug());
|
2016-04-30 13:03:22 +00:00
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
2016-10-07 21:31:53 +00:00
|
|
|
$this->assertCount(1, $crawler->filter('[id*="entry-"]'));
|
|
|
|
|
|
|
|
$entry->removeTag($tag);
|
|
|
|
$em->remove($tag);
|
|
|
|
$em->flush();
|
2016-04-30 13:03:22 +00:00
|
|
|
}
|
2018-01-24 16:53:00 +00:00
|
|
|
|
|
|
|
public function testRenameTagUsingTheFormInsideTagList()
|
|
|
|
{
|
2020-04-04 19:03:22 +00:00
|
|
|
$newTagLabel = 'rename label';
|
|
|
|
|
2018-01-24 16:53:00 +00:00
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($this->tagName);
|
2020-04-04 19:03:22 +00:00
|
|
|
|
2018-01-24 16:53:00 +00:00
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl('http://0.0.0.0/foo');
|
|
|
|
$entry->addTag($tag);
|
|
|
|
$this->getEntityManager()->persist($entry);
|
2020-04-04 19:03:22 +00:00
|
|
|
|
|
|
|
$entry2 = new Entry($this->getLoggedInUser());
|
|
|
|
$entry2->setUrl('http://0.0.0.0/bar');
|
|
|
|
$entry2->addTag($tag);
|
2021-08-03 06:36:56 +00:00
|
|
|
$this->getEntityManager()->persist($entry2);
|
2020-04-04 19:03:22 +00:00
|
|
|
|
2018-01-24 16:53:00 +00:00
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
|
|
|
|
|
|
|
// We make a first request to set an history and test redirection after tag deletion
|
|
|
|
$crawler = $client->request('GET', '/tag/list');
|
|
|
|
$form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form();
|
|
|
|
|
|
|
|
$data = [
|
2020-04-04 19:03:22 +00:00
|
|
|
'tag[label]' => $newTagLabel,
|
2018-01-24 16:53:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
|
|
|
|
2020-04-04 20:08:08 +00:00
|
|
|
$crawler = $client->followRedirect();
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]);
|
2020-04-04 20:08:08 +00:00
|
|
|
|
2018-01-24 16:53:00 +00:00
|
|
|
$freshEntry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry->getId());
|
|
|
|
|
2020-04-04 19:03:22 +00:00
|
|
|
$freshEntry2 = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry2->getId());
|
|
|
|
|
|
|
|
$tags = [];
|
|
|
|
|
|
|
|
$tagsFromEntry = $freshEntry->getTags()->toArray();
|
|
|
|
foreach ($tagsFromEntry as $key => $item) {
|
2018-01-24 16:53:00 +00:00
|
|
|
$tags[$key] = $item->getLabel();
|
|
|
|
}
|
|
|
|
|
2020-04-04 19:03:22 +00:00
|
|
|
$tagsFromEntry2 = $freshEntry2->getTags()->toArray();
|
|
|
|
foreach ($tagsFromEntry2 as $key => $item) {
|
|
|
|
$tags[$key] = $item->getLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertFalse(array_search($tag->getLabel(), $tags, true), 'Previous tag is not attach to entries anymore.');
|
2018-01-24 16:53:00 +00:00
|
|
|
|
|
|
|
$newTag = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
2020-04-04 19:03:22 +00:00
|
|
|
->findByLabel($newTagLabel);
|
|
|
|
|
|
|
|
$this->assertCount(1, $newTag, 'New tag exists.');
|
|
|
|
|
|
|
|
$this->assertTrue($newTag[0]->hasEntry($freshEntry), 'New tag is assigned to the entry.');
|
|
|
|
$this->assertTrue($newTag[0]->hasEntry($freshEntry2), 'New tag is assigned to the entry2.');
|
2018-01-24 16:53:00 +00:00
|
|
|
}
|
2019-05-11 18:07:38 +00:00
|
|
|
|
2020-04-04 20:08:08 +00:00
|
|
|
public function testRenameTagWithSameLabel()
|
|
|
|
{
|
|
|
|
$tagLabel = 'same label';
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($tagLabel);
|
|
|
|
|
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl('http://0.0.0.0/foobar');
|
|
|
|
$entry->addTag($tag);
|
|
|
|
$this->getEntityManager()->persist($entry);
|
|
|
|
|
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
|
|
|
|
|
|
|
// We make a first request to set an history and test redirection after tag deletion
|
|
|
|
$crawler = $client->request('GET', '/tag/list');
|
|
|
|
$form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'tag[label]' => $tagLabel,
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringNotContainsString('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]);
|
2020-04-04 20:08:08 +00:00
|
|
|
|
|
|
|
$freshEntry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry->getId());
|
|
|
|
|
|
|
|
$tags = [];
|
|
|
|
|
|
|
|
$tagsFromEntry = $freshEntry->getTags()->toArray();
|
|
|
|
foreach ($tagsFromEntry as $key => $item) {
|
|
|
|
$tags[$key] = $item->getLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertNotFalse(array_search($tag->getLabel(), $tags, true), 'Tag is still assigned to the entry.');
|
|
|
|
|
|
|
|
$newTag = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
|
|
|
->findByLabel($tagLabel);
|
|
|
|
|
|
|
|
$this->assertCount(1, $newTag);
|
|
|
|
$this->assertSame($tag->getId(), $newTag[0]->getId(), 'Tag is unchanged.');
|
|
|
|
|
|
|
|
$this->assertTrue($newTag[0]->hasEntry($freshEntry), 'Tag is still assigned to the entry.');
|
|
|
|
}
|
|
|
|
|
2020-04-15 20:41:03 +00:00
|
|
|
public function testRenameTagWithSameLabelDifferentCase()
|
|
|
|
{
|
|
|
|
$tagLabel = 'same label';
|
|
|
|
$newTagLabel = 'saMe labEl';
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($tagLabel);
|
|
|
|
|
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl('http://0.0.0.0/foobar');
|
|
|
|
$entry->addTag($tag);
|
|
|
|
$this->getEntityManager()->persist($entry);
|
|
|
|
|
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
|
|
|
|
|
|
|
// We make a first request to set an history and test redirection after tag deletion
|
|
|
|
$crawler = $client->request('GET', '/tag/list');
|
|
|
|
$form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'tag[label]' => $newTagLabel,
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringNotContainsString('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]);
|
2020-04-15 20:41:03 +00:00
|
|
|
|
|
|
|
$freshEntry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry->getId());
|
|
|
|
|
|
|
|
$tags = [];
|
|
|
|
|
|
|
|
$tagsFromEntry = $freshEntry->getTags()->toArray();
|
|
|
|
foreach ($tagsFromEntry as $key => $item) {
|
|
|
|
$tags[$key] = $item->getLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertFalse(array_search($newTagLabel, $tags, true));
|
|
|
|
|
|
|
|
$tagFromRepo = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
|
|
|
->findByLabel($tagLabel);
|
|
|
|
|
|
|
|
$newTagFromRepo = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
|
|
|
->findByLabel($newTagLabel);
|
|
|
|
|
|
|
|
$this->assertCount(0, $newTagFromRepo);
|
|
|
|
$this->assertCount(1, $tagFromRepo);
|
|
|
|
|
|
|
|
$this->assertSame($tag->getId(), $tagFromRepo[0]->getId(), 'Tag is unchanged.');
|
|
|
|
|
|
|
|
$this->assertTrue($tagFromRepo[0]->hasEntry($freshEntry), 'Tag is still assigned to the entry.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenameTagWithExistingLabel()
|
|
|
|
{
|
|
|
|
$tagLabel = 'existing label';
|
|
|
|
$previousTagLabel = 'previous label';
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($tagLabel);
|
|
|
|
|
|
|
|
$previousTag = new Tag();
|
|
|
|
$previousTag->setLabel($previousTagLabel);
|
|
|
|
|
|
|
|
$entry1 = new Entry($this->getLoggedInUser());
|
|
|
|
$entry1->setUrl('http://0.0.0.0/foobar');
|
|
|
|
$entry1->addTag($previousTag);
|
|
|
|
$this->getEntityManager()->persist($entry1);
|
|
|
|
|
|
|
|
$entry2 = new Entry($this->getLoggedInUser());
|
|
|
|
$entry2->setUrl('http://0.0.0.0/baz');
|
|
|
|
$entry2->addTag($tag);
|
|
|
|
$this->getEntityManager()->persist($entry2);
|
|
|
|
|
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
|
|
|
|
|
|
|
// We make a first request to set an history and test redirection after tag deletion
|
|
|
|
$crawler = $client->request('GET', '/tag/list');
|
|
|
|
$form = $crawler->filter('#tag-' . $previousTag->getId() . ' form')->form();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'tag[label]' => $tagLabel,
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringNotContainsString('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]);
|
2020-04-15 20:41:03 +00:00
|
|
|
|
|
|
|
$freshEntry1 = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry1->getId());
|
|
|
|
|
|
|
|
$freshEntry2 = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry2->getId());
|
|
|
|
|
|
|
|
$tagFromRepo = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
|
|
|
->findByLabel($tagLabel);
|
|
|
|
|
|
|
|
$previousTagFromRepo = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Tag')
|
|
|
|
->findByLabel($previousTagLabel);
|
|
|
|
|
|
|
|
$this->assertCount(1, $tagFromRepo);
|
|
|
|
|
|
|
|
$this->assertTrue($tagFromRepo[0]->hasEntry($freshEntry1));
|
|
|
|
$this->assertTrue($tagFromRepo[0]->hasEntry($freshEntry2), 'Tag is assigned to the entry.');
|
|
|
|
$this->assertFalse($previousTagFromRepo[0]->hasEntry($freshEntry1));
|
|
|
|
}
|
|
|
|
|
2019-05-11 18:07:38 +00:00
|
|
|
public function testAddUnicodeTagLabel()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl('http://0.0.0.0/tag-caché');
|
|
|
|
$this->getEntityManager()->persist($entry);
|
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
$this->getEntityManager()->clear();
|
|
|
|
|
|
|
|
$crawler = $client->request('GET', '/view/' . $entry->getId());
|
|
|
|
|
|
|
|
$form = $crawler->filter('form[name=tag]')->form();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'tag[label]' => 'cache',
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
|
|
|
|
$crawler = $client->request('GET', '/view/' . $entry->getId());
|
|
|
|
|
|
|
|
$form = $crawler->filter('form[name=tag]')->form();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'tag[label]' => 'caché',
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
|
|
|
|
$newEntry = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
|
|
|
->find($entry->getId());
|
|
|
|
|
|
|
|
$tags = $newEntry->getTags()->toArray();
|
|
|
|
foreach ($tags as $key => $tag) {
|
|
|
|
$tags[$key] = $tag->getLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertGreaterThanOrEqual(2, \count($tags));
|
|
|
|
$this->assertNotFalse(array_search('cache', $tags, true), 'Tag cache is assigned to the entry');
|
|
|
|
$this->assertNotFalse(array_search('caché', $tags, true), 'Tag caché is assigned to the entry');
|
|
|
|
}
|
2021-08-03 12:35:45 +00:00
|
|
|
|
|
|
|
public function testAssignTagsOnSearchResults()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
// Search on unread list
|
|
|
|
$crawler = $client->request('GET', '/unread/list');
|
|
|
|
|
|
|
|
$form = $crawler->filter('form[name=search]')->form();
|
|
|
|
$data = [
|
|
|
|
'search_entry[term]' => 'title',
|
|
|
|
];
|
|
|
|
|
|
|
|
$crawler = $client->submit($form, $data);
|
|
|
|
|
2022-04-20 21:13:17 +00:00
|
|
|
$client->click($crawler->selectLink('entry.list.assign_search_tag')->link());
|
|
|
|
$client->followRedirect();
|
2021-08-03 12:35:45 +00:00
|
|
|
|
|
|
|
$entries = $client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
2022-04-20 21:13:17 +00:00
|
|
|
->getBuilderForSearchByUser($this->getLoggedInUserId(), 'title', 'unread')
|
|
|
|
->getQuery()->getResult();
|
2021-08-03 12:35:45 +00:00
|
|
|
|
|
|
|
foreach ($entries as $entry) {
|
2022-04-20 21:13:17 +00:00
|
|
|
$tags = $entry->getTagsLabel();
|
|
|
|
|
|
|
|
$this->assertContains('title', $tags);
|
2021-08-03 12:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-07 18:29:03 +00:00
|
|
|
}
|