aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-05-19 07:39:30 +0200
committerJeremy Benoist <j0k3r@users.noreply.github.com>2016-05-19 07:39:30 +0200
commite7658cb00993fc24bddef26b6373197bd4503c99 (patch)
tree4885fba147b8835fd51e0dc65596dd56ee150322 /src
parentd30ec39008945cdbb98bf5db10640f2fe60d91db (diff)
parentbba271e619eabbd525d38d125e4b77f838cadba5 (diff)
downloadwallabag-e7658cb00993fc24bddef26b6373197bd4503c99.tar.gz
wallabag-e7658cb00993fc24bddef26b6373197bd4503c99.tar.zst
wallabag-e7658cb00993fc24bddef26b6373197bd4503c99.zip
Merge pull request #2092 from Rurik19/issue2089
Starred and Archived clears if article is already exists
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php8
-rw-r--r--src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php88
2 files changed, 92 insertions, 4 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 5202c524..af24e498 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -110,8 +110,8 @@ class WallabagRestController extends FOSRestController
110 110
111 $url = $request->request->get('url'); 111 $url = $request->request->get('url');
112 $title = $request->request->get('title'); 112 $title = $request->request->get('title');
113 $isArchived = (int) $request->request->get('archive'); 113 $isArchived = $request->request->get('archive');
114 $isStarred = (int) $request->request->get('starred'); 114 $isStarred = $request->request->get('starred');
115 115
116 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); 116 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId());
117 117
@@ -172,8 +172,8 @@ class WallabagRestController extends FOSRestController
172 $this->validateUserAccess($entry->getUser()->getId()); 172 $this->validateUserAccess($entry->getUser()->getId());
173 173
174 $title = $request->request->get('title'); 174 $title = $request->request->get('title');
175 $isArchived = (int) $request->request->get('archive'); 175 $isArchived = $request->request->get('archive');
176 $isStarred = (int) $request->request->get('starred'); 176 $isStarred = $request->request->get('starred');
177 177
178 if (!is_null($title)) { 178 if (!is_null($title)) {
179 $entry->setTitle($title); 179 $entry->setTitle($title);
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
index 2f2d92ee..4c787277 100644
--- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
+++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
@@ -423,4 +423,92 @@ class WallabagRestControllerTest extends WallabagApiTestCase
423 423
424 $this->assertEquals($this->client->getContainer()->getParameter('wallabag_core.version'), $content); 424 $this->assertEquals($this->client->getContainer()->getParameter('wallabag_core.version'), $content);
425 } 425 }
426
427 public function testSaveIsArchivedAfterPost()
428 {
429 $entry = $this->client->getContainer()
430 ->get('doctrine.orm.entity_manager')
431 ->getRepository('WallabagCoreBundle:Entry')
432 ->findOneBy(['user' => 1, 'isArchived' => true]);
433
434 if (!$entry) {
435 $this->markTestSkipped('No content found in db.');
436 }
437
438 $this->client->request('POST', '/api/entries.json', [
439 'url' => $entry->getUrl(),
440 ]);
441
442 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
443
444 $content = json_decode($this->client->getResponse()->getContent(), true);
445
446 $this->assertEquals(true, $content['is_archived']);
447 }
448
449 public function testSaveIsStarredAfterPost()
450 {
451 $entry = $this->client->getContainer()
452 ->get('doctrine.orm.entity_manager')
453 ->getRepository('WallabagCoreBundle:Entry')
454 ->findOneBy(['user' => 1, 'isStarred' => true]);
455
456 if (!$entry) {
457 $this->markTestSkipped('No content found in db.');
458 }
459
460 $this->client->request('POST', '/api/entries.json', [
461 'url' => $entry->getUrl(),
462 ]);
463
464 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
465
466 $content = json_decode($this->client->getResponse()->getContent(), true);
467
468 $this->assertEquals(true, $content['is_starred']);
469 }
470
471 public function testSaveIsArchivedAfterPatch()
472 {
473 $entry = $this->client->getContainer()
474 ->get('doctrine.orm.entity_manager')
475 ->getRepository('WallabagCoreBundle:Entry')
476 ->findOneBy(['user' => 1, 'isArchived' => true]);
477
478 if (!$entry) {
479 $this->markTestSkipped('No content found in db.');
480 }
481
482 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
483 'title' => $entry->getTitle().'++',
484 ]);
485
486 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
487
488 $content = json_decode($this->client->getResponse()->getContent(), true);
489
490 $this->assertEquals(true, $content['is_archived']);
491 }
492
493 public function testSaveIsStarredAfterPatch()
494 {
495 $entry = $this->client->getContainer()
496 ->get('doctrine.orm.entity_manager')
497 ->getRepository('WallabagCoreBundle:Entry')
498 ->findOneBy(['user' => 1, 'isStarred' => true]);
499
500 if (!$entry) {
501 $this->markTestSkipped('No content found in db.');
502 }
503 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
504 'title' => $entry->getTitle().'++',
505 ]);
506
507 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
508
509 $content = json_decode($this->client->getResponse()->getContent(), true);
510
511 $this->assertEquals(true, $content['is_starred']);
512 }
513
426} 514}