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