summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-08 14:28:18 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-08 14:28:18 +0200
commit1fccfbbf261a704cb1890e7f2afdb4e4ae29cadd (patch)
tree36031777126dbe8b9de102124cfd7b8660cfcb6b
parent7aa8c06258637f33a050119de7178146cce63dbf (diff)
try to fix scrutinizer bugs
-rw-r--r--tests/unit/utility/OPMLExporterTest.php36
-rw-r--r--utility/opmlexporter.php8
2 files changed, 27 insertions, 17 deletions
diff --git a/tests/unit/utility/OPMLExporterTest.php b/tests/unit/utility/OPMLExporterTest.php
index 1b8e76ca4..fe7b142e8 100644
--- a/tests/unit/utility/OPMLExporterTest.php
+++ b/tests/unit/utility/OPMLExporterTest.php
@@ -45,6 +45,16 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase {
}
+ private function getAttribute($item, $name) {
+ // used to fix scrutinizer errors
+ if ($item instanceof \DOMElement) {
+ return $item->getAttribute($name);
+ } else {
+ return null;
+ }
+ }
+
+
public function testBuildEmpty(){
$result = $this->exporter->build([], []);
$xpath = new \DOMXpath($result);
@@ -59,10 +69,10 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase {
$elems = $xpath->query('/opml/body/outline');
$this->assertEquals(2, $elems->length);
- $this->assertEquals($this->folder1->getName(), $elems->item(0)->getAttribute('title'));
- $this->assertEquals($this->folder1->getName(), $elems->item(0)->getAttribute('text'));
- $this->assertEquals($this->folder2->getName(), $elems->item(1)->getAttribute('title'));
- $this->assertEquals($this->folder2->getName(), $elems->item(1)->getAttribute('text'));
+ $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'title'));
+ $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'text'));
+ $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'title'));
+ $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'text'));
}
@@ -72,16 +82,16 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase {
$elems = $xpath->query('//outline');
$this->assertEquals(1, $elems->length);
- $this->assertEquals($this->feed1->getTitle(), $elems->item(0)->getAttribute('title'));
- $this->assertEquals($this->feed1->getTitle(), $elems->item(0)->getAttribute('text'));
- $this->assertEquals($this->feed1->getUrl(), $elems->item(0)->getAttribute('xmlUrl'));
- $this->assertEquals('', $elems->item(0)->getAttribute('htmlUrl'));
+ $this->assertEquals($this->feed1->getTitle(), $this->getAttribute($elems->item(0), 'title'));
+ $this->assertEquals($this->feed1->getTitle(), $this->getAttribute($elems->item(0), 'text'));
+ $this->assertEquals($this->feed1->getUrl(), $this->getAttribute($elems->item(0), 'xmlUrl'));
+ $this->assertEquals('', $this->getAttribute($elems->item(0), 'htmlUrl'));
}
public function testBuildReturnsFeedsAndFolders() {
$result = $this->exporter->build(
- [$this->folder1, $this->folder2],
+ [$this->folder1, $this->folder2],
[$this->feed1, $this->feed2]
);
$xpath = new \DOMXpath($result);
@@ -90,10 +100,10 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(3, $elems->length);
- $this->assertEquals($this->folder1->getName(), $elems->item(0)->getAttribute('title'));
- $this->assertEquals($this->folder2->getName(), $elems->item(1)->getAttribute('text'));
- $this->assertEquals($this->feed1->getUrl(), $elems->item(2)->getAttribute('xmlUrl'));
- $this->assertEquals($this->feed2->getLink(), $elems->item(1)->childNodes->item(0)->getAttribute('htmlUrl'));
+ $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'title'));
+ $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'text'));
+ $this->assertEquals($this->feed1->getUrl(), $this->getAttribute($elems->item(2), 'xmlUrl'));
+ $this->assertEquals($this->feed2->getLink(), $this->getAttribute($elems->item(1)->childNodes->item(0), 'htmlUrl'));
}
diff --git a/utility/opmlexporter.php b/utility/opmlexporter.php
index 98403e7f2..0efaba9b8 100644
--- a/utility/opmlexporter.php
+++ b/utility/opmlexporter.php
@@ -36,10 +36,10 @@ class OPMLExporter {
$head = $document->createElement('head');
$title = $document->createElement('title', 'Subscriptions');
- $head->appendChild( $title );
-
+ $head->appendChild($title);
+
$root->appendChild($head);
-
+
// body
$body = $document->createElement('body');
@@ -48,7 +48,7 @@ class OPMLExporter {
$folderOutline = $document->createElement('outline');
$folderOutline->setAttribute('title', $folder->getName());
$folderOutline->setAttribute('text', $folder->getName());
-
+
// feeds in folders
foreach ($feeds as $feed) {
if ($feed->getFolderId() === $folder->getId()) {