This class manage feeds specified in configuration file
Author: Vincent Composieux (vincent.composieux@gmail.com)
Inheritance: use trait Symfony\Component\DependencyInjection\ContainerAwareTrait
Ejemplo n.º 1
0
 /**
  * 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'));
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }
Ejemplo n.º 3
0
 /**
  * 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');
 }
Ejemplo n.º 4
0
 /**
  * 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');
 }
Ejemplo n.º 5
0
 /**
  * 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');
 }
Ejemplo n.º 6
0
 /**
  * Tests the dump() method without any items or entity set.
  */
 public function testDumpWithoutItemsOrEntity()
 {
     if (!method_exists($this->filesystem, 'dumpFile')) {
         $this->markTestSkipped('Test skipped as Filesystem::dumpFile() is not available in this version.');
     }
     $this->setExpectedException('\\LogicException', 'An entity should be set OR you should use setItems() first');
     // Given
     $this->service->setRootDir('/unit/test/');
     $this->service->setFilename('feed.rss');
     $this->service->setDirection('ASC');
     $feed = $this->getMockBuilder('Eko\\FeedBundle\\Feed\\Feed')->disableOriginalConstructor()->getMock();
     $feed->expects($this->once())->method('hasItems')->will($this->returnValue(true));
     $this->feedManager->expects($this->once())->method('get')->will($this->returnValue($feed));
     // When - Expects exception
     $this->service->dump();
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }