diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-05-24 16:44:03 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-05-31 14:00:15 +0200 |
commit | f0378b4d7c7b8c971239445f3a2a1535abab7d00 (patch) | |
tree | 2f8157ce6b50e454887827825ef8ebbc01dfdf70 /tests | |
parent | 9e349f08a651c43c6d5dd890303ed529c38c4fde (diff) | |
download | wallabag-f0378b4d7c7b8c971239445f3a2a1535abab7d00.tar.gz wallabag-f0378b4d7c7b8c971239445f3a2a1535abab7d00.tar.zst wallabag-f0378b4d7c7b8c971239445f3a2a1535abab7d00.zip |
Forced date can now be a timestamp too
Add adding more tests for forced content
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 11f1d410..103acf50 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -9,6 +9,8 @@ use Wallabag\CoreBundle\Entity\Tag; | |||
9 | use Wallabag\UserBundle\Entity\User; | 9 | use Wallabag\UserBundle\Entity\User; |
10 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; | 10 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; |
11 | use Graby\Graby; | 11 | use Graby\Graby; |
12 | use Monolog\Handler\TestHandler; | ||
13 | use Monolog\Logger; | ||
12 | 14 | ||
13 | class ContentProxyTest extends \PHPUnit_Framework_TestCase | 15 | class ContentProxyTest extends \PHPUnit_Framework_TestCase |
14 | { | 16 | { |
@@ -220,6 +222,11 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
220 | 'url' => 'http://1.1.1.1', | 222 | 'url' => 'http://1.1.1.1', |
221 | 'content_type' => 'text/html', | 223 | 'content_type' => 'text/html', |
222 | 'language' => 'fr', | 224 | 'language' => 'fr', |
225 | 'date' => '1395635872', | ||
226 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], | ||
227 | 'all_headers' => [ | ||
228 | 'Cache-Control' => 'no-cache', | ||
229 | ] | ||
223 | ] | 230 | ] |
224 | ); | 231 | ); |
225 | 232 | ||
@@ -230,6 +237,80 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
230 | $this->assertEquals('fr', $entry->getLanguage()); | 237 | $this->assertEquals('fr', $entry->getLanguage()); |
231 | $this->assertEquals(4.0, $entry->getReadingTime()); | 238 | $this->assertEquals(4.0, $entry->getReadingTime()); |
232 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | 239 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); |
240 | $this->assertEquals('24/03/2014', $entry->getPublishedAt()->format('d/m/Y')); | ||
241 | $this->assertContains('Jeremy', $entry->getPublishedBy()); | ||
242 | $this->assertContains('Nico', $entry->getPublishedBy()); | ||
243 | $this->assertContains('Thomas', $entry->getPublishedBy()); | ||
244 | $this->assertContains('no-cache', $entry->getHeaders()); | ||
245 | } | ||
246 | |||
247 | public function testWithForcedContentAndDatetime() | ||
248 | { | ||
249 | $tagger = $this->getTaggerMock(); | ||
250 | $tagger->expects($this->once()) | ||
251 | ->method('tag'); | ||
252 | |||
253 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | ||
254 | $entry = $proxy->updateEntry( | ||
255 | new Entry(new User()), | ||
256 | 'http://0.0.0.0', | ||
257 | [ | ||
258 | 'html' => str_repeat('this is my content', 325), | ||
259 | 'title' => 'this is my title', | ||
260 | 'url' => 'http://1.1.1.1', | ||
261 | 'content_type' => 'text/html', | ||
262 | 'language' => 'fr', | ||
263 | 'date' => '2016-09-08T11:55:58+0200', | ||
264 | ] | ||
265 | ); | ||
266 | |||
267 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | ||
268 | $this->assertEquals('this is my title', $entry->getTitle()); | ||
269 | $this->assertContains('this is my content', $entry->getContent()); | ||
270 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
271 | $this->assertEquals('fr', $entry->getLanguage()); | ||
272 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
273 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
274 | $this->assertEquals('08/09/2016', $entry->getPublishedAt()->format('d/m/Y')); | ||
275 | } | ||
276 | |||
277 | public function testWithForcedContentAndBadDate() | ||
278 | { | ||
279 | $tagger = $this->getTaggerMock(); | ||
280 | $tagger->expects($this->once()) | ||
281 | ->method('tag'); | ||
282 | |||
283 | $logger = new Logger('foo'); | ||
284 | $handler = new TestHandler(); | ||
285 | $logger->pushHandler($handler); | ||
286 | |||
287 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getTagRepositoryMock(), $logger, $this->fetchingErrorMessage); | ||
288 | $entry = $proxy->updateEntry( | ||
289 | new Entry(new User()), | ||
290 | 'http://0.0.0.0', | ||
291 | [ | ||
292 | 'html' => str_repeat('this is my content', 325), | ||
293 | 'title' => 'this is my title', | ||
294 | 'url' => 'http://1.1.1.1', | ||
295 | 'content_type' => 'text/html', | ||
296 | 'language' => 'fr', | ||
297 | 'date' => '01 02 2012', | ||
298 | ] | ||
299 | ); | ||
300 | |||
301 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | ||
302 | $this->assertEquals('this is my title', $entry->getTitle()); | ||
303 | $this->assertContains('this is my content', $entry->getContent()); | ||
304 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
305 | $this->assertEquals('fr', $entry->getLanguage()); | ||
306 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
307 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
308 | $this->assertNull($entry->getPublishedAt()); | ||
309 | |||
310 | $records = $handler->getRecords(); | ||
311 | |||
312 | $this->assertCount(1, $records); | ||
313 | $this->assertContains('Error while defining date', $records[0]['message']); | ||
233 | } | 314 | } |
234 | 315 | ||
235 | public function testTaggerThrowException() | 316 | public function testTaggerThrowException() |