/** * Check if the feed data are properly loaded from configuration settings */ public function testGetFeedData() { $feed = $this->manager->get('article'); $this->assertEquals('My articles/posts', $feed->get('title')); $this->assertEquals('Latests articles', $feed->get('description')); $this->assertEquals('http://github.com/eko/FeedBundle', $feed->get('link')); $this->assertEquals('utf-8', $feed->get('encoding')); $this->assertEquals('Vincent Composieux', $feed->get('author')); }
/** * @return string */ public function get() { $key = 'feed'; if ($this->cache->contains($key)) { return $this->cache->fetch($key); } $articles = $this->articleRepository->findPublishedOrderedByPublishDate(); $feed = $this->feedManager->get('article'); $feed->addFromArray($articles); $renderedFeed = $feed->render('rss'); $this->cache->save($key, $renderedFeed); return $renderedFeed; }
/** * Check if an \InvalidArgumentException is thrown * when formatter asked for rendering does not exists */ public function testFormatterNotFoundException() { $feed = $this->manager->get('article'); $feed->add(new FakeItemInterfaceEntity()); $this->setExpectedException('InvalidArgumentException', "Format 'unknown_formatter' is not available. Please see documentation."); $feed->render('unknown_formatter'); }
/** * Check if an \InvalidArgumentException is thrown * when formatter asked for rendering does not exists */ public function testFormatterNotFoundException() { $feed = $this->manager->get('article'); $feed->add(new FakeItemInterfaceEntity()); $this->setExpectedException('InvalidArgumentException', "Unable to find a formatter service for format 'unknown_formatter'."); $feed->render('unknown_formatter'); }
/** * Check if an exception is thrown when trying to render a non-existant method with RoutedItemInterface */ public function testNonExistantCustomFieldWithRoutedItemInterface() { $feed = $this->manager->get('article'); $feed->add(new FakeRoutedItemInterfaceEntity()); $feed->addField(new Field('fake_custom', 'getFeedDoNotExistsItemCustomMethod')); $this->setExpectedException('InvalidArgumentException', 'Method "getFeedDoNotExistsItemCustomMethod" should be defined in your entity.'); $feed->render('rss'); }
/** * Check if values are well translated with "translatable" option. */ public function testTranslatableValue() { $config = ['feeds' => ['article' => ['title' => 'My title', 'description' => 'My description', 'link' => 'http://github.com/eko/FeedBundle', 'encoding' => 'utf-8', 'author' => 'Vincent']]]; $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface'); $translator->expects($this->any())->method('trans')->will($this->returnValue('translatable-value')); $formatters = ['atom' => new AtomFormatter($translator, 'test')]; $manager = new FeedManager($this->getMockRouter(), $config, $formatters); $feed = $manager->get('article'); $feed->add(new FakeRoutedItemInterfaceEntity()); $feed->addItemField(new ItemField('fake_custom', 'getFeedItemCustom', ['translatable' => true])); $output = $feed->render('atom'); $this->assertContains('<fake_custom>translatable-value</fake_custom>', $output); }
/** * Sets items to the feed. * * @param array $items items list * * @return $this */ public function setItems(array $items) { $this->feedManager->get($this->name)->addFromArray($items); return $this; }