aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php265
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php60
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php)4
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php)4
-rw-r--r--tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php (renamed from tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php)4
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php143
-rw-r--r--tests/Wallabag/CoreBundle/fixtures/unnamed.pngbin0 -> 3688 bytes
7 files changed, 474 insertions, 6 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 1954c654..8d0644d1 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -3,6 +3,11 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\UserBundle\Entity\User;
8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\AnnotationBundle\Entity\Annotation;
6 11
7class ConfigControllerTest extends WallabagCoreTestCase 12class ConfigControllerTest extends WallabagCoreTestCase
8{ 13{
@@ -570,4 +575,264 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 575 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 576 $config->set('demo_mode_username', 'wallabag');
572 } 577 }
578
579 public function testDeleteUserButtonVisibility()
580 {
581 $this->logInAs('admin');
582 $client = $this->getClient();
583
584 $crawler = $client->request('GET', '/config');
585
586 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
587 $this->assertContains('config.form_user.delete.button', $body[0]);
588
589 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
590
591 $user = $em
592 ->getRepository('WallabagUserBundle:User')
593 ->findOneByUsername('empty');
594 $user->setExpired(1);
595 $em->persist($user);
596
597 $user = $em
598 ->getRepository('WallabagUserBundle:User')
599 ->findOneByUsername('bob');
600 $user->setExpired(1);
601 $em->persist($user);
602
603 $em->flush();
604
605 $crawler = $client->request('GET', '/config');
606
607 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
608 $this->assertNotContains('config.form_user.delete.button', $body[0]);
609
610 $client->request('GET', '/account/delete');
611 $this->assertEquals(403, $client->getResponse()->getStatusCode());
612
613 $user = $em
614 ->getRepository('WallabagUserBundle:User')
615 ->findOneByUsername('empty');
616 $user->setExpired(0);
617 $em->persist($user);
618
619 $user = $em
620 ->getRepository('WallabagUserBundle:User')
621 ->findOneByUsername('bob');
622 $user->setExpired(0);
623 $em->persist($user);
624
625 $em->flush();
626 }
627
628 public function testDeleteAccount()
629 {
630 $client = $this->getClient();
631 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
632
633 $user = new User();
634 $user->setName('Wallace');
635 $user->setEmail('wallace@wallabag.org');
636 $user->setUsername('wallace');
637 $user->setPlainPassword('wallace');
638 $user->setEnabled(true);
639 $user->addRole('ROLE_SUPER_ADMIN');
640
641 $em->persist($user);
642
643 $config = new Config($user);
644
645 $config->setTheme('material');
646 $config->setItemsPerPage(30);
647 $config->setReadingSpeed(1);
648 $config->setLanguage('en');
649 $config->setPocketConsumerKey('xxxxx');
650
651 $em->persist($config);
652 $em->flush();
653
654 $this->logInAs('wallace');
655 $loggedInUserId = $this->getLoggedInUserId();
656
657 // create entry to check after user deletion
658 // that this entry is also deleted
659 $crawler = $client->request('GET', '/new');
660
661 $this->assertEquals(200, $client->getResponse()->getStatusCode());
662
663 $form = $crawler->filter('form[name=entry]')->form();
664 $data = [
665 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
666 ];
667
668 $client->submit($form, $data);
669 $this->assertEquals(302, $client->getResponse()->getStatusCode());
670
671 $crawler = $client->request('GET', '/config');
672
673 $deleteLink = $crawler->filter('.delete-account')->last()->link();
674
675 $client->click($deleteLink);
676 $this->assertEquals(302, $client->getResponse()->getStatusCode());
677
678 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
679 $user = $em
680 ->getRepository('WallabagUserBundle:User')
681 ->createQueryBuilder('u')
682 ->where('u.username = :username')->setParameter('username', 'wallace')
683 ->getQuery()
684 ->getOneOrNullResult()
685 ;
686
687 $this->assertNull($user);
688
689 $entries = $client->getContainer()
690 ->get('doctrine.orm.entity_manager')
691 ->getRepository('WallabagCoreBundle:Entry')
692 ->findByUser($loggedInUserId);
693
694 $this->assertEmpty($entries);
695 }
696
697 public function testReset()
698 {
699 $this->logInAs('empty');
700 $client = $this->getClient();
701
702 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
703
704 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
705
706 $tag = new Tag();
707 $tag->setLabel('super');
708 $em->persist($tag);
709
710 $entry = new Entry($user);
711 $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
712 $entry->setContent('Youhou');
713 $entry->setTitle('Youhou');
714 $entry->addTag($tag);
715 $em->persist($entry);
716
717 $entry2 = new Entry($user);
718 $entry2->setUrl('http://www.lemonde.de/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
719 $entry2->setContent('Youhou');
720 $entry2->setTitle('Youhou');
721 $entry2->addTag($tag);
722 $em->persist($entry2);
723
724 $annotation = new Annotation($user);
725 $annotation->setText('annotated');
726 $annotation->setQuote('annotated');
727 $annotation->setRanges([]);
728 $annotation->setEntry($entry);
729 $em->persist($annotation);
730
731 $em->flush();
732
733 // reset annotations
734 $crawler = $client->request('GET', '/config#set3');
735
736 $this->assertEquals(200, $client->getResponse()->getStatusCode());
737
738 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
739
740 $this->assertEquals(302, $client->getResponse()->getStatusCode());
741 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
742
743 $annotationsReset = $em
744 ->getRepository('WallabagAnnotationBundle:Annotation')
745 ->findAnnotationsByPageId($entry->getId(), $user->getId());
746
747 $this->assertEmpty($annotationsReset, 'Annotations were reset');
748
749 // reset tags
750 $crawler = $client->request('GET', '/config#set3');
751
752 $this->assertEquals(200, $client->getResponse()->getStatusCode());
753
754 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
755
756 $this->assertEquals(302, $client->getResponse()->getStatusCode());
757 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
758
759 $tagReset = $em
760 ->getRepository('WallabagCoreBundle:Tag')
761 ->countAllTags($user->getId());
762
763 $this->assertEquals(0, $tagReset, 'Tags were reset');
764
765 // reset entries
766 $crawler = $client->request('GET', '/config#set3');
767
768 $this->assertEquals(200, $client->getResponse()->getStatusCode());
769
770 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
771
772 $this->assertEquals(302, $client->getResponse()->getStatusCode());
773 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
774
775 $entryReset = $em
776 ->getRepository('WallabagCoreBundle:Entry')
777 ->countAllEntriesByUsername($user->getId());
778
779 $this->assertEquals(0, $entryReset, 'Entries were reset');
780 }
781
782 public function testResetEntriesCascade()
783 {
784 $this->logInAs('empty');
785 $client = $this->getClient();
786
787 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
788
789 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
790
791 $tag = new Tag();
792 $tag->setLabel('super');
793 $em->persist($tag);
794
795 $entry = new Entry($user);
796 $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
797 $entry->setContent('Youhou');
798 $entry->setTitle('Youhou');
799 $entry->addTag($tag);
800 $em->persist($entry);
801
802 $annotation = new Annotation($user);
803 $annotation->setText('annotated');
804 $annotation->setQuote('annotated');
805 $annotation->setRanges([]);
806 $annotation->setEntry($entry);
807 $em->persist($annotation);
808
809 $em->flush();
810
811 $crawler = $client->request('GET', '/config#set3');
812
813 $this->assertEquals(200, $client->getResponse()->getStatusCode());
814
815 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
816
817 $this->assertEquals(302, $client->getResponse()->getStatusCode());
818 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
819
820 $entryReset = $em
821 ->getRepository('WallabagCoreBundle:Entry')
822 ->countAllEntriesByUsername($user->getId());
823
824 $this->assertEquals(0, $entryReset, 'Entries were reset');
825
826 $tagReset = $em
827 ->getRepository('WallabagCoreBundle:Tag')
828 ->countAllTags($user->getId());
829
830 $this->assertEquals(0, $tagReset, 'Tags were reset');
831
832 $annotationsReset = $em
833 ->getRepository('WallabagAnnotationBundle:Annotation')
834 ->findAnnotationsByPageId($entry->getId(), $user->getId());
835
836 $this->assertEmpty($annotationsReset, 'Annotations were reset');
837 }
573} 838}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 05113650..4ab06dbf 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -836,4 +836,64 @@ class EntryControllerTest extends WallabagCoreTestCase
836 $client->request('GET', '/share/'.$content->getUuid()); 836 $client->request('GET', '/share/'.$content->getUuid());
837 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 837 $this->assertEquals(404, $client->getResponse()->getStatusCode());
838 } 838 }
839
840 public function testNewEntryWithDownloadImagesEnabled()
841 {
842 $this->logInAs('admin');
843 $client = $this->getClient();
844
845 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
846 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
847
848 $crawler = $client->request('GET', '/new');
849
850 $this->assertEquals(200, $client->getResponse()->getStatusCode());
851
852 $form = $crawler->filter('form[name=entry]')->form();
853
854 $data = [
855 'entry[url]' => $url,
856 ];
857
858 $client->submit($form, $data);
859
860 $this->assertEquals(302, $client->getResponse()->getStatusCode());
861
862 $em = $client->getContainer()
863 ->get('doctrine.orm.entity_manager');
864
865 $entry = $em
866 ->getRepository('WallabagCoreBundle:Entry')
867 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
868
869 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
870 $this->assertEquals($url, $entry->getUrl());
871 $this->assertContains('Perpignan', $entry->getTitle());
872 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
873
874 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
875 }
876
877 /**
878 * @depends testNewEntryWithDownloadImagesEnabled
879 */
880 public function testRemoveEntryWithDownloadImagesEnabled()
881 {
882 $this->logInAs('admin');
883 $client = $this->getClient();
884
885 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
886 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
887
888 $content = $client->getContainer()
889 ->get('doctrine.orm.entity_manager')
890 ->getRepository('WallabagCoreBundle:Entry')
891 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
892
893 $client->request('GET', '/delete/'.$content->getId());
894
895 $this->assertEquals(302, $client->getResponse()->getStatusCode());
896
897 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
898 }
839} 899}
diff --git a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
index 078bb69a..84a54d3a 100644
--- a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\EventListener; 3namespace Tests\Wallabag\CoreBundle\Event\Listener;
4 4
5use Symfony\Component\EventDispatcher\EventDispatcher; 5use Symfony\Component\EventDispatcher\EventDispatcher;
6use Symfony\Component\HttpFoundation\Request; 6use Symfony\Component\HttpFoundation\Request;
@@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
9use Symfony\Component\HttpKernel\Event\GetResponseEvent; 9use Symfony\Component\HttpKernel\Event\GetResponseEvent;
10use Symfony\Component\HttpKernel\HttpKernelInterface; 10use Symfony\Component\HttpKernel\HttpKernelInterface;
11use Symfony\Component\HttpKernel\KernelEvents; 11use Symfony\Component\HttpKernel\KernelEvents;
12use Wallabag\CoreBundle\EventListener\LocaleListener; 12use Wallabag\CoreBundle\Event\Listener\LocaleListener;
13 13
14class LocaleListenerTest extends \PHPUnit_Framework_TestCase 14class LocaleListenerTest extends \PHPUnit_Framework_TestCase
15{ 15{
diff --git a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
index e9ac7c1d..45aecc63 100644
--- a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\EventListener; 3namespace Tests\Wallabag\CoreBundle\Event\Listener;
4 4
5use Symfony\Component\HttpFoundation\Request; 5use Symfony\Component\HttpFoundation\Request;
6use Symfony\Component\HttpFoundation\Session\Session; 6use Symfony\Component\HttpFoundation\Session\Session;
@@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
8use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; 8use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
9use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 9use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
10use Wallabag\CoreBundle\Entity\Config; 10use Wallabag\CoreBundle\Entity\Config;
11use Wallabag\CoreBundle\EventListener\UserLocaleListener; 11use Wallabag\CoreBundle\Event\Listener\UserLocaleListener;
12use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
13 13
14class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase 14class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase
diff --git a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php
index 4ae76703..b8cd0fad 100644
--- a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php
@@ -1,11 +1,11 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\Subscriber; 3namespace Tests\Wallabag\CoreBundle\Event\Subscriber;
4 4
5use Doctrine\Common\EventManager; 5use Doctrine\Common\EventManager;
6use Doctrine\ORM\Event\LoadClassMetadataEventArgs; 6use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
7use Doctrine\ORM\Mapping\ClassMetadata; 7use Doctrine\ORM\Mapping\ClassMetadata;
8use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber; 8use Wallabag\CoreBundle\Event\Subscriber\TablePrefixSubscriber;
9 9
10class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase 10class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase
11{ 11{
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
new file mode 100644
index 00000000..920c21d9
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
@@ -0,0 +1,143 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Helper;
4
5use Wallabag\CoreBundle\Helper\DownloadImages;
6use Psr\Log\NullLogger;
7use Monolog\Logger;
8use Monolog\Handler\TestHandler;
9use GuzzleHttp\Client;
10use GuzzleHttp\Subscriber\Mock;
11use GuzzleHttp\Message\Response;
12use GuzzleHttp\Stream\Stream;
13
14class DownloadImagesTest extends \PHPUnit_Framework_TestCase
15{
16 public function testProcessHtml()
17 {
18 $client = new Client();
19
20 $mock = new Mock([
21 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
22 ]);
23
24 $client->getEmitter()->attach($mock);
25
26 $logHandler = new TestHandler();
27 $logger = new Logger('test', array($logHandler));
28
29 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
30
31 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY');
32
33 $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res);
34 }
35
36 public function testProcessHtmlWithBadImage()
37 {
38 $client = new Client();
39
40 $mock = new Mock([
41 new Response(200, ['content-type' => 'application/json'], Stream::factory('')),
42 ]);
43
44 $client->getEmitter()->attach($mock);
45
46 $logHandler = new TestHandler();
47 $logger = new Logger('test', array($logHandler));
48
49 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
50 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY');
51
52 $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type');
53 }
54
55 public function singleImage()
56 {
57 return [
58 ['image/pjpeg', 'jpeg'],
59 ['image/jpeg', 'jpeg'],
60 ['image/png', 'png'],
61 ['image/gif', 'gif'],
62 ];
63 }
64
65 /**
66 * @dataProvider singleImage
67 */
68 public function testProcessSingleImage($header, $extension)
69 {
70 $client = new Client();
71
72 $mock = new Mock([
73 new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
74 ]);
75
76 $client->getEmitter()->attach($mock);
77
78 $logHandler = new TestHandler();
79 $logger = new Logger('test', array($logHandler));
80
81 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
82 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
83
84 $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.'.$extension, $res);
85 }
86
87 public function testProcessSingleImageWithBadUrl()
88 {
89 $client = new Client();
90
91 $mock = new Mock([
92 new Response(404, []),
93 ]);
94
95 $client->getEmitter()->attach($mock);
96
97 $logHandler = new TestHandler();
98 $logger = new Logger('test', array($logHandler));
99
100 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
101 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
102
103 $this->assertFalse($res, 'Image can not be found, so it will not be replaced');
104 }
105
106 public function testProcessSingleImageWithBadImage()
107 {
108 $client = new Client();
109
110 $mock = new Mock([
111 new Response(200, ['content-type' => 'image/png'], Stream::factory('')),
112 ]);
113
114 $client->getEmitter()->attach($mock);
115
116 $logHandler = new TestHandler();
117 $logger = new Logger('test', array($logHandler));
118
119 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
120 $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
121
122 $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced');
123 }
124
125 public function testProcessSingleImageFailAbsolute()
126 {
127 $client = new Client();
128
129 $mock = new Mock([
130 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
131 ]);
132
133 $client->getEmitter()->attach($mock);
134
135 $logHandler = new TestHandler();
136 $logger = new Logger('test', array($logHandler));
137
138 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
139 $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY');
140
141 $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced');
142 }
143}
diff --git a/tests/Wallabag/CoreBundle/fixtures/unnamed.png b/tests/Wallabag/CoreBundle/fixtures/unnamed.png
new file mode 100644
index 00000000..e6dd9caa
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/fixtures/unnamed.png
Binary files differ