3 namespace Tests\Wallabag\ImportBundle\Consumer\AMQP
;
5 use Wallabag\ImportBundle\Consumer\RedisEntryConsumer
;
6 use Wallabag\UserBundle\Entity\User
;
7 use Wallabag\CoreBundle\Entity\Entry
;
9 class RedisEntryConsumerTest
extends \PHPUnit_Framework_TestCase
11 public function testMessageOk()
13 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
14 ->disableOriginalConstructor()
18 ->expects($this->once())
22 ->expects($this->exactly(2))
27 "item_id": "1402935436",
28 "resolved_id": "1402935436",
29 "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial",
30 "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules",
33 "time_added": "1473020899",
34 "time_updated": "1473020899",
36 "time_favorited": "0",
38 "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules",
39 "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial",
40 "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...",
48 "item_id": "1402935436",
52 "item_id": "1402935436",
58 "item_id": "1402935436",
59 "author_id": "2484273",
60 "name": "Adam Rosenberg",
61 "url": "http://mashable.com/author/adam-rosenberg/"
65 "item_id": "1402935436",
66 "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg",
72 "item_id": "1402935436",
74 "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg",
77 "credit": "Image: Steve Eichner/NameFace/Sipa USA",
86 $entry = new Entry($user);
88 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
89 ->disableOriginalConstructor()
93 ->expects($this->once())
95 // userId from the body json above
99 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
100 ->disableOriginalConstructor()
104 ->expects($this->once())
109 ->expects($this->once())
110 ->method('parseEntry')
111 ->with(json_decode($body, true))
112 ->willReturn($entry);
114 $consumer = new RedisEntryConsumer(
120 $res = $consumer->manage($body);
122 $this->assertTrue($res);
125 public function testMessageWithBadUser()
127 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
128 ->disableOriginalConstructor()
132 ->expects($this->never())
136 ->expects($this->never())
139 $body = '{ "userId": 123 }';
142 $entry = new Entry($user);
144 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
145 ->disableOriginalConstructor()
149 ->expects($this->once())
151 // userId from the body json above
155 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
156 ->disableOriginalConstructor()
159 $consumer = new RedisEntryConsumer(
165 $res = $consumer->manage($body);
167 $this->assertFalse($res);
170 public function testMessageWithEntryProcessed()
172 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
173 ->disableOriginalConstructor()
177 ->expects($this->never())
181 ->expects($this->never())
184 $body = '{ "userId": 123 }';
188 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
189 ->disableOriginalConstructor()
193 ->expects($this->once())
195 // userId from the body json above
199 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
200 ->disableOriginalConstructor()
204 ->expects($this->once())
209 ->expects($this->once())
210 ->method('parseEntry')
211 ->with(json_decode($body, true))
214 $consumer = new RedisEntryConsumer(
220 $res = $consumer->manage($body);
222 $this->assertFalse($res);
223 $this->assertFalse($consumer->isStopJob($body));