From 1fccfbbf261a704cb1890e7f2afdb4e4ae29cadd Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 8 Oct 2014 14:28:18 +0200 Subject: try to fix scrutinizer bugs --- tests/unit/utility/OPMLExporterTest.php | 36 +++++++++++++++++++++------------ utility/opmlexporter.php | 8 ++++---- 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()) { -- cgit v1.2.3