/** * {@inheritdoc} */ public function parse(SourceInterface $source, StreamInterface $stream) { $feed = new \SimplePie(); $table = $this->getTableFactory()->create(); // @todo Use file directly. $feed->set_raw_data((string) $stream); $feed->init(); $table->setField('feed_title', $feed->get_title()); foreach ($feed->get_items(0, 0) as $item) { $this->parseItem($table, $item); } return $table; }
public function testParse() { $file = __DIR__ . '/test_data/drupalplanet.rss2'; $parser = new SimplePie(); $result = $parser->parse(new Source(NULL), new StreamStub($file)); $first = $result->shift(); $this->assertEquals('Adaptivethemes: Why I killed Node, may it RIP', $first->get('title')); $this->assertEquals(1256317246, $first->get('date')); $this->assertEquals('http://adaptivethemes.com/why-i-killed-node-may-it-rip', $first->get('id')); $this->assertEquals('http://adaptivethemes.com/why-i-killed-node-may-it-rip', $first->get('permalink')); $this->assertEquals('<p>Myself, like many others, have always had an acrimonious relationship with the word “node”. It didn’t exactly get off to a good start when node presented me with a rude “wtf” moment when we first met. Things only went down hill after that, node remaining aloof and abstract, without ever just coming out and telling me what it actually was.</p> <div></div>', $first->get('content')); $this->assertSame('lawyer@boyer.net (Lawyer Boyer)', $first->get('author_email')); $second = $result->shift(); $this->assertEquals('Midwestern Mac, LLC: Managing News - Revolutionary—not Evolutionary—Step for Drupal', $second->get('title')); $this->assertEquals(1256273895, $second->get('date')); $this->assertEquals('http://www.midwesternmac.com/blogs/geerlingguy/managing-news-revolutionary%E2%80%94not-evolutionary%E2%80%94step-drupal', $second->get('id')); $this->assertEquals('http://www.midwesternmac.com/blogs/geerlingguy/managing-news-revolutionary%E2%80%94not-evolutionary%E2%80%94step-drupal', $second->get('permalink')); $this->assertEquals('Fun description', $second->get('content')); }