diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index c9dad0df7..2d73a9add 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -83,7 +83,8 @@ class InstallCommand extends ContainerAwareCommand
$help = 'Needs one of sqlite, mysql or pgsql PDO drivers';
}
- $rows[] = array($label, $status, $help);
+ $rows = [];
+ $rows[] = [$label, $status, $help];
foreach ($this->functionExists as $functionRequired) {
$label = '
Unable to retrieve readable content.
', $entry->getContent()); + $this->assertEmpty($entry->getPreviewPicture()); + $this->assertEmpty($entry->getMimetype()); + $this->assertEmpty($entry->getLanguage()); + $this->assertEquals(0.0, $entry->getReadingTime()); + $this->assertEquals(false, $entry->getDomainName()); + } + public function testWithEmptyContent() { $tagger = $this->getTaggerMock(); @@ -121,6 +155,57 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('1.1.1.1', $entry->getDomainName()); } + public function testWithForcedContent() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $graby = $this->getMockBuilder('Graby\Graby')->getMock(); + + $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); + $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + ]); + + $this->assertEquals('http://1.1.1.1', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertContains('this is my content', $entry->getContent()); + $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertEquals('fr', $entry->getLanguage()); + $this->assertEquals(4.0, $entry->getReadingTime()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + } + + public function testTaggerThrowException() + { + $graby = $this->getMockBuilder('Graby\Graby') + ->disableOriginalConstructor() + ->getMock(); + + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag') + ->will($this->throwException(new \Exception())); + + $tagRepo = $this->getTagRepositoryMock(); + $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger()); + + $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + ]); + + $this->assertCount(0, $entry->getTags()); + } + public function testAssignTagsWithArrayAndExtraSpaces() { $graby = $this->getMockBuilder('Graby\Graby') diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index 1d8042192..11ce649d6 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php @@ -38,6 +38,15 @@ class PocketController extends Controller $requestToken = $this->get('wallabag_import.pocket.import') ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface::ABSOLUTE_URL)); + if (false === $requestToken) { + $this->get('session')->getFlashBag()->add( + 'notice', + 'flashes.import.notice.failed' + ); + + return $this->redirect($this->generateUrl('import_pocket')); + } + $this->get('session')->set('import.pocket.code', $requestToken); $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']); diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 4499ce699..f598e6112 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -68,7 +68,7 @@ class PocketImport implements ImportInterface * * @param string $redirectUri Redirect url in case of error * - * @return string request_token for callback method + * @return string|false request_token for callback method */ public function getRequestToken($redirectUri) { diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 173a587f1..82160bae1 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -7,7 +7,6 @@ use Psr\Log\NullLogger; use Doctrine\ORM\EntityManager; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Tools\Utils; use Wallabag\CoreBundle\Helper\ContentProxy; class WallabagV1Import implements ImportInterface @@ -153,19 +152,25 @@ class WallabagV1Import implements ImportInterface continue; } - // @see ContentProxy->updateEntry - $entry = new Entry($this->user); - $entry->setUrl($importedEntry['url']); + $data = [ + 'title' => $importedEntry['title'], + 'html' => $importedEntry['content'], + 'url' => $importedEntry['url'], + 'content_type' => '', + 'language' => '', + ]; + // force content to be refreshed in case on bad fetch in the v1 installation if (in_array($importedEntry['title'], $untitled)) { - $entry = $this->contentProxy->updateEntry($entry, $importedEntry['url']); - } else { - $entry->setContent($importedEntry['content']); - $entry->setTitle($importedEntry['title']); - $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); - $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); + $data = []; } + $entry = $this->contentProxy->updateEntry( + new Entry($this->user), + $importedEntry['url'], + $data + ); + if (array_key_exists('tags', $importedEntry) && $importedEntry['tags'] != '') { $this->contentProxy->assignTagsToEntry( $entry, diff --git a/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php index 174641fd5..403fe9b0d 100644 --- a/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php +++ b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php @@ -17,13 +17,36 @@ class PocketControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); } - public function testImportPocketAuth() + public function testImportPocketAuthBadToken() { $this->logInAs('admin'); $client = $this->getClient(); $crawler = $client->request('GET', '/import/pocket/auth'); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + } + + public function testImportPocketAuth() + { + $this->markTestSkipped('PocketImport: Find a way to properly mock a service.'); + + $this->logInAs('admin'); + $client = $this->getClient(); + + $pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport') + ->disableOriginalConstructor() + ->getMock(); + + $pocketImport + ->expects($this->once()) + ->method('getRequestToken') + ->willReturn('token'); + + $client->getContainer()->set('wallabag_import.pocket.import', $pocketImport); + + $crawler = $client->request('GET', '/import/pocket/auth'); + $this->assertEquals(301, $client->getResponse()->getStatusCode()); $this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location')); } diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php index 496cf2d37..540eb7da2 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php @@ -3,6 +3,7 @@ namespace Wallabag\ImportBundle\Tests\Import; use Wallabag\UserBundle\Entity\User; +use Wallabag\CoreBundle\Entity\Entry; use Wallabag\ImportBundle\Import\WallabagV1Import; use Monolog\Logger; use Monolog\Handler\TestHandler; @@ -71,7 +72,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->once()) + ->expects($this->exactly(3)) ->method('updateEntry') ->willReturn($entry); @@ -99,6 +100,11 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->method('getRepository') ->willReturn($entryRepo); + $this->contentProxy + ->expects($this->exactly(3)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + // check that every entry persisted are archived $this->em ->expects($this->any())