summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-25 12:02:30 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-25 12:03:21 +0200
commit4ca4b190c831163572491e1afbc42f2799652d76 (patch)
treec8083f8b6751f5cf110e75f0ab573678af1216dd
parent01923197d675380404ef9fe0ff3aef743afc65ad (diff)
import in reversed order because first item is the newest one, #80
-rw-r--r--tests/unit/utility/ImportParserTest.php44
-rw-r--r--utility/importparser.php8
2 files changed, 39 insertions, 13 deletions
diff --git a/tests/unit/utility/ImportParserTest.php b/tests/unit/utility/ImportParserTest.php
index 4014988a4..1a14479fd 100644
--- a/tests/unit/utility/ImportParserTest.php
+++ b/tests/unit/utility/ImportParserTest.php
@@ -52,15 +52,14 @@ class ImportParserTest extends \OCA\AppFramework\Utility\TestUtility {
array(
'id' => "tag:google.com,2005:reader/item/f9fd1dd3c19262e1",
'title' => "[HorribleSubs] Mushibugyo - 01 [720p].mkv",
- "published" => 1365415485,
-
- "alternate" => array( array(
- "href" => "http://www.nyaa.eu/?page=view&tid=421561",
- "type" => "text/html"
- )),
- "summary" => array(
- "content" => "1596 seeder(s), 775 leecher(s), 8005 download(s) - 316.7 MiB - Trusted"
- )
+ "published" => 1365415485,
+ "alternate" => array( array(
+ "href" => "http://www.nyaa.eu/?page=view&tid=421561",
+ "type" => "text/html"
+ )),
+ "summary" => array(
+ "content" => "1596 seeder(s), 775 leecher(s), 8005 download(s) - 316.7 MiB - Trusted"
+ )
)
)
);
@@ -118,9 +117,9 @@ class ImportParserTest extends \OCA\AppFramework\Utility\TestUtility {
array(
"published" => 1365415485,
- "summary" => array(
- "content" => "1596 seeder(s), 775 leecher(s), 8005 download(s) - 316.7 MiB - Trusted"
- )
+ "summary" => array(
+ "content" => "1596 seeder(s), 775 leecher(s), 8005 download(s) - 316.7 MiB - Trusted"
+ )
)
)
);
@@ -147,4 +146,25 @@ class ImportParserTest extends \OCA\AppFramework\Utility\TestUtility {
$this->assertEquals(array($out), $result);
}
+
+ public function testParsesReverse() {
+ $this->in['items'][1]= array(
+ 'id' => "tag",
+ 'title' => "[HorribleSubs] Mushibugyo - 01 [720p].mkv",
+ "published" => 1365415485,
+ "alternate" => array( array(
+ "href" => "http://www.nyaa.eu/?page=view&tid=421561",
+ "type" => "text/html"
+ )),
+ "summary" => array(
+ "content" => "1596 seeder(s), 775 leecher(s), 8005 download(s) - 316.7 MiB - Trusted"
+ )
+ );
+
+ $result = $this->parser->parse($this->in);
+
+ $this->assertEquals('tag', $result[0]->getGuid());
+ $this->assertEquals('tag:google.com,2005:reader/item/f9fd1dd3c19262e1',
+ $result[1]->getGuid());
+ }
}
diff --git a/utility/importparser.php b/utility/importparser.php
index 4babefda5..38dec4b44 100644
--- a/utility/importparser.php
+++ b/utility/importparser.php
@@ -42,7 +42,13 @@ class ImportParser {
$items = array();
if(array_key_exists('items', $json)) {
- foreach($json['items'] as $entry) {
+ $jsonItems = $json['items'];
+
+ // reverse because highest entry is the newest one and we cant rely
+ // on a set pubdate
+ for($i=count($jsonItems)-1; $i>=0; $i--) {
+ $entry = $jsonItems[$i];
+
// we require title, guid and url
if(!array_key_exists('title', $entry)
|| !array_key_exists('id', $entry)