]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #3095 from aaa2000/api-error-on-fail-fetch-content
authorThomas Citharel <tcit@tcit.fr>
Wed, 10 May 2017 07:38:55 +0000 (09:38 +0200)
committerGitHub <noreply@github.com>
Wed, 10 May 2017 07:38:55 +0000 (09:38 +0200)
Create a new entry via API even when its content can't be retrieved

src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
src/Wallabag/CoreBundle/Resources/views/themes/common/Static/about.html.twig
tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php

index e9e1aca3b2c2d6ea2f08453cc615db659aee1b33..54c1747c5a9fb9412f3101892df651b12e34d07d 100644 (file)
@@ -98,12 +98,13 @@ class EntryRestController extends WallabagRestController
         $tags = $request->query->get('tags', '');
         $since = $request->query->get('since', 0);
 
+        /** @var \Pagerfanta\Pagerfanta $pager */
         $pager = $this->getDoctrine()
             ->getRepository('WallabagCoreBundle:Entry')
             ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order, $since, $tags);
 
-        $pager->setCurrentPage($page);
         $pager->setMaxPerPage($perPage);
+        $pager->setCurrentPage($page);
 
         $pagerfantaFactory = new PagerfantaFactory('page', 'perPage');
         $paginatedCollection = $pagerfantaFactory->createRepresentation(
index ee66c728a88558cd21511076782418ef62674ab3..556578d1a7bf6cc896d2888a07dd70c503a85c26 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wallabag\CoreBundle\Form\Type;
 
 use Doctrine\ORM\EntityRepository;
+use Lexik\Bundle\FormFilterBundle\Filter\FilterOperands;
 use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\NumberRangeFilterType;
 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\DateRangeFilterType;
@@ -33,7 +34,7 @@ class EntryFilterType extends AbstractType
         $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
 
         if (null === $this->user || !is_object($this->user)) {
-            return null;
+            return;
         }
     }
 
@@ -41,6 +42,14 @@ class EntryFilterType extends AbstractType
     {
         $builder
             ->add('readingTime', NumberRangeFilterType::class, [
+                'left_number_options' => [
+                    'condition_operator' => FilterOperands::OPERATOR_GREATER_THAN_EQUAL,
+                    'attr' => ['min' => 0],
+                ],
+                'right_number_options' => [
+                    'condition_operator' => FilterOperands::OPERATOR_LOWER_THAN_EQUAL,
+                    'attr' => ['min' => 0],
+                ],
                 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                     $lower = $values['value']['left_number'][0];
                     $upper = $values['value']['right_number'][0];
index db193e8199efee2a66452095ce748c7d802ed7fe..f82e5dc5262ba1eb2383ee931fa2b7580372602b 100644 (file)
                             <tr><td>hoa/zformat</td><td>BSD-3-Clause</td></tr>
                             <tr><td>htmlawed/htmlawed</td><td>GPL-2.0+ or LGPL-3.0</td></tr>
                             <tr><td>incenteev/composer-parameter-handler</td><td>MIT</td></tr>
-                            <tr><td>j0k3r/graby</td><td>AGPL-3.0</td></tr>
-                            <tr><td>j0k3r/graby-site-config</td><td>AGPL-3.0</td></tr>
+                            <tr><td>j0k3r/graby</td><td>MIT</td></tr>
+                            <tr><td>j0k3r/graby-site-config</td><td>Public domain</td></tr>
                             <tr><td>j0k3r/php-readability</td><td>Apache-2.0</td></tr>
                             <tr><td>j0k3r/safecurl</td><td>MIT</td></tr>
                             <tr><td>jdorn/sql-formatter</td><td>MIT</td></tr>
index deafd1fab70513dfad35c06a2ca8819897431646..0a65f9cee0628a78a38ab6b2fd7ce259c1383371 100644 (file)
@@ -157,6 +157,22 @@ class EntryRestControllerTest extends WallabagApiTestCase
         $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
     }
 
+    public function testGetEntriesOnPageTwo()
+    {
+        $this->client->request('GET', '/api/entries', [
+            'page' => 2,
+            'perPage' => 2,
+        ]);
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertGreaterThanOrEqual(0, $content['total']);
+        $this->assertEquals(2, $content['page']);
+        $this->assertEquals(2, $content['limit']);
+    }
+
     public function testGetStarredEntries()
     {
         $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
index 3eb6d47fb9feb875dd45053801f100515beabf7a..7db4cf1ff46aef5e7efa84bba45f32211a3c387e 100644 (file)
@@ -591,6 +591,26 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertCount(1, $crawler->filter('div[class=entry]'));
     }
 
+    public function testFilterOnReadingTimeWithNegativeValue()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/unread/list');
+
+        $form = $crawler->filter('button[id=submit-filter]')->form();
+
+        $data = [
+            'entry_filter[readingTime][right_number]' => -22,
+            'entry_filter[readingTime][left_number]' => -22,
+        ];
+
+        $crawler = $client->submit($form, $data);
+
+        // forcing negative value results in no entry displayed
+        $this->assertCount(0, $crawler->filter('div[class=entry]'));
+    }
+
     public function testFilterOnReadingTimeOnlyUpper()
     {
         $this->logInAs('admin');