add tests

This commit is contained in:
Thomas Citharel 2016-02-11 15:48:20 +01:00
parent da0a9e01e9
commit eaf9dad777
5 changed files with 75 additions and 12 deletions

View file

@ -15,7 +15,7 @@ class WallabagV1Import implements ImportInterface
protected $user;
protected $em;
protected $logger;
private $contentProxy;
protected $contentProxy;
protected $skippedEntries = 0;
protected $importedEntries = 0;
protected $filepath;
@ -126,10 +126,9 @@ class WallabagV1Import implements ImportInterface
protected function parseEntries($entries)
{
$i = 1;
/*
* Untitled in all languages from v1. This should never have been translated
*/
$untitled = array('Untitled', 'Sans titre', 'podle nadpisu', 'Sin título', 'با عنوان', 'per titolo', 'Sem título', 'Без названия', 'po naslovu', 'Без назви');
//Untitled in all languages from v1. This should never have been translated
$untitled = array('Untitled', 'Sans titre', 'podle nadpisu', 'Sin título', 'با عنوان', 'per titolo', 'Sem título', 'Без названия', 'po naslovu', 'Без назви', 'No title found', '');
foreach ($entries as $importedEntry) {
$existingEntry = $this->em
@ -145,7 +144,7 @@ class WallabagV1Import implements ImportInterface
$entry = new Entry($this->user);
$entry->setUrl($importedEntry['url']);
if (in_array($importedEntry['title'], $untitled)) {
$entry = $this->contentProxy->updateEntry($entry, $entry->getUrl());
$entry = $this->contentProxy->updateEntry($entry, $importedEntry['url']);
} else {
$entry->setContent($importedEntry['content']);
$entry->setTitle($importedEntry['title']);

View file

@ -57,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()

View file

@ -57,7 +57,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$entryRepo->expects($this->exactly(2))
$entryRepo->expects($this->exactly(3))
->method('findByUrlAndUserId')
->will($this->onConsecutiveCalls(false, true, false));
@ -69,7 +69,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
$res = $wallabagV2Import->import();
$this->assertTrue($res);
$this->assertEquals(['skipped' => 1, 'imported' => 1], $wallabagV2Import->getSummary());
$this->assertEquals(['skipped' => 1, 'imported' => 2], $wallabagV2Import->getSummary());
}
public function testImportBadFile()

View file

@ -46,5 +46,21 @@
"is_fav": "0",
"content": "\n<div class=\"row\">\n<div class=\"col-lg-8 col-md-12 col-xs-12 col-sm-12\">\n<p>wallabag (formerly poche) is a <strong>self hostable application for saving web pages</strong>. Unlike other services, wallabag is free (as in freedom) and open source.</p>\n</div>\n\n</div>\n<div class=\"row\">\n<div class=\"col-lg-8 col-md-12 col-xs-12 col-sm-12\">\n<p>With this application you will not miss content anymore. <strong>Click, save, read it when you want</strong>. It saves the content you select so that you can read it when you have time.</p>\n</div>\n\n</div>\n<div class=\"row\">\n<div class=\"col-lg-6 col-md-12 col-xs-12 col-sm-12\">\n<h2>How it works</h2>\n<p>Thanks to the bookmarklet or <a title=\"Downloads\" href=\"http://www.wallabag.org/downloads/\">third-party applications</a>, you save an article in your wallabag to read it later. Then, when you open your wallabag, <strong>you can comfortably read your articles</strong>.</p>\n<h2>How to use wallabag</h2>\n<p>There are two ways to use wallabag: you can <a href=\"http://www.wallabag.org/frequently-asked-questions/#How_can_I_install_wallabag_and_what_are_the_requirements\">install it</a> on your web server or you can <a href=\"http://app.inthepoche.com\">create an account</a> at Framabag (we install and upgrade wallabag for you).</p>\n</div>\n\n</div>\n",
"user_id": "1"
},
{
"0": "4",
"1": "Sans titre",
"2": "http:\/\/www.konradlischka.info\/2016\/01\/blog\/wie-ein-deutsches-start-up-mit-wagniskapital-die-marktluecke-fuer-lokalen-digitaljournalismus-schliessen-will\/",
"3": "0",
"4": "0",
"5": "[unable to retrieve full-text content]",
"6": "1",
"id": "4",
"title": "Sans titre",
"url": "http:\/\/www.konradlischka.info\/2016\/01\/blog\/wie-ein-deutsches-start-up-mit-wagniskapital-die-marktluecke-fuer-lokalen-digitaljournalismus-schliessen-will\/",
"is_read": "0",
"is_fav": "0",
"content": "[unable to retrieve full-text content]",
"user_id": "1"
}
]

File diff suppressed because one or more lines are too long