sut = new \FeedParser(); } public function testRss1() { $xml = << hello feed http://meerkat.oreillynet.com Meerkat: An Open Wire Service XML: A Disruptive Technology http://c.moreover.com/click/here.pl?r123 desc XML; $feed = $this->sut->parseFeed($xml); $this->assertSame('hello feed', $feed['title']); $this->assertSame('http://meerkat.oreillynet.com', $feed['uri']); $this->assertSame(null, $feed['icon']); $item = $feed['items'][0]; $this->assertSame('XML: A Disruptive Technology', $item['title']); $this->assertSame('http://c.moreover.com/click/here.pl?r123', $item['uri']); $this->assertSame('desc', $item['content']); } public function testRss2() { $xml = << hello feed https://example.com/ https://example.com/2.ico hello world https://example.com/1 desc2 Tue, 26 Apr 2022 00:00:00 +0200 root XML; $feed = $this->sut->parseFeed($xml); $this->assertSame('hello feed', $feed['title']); $this->assertSame('https://example.com/', $feed['uri']); $this->assertSame('https://example.com/2.ico', $feed['icon']); $item = $feed['items'][0]; $this->assertSame('hello world', $item['title']); $this->assertSame('https://example.com/1', $item['uri']); $this->assertSame(1650924000, $item['timestamp']); $this->assertSame('root', $item['author']); $this->assertSame('desc2', $item['content']); $this->assertSame(['https://example.com/1.png'], $item['enclosures']); } public function testAtom() { $xml = << hello feed https://example.com/2.ico hello world root html 2015-11-05T14:38:49+01:00 XML; $feed = $this->sut->parseFeed($xml); $this->assertSame('hello feed', $feed['title']); $this->assertSame('https://example.com/1', $feed['uri']); $this->assertSame('https://example.com/2.ico', $feed['icon']); $item = $feed['items'][0]; $this->assertSame('hello world', $item['title']); $this->assertSame('https://example.com/1', $item['uri']); $this->assertSame(1446730729, $item['timestamp']); $this->assertSame('root', $item['author']); $this->assertSame('html', $item['content']); } public function testAppleItunesModule() { $xml = << 30:05 XML; $feed = $this->sut->parseFeed($xml); $expected = [ 'title' => '', 'uri' => '', 'icon' => '', 'items' => [ [ 'uri' => '', 'title' => '', 'content' => '', 'timestamp' => '', 'author' => '', 'itunes' => [ 'duration' => '30:05', ], 'enclosure' => [ 'url' => 'https://example.com/1.mp3', 'length' => '48123248', 'type' => 'audio/mpeg', ], 'enclosures' => [ 'https://example.com/1.mp3', ], ] ], ]; $this->assertEquals($expected, $feed); } }