diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@smile.fr> | 2016-01-20 14:37:01 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@smile.fr> | 2016-01-20 14:37:01 +0100 |
commit | 6785f4aa749e381081b93e3db46424cc7475eab8 (patch) | |
tree | f8fb914c4febb93ee229c4b13f2488ee0c9fe2fc /src/Wallabag/ImportBundle/Tests/Import | |
parent | d481f42b7d383eb6211d1d3049d1a2c8288d9edb (diff) | |
download | wallabag-6785f4aa749e381081b93e3db46424cc7475eab8.tar.gz wallabag-6785f4aa749e381081b93e3db46424cc7475eab8.tar.zst wallabag-6785f4aa749e381081b93e3db46424cc7475eab8.zip |
[#1590] Add JSON import from wallabag v2
Diffstat (limited to 'src/Wallabag/ImportBundle/Tests/Import')
-rw-r--r-- | src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php | 12 | ||||
-rw-r--r-- | src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php | 97 |
2 files changed, 103 insertions, 6 deletions
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php index 90483480..1cb5a233 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php | |||
@@ -21,17 +21,17 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
21 | ->disableOriginalConstructor() | 21 | ->disableOriginalConstructor() |
22 | ->getMock(); | 22 | ->getMock(); |
23 | 23 | ||
24 | $pocket = new WallabagV1Import($this->em); | 24 | $wallabag = new WallabagV1Import($this->em); |
25 | 25 | ||
26 | $this->logHandler = new TestHandler(); | 26 | $this->logHandler = new TestHandler(); |
27 | $logger = new Logger('test', array($this->logHandler)); | 27 | $logger = new Logger('test', array($this->logHandler)); |
28 | $pocket->setLogger($logger); | 28 | $wallabag->setLogger($logger); |
29 | 29 | ||
30 | if (false === $unsetUser) { | 30 | if (false === $unsetUser) { |
31 | $pocket->setUser($this->user); | 31 | $wallabag->setUser($this->user); |
32 | } | 32 | } |
33 | 33 | ||
34 | return $pocket; | 34 | return $wallabag; |
35 | } | 35 | } |
36 | 36 | ||
37 | public function testInit() | 37 | public function testInit() |
@@ -77,7 +77,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
77 | $this->assertFalse($res); | 77 | $this->assertFalse($res); |
78 | 78 | ||
79 | $records = $this->logHandler->getRecords(); | 79 | $records = $this->logHandler->getRecords(); |
80 | $this->assertContains('WallabagV1Import: unable to read file', $records[0]['message']); | 80 | $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); |
81 | $this->assertEquals('ERROR', $records[0]['level_name']); | 81 | $this->assertEquals('ERROR', $records[0]['level_name']); |
82 | } | 82 | } |
83 | 83 | ||
@@ -91,7 +91,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
91 | $this->assertFalse($res); | 91 | $this->assertFalse($res); |
92 | 92 | ||
93 | $records = $this->logHandler->getRecords(); | 93 | $records = $this->logHandler->getRecords(); |
94 | $this->assertContains('WallabagV1Import: user is not defined', $records[0]['message']); | 94 | $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); |
95 | $this->assertEquals('ERROR', $records[0]['level_name']); | 95 | $this->assertEquals('ERROR', $records[0]['level_name']); |
96 | } | 96 | } |
97 | } | 97 | } |
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php new file mode 100644 index 00000000..4ebe93bf --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php | |||
@@ -0,0 +1,97 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Tests\Import; | ||
4 | |||
5 | use Wallabag\ImportBundle\Import\WallabagV2Import; | ||
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Monolog\Logger; | ||
8 | use Monolog\Handler\TestHandler; | ||
9 | |||
10 | class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | ||
11 | { | ||
12 | protected $user; | ||
13 | protected $em; | ||
14 | protected $logHandler; | ||
15 | |||
16 | private function getWallabagV2Import($unsetUser = false) | ||
17 | { | ||
18 | $this->user = new User(); | ||
19 | |||
20 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
21 | ->disableOriginalConstructor() | ||
22 | ->getMock(); | ||
23 | |||
24 | $wallabag = new WallabagV2Import($this->em); | ||
25 | |||
26 | $this->logHandler = new TestHandler(); | ||
27 | $logger = new Logger('test', array($this->logHandler)); | ||
28 | $wallabag->setLogger($logger); | ||
29 | |||
30 | if (false === $unsetUser) { | ||
31 | $wallabag->setUser($this->user); | ||
32 | } | ||
33 | |||
34 | return $wallabag; | ||
35 | } | ||
36 | |||
37 | public function testInit() | ||
38 | { | ||
39 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
40 | |||
41 | $this->assertEquals('wallabag v2', $wallabagV2Import->getName()); | ||
42 | $this->assertNotEmpty($wallabagV2Import->getUrl()); | ||
43 | $this->assertContains('This importer will import all your wallabag v2 articles.', $wallabagV2Import->getDescription()); | ||
44 | } | ||
45 | |||
46 | public function testImport() | ||
47 | { | ||
48 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
49 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
50 | |||
51 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
52 | ->disableOriginalConstructor() | ||
53 | ->getMock(); | ||
54 | |||
55 | $entryRepo->expects($this->exactly(2)) | ||
56 | ->method('findByUrlAndUserId') | ||
57 | ->will($this->onConsecutiveCalls(false, true, false)); | ||
58 | |||
59 | $this->em | ||
60 | ->expects($this->any()) | ||
61 | ->method('getRepository') | ||
62 | ->willReturn($entryRepo); | ||
63 | |||
64 | $res = $wallabagV2Import->import(); | ||
65 | |||
66 | $this->assertTrue($res); | ||
67 | $this->assertEquals(['skipped' => 1, 'imported' => 1], $wallabagV2Import->getSummary()); | ||
68 | } | ||
69 | |||
70 | public function testImportBadFile() | ||
71 | { | ||
72 | $wallabagV1Import = $this->getWallabagV2Import(); | ||
73 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.jsonx'); | ||
74 | |||
75 | $res = $wallabagV1Import->import(); | ||
76 | |||
77 | $this->assertFalse($res); | ||
78 | |||
79 | $records = $this->logHandler->getRecords(); | ||
80 | $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); | ||
81 | $this->assertEquals('ERROR', $records[0]['level_name']); | ||
82 | } | ||
83 | |||
84 | public function testImportUserNotDefined() | ||
85 | { | ||
86 | $wallabagV1Import = $this->getWallabagV2Import(true); | ||
87 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
88 | |||
89 | $res = $wallabagV1Import->import(); | ||
90 | |||
91 | $this->assertFalse($res); | ||
92 | |||
93 | $records = $this->logHandler->getRecords(); | ||
94 | $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); | ||
95 | $this->assertEquals('ERROR', $records[0]['level_name']); | ||
96 | } | ||
97 | } | ||