]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
cs & tests for wllbg v1 import
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Tests / Import / WallabagV1ImportTest.php
index 90483480816d5c212d52f100dd4a75a69b4687c1..9a563a1158eb18c3e8d506f2529517e1e66a3bf0 100644 (file)
@@ -12,6 +12,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
     protected $user;
     protected $em;
     protected $logHandler;
+    protected $contentProxy;
 
     private function getWallabagV1Import($unsetUser = false)
     {
@@ -21,17 +22,21 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()
             ->getMock();
 
-        $pocket = new WallabagV1Import($this->em);
+        $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $wallabag = new WallabagV1Import($this->em, $this->contentProxy);
 
         $this->logHandler = new TestHandler();
         $logger = new Logger('test', array($this->logHandler));
-        $pocket->setLogger($logger);
+        $wallabag->setLogger($logger);
 
         if (false === $unsetUser) {
-            $pocket->setUser($this->user);
+            $wallabag->setUser($this->user);
         }
 
-        return $pocket;
+        return $wallabag;
     }
 
     public function testInit()
@@ -52,19 +57,28 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(3))
+        $entryRepo->expects($this->exactly(4))
             ->method('findByUrlAndUserId')
-            ->will($this->onConsecutiveCalls(false, true, false));
+            ->will($this->onConsecutiveCalls(false, true, false, false));
 
         $this->em
             ->expects($this->any())
             ->method('getRepository')
             ->willReturn($entryRepo);
 
+        $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $this->contentProxy
+            ->expects($this->once())
+            ->method('updateEntry')
+            ->willReturn($entry);
+
         $res = $wallabagV1Import->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 1, 'imported' => 2], $wallabagV1Import->getSummary());
+        $this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary());
     }
 
     public function testImportBadFile()
@@ -77,7 +91,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
         $this->assertFalse($res);
 
         $records = $this->logHandler->getRecords();
-        $this->assertContains('WallabagV1Import: unable to read file', $records[0]['message']);
+        $this->assertContains('WallabagImport: unable to read file', $records[0]['message']);
         $this->assertEquals('ERROR', $records[0]['level_name']);
     }
 
@@ -91,7 +105,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
         $this->assertFalse($res);
 
         $records = $this->logHandler->getRecords();
-        $this->assertContains('WallabagV1Import: user is not defined', $records[0]['message']);
+        $this->assertContains('WallabagImport: user is not defined', $records[0]['message']);
         $this->assertEquals('ERROR', $records[0]['level_name']);
     }
 }