From c3510620ad0718d2ab1f856e3a838360a5ade314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 16:54:21 +0200 Subject: PoC of rule-based tagging --- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 8 ++- src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php | 82 ++++++++++++++++++++++ .../CoreBundle/Resources/config/services.yml | 14 ++++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 7fb41393..dc6e1184 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -13,10 +13,12 @@ use Wallabag\CoreBundle\Tools\Utils; class ContentProxy { protected $graby; + protected $tagger; - public function __construct(Graby $graby) + public function __construct(Graby $graby, RuleBasedTagger $tagger) { - $this->graby = $graby; + $this->graby = $graby; + $this->tagger = $tagger; } /** @@ -59,6 +61,8 @@ class ContentProxy $entry->setPreviewPicture($content['open_graph']['og_image']); } + $this->tagger->tag($entry); + return $entry; } } diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php new file mode 100644 index 00000000..012450b6 --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -0,0 +1,82 @@ +rulerz = $rulerz; + $this->tagRepository = $tagRepository; + } + + /** + * Add tags from rules defined by the user. + * + * @param Entry $entry Entry to tag. + */ + public function tag(Entry $entry) + { + $rules = $this->getRulesForUser($entry->getUser()); + + foreach ($rules as $rule) { + if (!$this->rulerz->satisfies($entry, $rule['rule'])) { + continue; + } + + foreach ($rule['tags'] as $label) { + $tag = $this->getTag($entry->getUser(), $label); + + $entry->addTag($tag); + } + } + } + + /** + * Fetch a tag for a user. + * + * @param User $user + * @param string $label The tag's label. + * + * @return Tag + */ + private function getTag(User $user, $label) + { + $tag = $this->tagRepository->findOneByLabelAndUserId($label, $user->getId()); + + if (!$tag) { + $tag = new Tag($user); + $tag->setLabel($label); + } + + return $tag; + } + + private function getRulesForUser(User $user) + { + return [ + [ + 'rule' => 'domainName = "github.com"', + 'tags' => ['github'], + ], + [ + 'rule' => 'readingTime >= 15', + 'tags' => ['long reading'], + ], + [ + 'rule' => 'readingTime <= 3 ', + 'tags' => ['short reading'], + ], + ]; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 8e21b052..4cf46b33 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -53,6 +53,20 @@ services: class: Wallabag\CoreBundle\Helper\ContentProxy arguments: - @wallabag_core.graby + - @wallabag_core.rule_based_tagger + + wallabag_core.rule_based_tagger: + class: Wallabag\CoreBundle\Helper\RuleBasedTagger + arguments: + - @rulerz + - @wallabag_core.tag_repository + + wallabag_core.tag_repository: + class: Wallabag\CoreBundle\Repository\TagRepository + factory_service: doctrine.orm.default_entity_manager + factory_method: getRepository + arguments: + - WallabagCoreBundle:Tag wallabag_core.registration_confirmed: class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener -- cgit v1.2.3 From ac9fec610a6485b39c856d9cb7d263ce8c5f1223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 17:14:50 +0200 Subject: Add TaggingRule entity --- src/Wallabag/CoreBundle/Entity/Config.php | 26 +++++ src/Wallabag/CoreBundle/Entity/TaggingRule.php | 128 +++++++++++++++++++++ src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php | 26 ++--- 3 files changed, 164 insertions(+), 16 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Entity/TaggingRule.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index b2a1915a..496fadb4 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -76,12 +76,18 @@ class Config */ private $user; + /** + * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\TaggingRule", mappedBy="config", cascade={"remove"}) + */ + private $taggingRules; + /* * @param User $user */ public function __construct(\Wallabag\UserBundle\Entity\User $user) { $this->user = $user; + $this->taggingRules = new ArrayCollection(); } /** @@ -237,4 +243,24 @@ class Config { return $this->rssLimit; } + + /** + * @param TaggingRule $rule + * + * @return Config + */ + public function addTaggingRule(TaggingRule $rule) + { + $this->taggingRules[] = $rule; + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getTaggingRules() + { + return $this->taggingRules; + } } diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php new file mode 100644 index 00000000..6d03a34d --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php @@ -0,0 +1,128 @@ +id; + } + + /** + * Set rule. + * + * @param string $rule + * + * @return TaggingRule + */ + public function setRule($rule) + { + $this->rule = $rule; + + return $this; + } + + /** + * Get rule. + * + * @return string + */ + public function getRule() + { + return $this->rule; + } + + /** + * Set tags. + * + * @param array $tags + * + * @return TaggingRule + */ + public function setTags(array $tags) + { + $this->tags = $tags; + + return $this; + } + + /** + * Get tags. + * + * @return array + */ + public function getTags() + { + return $this->tags; + } + + /** + * Set config. + * + * @param Config $config + * + * @return TaggingRule + */ + public function setConfig(Config $config) + { + $this->config = $config; + + return $this; + } + + /** + * Get config. + * + * @return Config + */ + public function getConfig() + { + return $this->config; + } +} diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php index 012450b6..bb933779 100644 --- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -30,11 +30,11 @@ class RuleBasedTagger $rules = $this->getRulesForUser($entry->getUser()); foreach ($rules as $rule) { - if (!$this->rulerz->satisfies($entry, $rule['rule'])) { + if (!$this->rulerz->satisfies($entry, $rule->getRule())) { continue; } - foreach ($rule['tags'] as $label) { + foreach ($rule->getTags() as $label) { $tag = $this->getTag($entry->getUser(), $label); $entry->addTag($tag); @@ -62,21 +62,15 @@ class RuleBasedTagger return $tag; } + /** + * Retrieves the tagging rules for a given user. + * + * @param User $user + * + * @return array + */ private function getRulesForUser(User $user) { - return [ - [ - 'rule' => 'domainName = "github.com"', - 'tags' => ['github'], - ], - [ - 'rule' => 'readingTime >= 15', - 'tags' => ['long reading'], - ], - [ - 'rule' => 'readingTime <= 3 ', - 'tags' => ['short reading'], - ], - ]; + return $user->getConfig()->getTaggingRules(); } } -- cgit v1.2.3 From f19f9f62d13c62f18884e8bd0fa67403e8cad8d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 17:30:58 +0200 Subject: Add a form to create tagging rules --- .../CoreBundle/Controller/ConfigController.php | 21 ++++++++++ .../DataTransformer/StringToListTransformer.php | 49 ++++++++++++++++++++++ .../CoreBundle/Form/Type/TaggingRuleType.php | 38 +++++++++++++++++ .../views/themes/material/Config/index.html.twig | 31 +++++++++++++- 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php create mode 100644 src/Wallabag/CoreBundle/Form/Type/TaggingRuleType.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 8bbe4ca0..24b86344 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -7,9 +7,11 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; use Wallabag\CoreBundle\Entity\Config; +use Wallabag\CoreBundle\Entity\TaggingRule; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; use Wallabag\CoreBundle\Form\Type\UserInformationType; +use Wallabag\CoreBundle\Form\Type\TaggingRuleType; use Wallabag\CoreBundle\Form\Type\NewUserType; use Wallabag\CoreBundle\Form\Type\RssType; use Wallabag\CoreBundle\Tools\Utils; @@ -98,6 +100,24 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config')); } + // handle tagging rule + $taggingRule = new TaggingRule(); + $newTaggingRule = $this->createForm(new TaggingRuleType(), $taggingRule); + $newTaggingRule->handleRequest($request); + + if ($newTaggingRule->isValid()) { + $taggingRule->setConfig($config); + $em->persist($taggingRule); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Tagging rules updated' + ); + + return $this->redirect($this->generateUrl('config')); + } + // handle adding new user $newUser = $userManager->createUser(); // enable created user by default @@ -136,6 +156,7 @@ class ConfigController extends Controller 'pwd' => $pwdForm->createView(), 'user' => $userForm->createView(), 'new_user' => $newUserForm->createView(), + 'new_tagging_rule' => $newTaggingRule->createView(), ), 'rss' => array( 'username' => $user->getUsername(), diff --git a/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php new file mode 100644 index 00000000..332a91b8 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php @@ -0,0 +1,49 @@ +separator = $separator; + } + + /** + * Transforms a list to a string. + * + * @param array|null $list + * + * @return string + */ + public function transform($list) + { + if (null === $list) { + return ''; + } + + return implode($this->separator, $list); + } + + /** + * Transforms a string to a list. + * + * @param string $string + * + * @return array|null + */ + public function reverseTransform($string) + { + if (!$string) { + return null; + } + + return array_filter(array_map('trim', explode($this->separator, $string))); + } +} diff --git a/src/Wallabag/CoreBundle/Form/Type/TaggingRuleType.php b/src/Wallabag/CoreBundle/Form/Type/TaggingRuleType.php new file mode 100644 index 00000000..7fbba38a --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/TaggingRuleType.php @@ -0,0 +1,38 @@ +add('rule', 'text', array('required' => true)) + ->add('save', 'submit') + ; + + $tagsField = $builder + ->create('tags', 'text') + ->addModelTransformer(new StringToListTransformer(',')); + + $builder->add($tagsField); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Wallabag\CoreBundle\Entity\TaggingRule', + )); + } + + public function getName() + { + return 'tagging_rule'; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 8f121a2b..d27a8ca6 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -15,8 +15,9 @@
  • {% trans %}RSS{% endtrans %}
  • {% trans %}User information{% endtrans %}
  • {% trans %}Password{% endtrans %}
  • +
  • {% trans %}Tags{% endtrans %}
  • {% if is_granted('ROLE_SUPER_ADMIN') %} -
  • {% trans %}Add a user{% endtrans %}
  • +
  • {% trans %}Add a user{% endtrans %}
  • {% endif %} @@ -183,6 +184,34 @@ +
    +
    + {{ form_errors(form.pwd) }} + +
    +
    + {{ form_label(form.new_tagging_rule.rule) }} + {{ form_errors(form.new_tagging_rule.rule) }} + {{ form_widget(form.new_tagging_rule.rule) }} +
    +
    + +
    +
    + {{ form_label(form.new_tagging_rule.tags) }} + {{ form_errors(form.new_tagging_rule.tags) }} + {{ form_widget(form.new_tagging_rule.tags) }} +
    +
    + + + + +
    +
    + {% if is_granted('ROLE_SUPER_ADMIN') %}
    {{ form_start(form.new_user) }} -- cgit v1.2.3 From 9cbb404b4a2f76ad387ee31160bcf461048bc003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 17:37:05 +0200 Subject: Add missing tagging rule repository --- src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php b/src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php new file mode 100644 index 00000000..de380738 --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php @@ -0,0 +1,9 @@ + Date: Sun, 11 Oct 2015 17:37:19 +0200 Subject: Display the tagging rules in the config --- .../Resources/views/themes/material/Config/index.html.twig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index d27a8ca6..1a8526f3 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -185,6 +185,18 @@
    +
    +
    +
      + {% for tagging_rule in app.user.config.taggingRules %} +
    • + if « {{ tagging_rule.rule }} » then tag as « {{ tagging_rule.tags|join(', ') }} » +
    • + {% endfor %} +
    +
    +
    +
    {{ form_errors(form.pwd) }} -- cgit v1.2.3 From e9fbd2d12e94c96d540f6f98758f6bc92a65e7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 17:46:53 +0200 Subject: Add a table explaining the available variables --- .../views/themes/material/Config/index.html.twig | 57 +++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 1a8526f3..885718f8 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -220,8 +220,63 @@ - + +
    +
    +

    + {% trans %}The following variables can be used to create tagging rules:{% endtrans %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    VariableMeaning
    title{% trans %}Title of the entry{% endtrans %}
    url{% trans %}URL of the entry{% endtrans %}
    isArchived{% trans %}Whether the entry is archived or not{% endtrans %}
    isStared{% trans %}Whether the entry is starred or not{% endtrans %}
    content{% trans %}The entry's content{% endtrans %}
    language{% trans %}The entry's language{% endtrans %}
    mimetype{% trans %}The entry's mime-type{% endtrans %}
    readingTime{% trans %}The estimated entry's reading time, in minutes{% endtrans %}
    domainName{% trans %}The domain name of the entry{% endtrans %}
    +

    +
    +
    {% if is_granted('ROLE_SUPER_ADMIN') %} -- cgit v1.2.3 From 1d7b350b259ccc0110318a377ae3b3752ec6b9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 22:22:24 +0200 Subject: Add missing use statement --- src/Wallabag/CoreBundle/Entity/Config.php | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index 496fadb4..1204efa8 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -2,6 +2,7 @@ namespace Wallabag\CoreBundle\Entity; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; -- cgit v1.2.3 From f530f7f5e19eb611ba79856d3ca3b7aebd2af367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 22:27:47 +0200 Subject: Fix ContentProxyTest --- .../CoreBundle/Tests/Helper/ContentProxyTest.php | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php index 4bce4708..1688a48a 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php @@ -10,6 +10,10 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase { public function testWithEmptyContent() { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(array('fetchContent')) ->disableOriginalConstructor() @@ -25,7 +29,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'language' => '', )); - $proxy = new ContentProxy($graby); + $proxy = new ContentProxy($graby, $tagger); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://0.0.0.0', $entry->getUrl()); @@ -40,6 +44,10 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase public function testWithEmptyContentButOG() { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(array('fetchContent')) ->disableOriginalConstructor() @@ -59,7 +67,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ), )); - $proxy = new ContentProxy($graby); + $proxy = new ContentProxy($graby, $tagger); $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); $this->assertEquals('http://domain.io', $entry->getUrl()); @@ -74,6 +82,10 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase public function testWithContent() { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(array('fetchContent')) ->disableOriginalConstructor() @@ -94,7 +106,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ), )); - $proxy = new ContentProxy($graby); + $proxy = new ContentProxy($graby, $tagger); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); @@ -106,4 +118,12 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals(4.0, $entry->getReadingTime()); $this->assertEquals('1.1.1.1', $entry->getDomainName()); } + + private function getTaggerMock() + { + return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') + ->setMethods(array('tag')) + ->disableOriginalConstructor() + ->getMock(); + } } -- cgit v1.2.3 From 003fa77438b13ceb9ceda245d6ad257801453d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Mon, 12 Oct 2015 21:43:24 +0200 Subject: Add tests for the StringToListTransformer class --- .../DataTransformer/StringToListTransformer.php | 14 +++++- .../StringToListTransformerTest.php | 50 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Tests/Form/DataTransformer/StringToListTransformerTest.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php index 332a91b8..23488d35 100644 --- a/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php +++ b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php @@ -6,10 +6,20 @@ use Doctrine\Common\Persistence\ObjectManager; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; +/** + * Transforms a comma-separated list to a proper PHP array. + * Example: the string "foo, bar" will become the array ["foo", "bar"] + */ class StringToListTransformer implements DataTransformerInterface { + /** + * @var string + */ private $separator; + /** + * @param string $separator The separator used in the list. + */ public function __construct($separator = ',') { $this->separator = $separator; @@ -40,10 +50,10 @@ class StringToListTransformer implements DataTransformerInterface */ public function reverseTransform($string) { - if (!$string) { + if ($string === null) { return null; } - return array_filter(array_map('trim', explode($this->separator, $string))); + return array_values(array_filter(array_map('trim', explode($this->separator, $string)))); } } diff --git a/src/Wallabag/CoreBundle/Tests/Form/DataTransformer/StringToListTransformerTest.php b/src/Wallabag/CoreBundle/Tests/Form/DataTransformer/StringToListTransformerTest.php new file mode 100644 index 00000000..d114e5f3 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Form/DataTransformer/StringToListTransformerTest.php @@ -0,0 +1,50 @@ +assertSame($expectedResult, $transformer->transform($inputData)); + } + + public function transformProvider() + { + return array( + array( null, '' ), + array( array(), '' ), + array( array('single value'), 'single value' ), + array( array('first value', 'second value'), 'first value,second value' ), + ); + } + + /** + * @dataProvider reverseTransformProvider + */ + public function testReverseTransformWithValidData($inputData, $expectedResult) + { + $transformer = new StringToListTransformer(); + + $this->assertSame($expectedResult, $transformer->reverseTransform($inputData)); + } + + public function reverseTransformProvider() + { + return array( + array( null, null ), + array( '', array() ), + array( 'single value', array('single value') ), + array( 'first value,second value', array('first value', 'second value') ), + array( 'first value, second value', array('first value', 'second value') ), + array( 'first value, , second value', array('first value', 'second value') ), + ); + } +} -- cgit v1.2.3 From 71ef0ed2542e3dff3b64910ef9e3543fa568ffdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Wed, 14 Oct 2015 20:24:02 +0200 Subject: =?UTF-8?q?Rename=20the=20=C2=AB=20Tags=20=C2=BB=20tab=20to=20?= =?UTF-8?q?=C2=AB=20Tagging=20rules=20=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreBundle/Resources/views/themes/material/Config/index.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 885718f8..993c5826 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -15,7 +15,7 @@
  • {% trans %}RSS{% endtrans %}
  • {% trans %}User information{% endtrans %}
  • {% trans %}Password{% endtrans %}
  • -
  • {% trans %}Tags{% endtrans %}
  • +
  • {% trans %}Tagging rules{% endtrans %}
  • {% if is_granted('ROLE_SUPER_ADMIN') %}
  • {% trans %}Add a user{% endtrans %}
  • {% endif %} -- cgit v1.2.3 From 3447d1ee07bb64e57e69164127529f957dd47822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Wed, 14 Oct 2015 22:48:58 +0200 Subject: =?UTF-8?q?Add=20na=C3=AFve=20validation=20for=20tagging=20rules?= =?UTF-8?q?=20(only=20checks=20the=20syntax)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Wallabag/CoreBundle/Entity/TaggingRule.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php index 6d03a34d..20c15258 100644 --- a/src/Wallabag/CoreBundle/Entity/TaggingRule.php +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php @@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; +use KPhoen\RulerZBundle\Validator\Constraints as RulerZAssert; /** * Config. @@ -27,6 +28,7 @@ class TaggingRule * @var string * * @Assert\NotBlank() + * @RulerZAssert\ValidRule() * @ORM\Column(name="rule", type="string", nullable=false) */ private $rule; -- cgit v1.2.3 From 1dc4e5da2e281ee8acc69ff025c42369cf778387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 17 Oct 2015 16:57:41 +0200 Subject: Also validate used variables when creating tagging rules --- src/Wallabag/CoreBundle/Entity/TaggingRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php index 20c15258..97a29336 100644 --- a/src/Wallabag/CoreBundle/Entity/TaggingRule.php +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php @@ -28,7 +28,7 @@ class TaggingRule * @var string * * @Assert\NotBlank() - * @RulerZAssert\ValidRule() + * @RulerZAssert\ValidRule(allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"}) * @ORM\Column(name="rule", type="string", nullable=false) */ private $rule; -- cgit v1.2.3 From 1c9cd2a7f03a66a1ae5132ff270e94a7fe6eb9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 17 Oct 2015 17:45:51 +0200 Subject: Errors in the automatic tagging do not prevent the entry from being added --- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 14 ++++++++++++-- src/Wallabag/CoreBundle/Resources/config/services.yml | 1 + src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php | 11 ++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index dc6e1184..3d585e61 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Helper; use Graby\Graby; +use Psr\Log\LoggerInterface as Logger; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Tools\Utils; @@ -14,11 +15,13 @@ class ContentProxy { protected $graby; protected $tagger; + protected $logger; - public function __construct(Graby $graby, RuleBasedTagger $tagger) + public function __construct(Graby $graby, RuleBasedTagger $tagger, Logger $logger) { $this->graby = $graby; $this->tagger = $tagger; + $this->logger = $logger; } /** @@ -61,7 +64,14 @@ class ContentProxy $entry->setPreviewPicture($content['open_graph']['og_image']); } - $this->tagger->tag($entry); + try { + $this->tagger->tag($entry); + } catch (\Exception $e) { + $this->logger->error('Error while trying to automatically tag an entry.', array( + 'entry_url' => $url, + 'error_msg' => $e->getMessage(), + )); + } return $entry; } diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 4cf46b33..0100a62d 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -54,6 +54,7 @@ services: arguments: - @wallabag_core.graby - @wallabag_core.rule_based_tagger + - @logger wallabag_core.rule_based_tagger: class: Wallabag\CoreBundle\Helper\RuleBasedTagger diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php index 1688a48a..f59edb0c 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php @@ -29,7 +29,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'language' => '', )); - $proxy = new ContentProxy($graby, $tagger); + $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock()); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://0.0.0.0', $entry->getUrl()); @@ -67,7 +67,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ), )); - $proxy = new ContentProxy($graby, $tagger); + $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock()); $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); $this->assertEquals('http://domain.io', $entry->getUrl()); @@ -106,7 +106,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ), )); - $proxy = new ContentProxy($graby, $tagger); + $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock()); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); @@ -126,4 +126,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); } + + private function getLoggerMock() + { + return $this->getMock('Psr\Log\LoggerInterface'); + } } -- cgit v1.2.3 From 5a166c5c1af645b1b1ba77ba5f2e24094e7b60e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 17 Oct 2015 18:34:18 +0200 Subject: Add tests for the RuleBasedTagger class --- .../Tests/Helper/RuleBasedTaggerTest.php | 158 +++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php new file mode 100644 index 00000000..56a1ed61 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php @@ -0,0 +1,158 @@ +rulerz = $this->getRulerZMock(); + $this->repository = $this->getTagRepositoryMock(); + + $this->tagger = new RuleBasedTagger($this->rulerz, $this->repository); + } + + public function testTagWithNoRule() + { + $entry = new Entry($this->getUser()); + + $this->tagger->tag($entry); + + $this->assertTrue($entry->getTags()->isEmpty()); + } + + public function testTagWithNoMatchingRule() + { + $taggingRule = $this->getTaggingRule('rule as string', array('foo', 'bar')); + $user = $this->getUser([$taggingRule]); + $entry = new Entry($user); + + $this->rulerz + ->expects($this->once()) + ->method('satisfies') + ->with($entry, 'rule as string') + ->willReturn(false); + + $this->tagger->tag($entry); + + $this->assertTrue($entry->getTags()->isEmpty()); + } + + public function testTagWithAMatchingRule() + { + $taggingRule = $this->getTaggingRule('rule as string', array('foo', 'bar')); + $user = $this->getUser([$taggingRule]); + $entry = new Entry($user); + + $this->rulerz + ->expects($this->once()) + ->method('satisfies') + ->with($entry, 'rule as string') + ->willReturn(true); + + $this->tagger->tag($entry); + + $this->assertFalse($entry->getTags()->isEmpty()); + + $tags = $entry->getTags(); + $this->assertSame('foo', $tags[0]->getLabel()); + $this->assertSame($user, $tags[0]->getUser()); + $this->assertSame('bar', $tags[1]->getLabel()); + $this->assertSame($user, $tags[1]->getUser()); + } + + public function testTagWithAMixOfMatchingRules() + { + $taggingRule = $this->getTaggingRule('bla bla', array('hey')); + $otherTaggingRule = $this->getTaggingRule('rule as string', array('foo')); + + $user = $this->getUser([$taggingRule, $otherTaggingRule]); + $entry = new Entry($user); + + $this->rulerz + ->method('satisfies') + ->will($this->onConsecutiveCalls(false, true)); + + $this->tagger->tag($entry); + + $this->assertFalse($entry->getTags()->isEmpty()); + + $tags = $entry->getTags(); + $this->assertSame('foo', $tags[0]->getLabel()); + $this->assertSame($user, $tags[0]->getUser()); + } + + public function testWhenTheTagExists() + { + $taggingRule = $this->getTaggingRule('rule as string', array('foo')); + $user = $this->getUser([$taggingRule]); + $entry = new Entry($user); + $tag = new Tag($user); + + $this->rulerz + ->expects($this->once()) + ->method('satisfies') + ->with($entry, 'rule as string') + ->willReturn(true); + + $this->repository + ->expects($this->once()) + ->method('findOneByLabelAndUserId') + ->willReturn($tag); + + $this->tagger->tag($entry); + + $this->assertFalse($entry->getTags()->isEmpty()); + + $tags = $entry->getTags(); + $this->assertSame($tag, $tags[0]); + } + + private function getUser(array $taggingRules = []) + { + $user = new User(); + $config = new Config($user); + + $user->setConfig($config); + + foreach ($taggingRules as $rule) { + $config->addTaggingRule($rule); + } + + return $user; + } + + private function getTaggingRule($rule, array $tags) + { + $taggingRule = new TaggingRule(); + $taggingRule->setRule($rule); + $taggingRule->setTags($tags); + + return $taggingRule; + } + + private function getRulerZMock() + { + return $this->getMockBuilder('RulerZ\RulerZ') + ->disableOriginalConstructor() + ->getMock(); + } + + private function getTagRepositoryMock() + { + return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') + ->disableOriginalConstructor() + ->getMock(); + } +} -- cgit v1.2.3 From c23fc05df86c3cdb8eb40994b98d057f4a81b02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 18 Oct 2015 14:32:58 +0200 Subject: Validate used operators when creating tagging rules --- src/Wallabag/CoreBundle/Entity/TaggingRule.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php index 97a29336..472ae582 100644 --- a/src/Wallabag/CoreBundle/Entity/TaggingRule.php +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php @@ -28,7 +28,10 @@ class TaggingRule * @var string * * @Assert\NotBlank() - * @RulerZAssert\ValidRule(allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"}) + * @RulerZAssert\ValidRule( + * allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"}, + * allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or"} + * ) * @ORM\Column(name="rule", type="string", nullable=false) */ private $rule; -- cgit v1.2.3 From 625acf335298186b4ff983f9321900d1238e854b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 24 Oct 2015 15:11:06 +0200 Subject: Add a command to automatically tag all entries for a user --- src/Wallabag/CoreBundle/Command/TagAllCommand.php | 66 ++++++++++++++++++++++ src/Wallabag/CoreBundle/Entity/Entry.php | 4 ++ src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php | 38 ++++++++++++- .../CoreBundle/Resources/config/services.yml | 8 +++ .../Tests/Helper/RuleBasedTaggerTest.php | 19 +++++-- .../UserBundle/Repository/UserRepository.php | 15 +++++ 6 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Command/TagAllCommand.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Command/TagAllCommand.php b/src/Wallabag/CoreBundle/Command/TagAllCommand.php new file mode 100644 index 00000000..2cf3f808 --- /dev/null +++ b/src/Wallabag/CoreBundle/Command/TagAllCommand.php @@ -0,0 +1,66 @@ +setName('wallabag:tag:all') + ->setDescription('Tag all entries using the tagging rules.') + ->addArgument( + 'username', + InputArgument::REQUIRED, + 'User to tag entries for.' + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + try { + $user = $this->getUser($input->getArgument('username')); + } catch (NoResultException $e) { + $output->writeln(sprintf('User %s not found.', $input->getArgument('username'))); + + return 1; + } + $tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger'); + + $output->write(sprintf('Tagging entries for user « %s »... ', $user->getUserName())); + + $entries = $tagger->tagAllForUser($user); + + $em = $this->getDoctrine()->getManager(); + foreach ($entries as $entry) { + $em->persist($entry); + } + $em->flush(); + + $output->writeln('Done.'); + } + + /** + * Fetches a user from its username. + * + * @param string $username + * + * @return \Wallabag\UserBundle\Entity\User + */ + private function getUser($username) + { + return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); + } + + private function getDoctrine() + { + return $this->getContainer()->get('doctrine'); + } +} diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 5aa582f8..608ed2f0 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -458,6 +458,10 @@ class Entry */ public function addTag(Tag $tag) { + if ($this->tags->contains($tag)) { + return; + } + $this->tags[] = $tag; $tag->addEntry($this); } diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php index bb933779..3f9953c0 100644 --- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -6,6 +6,7 @@ use RulerZ\RulerZ; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; +use Wallabag\CoreBundle\Repository\EntryRepository; use Wallabag\CoreBundle\Repository\TagRepository; use Wallabag\UserBundle\Entity\User; @@ -13,11 +14,13 @@ class RuleBasedTagger { private $rulerz; private $tagRepository; + private $entryRepository; - public function __construct(RulerZ $rulerz, TagRepository $tagRepository) + public function __construct(RulerZ $rulerz, TagRepository $tagRepository, EntryRepository $entryRepository) { - $this->rulerz = $rulerz; - $this->tagRepository = $tagRepository; + $this->rulerz = $rulerz; + $this->tagRepository = $tagRepository; + $this->entryRepository = $entryRepository; } /** @@ -42,6 +45,35 @@ class RuleBasedTagger } } + /** + * Apply all the tagging rules defined by a user on its entries. + * + * @param User $user + * + * @return array A list of modified entries. + */ + public function tagAllForUser(User $user) + { + $rules = $this->getRulesForUser($user); + $entries = array(); + + foreach ($rules as $rule) { + $qb = $this->entryRepository->getBuilderForAllByUser($user->getId()); + $entries = $this->rulerz->filter($qb, $rule->getRule()); + + foreach ($entries as $entry) { + foreach ($rule->getTags() as $label) { + $tag = $this->getTag($user, $label); + + $entry->addTag($tag); + $entries[] = $entry; + } + } + } + + return $entries; + } + /** * Fetch a tag for a user. * diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 0100a62d..cef4450d 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -61,6 +61,14 @@ services: arguments: - @rulerz - @wallabag_core.tag_repository + - @wallabag_core.entry_repository + + wallabag_core.entry_repository: + class: Wallabag\CoreBundle\Repository\EntryRepository + factory_service: doctrine.orm.default_entity_manager + factory_method: getRepository + arguments: + - WallabagCoreBundle:Entry wallabag_core.tag_repository: class: Wallabag\CoreBundle\Repository\TagRepository diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php index 56a1ed61..5180f7dd 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php @@ -12,15 +12,17 @@ use Wallabag\CoreBundle\Helper\RuleBasedTagger; class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase { private $rulerz; - private $repository; + private $tagRepository; + private $entryRepository; private $tagger; public function setUp() { - $this->rulerz = $this->getRulerZMock(); - $this->repository = $this->getTagRepositoryMock(); + $this->rulerz = $this->getRulerZMock(); + $this->tagRepository = $this->getTagRepositoryMock(); + $this->entryRepository = $this->getEntryRepositoryMock(); - $this->tagger = new RuleBasedTagger($this->rulerz, $this->repository); + $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository); } public function testTagWithNoRule() @@ -106,7 +108,7 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase ->with($entry, 'rule as string') ->willReturn(true); - $this->repository + $this->tagRepository ->expects($this->once()) ->method('findOneByLabelAndUserId') ->willReturn($tag); @@ -155,4 +157,11 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); } + + private function getEntryRepositoryMock() + { + return $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + } } diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index c020f3ca..009c4881 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -23,4 +23,19 @@ class UserRepository extends EntityRepository ->getQuery() ->getOneOrNullResult(); } + + /** + * Find a user by its username. + * + * @param string $username + * + * @return User + */ + public function findOneByUserName($username) + { + return $this->createQueryBuilder('u') + ->andWhere('u.username = :username')->setParameter('username', $username) + ->getQuery() + ->getSingleResult(); + } } -- cgit v1.2.3 From 52e423f30761561fa2ad82c708d9fa9186562b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 25 Oct 2015 10:45:15 +0100 Subject: Provide a way to delete tagging rules --- .../CoreBundle/Controller/ConfigController.php | 27 ++++++++++++++++++++++ .../views/themes/material/Config/index.html.twig | 3 +++ 2 files changed, 30 insertions(+) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 24b86344..de1536c9 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -188,6 +188,33 @@ class ConfigController extends Controller return $request->headers->get('referer') ? $this->redirect($request->headers->get('referer')) : $this->redirectToRoute('config'); } + /** + * Deletes a tagging rule and redirect to the config homepage. + * + * @param TaggingRule $rule + * + * @Route("/tagging-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_tagging_rule") + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function deleteTaggingRule(TaggingRule $rule) + { + if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { + throw $this->createAccessDeniedException('You can not access this tagging ryle.'); + } + + $em = $this->getDoctrine()->getManager(); + $em->remove($rule); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Tagging rule deleted' + ); + + return $this->redirect($this->generateUrl('config')); + } + /** * Retrieve config for the current user. * If no config were found, create a new one. diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 993c5826..1457fe51 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -191,6 +191,9 @@ {% for tagging_rule in app.user.config.taggingRules %}
  • if « {{ tagging_rule.rule }} » then tag as « {{ tagging_rule.tags|join(', ') }} » + + +
  • {% endfor %} -- cgit v1.2.3 From 9b88658c047514a75bc9a9e3578cbeba32c5c5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 25 Oct 2015 14:34:43 +0100 Subject: Update baggy theme --- .../views/themes/baggy/Config/index.html.twig | 33 ++++++++++++++++++++++ .../views/themes/material/Config/index.html.twig | 4 +-- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig index 7a7d6af1..cc797c63 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig @@ -145,6 +145,39 @@ {{ form_rest(form.pwd) }} +

    {% trans %}Tagging rules{% endtrans %}

    + +
      + {% for tagging_rule in app.user.config.taggingRules %} +
    • + if « {{ tagging_rule.rule }} » then tag as « {{ tagging_rule.tags|join(', ') }} » + +
    • + {% endfor %} +
    + +
    + {{ form_errors(form.new_tagging_rule) }} + +
    +
    + {{ form_label(form.new_tagging_rule.rule) }} + {{ form_errors(form.new_tagging_rule.rule) }} + {{ form_widget(form.new_tagging_rule.rule) }} +
    +
    + +
    +
    + {{ form_label(form.new_tagging_rule.tags) }} + {{ form_errors(form.new_tagging_rule.tags) }} + {{ form_widget(form.new_tagging_rule.tags) }} +
    +
    + + {{ form_rest(form.new_tagging_rule) }} +
    + {% if is_granted('ROLE_SUPER_ADMIN') %}

    {% trans %}Add a user{% endtrans %}

    diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 1457fe51..810c02fa 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -200,8 +200,8 @@ -
    - {{ form_errors(form.pwd) }} + + {{ form_errors(form.new_tagging_rule) }}
    -- cgit v1.2.3 From 8a99c7a86b138faee5dc92ab6ecbd281dbd19451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 31 Oct 2015 16:21:56 +0100 Subject: Add a few functional tests for the tagging rules creation form --- .../Tests/Controller/ConfigControllerTest.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 7085151a..4eb67ffd 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -479,4 +479,59 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); $this->assertContains($expectedMessage, $alert[0]); } + + public function testTaggingRuleCreation() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config'); + + $this->assertTrue($client->getResponse()->isSuccessful()); + + $form = $crawler->filter('button[id=tagging_rule_save]')->form(); + + $data = array( + 'tagging_rule[rule]' => 'readingTime <= 3', + 'tagging_rule[tags]' => 'short reading', + ); + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); + $this->assertContains('Tagging rules updated', $alert[0]); + + $deleteLink = $crawler->filter('.delete')->eq(0)->link(); + + $crawler = $client->click($deleteLink); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); + $this->assertContains('Tagging rule deleted', $alert[0]); + } + + public function dataForTaggingRuleFailed() + { + return array( + array( + array( + 'rss_config[rule]' => 'unknownVar <= 3', + 'rss_config[tags]' => 'cool tag', + ), + 'The variable « unknownVar » does not exist.', + ), + array( + array( + 'rss_config[rule]' => 'length(domainName) <= 42', + 'rss_config[tags]' => 'cool tag', + ), + 'The operator « length » does not exist.', + ), + ); + } } -- cgit v1.2.3 From 7b1648961d2a9770e801f414d297efe3aace07e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 31 Oct 2015 16:29:38 +0100 Subject: Fix incorrect comment. --- src/Wallabag/CoreBundle/Entity/TaggingRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php index 472ae582..851af932 100644 --- a/src/Wallabag/CoreBundle/Entity/TaggingRule.php +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php @@ -7,7 +7,7 @@ use Symfony\Component\Validator\Constraints as Assert; use KPhoen\RulerZBundle\Validator\Constraints as RulerZAssert; /** - * Config. + * Tagging rule. * * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TaggingRuleRepository") * @ORM\Table -- cgit v1.2.3 From 0c5bcd82bafbc91820857f7647186431273bc483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 31 Oct 2015 16:38:49 +0100 Subject: Use Psr\Log\NullLogger instead of creating a mock --- src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php index f59edb0c..ef7cbd5b 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php @@ -2,6 +2,9 @@ namespace Wallabag\CoreBundle\Tests\Helper; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Psr\Log\NullLogger; + use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\ContentProxy; @@ -29,7 +32,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'language' => '', )); - $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock()); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger()); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://0.0.0.0', $entry->getUrl()); @@ -67,7 +70,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ), )); - $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock()); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger()); $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); $this->assertEquals('http://domain.io', $entry->getUrl()); @@ -106,7 +109,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ), )); - $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock()); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger()); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); @@ -127,8 +130,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->getMock(); } - private function getLoggerMock() + private function getLogger() { - return $this->getMock('Psr\Log\LoggerInterface'); + return new NullLogger(); } } -- cgit v1.2.3 From b7b20054947676ab0d4c89c3c4a64db4e52db203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Wed, 11 Nov 2015 16:44:57 +0100 Subject: Fix the creation of the repository services --- src/Wallabag/CoreBundle/Resources/config/services.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index cef4450d..03d33560 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -65,15 +65,13 @@ services: wallabag_core.entry_repository: class: Wallabag\CoreBundle\Repository\EntryRepository - factory_service: doctrine.orm.default_entity_manager - factory_method: getRepository + factory: [ @doctrine.orm.default_entity_manager, getRepository ] arguments: - WallabagCoreBundle:Entry wallabag_core.tag_repository: class: Wallabag\CoreBundle\Repository\TagRepository - factory_service: doctrine.orm.default_entity_manager - factory_method: getRepository + factory: [ @doctrine.orm.default_entity_manager, getRepository ] arguments: - WallabagCoreBundle:Tag -- cgit v1.2.3 From 5c514b0be320d683c22a3044d875a5e4b5fe6ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Wed, 11 Nov 2015 17:06:36 +0100 Subject: Improve the tagging rules documentation --- .../views/themes/material/Config/index.html.twig | 50 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 810c02fa..a6fd2f11 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -227,14 +227,40 @@
    +

    {% trans %}FAQ{% endtrans %}

    + +
    {% trans %}What does « tagging rules » mean?{% endtrans %}
    +

    + {% trans %} + They are rules used by Wallabag to automatically tag new entries.
    + Each time a new entry is added, all the tagging rules will be used to add + the tags you configured, thus saving you the trouble to manually classify + your entries. + {% endtrans %} +

    + +
    {% trans %}How do I use them?{% endtrans %}
    +

    + {% trans %} + Let assume you want to tag new entries as « short reading » when the reading time is inferior to 3 minutes.
    + In that case, you should put « readingTime <= 3 » in the Rule field and « short reading » in the Tags + field.
    + Several tags can added simultaneously by separating them by a comma: « short reading, must read »
    + Complex rules can be written by using predefined operators: if « readingTime >= 5 AND domainName = "github.com" » then tag as « long reading, github » + {% endtrans %} +

    + +
    {% trans %}Which variables and operators can I use to write rules?{% endtrans %}

    - {% trans %}The following variables can be used to create tagging rules:{% endtrans %} + {% trans %}The following variables and operators can be used to create tagging rules:{% endtrans %} - - + + + + @@ -242,38 +268,56 @@ + + + + + + + + + + + + + + + + + +
    VariableMeaning{% trans %}Variable{% endtrans %}{% trans %}Meaning{% endtrans %}{% trans %}Operator{% endtrans %}{% trans %}Meaning{% endtrans %}
    title {% trans %}Title of the entry{% endtrans %}<={% trans %}Less than…{% endtrans %}
    url {% trans %}URL of the entry{% endtrans %}<{% trans %}Strictly less than…{% endtrans %}
    isArchived {% trans %}Whether the entry is archived or not{% endtrans %}=>{% trans %}Greater than…{% endtrans %}
    isStared {% trans %}Whether the entry is starred or not{% endtrans %}>{% trans %}Strictly greater than…{% endtrans %}
    content {% trans %}The entry's content{% endtrans %}={% trans %}Equal to…{% endtrans %}
    language {% trans %}The entry's language{% endtrans %}!={% trans %}Not equal to…{% endtrans %}
    mimetype {% trans %}The entry's mime-type{% endtrans %}OR{% trans %}One rule or another{% endtrans %}
    readingTime {% trans %}The estimated entry's reading time, in minutes{% endtrans %}AND{% trans %}One rule and another{% endtrans %}
    domainName {% trans %}The domain name of the entry{% endtrans %}
    -- cgit v1.2.3 From a6e27f74663637ecc4a4cf84028e6b5a3556a6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Fri, 13 Nov 2015 14:37:58 +0100 Subject: Add matches operator --- src/Wallabag/CoreBundle/Entity/TaggingRule.php | 2 +- src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php | 15 +++++++++++++++ src/Wallabag/CoreBundle/Operator/PHP/Matches.php | 11 +++++++++++ src/Wallabag/CoreBundle/Resources/config/services.yml | 10 ++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php create mode 100644 src/Wallabag/CoreBundle/Operator/PHP/Matches.php (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php index 851af932..4eab590f 100644 --- a/src/Wallabag/CoreBundle/Entity/TaggingRule.php +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php @@ -30,7 +30,7 @@ class TaggingRule * @Assert\NotBlank() * @RulerZAssert\ValidRule( * allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"}, - * allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or"} + * allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or", "matches"} * ) * @ORM\Column(name="rule", type="string", nullable=false) */ diff --git a/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php b/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php new file mode 100644 index 00000000..dc47c982 --- /dev/null +++ b/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php @@ -0,0 +1,15 @@ + Date: Fri, 13 Nov 2015 20:48:51 +0100 Subject: Add phpdoc for all Matches implementations --- src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php | 10 ++++++++++ src/Wallabag/CoreBundle/Operator/PHP/Matches.php | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php b/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php index dc47c982..e6bb03b1 100644 --- a/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php +++ b/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php @@ -2,6 +2,16 @@ namespace Wallabag\CoreBundle\Operator\Doctrine; +/** + * Provides a "matches" operator used for tagging rules. + * + * It asserts that a given pattern is contained in a subject, in a + * case-insensitive way. + * + * This operator will be used to compile tagging rules in DQL, usable + * by Doctrine ORM. + * It's registered in RulerZ using a service (wallabag.operator.doctrine.matches); + */ class Matches { public function __invoke($subject, $pattern) diff --git a/src/Wallabag/CoreBundle/Operator/PHP/Matches.php b/src/Wallabag/CoreBundle/Operator/PHP/Matches.php index 4768900c..987ed2a5 100644 --- a/src/Wallabag/CoreBundle/Operator/PHP/Matches.php +++ b/src/Wallabag/CoreBundle/Operator/PHP/Matches.php @@ -2,6 +2,16 @@ namespace Wallabag\CoreBundle\Operator\PHP; +/** + * Provides a "matches" operator used for tagging rules. + * + * It asserts that a given pattern is contained in a subject, in a + * case-insensitive way. + * + * This operator will be used to compile tagging rules in PHP, usable + * directly on Entry objects for instance. + * It's registered in RulerZ using a service (wallabag.operator.array.matches); + */ class Matches { public function __invoke($subject, $pattern) -- cgit v1.2.3 From aeff8aa765579259c1427dc469ff78ebdebfc72c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Fri, 13 Nov 2015 20:57:46 +0100 Subject: Document the matches operator in the FAQ --- .../Resources/views/themes/material/Config/index.html.twig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index a6fd2f11..e08393a2 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -316,8 +316,13 @@ domainName {% trans %}The domain name of the entry{% endtrans %} - - + matches + + {% trans %} + Tests that a subject is matches a search (case-insensitive).
    + Example: title matches "football" + {% endtrans %} + -- cgit v1.2.3 From 958671a7ae2f19c4b919ed4ba0161e7d300411b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Fri, 13 Nov 2015 21:23:39 +0100 Subject: Add a quick test --- .../CoreBundle/DataFixtures/ORM/LoadConfigData.php | 8 +++++ .../Tests/Controller/ConfigControllerTest.php | 2 +- .../Tests/Controller/EntryControllerTest.php | 35 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php index cb0c52c4..84b78a89 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php @@ -6,6 +6,7 @@ use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Wallabag\CoreBundle\Entity\Config; +use Wallabag\CoreBundle\Entity\TaggingRule; class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface { @@ -15,6 +16,13 @@ class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface public function load(ObjectManager $manager) { $adminConfig = new Config($this->getReference('admin-user')); + $taggingRule = new TaggingRule(); + + $taggingRule->setConfig($adminConfig); + $taggingRule->setRule('title matches "wallabag"'); + $taggingRule->setTags(['wallabag']); + $manager->persist($taggingRule); + $adminConfig->setTheme('material'); $adminConfig->setItemsPerPage(30); $adminConfig->setLanguage('en_US'); diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 4eb67ffd..7b32354f 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -505,7 +505,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); $this->assertContains('Tagging rules updated', $alert[0]); - $deleteLink = $crawler->filter('.delete')->eq(0)->link(); + $deleteLink = $crawler->filter('.delete')->last()->link(); $crawler = $client->click($deleteLink); $this->assertEquals(302, $client->getResponse()->getStatusCode()); diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 56b4c9e4..9f2bcd6c 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -102,6 +102,41 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('Google', $alert[0]); } + /** + * This test will require an internet connection. + */ + public function testPostNewThatWillBeTaggued() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = array( + 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', + ); + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $em = $client->getContainer() + ->get('doctrine.orm.entity_manager'); + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($url); + $this->assertCount(1, $entry->getTags()); + + $em->remove($entry); + $em->flush(); + } + public function testArchive() { $this->logInAs('admin'); -- cgit v1.2.3 From 69edb774eb360ea33646fcc81cd4ea71fa137680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Mon, 16 Nov 2015 13:34:00 +0100 Subject: Assert that the tag has is the good one --- src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 9f2bcd6c..af62aee8 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -131,7 +131,10 @@ class EntryControllerTest extends WallabagCoreTestCase $entry = $em ->getRepository('WallabagCoreBundle:Entry') ->findOneByUrl($url); - $this->assertCount(1, $entry->getTags()); + $tags = $entry->getTags(); + + $this->assertCount(1, $tags); + $this->assertEquals('wallabag', $tags[0]->getLabel()); $em->remove($entry); $em->flush(); -- cgit v1.2.3 From c13eda461f88ba16c88d7c398322a59b294e6c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Mon, 16 Nov 2015 14:01:43 +0100 Subject: Clean the tagging rule creation form --- src/Wallabag/CoreBundle/Controller/ConfigController.php | 2 +- .../CoreBundle/Resources/views/themes/material/Config/index.html.twig | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index de1536c9..7a187710 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -102,7 +102,7 @@ class ConfigController extends Controller // handle tagging rule $taggingRule = new TaggingRule(); - $newTaggingRule = $this->createForm(new TaggingRuleType(), $taggingRule); + $newTaggingRule = $this->createForm(new TaggingRuleType(), $taggingRule, array('action' => $this->generateUrl('config').'#set5')); $newTaggingRule->handleRequest($request); if ($newTaggingRule->isValid()) { diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index e08393a2..d060311d 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -200,7 +200,7 @@

    - + {{ form_start(form.new_tagging_rule) }} {{ form_errors(form.new_tagging_rule) }}
    @@ -332,7 +332,7 @@
    {% if is_granted('ROLE_SUPER_ADMIN') %} -
    +
    {{ form_start(form.new_user) }} {{ form_errors(form.new_user) }} -- cgit v1.2.3 From 752b90d1f2e279d3662d5431b09c7587df2937ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 29 Nov 2015 16:19:02 +0100 Subject: Fix tagging rules ordering --- src/Wallabag/CoreBundle/Entity/Config.php | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index 1204efa8..2ca4182e 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -79,6 +79,7 @@ class Config /** * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\TaggingRule", mappedBy="config", cascade={"remove"}) + * @ORM\OrderBy({"id" = "ASC"}) */ private $taggingRules; -- cgit v1.2.3