mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-23 01:21:03 +00:00
add tests
This commit is contained in:
parent
da0a9e01e9
commit
eaf9dad777
5 changed files with 75 additions and 12 deletions
|
@ -15,7 +15,7 @@ class WallabagV1Import implements ImportInterface
|
||||||
protected $user;
|
protected $user;
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $logger;
|
protected $logger;
|
||||||
private $contentProxy;
|
protected $contentProxy;
|
||||||
protected $skippedEntries = 0;
|
protected $skippedEntries = 0;
|
||||||
protected $importedEntries = 0;
|
protected $importedEntries = 0;
|
||||||
protected $filepath;
|
protected $filepath;
|
||||||
|
@ -126,10 +126,9 @@ class WallabagV1Import implements ImportInterface
|
||||||
protected function parseEntries($entries)
|
protected function parseEntries($entries)
|
||||||
{
|
{
|
||||||
$i = 1;
|
$i = 1;
|
||||||
/*
|
|
||||||
* Untitled in all languages from v1. This should never have been translated
|
//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', '');
|
||||||
$untitled = array('Untitled', 'Sans titre', 'podle nadpisu', 'Sin título', 'با عنوان', 'per titolo', 'Sem título', 'Без названия', 'po naslovu', 'Без назви');
|
|
||||||
|
|
||||||
foreach ($entries as $importedEntry) {
|
foreach ($entries as $importedEntry) {
|
||||||
$existingEntry = $this->em
|
$existingEntry = $this->em
|
||||||
|
@ -145,7 +144,7 @@ class WallabagV1Import implements ImportInterface
|
||||||
$entry = new Entry($this->user);
|
$entry = new Entry($this->user);
|
||||||
$entry->setUrl($importedEntry['url']);
|
$entry->setUrl($importedEntry['url']);
|
||||||
if (in_array($importedEntry['title'], $untitled)) {
|
if (in_array($importedEntry['title'], $untitled)) {
|
||||||
$entry = $this->contentProxy->updateEntry($entry, $entry->getUrl());
|
$entry = $this->contentProxy->updateEntry($entry, $importedEntry['url']);
|
||||||
} else {
|
} else {
|
||||||
$entry->setContent($importedEntry['content']);
|
$entry->setContent($importedEntry['content']);
|
||||||
$entry->setTitle($importedEntry['title']);
|
$entry->setTitle($importedEntry['title']);
|
||||||
|
|
|
@ -57,19 +57,28 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$entryRepo->expects($this->exactly(3))
|
$entryRepo->expects($this->exactly(4))
|
||||||
->method('findByUrlAndUserId')
|
->method('findByUrlAndUserId')
|
||||||
->will($this->onConsecutiveCalls(false, true, false));
|
->will($this->onConsecutiveCalls(false, true, false, false));
|
||||||
|
|
||||||
$this->em
|
$this->em
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('getRepository')
|
->method('getRepository')
|
||||||
->willReturn($entryRepo);
|
->willReturn($entryRepo);
|
||||||
|
|
||||||
|
$entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$this->contentProxy
|
||||||
|
->expects($this->once())
|
||||||
|
->method('updateEntry')
|
||||||
|
->willReturn($entry);
|
||||||
|
|
||||||
$res = $wallabagV1Import->import();
|
$res = $wallabagV1Import->import();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertEquals(['skipped' => 1, 'imported' => 2], $wallabagV1Import->getSummary());
|
$this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testImportBadFile()
|
public function testImportBadFile()
|
||||||
|
|
|
@ -57,7 +57,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$entryRepo->expects($this->exactly(2))
|
$entryRepo->expects($this->exactly(3))
|
||||||
->method('findByUrlAndUserId')
|
->method('findByUrlAndUserId')
|
||||||
->will($this->onConsecutiveCalls(false, true, false));
|
->will($this->onConsecutiveCalls(false, true, false));
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
||||||
$res = $wallabagV2Import->import();
|
$res = $wallabagV2Import->import();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertEquals(['skipped' => 1, 'imported' => 1], $wallabagV2Import->getSummary());
|
$this->assertEquals(['skipped' => 1, 'imported' => 2], $wallabagV2Import->getSummary());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testImportBadFile()
|
public function testImportBadFile()
|
||||||
|
|
|
@ -46,5 +46,21 @@
|
||||||
"is_fav": "0",
|
"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",
|
"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"
|
"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
Loading…
Reference in a new issue