3 namespace Tests\Wallabag\ImportBundle\Consumer\AMQP
;
5 use Wallabag\CoreBundle\Entity\Entry
;
6 use Wallabag\ImportBundle\Consumer\RedisEntryConsumer
;
7 use Wallabag\UserBundle\Entity\User
;
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 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
115 ->disableOriginalConstructor()
119 ->expects($this->once())
120 ->method('dispatch');
122 $consumer = new RedisEntryConsumer(
129 $res = $consumer->manage($body);
131 $this->assertTrue($res);
134 public function testMessageWithBadUser()
136 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
137 ->disableOriginalConstructor()
141 ->expects($this->never())
145 ->expects($this->never())
148 $body = '{ "userId": 123 }';
151 $entry = new Entry($user);
153 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
154 ->disableOriginalConstructor()
158 ->expects($this->once())
160 // userId from the body json above
164 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
165 ->disableOriginalConstructor()
168 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
169 ->disableOriginalConstructor()
173 ->expects($this->never())
174 ->method('dispatch');
176 $consumer = new RedisEntryConsumer(
183 $res = $consumer->manage($body);
185 $this->assertTrue($res);
188 public function testMessageWithEntryProcessed()
190 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
191 ->disableOriginalConstructor()
195 ->expects($this->never())
199 ->expects($this->never())
202 $body = '{ "userId": 123 }';
206 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
207 ->disableOriginalConstructor()
211 ->expects($this->once())
213 // userId from the body json above
217 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
218 ->disableOriginalConstructor()
222 ->expects($this->once())
227 ->expects($this->once())
228 ->method('parseEntry')
229 ->with(json_decode($body, true))
232 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
233 ->disableOriginalConstructor()
237 ->expects($this->never())
238 ->method('dispatch');
240 $consumer = new RedisEntryConsumer(
247 $res = $consumer->manage($body);
249 $this->assertTrue($res);
250 $this->assertFalse($consumer->isStopJob($body));