From 897aa1d309ffd89a34dbb524c31e9a29eb80038c Mon Sep 17 00:00:00 2001 From: Kevin Jiang Date: Sun, 7 Jul 2024 01:06:22 +1200 Subject: [PATCH] Adding tests for tagging rules reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix test: associate tagging rule with user config Update src/Repository/TaggingRuleRepository.php Co-authored-by: Jérémy Benoist Update src/Controller/ConfigController.php Co-authored-by: Jérémy Benoist Update src/Repository/TaggingRuleRepository.php Co-authored-by: Jérémy Benoist --- src/Controller/ConfigController.php | 2 +- src/Repository/TaggingRuleRepository.php | 4 ++-- tests/Controller/ConfigControllerTest.php | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 1ce402ba6..80ab75095 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -576,7 +576,7 @@ class ConfigController extends AbstractController $annotationRepository->removeAllByUserId($this->getUser()->getId()); break; case 'tagging_rules': - $taggingRuleRepository->removeAllTaggingRules($this->getConfig()->getId()); + $taggingRuleRepository->removeAllByConfigId($this->getConfig()->getId()); break; case 'tags': $this->removeAllTagsByUserId($this->getUser()->getId()); diff --git a/src/Repository/TaggingRuleRepository.php b/src/Repository/TaggingRuleRepository.php index 8b03a6c4e..3d068c273 100644 --- a/src/Repository/TaggingRuleRepository.php +++ b/src/Repository/TaggingRuleRepository.php @@ -14,12 +14,12 @@ class TaggingRuleRepository extends ServiceEntityRepository } /** - * Remove all tagging rule for a config. + * Remove all tagging rules for a config. * Used when a user wants to reset. * * @param int $configId */ - public function removeAllTaggingRules($configId) + public function removeAllByConfigId($configId) { $this->getEntityManager() ->createQuery('DELETE FROM Wallabag\Entity\TaggingRule tr WHERE tr.config = :configId') diff --git a/tests/Controller/ConfigControllerTest.php b/tests/Controller/ConfigControllerTest.php index 997378ba5..922f8b28c 100644 --- a/tests/Controller/ConfigControllerTest.php +++ b/tests/Controller/ConfigControllerTest.php @@ -870,6 +870,12 @@ class ConfigControllerTest extends WallabagTestCase $tag->setLabel('super'); $em->persist($tag); + $taggingRule = new TaggingRule(); + $taggingRule->setConfig($user->getConfig()); + $taggingRule->setRule('readingTime <= 30'); + $taggingRule->setTags(['aTestTag']); + $em->persist($taggingRule); + $entry = new Entry($user); $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); $entry->setContent('Youhou'); @@ -910,6 +916,23 @@ class ConfigControllerTest extends WallabagTestCase $this->assertEmpty($annotationsReset, 'Annotations were reset'); + // reset taggingRules + $crawler = $client->request('GET', '/config#set3'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=reset-tagging-rules]')->form(); + $client->submit($form); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertStringContainsString('flashes.config.notice.tagging_rules_reset', $client->getContainer()->get(SessionInterface::class)->getFlashBag()->get('notice')[0]); + + $taggingRuleReset = $em + ->getRepository(TaggingRule::class) + ->count(['config' => $user->getConfig()]); + + $this->assertSame(0, $taggingRuleReset, 'Tagging rules were reset'); + // reset tags $crawler = $client->request('GET', '/config#set3');