diff --git a/Controller/StreamController.php b/Controller/StreamController.php index aaea3ba..a2ec6a1 100644 --- a/Controller/StreamController.php +++ b/Controller/StreamController.php @@ -2,9 +2,7 @@ namespace Debril\RssAtomBundle\Controller; -use Debril\RssAtomBundle\Protocol\FeedFormatter; -use Debril\RssAtomBundle\Protocol\FeedOutInterface; -use FeedIo\Feed; +use FeedIo\FeedInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -100,15 +98,10 @@ protected function createStreamResponse(array $options, $format, $source = self: $content = $this->getContent($options, $source); if ($this->mustForceRefresh() || $content->getLastModified() > $this->getModifiedSince()) { - $response = new Response($this->getStringOutput($content, $format)); + $response = new Response($this->getFeedIo()->format($content, $format)->saveXML()); $response->headers->set('Content-Type', 'application/xhtml+xml'); + $this->setFeedHeaders($response, $content); - if (! $this->container->getParameter('debril_rss_atom.private_feeds')) { - $response->setPublic(); - } - - $response->setMaxAge(3600); - $response->setLastModified($content->getLastModified()); } else { $response = new Response(); $response->setNotModified(); @@ -118,19 +111,21 @@ protected function createStreamResponse(array $options, $format, $source = self: } /** - * @param $feed - * @param $format - * @return string - * @throws \Exception + * @param Response $response + * @param FeedInterface $feed + * @return $this */ - protected function getStringOutput($feed, $format) + protected function setFeedHeaders(Response $response, FeedInterface $feed) { - if ( $feed instanceof Feed ) { - return $this->getFeedIo()->format($feed, $format)->saveXML(); + $response->headers->set('Content-Type', 'application/xhtml+xml'); + if (! $this->isPrivate() ) { + $response->setPublic(); } - $formatter = $this->getFormatter($format); - return $formatter->toString($feed); + $response->setMaxAge(3600); + $response->setLastModified($feed->getLastModified()); + + return $this; } /** @@ -141,7 +136,7 @@ protected function getStringOutput($feed, $format) * @param array $options * @param string $source * - * @return FeedOutInterface + * @return FeedInterface * * @throws \Exception */ @@ -175,26 +170,11 @@ protected function mustForceRefresh() } /** - * Get the accurate formatter. - * - * @param string $format - * - * @throws \Exception - * - * @return FeedFormatter + * @return boolean true if the feed must be private */ - protected function getFormatter($format) + protected function isPrivate() { - $services = array( - 'rss' => 'debril.formatter.rss', - 'atom' => 'debril.formatter.atom', - ); - - if (!array_key_exists($format, $services)) { - throw new \Exception("Unsupported format {$format}"); - } - - return $this->get($services[$format]); + return $this->container->getParameter('debril_rss_atom.private_feeds'); } /** @@ -204,4 +184,5 @@ protected function getFeedIo() { return $this->container->get('feedio'); } + } diff --git a/DebrilRssAtomBundle.php b/DebrilRssAtomBundle.php index 72bd3e2..f699b62 100644 --- a/DebrilRssAtomBundle.php +++ b/DebrilRssAtomBundle.php @@ -2,16 +2,9 @@ namespace Debril\RssAtomBundle; -use Debril\RssAtomBundle\DependencyInjection\CompilerPass\DriverCompilerPass; use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\DependencyInjection\ContainerBuilder; class DebrilRssAtomBundle extends Bundle { - public function build(ContainerBuilder $container) - { - parent::build($container); - $container->addCompilerPass(new DriverCompilerPass()); - } } diff --git a/DependencyInjection/CompilerPass/DriverCompilerPass.php b/DependencyInjection/CompilerPass/DriverCompilerPass.php deleted file mode 100644 index bdd82a6..0000000 --- a/DependencyInjection/CompilerPass/DriverCompilerPass.php +++ /dev/null @@ -1,59 +0,0 @@ -getExtensionConfig('debril_rss_atom'); - - $configTree = new Configuration(); - $processor = new Processor(); - $config = $processor->processConfiguration($configTree, $configs); - - switch ($config['driver']) { - case 'curl': - // nothing to do - break; - case 'file': - $container - ->getDefinition('debril.reader') - ->replaceArgument(0, new Reference('debril.file')); - - break; - case 'guzzle': - if (! isset($config['driver_service'])) { - throw new \Exception('When setting debril_rss_atom.driver to "guzzle", you should provide Client service ID in debril_rss_atom.driver_service!'); - } - - $guzzlebridge = $container->getDefinition('debril.http.guzzle_bridge'); - $guzzlebridge->addArgument(new Reference($config['driver_service'])); - - $container - ->getDefinition('debril.reader') - ->replaceArgument(0, $guzzlebridge); - break; - case 'service': - if (! isset($config['driver_service'])) { - throw new \Exception('When setting debril_rss_atom.driver to "service", you should provide service ID in debril_rss_atom.driver_service!'); - } - - $container - ->getDefinition('debril.reader') - ->replaceArgument(0, new Reference($config['driver_service'])); - break; - default: - throw new \Exception('Unable to handle debril_rss_atom.driver value!'); - } - } -} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index cba19a4..b495545 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -28,28 +28,6 @@ public function getConfigTreeBuilder() ->arrayNode('date_formats') ->prototype('scalar')->end() ->end() - ->enumNode('driver') - ->info('Driver to use to fetch RSS feed. Valid values are "curl" (default), "file", "guzzle", "service".') - ->values(array('curl', 'file', 'guzzle', 'service')) - ->defaultValue('curl') - ->end() - ->scalarNode('driver_service') - ->info('If driver is set to "csa-guzzle" or "service", the ID of the service to use') - ->end() - ->arrayNode('curlopt') - ->info('Parameters for curl requests') - ->children() - ->scalarNode('timeout') - ->info('Timeout in seconds for curl requests') - ->end() - ->scalarNode('useragent') - ->info('User agent for curl requests') - ->end() - ->scalarNode('maxredirs') - ->info('Maximum redirects for curl requests') - ->end() - ->end() - ->end() ->end() ; diff --git a/DependencyInjection/DebrilRssAtomExtension.php b/DependencyInjection/DebrilRssAtomExtension.php index fc80582..4c461d4 100644 --- a/DependencyInjection/DebrilRssAtomExtension.php +++ b/DependencyInjection/DebrilRssAtomExtension.php @@ -15,6 +15,23 @@ */ class DebrilRssAtomExtension extends Extension { + + /** + * @var array + */ + protected $defaultDateFormats = [ + \DateTime::RFC3339, + \DateTime::RSS, + \DateTime::W3C, + 'Y-m-d\TH:i:s.uP', + 'Y-m-d', + 'd/m/Y', + 'd M Y H:i:s P', + 'D, d M Y H:i O', + 'D, d M Y H:i:s O', + 'D M d Y H:i:s e', + ]; + /** * {@inheritDoc} */ @@ -25,40 +42,10 @@ public function load(array $configs, ContainerBuilder $container) $this->setDefinition($container, 'logger', 'Psr\Log\NullLogger'); - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.xml'); - - $default = array( - \DateTime::RFC3339, - \DateTime::RSS, - \DateTime::W3C, - 'Y-m-d\TH:i:s.uP', - 'Y-m-d', - 'd/m/Y', - 'd M Y H:i:s P', - 'D, d M Y H:i O', - 'D, d M Y H:i:s O', - 'D M d Y H:i:s e', - ); - - if (!isset($config['date_formats'])) { - $container->setParameter( - 'debril_rss_atom.date_formats', - $default - ); - } else { - $container->setParameter( - 'debril_rss_atom.date_formats', - array_merge($default, $config['date_formats']) - ); - } - - if ( !isset($config['curlopt']) ) { - $container->setParameter('debril_rss_atom.curlopt', array()); - } else { - $container->setParameter('debril_rss_atom.curlopt', $config['curlopt']); - } + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('services.yml'); + $this->setDateFormats($container, $config); $container->setParameter('debril_rss_atom.private_feeds', $config['private']); } @@ -73,6 +60,26 @@ protected function setDefinition(ContainerBuilder $container, $serviceName, $cla if ( ! $container->hasDefinition($serviceName) && ! $container->hasAlias($serviceName)) { $container->setDefinition($serviceName, new Definition($className)); } + + return $this; + } + + /** + * @param ContainerBuilder $container + * @param array $config + * @return $this + */ + protected function setDateFormats(ContainerBuilder $container, array $config) + { + $dateFormats = isset($config['date_formats']) ? + array_merge($this->defaultDateFormats, $config['date_formats']): + $this->defaultDateFormats; + + $container->setParameter( + 'debril_rss_atom.date_formats', + $dateFormats + ); + return $this; } } diff --git a/Driver/FileDriver.php b/Driver/FileDriver.php deleted file mode 100644 index 9f224fc..0000000 --- a/Driver/FileDriver.php +++ /dev/null @@ -1,43 +0,0 @@ -setHttpCode(HttpDriverResponse::HTTP_CODE_OK); - $response->setBody($body); - - return $response; - } -} diff --git a/Driver/GuzzleBridgeDriver.php b/Driver/GuzzleBridgeDriver.php deleted file mode 100644 index 0dd09cc..0000000 --- a/Driver/GuzzleBridgeDriver.php +++ /dev/null @@ -1,43 +0,0 @@ -client = $client; - } - - /** - * @param string $url - * @param \DateTime $lastModified - * - * @return HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function getResponse($url, \DateTime $lastModified) - { - $ressource = $this->client->request('GET', $url); - - $response = new HttpDriverResponse(); - $response->setHttpCode($ressource->getStatusCode()); - $response->setHttpVersion($ressource->getProtocolVersion()); - $response->setHttpMessage($ressource->getReasonPhrase()); - $response->setHeaders($ressource->getHeaders()); - $response->setBody($ressource->getBody()); - - return $response; - } -} diff --git a/Driver/HttpCurlDriver.php b/Driver/HttpCurlDriver.php deleted file mode 100644 index b728934..0000000 --- a/Driver/HttpCurlDriver.php +++ /dev/null @@ -1,105 +0,0 @@ -options = $options; - - $defaults = array('timeout' => 10, - 'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5', - 'maxredirs' => 5); - - foreach ( $defaults as $key => $value ) { - if ( !isset( $this->options[$key]) ) { - $this->options[$key] = $value; - } - } - } - - /** - * @param string $url - * @param \DateTime $lastModified - * - * @return \Debril\RssAtomBundle\Driver\HttpDriverResponse - * - * @throws DriverUnreachableResourceException - * @deprecated removed in version 3.0 - */ - public function getResponse($url, \DateTime $lastModified) - { - $curl = curl_init($url); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HEADER, true); - curl_setopt($curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE); - curl_setopt($curl, CURLOPT_USERAGENT, $this->options['useragent']); - curl_setopt($curl, CURLOPT_TIMEVALUE, $lastModified->getTimestamp()); - curl_setopt($curl, CURLOPT_TIMEOUT, $this->options['timeout']); - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curl, CURLOPT_MAXREDIRS, $this->options['maxredirs']); - curl_setopt($curl, CURLOPT_HTTPHEADER, ['Accept-Encoding: gzip, deflate']); - $curlReturn = curl_exec($curl); - - if (!$curlReturn) { - $err = curl_error($curl); - throw new DriverUnreachableResourceException("Error accessing {$url} : {$err}"); - } - - $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); - curl_close($curl); - - return $this->getHttpResponse( - substr($curlReturn, 0, $headerSize), - substr($curlReturn, $headerSize) - ); - } - - /** - * @param string $headerString - * @param string $body - * - * @return \Debril\RssAtomBundle\Driver\HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function getHttpResponse($headerString, $body) - { - $headers = array(); - preg_match('/(?\S+) (?P\d+) (?P\V+)/', $headerString, $headers); - - $response = new HttpDriverResponse(); - - $response->setBody($body); - $response->setHttpCode($headers['code']); - $response->setHttpMessage($headers['message']); - $response->setHttpVersion($headers['version']); - $response->setHeaders($headerString); - - return $response; - } -} diff --git a/Driver/HttpDriverInterface.php b/Driver/HttpDriverInterface.php deleted file mode 100644 index a306e7d..0000000 --- a/Driver/HttpDriverInterface.php +++ /dev/null @@ -1,25 +0,0 @@ -getHttpCode() === self::HTTP_CODE_OK; - } - - /** - * @return bool - * @deprecated removed in version 3.0 - */ - public function getHttpCodeIsRedirection() - { - return in_array( - $this->getHttpCode(), - array( - self::HTTP_CODE_MOVE_PERMANENTLY, - self::HTTP_CODE_FOUND, - ) - ); - } - - /** - * @return bool - * @deprecated removed in version 3.0 - */ - public function getHttpCodeIsCached() - { - return in_array( - $this->getHttpCode(), - array( - self::HTTP_CODE_NOT_MODIFIED, - ) - ); - } - - /** - * @return int - * @deprecated removed in version 3.0 - */ - public function getHttpCode() - { - return $this->httpCode; - } - - /** - * @param int $httpCode - * - * @return HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function setHttpCode($httpCode) - { - $this->httpCode = (int) $httpCode; - - return $this; - } - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getHttpVersion() - { - return $this->httpVersion; - } - - /** - * @param string $httpVersion - * - * @return HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function setHttpVersion($httpVersion) - { - $this->httpVersion = $httpVersion; - - return $this; - } - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getHttpMessage() - { - return $this->httpMessage; - } - - /** - * @param string $httpMessage - * - * @return HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function setHttpMessage($httpMessage) - { - $this->httpMessage = $httpMessage; - - return $this; - } - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * @param string $headers - * - * @return HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function setHeaders($headers) - { - $this->headers = $headers; - - return $this; - } - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getBody() - { - return $this->body; - } - - /** - * @param string $body - * - * @return HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function setBody($body) - { - $this->body = $body; - - return $this; - } -} diff --git a/Protocol/CategoryInInterface.php b/Protocol/CategoryInInterface.php deleted file mode 100644 index 28663c0..0000000 --- a/Protocol/CategoryInInterface.php +++ /dev/null @@ -1,29 +0,0 @@ - - * Rss : rss.channel.item.category[term] - * - * @param string $name - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function setName($name); -} diff --git a/Protocol/CategoryOutInterface.php b/Protocol/CategoryOutInterface.php deleted file mode 100644 index 1860352..0000000 --- a/Protocol/CategoryOutInterface.php +++ /dev/null @@ -1,25 +0,0 @@ - - * Rss : rss.channel.item.category[term] - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getName(); -} diff --git a/Protocol/FeedFormatter.php b/Protocol/FeedFormatter.php deleted file mode 100644 index 811c039..0000000 --- a/Protocol/FeedFormatter.php +++ /dev/null @@ -1,75 +0,0 @@ -toDom($content); - - return $element->saveXML(); - } - - /** - * @param FeedOutInterface $content - * - * @return \DomDocument - * @deprecated removed in version 3.0 - */ - public function toDom(FeedOutInterface $content) - { - $element = $this->getRootElement(); - - $this->setMetas($element, $content); - $this->setEntries($element, $content); - - return $element; - } - - /** - * @param \DomDocument $document - * @param FeedOutInterface $content - * @deprecated removed in version 3.0 - */ - public function setEntries(\DomDocument $document, FeedOutInterface $content) - { - $items = $content->getItems(); - foreach ($items as $item) { - $this->addEntry($document, $item); - } - } -} diff --git a/Protocol/FeedInInterface.php b/Protocol/FeedInInterface.php deleted file mode 100644 index 6985cb6..0000000 --- a/Protocol/FeedInInterface.php +++ /dev/null @@ -1,73 +0,0 @@ - - * Rss : rss.channel.item . - * - * @param ItemInInterface $item - * @deprecated removed in version 3.0 - */ - public function addItem(ItemInInterface $item); - - /** - * Atom : feed.updated - * Rss : rss.channel.lastBuildDate - * or rss.channel.pubDate . - * - * @param \DateTime $lastModified - * @deprecated removed in version 3.0 - */ - public function setLastModified(\DateTime $lastModified); - - /** - * Atom : feed.title - * Rss : rss.channel.title <rss><channel><title>. - * - * @param string $title - * @deprecated removed in version 3.0 - */ - public function setTitle($title); - - /** - * Atom : feed.subtitle <feed><subtitle> - * Rss : rss.channel.description <rss><channel><description>. - * - * @param string $description - * @deprecated removed in version 3.0 - */ - public function setDescription($description); - - /** - * Atom : feed.link <feed><link> - * Rss : rss.channel.link <rss><channel><link>. - * - * @param string $link - * @deprecated removed in version 3.0 - */ - public function setLink($link); - - /** - * Atom : feed.id <feed><id> - * Rss : rss.channel.id <rss><channel><id>. - * - * @param string $id - * @deprecated removed in version 3.0 - */ - public function setPublicId($id); -} diff --git a/Protocol/FeedInterface.php b/Protocol/FeedInterface.php deleted file mode 100644 index 0620cf8..0000000 --- a/Protocol/FeedInterface.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2014, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol; - -/** - * Transitional interface which deprecates FeedInInterface and FeedOutInterface - * Interface FeedInterface. - */ -interface FeedInterface extends FeedInInterface, FeedOutInterface -{ -} diff --git a/Protocol/FeedOutInterface.php b/Protocol/FeedOutInterface.php deleted file mode 100644 index 68c60d3..0000000 --- a/Protocol/FeedOutInterface.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol; - -/** - * Interface used to send a RSS/ATOM stream to Formatter classes. - */ -/** - * Interface FeedOutInterface. - */ -interface FeedOutInterface -{ - /** - * Atom : feed.updated <feed><updated> - * Rss : rss.channel.lastBuildDate <rss><channel><lastBuildDate>. - * - * @return \DateTime - * @deprecated removed in version 3.0 - */ - public function getLastModified(); - - /** - * Atom : feed.title <feed><title> - * Rss : rss.channel.title <rss><channel><title>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getTitle(); - - /** - * Atom : feed.subtitle <feed><subtitle> - * Rss : rss.channel.description <rss><channel><description>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getDescription(); - - /** - * Atom : feed.link <feed><link> - * Rss : rss.channel.link <rss><channel><link>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getLink(); - - /** - * Atom : feed.id <feed><id> - * Rss : rss.channel.id <rss><channel><id>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getPublicId(); - - /** - * Atom : feed.entry <feed><entry> - * Rss : rss.channel.item <rss><channel><item>. - * - * @return ItemOutInterface[] - * @deprecated removed in version 3.0 - */ - public function getItems(); -} diff --git a/Protocol/FeedReader.php b/Protocol/FeedReader.php deleted file mode 100644 index 8d88dec..0000000 --- a/Protocol/FeedReader.php +++ /dev/null @@ -1,264 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol; - -use Debril\RssAtomBundle\Protocol\Filter\ModifiedSince; -use Debril\RssAtomBundle\Protocol\Parser\XmlParser; -use SimpleXMLElement; -use Debril\RssAtomBundle\Driver\HttpDriverInterface; -use Debril\RssAtomBundle\Driver\HttpDriverResponse; -use Debril\RssAtomBundle\Protocol\Parser\Factory; -use Debril\RssAtomBundle\Exception\ParserException; -use Debril\RssAtomBundle\Exception\FeedException\FeedCannotBeReadException; -use Debril\RssAtomBundle\Exception\FeedException\FeedNotFoundException; -use Debril\RssAtomBundle\Exception\FeedException\FeedNotModifiedException; -use Debril\RssAtomBundle\Exception\FeedException\FeedServerErrorException; -use Debril\RssAtomBundle\Exception\FeedException\FeedForbiddenException; - -/** - * Class to read any kind of supported feeds (RSS, ATOM, and more if you need). - * - * FeedReader uses an HttpDriverInterface to pull feeds and one more Parser instances to - * parse them. For each feed, FeedReader automatically chooses the accurate - * Parser and use it to return a FeedContent instance. - * - * <code> - * // HttpDriverInterface and Factory instances are required to construct a FeedReader. - * // Here we use the HttpCurlDriver (recommanded) - * $reader = new FeedReader(new HttpCurlDriver(), new Factory()); - * - * // now we add the parsers - * $reader->addParser(new AtomParser()); - * $reader->addParser(new RssParser()); - * - * // $url is obviously the feed you want to read - * // $dateTime is the last moment you read the feed - * $content = $reader->getFeedContent($url, $dateTime); - * - * // now we can display the feed's content - * echo $feed->getTitle(); - * - * // each - * foreach( $content->getItems() as $item ) - * { - * echo $item->getTitle(); - * echo $item->getSummary(); - * } - * </code> - * @deprecated removed in version 3.0 - */ -class FeedReader -{ - /** - * @var Parser[] - */ - protected $parsers = array(); - - /** - * @var HttpDriverInterface - */ - protected $driver = null; - - /** - * @var Factory - */ - protected $factory = null; - - /** - * @var XmlParser - */ - protected $xmlParser = null; - - /** - * @param HttpDriverInterface $driver - * @param Factory $factory - * @deprecated removed in version 3.0 - */ - public function __construct(HttpDriverInterface $driver, Factory $factory, XmlParser $xmlParser) - { - $this->driver = $driver; - $this->factory = $factory; - $this->xmlParser = $xmlParser; - } - - /** - * Add a Parser. - * - * @param Parser $parser - * - * @return FeedReader - * @deprecated removed in version 3.0 - */ - public function addParser(Parser $parser) - { - $parser->setFactory($this->factory); - $this->parsers[] = $parser; - - return $this; - } - - /** - * @return HttpDriverInterface - * @deprecated removed in version 3.0 - */ - public function getDriver() - { - return $this->driver; - } - - /** - * Read a feed using its url and create a FeedInInterface instance - * Second parameter can be either a \DateTime instance or a numeric limit. - * - * @param string $url - * @param \DateTime $arg - * - * @return FeedInInterface|FeedContent - * @deprecated removed in version 3.0 - */ - public function getFeedContent($url, $arg = null) - { - if (is_numeric($arg)) { - return $this->getFilteredContent($url, array( - new Filter\Limit($arg), - )); - } - if ($arg instanceof \DateTime) { - return $this->getFeedContentSince($url, $arg); - } - - return $this->getFilteredContent($url, array()); - } - - /** - * @param string $url - * @param array $filters - * @param \DateTime $modifiedSince - * - * @return FeedInInterface - * @deprecated removed in version 3.0 - */ - public function getFilteredContent($url, array $filters, \DateTime $modifiedSince = null) - { - $response = $this->getResponse($url, $modifiedSince); - - return $this->parseBody($response, $this->factory->newFeed(), $filters); - } - - /** - * @param string $url - * @param \DateTime $modifiedSince - * - * @return FeedInInterface - * @deprecated removed in version 3.0 - */ - public function getFeedContentSince($url, \DateTime $modifiedSince) - { - $filters = array( - new Filter\ModifiedSince($modifiedSince), - ); - - return $this->getFilteredContent($url, $filters); - } - - /** - * Read a feed using its url and hydrate the given FeedInInterface instance. - * - * @param string $url - * @param FeedInInterface $feed - * @param \DateTime $modifiedSince - * - * @return FeedInInterface - * @deprecated removed in version 3.0 - */ - public function readFeed($url, FeedInInterface $feed, \DateTime $modifiedSince) - { - $response = $this->getResponse($url, $modifiedSince); - - $filters = array( - new ModifiedSince($modifiedSince), - ); - - return $this->parseBody($response, $feed, $filters); - } - - /** - * Read the XML stream hosted at $url. - * - * @param $url - * @param \Datetime $modifiedSince - * - * @return HttpDriverResponse - * @deprecated removed in version 3.0 - */ - public function getResponse($url, \Datetime $modifiedSince = null) - { - if (is_null($modifiedSince)) { - $modifiedSince = new \DateTime('@0'); - } - - return $this->getDriver()->getResponse($url, $modifiedSince); - } - - /** - * Parse the body of a feed and write it into the FeedInInterface instance. - * - * @param HttpDriverResponse $response - * @param FeedInInterface $feed - * @param array $filters - * - * @return FeedInInterface - * @deprecated removed in version 3.0 - */ - public function parseBody(HttpDriverResponse $response, FeedInInterface $feed, array $filters = array()) - { - if ($response->getHttpCodeIsOk() - || $response->getHttpCodeIsRedirection()) { - $xmlBody = $this->xmlParser->parseString($response->getBody()); - $parser = $this->getAccurateParser($xmlBody); - - return $parser->parse($xmlBody, $feed, $filters); - } - - switch ($response->getHttpCode()) { - case HttpDriverResponse::HTTP_CODE_NOT_FOUND: - throw new FeedNotFoundException($response->getHttpMessage()); - case HttpDriverResponse::HTTP_CODE_NOT_MODIFIED: - throw new FeedNotModifiedException($response->getHttpMessage()); - case HttpDriverResponse::HTTP_CODE_SERVER_ERROR: - throw new FeedServerErrorException($response->getHttpMessage()); - case HttpDriverResponse::HTTP_CODE_FORBIDDEN: - throw new FeedForbiddenException($response->getHttpMessage()); - default: - throw new FeedCannotBeReadException($response->getHttpMessage(), $response->getHttpCode()); - } - } - - /** - * Choose the accurate Parser for the XML stream. - * - * @param SimpleXMLElement $xmlBody - * - * @throws ParserException - * - * @return Parser - * @deprecated removed in version 3.0 - */ - public function getAccurateParser(SimpleXMLElement $xmlBody) - { - foreach ($this->parsers as $parser) { - if ($parser->canHandle($xmlBody)) { - return $parser; - } - } - - throw new ParserException('No parser can handle this stream'); - } -} diff --git a/Protocol/Filter/Limit.php b/Protocol/Filter/Limit.php deleted file mode 100644 index b90b4b5..0000000 --- a/Protocol/Filter/Limit.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Filter; - -use Debril\RssAtomBundle\Protocol\FilterInterface; -use Debril\RssAtomBundle\Protocol\Parser\Item; -use Debril\RssAtomBundle\Protocol\ItemOutInterface; - -/** - * Class Limit. - * @deprecated removed in version 3.0 - */ -class Limit implements FilterInterface -{ - /** - * @var int - */ - protected $limit; - - /** - * @var int - */ - protected $count = 0; - - /** - * @param int $limit - * @deprecated removed in version 3.0 - */ - public function __construct($limit) - { - $this->limit = $limit; - } - - /** - * @param Item $item - * - * @return bool - * @deprecated removed in version 3.0 - */ - public function isValid(ItemOutInterface $item) - { - return ($this->limit > $this->count++); - } -} diff --git a/Protocol/Filter/ModifiedSince.php b/Protocol/Filter/ModifiedSince.php deleted file mode 100644 index d4c80fb..0000000 --- a/Protocol/Filter/ModifiedSince.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Filter; - -use Debril\RssAtomBundle\Protocol\FilterInterface; -use Debril\RssAtomBundle\Protocol\Parser\Item; -use Debril\RssAtomBundle\Protocol\ItemOutInterface; - -/** - * Class ModifiedSince. - * @deprecated removed in version 3.0 - */ -class ModifiedSince implements FilterInterface -{ - /** - * @var \DateTime - */ - protected $date; - - /** - * @param \DateTime $date - * @deprecated removed in version 3.0 - */ - public function __construct(\DateTime $date) - { - $this->date = $date; - } - - /** - * @return \DateTime - * @deprecated removed in version 3.0 - */ - public function getDate() - { - return $this->date; - } - - /** - * The item is valid if it was last updated after the modified since date. - * - * @param Item $item - * - * @return bool - * @deprecated removed in version 3.0 - */ - public function isValid(ItemOutInterface $item) - { - if ($item->getUpdated() instanceof \DateTime) { - return $item->getUpdated() > $this->getDate(); - } - - return false; - } -} diff --git a/Protocol/FilterInterface.php b/Protocol/FilterInterface.php deleted file mode 100644 index 7898b14..0000000 --- a/Protocol/FilterInterface.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol; - -use Debril\RssAtomBundle\Protocol\Parser\Item; -use Debril\RssAtomBundle\Protocol\ItemOutInterface; - -/** - * Interface FilterInterface. - */ -interface FilterInterface -{ - /** - * @param Item $item - * - * @return bool - * @deprecated removed in version 3.0 - */ - public function isValid(ItemOutInterface $item); -} diff --git a/Protocol/Formatter/FeedAtomFormatter.php b/Protocol/Formatter/FeedAtomFormatter.php deleted file mode 100644 index b4805e3..0000000 --- a/Protocol/Formatter/FeedAtomFormatter.php +++ /dev/null @@ -1,133 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Formatter; - -use Debril\RssAtomBundle\Protocol\FeedFormatter; -use Debril\RssAtomBundle\Protocol\FeedOutInterface; -use Debril\RssAtomBundle\Protocol\ItemOutInterface; - -/** - * Class FeedAtomFormatter. - * @deprecated removed in version 3.0 - */ -class FeedAtomFormatter extends FeedFormatter -{ - const CONTENT_TYPE_HTML = 'html'; - - /** - * @param FeedOutInterface $content - * - * @return string - * @deprecated removed in version 3.0 - */ - public function toString(FeedOutInterface $content) - { - $element = $this->toDom($content); - - return str_replace('default:', '', $element->saveXML()); - } - - /** - * @return \DomDocument - * @deprecated removed in version 3.0 - */ - public function getRootElement() - { - $dom = new \DOMDocument('1.0', 'utf-8'); - $element = $dom->createElement('feed'); - $element->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); - $dom->appendChild($element); - - return $dom; - } - - /** - * @param \DomDocument $document - * @param FeedOutInterface $content - * @deprecated removed in version 3.0 - */ - public function setMetas(\DOMDocument $document, FeedOutInterface $content) - { - $elements = array(); - $elements[] = $document->createElement('title', htmlspecialchars($content->getTitle())); - $elements[] = $document->createElement('subtitle', $content->getDescription()); - $elements[] = $document->createElement('id', $content->getLink()); - - $link = $document->createElement('link'); - $link->setAttribute('href', $content->getLink()); - $link->setAttribute('rel', 'self'); - - $elements[] = $link; - $elements[] = $document->createElement('updated', $content->getLastModified()->format(\DateTime::ATOM)); - - foreach ($elements as $element) { - $document->documentElement->appendChild($element); - } - } - - /** - * @param \DOMDocument $document - * @param ItemOutInterface $item - */ - protected function addEntry(\DOMDocument $document, ItemOutInterface $item) - { - $entry = $document->createElement('entry'); - - $elements = array(); - $elements[] = $document->createElement('title', htmlspecialchars($item->getTitle())); - - $link = $document->createElement('link'); - $link->setAttribute('href', $item->getLink()); - $elements[] = $link; - - $elements[] = $document->createElement('id', $item->getLink()); - $elements[] = $document->createElement('updated', $item->getUpdated()->format(\DateTime::ATOM)); - - if (strlen($item->getSummary()) > 0) { - $summary = $document->createElement('summary', htmlspecialchars($item->getSummary(), ENT_COMPAT, 'UTF-8')); - $summary->setAttribute('type', self::CONTENT_TYPE_HTML); - } - - $content = $document->createElement('content', htmlspecialchars($item->getDescription(), ENT_COMPAT, 'UTF-8')); - $content->setAttribute('type', self::CONTENT_TYPE_HTML); - $elements[] = $content; - - if (!is_null($item->getComment())) { - $comments = $document->createElement('link'); - $comments->setAttribute('href', $item->getComment()); - $comments->setAttribute('rel', 'related'); - - $elements[] = $comments; - } - - if (!is_null($item->getAuthor())) { - $author = $document->createElement('author'); - $author->appendChild($document->createElement('name', $item->getAuthor())); - - $elements[] = $author; - } - - foreach ($item->getMedias() as $media) { - $mediaLink = $document->createElement('link'); - $mediaLink->setAttribute('rel', 'enclosure'); - $mediaLink->setAttribute('href', $media->getUrl()); - $mediaLink->setAttribute('length', $media->getLength()); - $mediaLink->setAttribute('type', $media->getType()); - - $elements[] = $mediaLink; - } - - foreach ($elements as $element) { - $entry->appendChild($element); - } - - $document->documentElement->appendChild($entry); - } -} diff --git a/Protocol/Formatter/FeedRssFormatter.php b/Protocol/Formatter/FeedRssFormatter.php deleted file mode 100644 index 5cfbbe2..0000000 --- a/Protocol/Formatter/FeedRssFormatter.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Formatter; - -use Debril\RssAtomBundle\Protocol\FeedFormatter; -use Debril\RssAtomBundle\Protocol\FeedOutInterface; -use Debril\RssAtomBundle\Protocol\ItemOutInterface; - -/** - * Class FeedRssFormatter. - * @deprecated removed in version 3.0 - */ -class FeedRssFormatter extends FeedFormatter -{ - /** - * @return \DomDocument - * @deprecated removed in version 3.0 - */ - public function getRootElement() - { - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->formatOutput = true; - - $rss = $dom->createElement('rss'); - $rss->setAttribute('version', '2.0'); - $channel = $dom->createElement('channel'); - $rss->appendChild($channel); - $dom->appendChild($rss); - - return $dom; - } - - /** - * @param \DomDocument $document - * @param FeedOutInterface $content - * @deprecated removed in version 3.0 - */ - public function setMetas(\DOMDocument $document, FeedOutInterface $content) - { - $elements = array(); - $elements[] = $document->createElement('title', htmlspecialchars($content->getTitle())); - $elements[] = $document->createElement('description', htmlspecialchars($content->getDescription())); - $elements[] = $document->createElement('link', $content->getLink()); - - $elements[] = $document->createElement('lastBuildDate', $content->getLastModified()->format(\DateTime::RSS)); - $elements[] = $document->createElement('pubDate', $content->getLastModified()->format(\DateTime::RSS)); - - foreach ($elements as $element) { - $document->documentElement->firstChild->appendChild($element); - } - } - - /** - * @param \DomDocument $document - * @param ItemOutInterface $item - */ - protected function addEntry(\DomDocument $document, ItemOutInterface $item) - { - $entry = $document->createElement('item'); - - $elements = array(); - $elements[] = $document->createElement('title', htmlspecialchars($item->getTitle())); - - $elements[] = $document->createElement('link', $item->getLink()); - $elements[] = $document->createElement('guid', $item->getPublicId()); - $elements[] = $document->createElement('pubDate', $item->getUpdated()->format(\DateTime::RSS)); - $elements[] = $document->createElement('comments', $item->getComment()); - $elements[] = $document->createElement('description', htmlspecialchars($item->getDescription(), ENT_COMPAT, 'UTF-8')); - - $mediaCount = 0; - foreach ($item->getMedias() as $media) { - // We can have only one enclosure in RSS 2.0 - // We use as a fallback Yahoo RSS Media extension - if (0 === $mediaCount) { - $mediaElement = $document->createElement('enclosure'); - $mediaElement->setAttribute('url', $media->getUrl()); - $mediaElement->setAttribute('length', $media->getLength()); - $mediaElement->setAttribute('type', $media->getType()); - } - - $mediaElement = $document->createElement('media:content'); - $mediaElement->setAttribute('url', $media->getUrl()); - $mediaElement->setAttribute('fileSize', $media->getLength()); - $mediaElement->setAttribute('type', $media->getType()); - $mediaElement->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/'); - - - $elements[] = $mediaElement; - - $mediaCount++; - } - - if (!is_null($item->getAuthor())) { - $elements[] = $document->createElement('author', $item->getAuthor()); - } - foreach ($elements as $element) { - $entry->appendChild($element); - } - - $document->documentElement->firstChild->appendChild($entry); - } -} diff --git a/Protocol/ItemInInterface.php b/Protocol/ItemInInterface.php deleted file mode 100644 index 93861aa..0000000 --- a/Protocol/ItemInInterface.php +++ /dev/null @@ -1,106 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol; - -use Debril\RssAtomBundle\Protocol\Parser\Media; - -/** - * interface used to represent incoming items - * Interface ItemInInterface. - */ -interface ItemInInterface -{ - /** - * Atom : feed.entry.title <feed><entry><title> - * Rss : rss.channel.item.title <rss><channel><item><title>. - * - * @param string $title - * @deprecated removed in version 3.0 - */ - public function setTitle($title); - - /** - * Atom : feed.entry.id <feed><entry><id> - * Rss : rss.channel.item.guid <rss><channel><item><guid>. - * - * @param string $id - * @deprecated removed in version 3.0 - */ - public function setPublicId($id); - - /** - * Atom : feed.entry.content <feed><entry><content> - * Rss : rss.channel.item.description <rss><channel><item><description>. - * - * @param string $description - * @deprecated removed in version 3.0 - */ - public function setDescription($description); - - /** - * Atom : feed.entry.summary <feed><entry><summary>. - * - * @param string $summary - * @deprecated removed in version 3.0 - */ - public function setSummary($summary); - - /** - * Atom : feed.entry.updated <feed><entry><updated> - * Rss : rss.channel.item.pubDate <rss><channel><item><pubDate>. - * - * @param \DateTime $updated - * @deprecated removed in version 3.0 - */ - public function setUpdated(\DateTime $updated); - - /** - * Atom : feed.entry.link <feed><entry><link> - * Rss : rss.channel.item.link <rss><channel><item><link>. - * - * @param string $link - * @deprecated removed in version 3.0 - */ - public function setLink($link); - - /** - * Atom : feed.entry.author.name <feed><entry><author><name> - * Rss : rss.channel.item.author <rss><channel><item><author>. - * - * @param string $author - * @deprecated removed in version 3.0 - */ - public function setAuthor($author); - - /** - * Rss : rss.channel.item.comment <rss><channel><item><comment>. - * - * @param string $comment - * @deprecated removed in version 3.0 - */ - public function setComment($comment); - - /** - * Rss : rss.channel.item.enclosure <rss><channel><item><enclosure>. - * - * @param Media $media - * @deprecated removed in version 3.0 - */ - public function addMedia(Media $media); - - /** - * Atom : feed.entry.category <feed><entry><category> - * Rss : rss.channel.item.category[term] <rss><channel><item><category> - * - * @param CategoryInInterface $category - * @deprecated removed in version 3.0 - */ - public function addCategory(CategoryInInterface $category); -} diff --git a/Protocol/ItemOutInterface.php b/Protocol/ItemOutInterface.php deleted file mode 100644 index d3e534d..0000000 --- a/Protocol/ItemOutInterface.php +++ /dev/null @@ -1,107 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol; - -/** - * Item sent to Formatter classes. - */ -/** - * Interface ItemOutInterface. - */ -interface ItemOutInterface -{ - /** - * Atom : feed.entry.title <feed><entry><title> - * Rss : rss.channel.item.title <rss><channel><item><title>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getTitle(); - - /** - * Atom : feed.entry.id <feed><entry><id> - * Rss : rss.channel.item.guid <rss><channel><item><guid>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getPublicId(); - - /** - * Atom : feed.entry.content <feed><entry><content> - * Rss : rss.channel.item.description <rss><channel><item><description>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getDescription(); - - /** - * Atom : feed.entry.summary <feed><entry><summary>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getSummary(); - - /** - * Atom : feed.entry.updated <feed><entry><updated> - * Rss : rss.channel.item.pubDate <rss><channel><item><pubDate>. - * - * @return \DateTime - * @deprecated removed in version 3.0 - */ - public function getUpdated(); - - /** - * Atom : feed.entry.link <feed><entry><link> - * Rss : rss.channel.item.link <rss><channel><item><link>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getLink(); - - /** - * Atom : feed.entry.author.name <feed><entry><author><name> - * Rss : rss.channel.item.author <rss><channel><item><author>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getAuthor(); - - /** - * atom : feed.entry.link[rel="alternate"] <feed><entry><link rel="alternate" /> - * Rss : rss.channel.item.comment <rss><channel><item><comment>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getComment(); - - /** - * Rss : rss.channel.item.enclosure for the first one <rss><channel><item><enclosure>, and rss.channel.item.media:content <rss><channel><item><media:content> for all media - * - * @return \ArrayIterator|MediaOutInterface[] $medias - * @deprecated removed in version 3.0 - */ - public function getMedias(); - - /** - * Atom : feed.entry.category <feed><entry><category> - * Rss : rss.channel.item.category[term] <rss><channel><item><category> - * - * @return CategoryOutInterface[] - * @deprecated removed in version 3.0 - */ - public function getCategories(); -} diff --git a/Protocol/MediaOutInterface.php b/Protocol/MediaOutInterface.php deleted file mode 100644 index 5fb80e6..0000000 --- a/Protocol/MediaOutInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol; - -/** - * Interface MediaOutInterface - */ -interface MediaOutInterface -{ - /** - * Rss : rss.entry.media:content url attribute - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getUrl(); - - /** - * Rss : rss.entry.media:content type attribute - * - * @return string mime type - * @deprecated removed in version 3.0 - */ - public function getType(); - - /** - * Rss : rss.entry.media:content fileSize attribute - * - * @return integer fle size or 0 if unknown - * @deprecated removed in version 3.0 - */ - public function getLength(); -} diff --git a/Protocol/Parser.php b/Protocol/Parser.php deleted file mode 100644 index ec018c8..0000000 --- a/Protocol/Parser.php +++ /dev/null @@ -1,389 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol; - -use Debril\RssAtomBundle\Protocol\Filter\ModifiedSince; -use Debril\RssAtomBundle\Protocol\Parser\Item; -use Debril\RssAtomBundle\Exception\ParserException; -use Debril\RssAtomBundle\Protocol\Parser\Factory; -use Debril\RssAtomBundle\Protocol\Parser\Media; - -/** - * Class Parser. - */ -abstract class Parser -{ - /** - * System's time zone. - * - * @var \DateTimeZone - */ - protected static $timezone; - - /** - * List of mandatory fields. - * - * @var string[] - */ - protected $mandatoryFields = array(); - - /** - * Feed's date format. - * - * @var string[] - */ - protected $dateFormats = array(); - - /** - * @var Factory - */ - protected $factory; - - /** - * Parses the feed's body to create a FeedContent instance. - * - * @param \SimpleXMLElement $xmlBody - * @param \Debril\RssAtomBundle\Protocol\FeedInterface $feed - * @param array $filters - * - * @throws ParserException - * - * @return FeedInterface - * @deprecated removed in version 3.0 - */ - public function parse(\SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters = array()) - { - if (!$this->canHandle($xmlBody)) { - throw new ParserException('this is not a supported format'); - } - - $this->checkBodyStructure($xmlBody); - - $xmlBody = $this->registerNamespaces($xmlBody); - - return $this->parseBody($xmlBody, $feed, $filters); - } - - /** - * @param \SimpleXMLElement $body - * - * @throws ParserException - */ - protected function checkBodyStructure(\SimpleXMLElement $body) - { - $errors = array(); - - foreach ($this->mandatoryFields as $field) { - if (!isset($body->$field)) { - $errors[] = "missing {$field}"; - } - } - - if (0 < count($errors)) { - $report = implode(', ', $errors); - throw new ParserException( - "error while parsing the feed : {$report}" - ); - } - } - - /** - * @param array $dates - * @deprecated removed in version 3.0 - */ - public function setDateFormats(array $dates) - { - $this->dateFormats = $dates; - } - - /** - * @param string $date - * - * @return string date Format - * - * @throws ParserException - * @deprecated removed in version 3.0 - */ - public function guessDateFormat($date) - { - $date = trim($date); - foreach ($this->dateFormats as $format) { - $test = \DateTime::createFromFormat($format, $date); - if ($test instanceof \DateTime) { - return $format; - } - } - - throw new ParserException('Impossible to guess date format : '.$date); - } - - /** - * @return ItemInInterface - * @deprecated removed in version 3.0 - */ - public function newItem() - { - if ($this->getFactory() instanceof Factory) { - return $this->getFactory()->newItem(); - } - - return new Item(); - } - - /** - * @return Factory - * @deprecated removed in version 3.0 - */ - public function getFactory() - { - return $this->factory; - } - - /** - * @param Factory $factory - * - * @return Parser - * @deprecated removed in version 3.0 - */ - public function setFactory(Factory $factory) - { - $this->factory = $factory; - - return $this; - } - - /** - * @deprecated since 1.3.0 replaced by addValidItem - * - * @param FeedInInterface $feed - * @param ItemInInterface $item - * @param \DateTime $modifiedSince - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function addAcceptableItem(FeedInInterface $feed, ItemInInterface $item, \DateTime $modifiedSince) - { - $filters = array( - new ModifiedSince($modifiedSince), - ); - - return $this->addValidItem($feed, $item, $filters); - } - - /** - * @param FeedInInterface $feed - * @param ItemInInterface $item - * @param array $filters - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function addValidItem(FeedInInterface $feed, ItemInInterface $item, array $filters = array()) - { - if ($this->isValid($item, $filters)) { - $feed->addItem($item); - } - - return $this; - } - - /** - * @param ItemInInterface $item - * @param array $filters - * - * @return bool - * @deprecated removed in version 3.0 - */ - public function isValid(ItemInInterface $item, array $filters = array()) - { - $valid = true; - foreach ($filters as $filter) { - if ($filter instanceof FilterInterface) { - $valid = $filter->isValid($item) ? $valid : false; - } - } - - return $valid; - } - - /** - * Creates a DateTime instance for the given string. Default format is RFC2822. - * - * @param string $string - * @param string $format - * - * @return \DateTime - * @deprecated removed in version 3.0 - */ - public static function convertToDateTime($string, $format = \DateTime::RFC2822) - { - $string = trim($string); - $date = \DateTime::createFromFormat($format, $string); - - if (!$date instanceof \DateTime) { - throw new ParserException("date is the wrong format : {$string} - expected {$format}"); - } - - $date->setTimezone(static::getSystemTimezone()); - - return $date; - } - - /** - * Returns the system's timezone. - * - * @return \DateTimeZone - * @deprecated removed in version 3.0 - */ - public static function getSystemTimezone() - { - if (is_null(static::$timezone)) { - static::$timezone = new \DateTimeZone(date_default_timezone_get()); - } - - return static::$timezone; - } - - /** - * Reset the system's time zone. - * @deprecated removed in version 3.0 - */ - public static function resetTimezone() - { - static::$timezone = null; - } - - /** - * register Namespaces. - * - * @param \SimpleXMLElement $xmlBody - * - * @return \SimpleXMLElement - */ - protected function registerNamespaces(\SimpleXMLElement $xmlBody) - { - $namespaces = $xmlBody->getNamespaces(true); - foreach ($namespaces as $prefix => $ns) { - if ($prefix != '') { - $xmlBody->registerXPathNamespace($prefix, $ns); - } - } - - return $xmlBody; - } - - /** - * @param \SimpleXMLElement $xmlElement - * @param array $namespaces - * - * @return array - */ - protected function getAdditionalNamespacesElements(\SimpleXMLElement $xmlElement, $namespaces) - { - $additional = array(); - foreach ($namespaces as $prefix => $ns) { - if ($prefix != '') { - $additionalElement = $xmlElement->children($ns); - if (!empty($additionalElement)) { - $additional[$prefix] = $additionalElement; - } - } - } - - return $additional; - } - - /** - * @param \SimpleXMLElement $element - * @param string $attributeName - * - * @return string|null - * @deprecated removed in version 3.0 - */ - public function getAttributeValue(\SimpleXMLElement $element, $attributeName) - { - $attributes = $element[0]->attributes(); - foreach ($attributes as $name => $value) { - if (strcasecmp($name, $attributeName) === 0) { - return (string) $value; - } - } - - return; - } - - /** - * @param \SimpleXMLElement $element - * - * @return Media - * @deprecated removed in version 3.0 - */ - public function createMedia(\SimpleXMLElement $element) - { - $media = new Media(); - $media->setUrl($this->searchAttributeValue($element, array('url', 'href', 'link'))) - ->setType($this->getAttributeValue($element, 'type')) - ->setLength($this->getAttributeValue($element, 'length')); - - return $media; - } - - /** - * Looks for an attribute value under different possible names. - * - * @param \SimpleXMLElement $element - * @param array $names - * - * @return null|string|void - * @deprecated removed in version 3.0 - */ - public function searchAttributeValue(\SimpleXMLElement $element, array $names) - { - foreach ($names as $name) { - $value = $this->getAttributeValue($element, $name); - if (!is_null($value)) { - return (string) $value; - } - } - - return; - } - - /** - * Tells if the parser can handle the feed or not. - * - * @param \SimpleXMLElement $xmlBody - * - * @return bool - */ - abstract public function canHandle(\SimpleXMLElement $xmlBody); - - /** - * Performs the actual conversion into a FeedContent instance. - * - * @param \SimpleXMLElement $body - * @param FeedInterface $feed - * @param array $filters - * - * @return FeedInInterface - */ - abstract protected function parseBody(\SimpleXMLElement $body, FeedInterface $feed, array $filters); - - /** - * Handles enclosures if any. - * - * @param \SimpleXMLElement $element - * @param ItemInInterface $item - * - * @return $this - */ - abstract protected function handleEnclosure(\SimpleXMLElement $element, ItemInInterface $item); -} diff --git a/Protocol/Parser/AtomParser.php b/Protocol/Parser/AtomParser.php deleted file mode 100644 index df3469d..0000000 --- a/Protocol/Parser/AtomParser.php +++ /dev/null @@ -1,179 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Exception\ParserException; -use Debril\RssAtomBundle\Protocol\FeedInterface; -use Debril\RssAtomBundle\Protocol\ItemInInterface; -use Debril\RssAtomBundle\Protocol\Parser; -use SimpleXMLElement; - -/** - * Class AtomParser. - * @deprecated removed in version 3.0 - */ -class AtomParser extends Parser -{ - protected $mandatoryFields = array( - 'id', - 'updated', - 'title', - 'link', - 'entry', - ); - - /** - * - * @deprecated removed in version 3.0 - */ - public function __construct() - { - $this->setdateFormats(array(\DateTime::RFC3339)); - } - - /** - * @param SimpleXMLElement $xmlBody - * - * @return bool - * @deprecated removed in version 3.0 - */ - public function canHandle(SimpleXMLElement $xmlBody) - { - return 'feed' === $xmlBody->getName(); - } - - /** - * @param SimpleXMLElement $xmlBody - * @param FeedInterface $feed - * @param array $filters - * - * @return FeedInterface - * - * @throws ParserException - */ - protected function parseBody(SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters) - { - $this->parseHeaders($xmlBody, $feed); - - $namespaces = $xmlBody->getNamespaces(true); - - foreach ($xmlBody->entry as $xmlElement) { - $itemFormat = isset($itemFormat) ? $itemFormat : $this->guessDateFormat($xmlElement->updated); - - $item = $this->newItem(); - $item->setTitle($xmlElement->title) - ->setPublicId($xmlElement->id) - ->setSummary($this->parseContent($xmlElement->summary)) - ->setDescription($this->parseContent($xmlElement->content)) - ->setUpdated(static::convertToDateTime($xmlElement->updated, $itemFormat)); - - $item->setLink($this->detectLink($xmlElement, 'alternate')); - - if ($xmlElement->author) { - $item->setAuthor($xmlElement->author->name); - } - - $item->setAdditional($this->getAdditionalNamespacesElements($xmlElement, $namespaces)); - $this->handleEnclosure($xmlElement, $item); - - $this->parseCategories($xmlElement, $item); - - $this->addValidItem($feed, $item, $filters); - } - - return $feed; - } - - /** - * @param SimpleXMLElement $xmlBody - * @param FeedInterface $feed - * - * @throws ParserException - */ - protected function parseHeaders(SimpleXMLElement $xmlBody, FeedInterface $feed) - { - $feed->setPublicId($xmlBody->id); - - $feed->setLink(current($this->detectLink($xmlBody, 'self'))); - $feed->setTitle($xmlBody->title); - $feed->setDescription($xmlBody->subtitle); - - $format = $this->guessDateFormat($xmlBody->updated); - $updated = static::convertToDateTime($xmlBody->updated, $format); - $feed->setLastModified($updated); - } - - /** - * @param SimpleXMLElement $xmlElement - * @param string $type - */ - protected function detectLink(SimpleXMLElement $xmlElement, $type) - { - foreach ($xmlElement->link as $xmlLink) { - if ((string) $xmlLink['rel'] === $type) { - return $xmlLink['href']; - } - } - - // return the first if the desired link does not exist - return $xmlElement->link[0]['href']; - } - - protected function parseContent(SimpleXMLElement $content) - { - if ($content && 0 < $content->children()->count()) { - $out = ''; - foreach ($content->children() as $child) { - $out .= $child->asXML(); - } - - return $out; - } - - return $content; - } - - /** - * Handles enclosures if any. - * - * @param SimpleXMLElement $element - * @param ItemInInterface $item - * - * @return $this - */ - protected function handleEnclosure(SimpleXMLElement $element, ItemInInterface $item) - { - foreach ($element->link as $link) { - if (strcasecmp($this->getAttributeValue($link, 'rel'), 'enclosure') === 0) { - $media = $this->createMedia($link); - $item->addMedia($media); - } - } - - return $this; - } - - /** - * Parse category elements. - * We may have more than one. - * - * @param SimpleXMLElement $element - * @param ItemInInterface $item - */ - protected function parseCategories(SimpleXMLElement $element, ItemInInterface $item) - { - foreach ($element->category as $xmlCategory) { - $category = new Category(); - $category->setName($this->getAttributeValue($xmlCategory, 'term')); - - $item->addCategory($category); - } - } -} diff --git a/Protocol/Parser/Category.php b/Protocol/Parser/Category.php deleted file mode 100644 index f3513ac..0000000 --- a/Protocol/Parser/Category.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\CategoryInInterface; -use Debril\RssAtomBundle\Protocol\CategoryOutInterface; - -/** - * Class Category - * @deprecated removed in version 3.0 - */ -class Category implements CategoryInInterface, CategoryOutInterface -{ - /** - * Atom : feed.entry.category <feed><entry><category> - * Rss : rss.channel.item.category[term] <rss><channel><item><category> - * - * @var string - */ - protected $name; - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } -} diff --git a/Protocol/Parser/Factory.php b/Protocol/Parser/Factory.php deleted file mode 100644 index 8373ec3..0000000 --- a/Protocol/Parser/Factory.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\FeedInInterface; -use Debril\RssAtomBundle\Protocol\ItemInInterface; - -/** - * Class Factory. - * @deprecated removed in version 3.0 - */ -class Factory -{ - /** - * @var string - */ - protected $feedClass = 'Debril\RssAtomBundle\Protocol\Parser\FeedContent'; - - /** - * @var string - */ - protected $itemClass = 'Debril\RssAtomBundle\Protocol\Parser\Item'; - - /** - * @return FeedInInterface - * - * @throws \Exception - * @deprecated removed in version 3.0 - */ - public function newFeed() - { - $newFeed = new $this->feedClass(); - if (!$newFeed instanceof FeedInInterface) { - throw new \Exception("{$this->feedClass} does not implement FeedInInterface interface"); - } - - return $newFeed; - } - - /** - * @return ItemInInterface - * - * @throws \Exception - * @deprecated removed in version 3.0 - */ - public function newItem() - { - $newItem = new $this->itemClass(); - if (!$newItem instanceof ItemInInterface) { - throw new \Exception("{$this->itemClass} does not implement ItemInInterface interface"); - } - - return $newItem; - } - - /** - * @param string $feedClass - * - * @return Factory - * - * @throws \Exception - * @deprecated removed in version 3.0 - */ - public function setFeedClass($feedClass) - { - if (!class_exists($feedClass)) { - throw new \Exception("{$feedClass} does not exist"); - } - - $this->feedClass = $feedClass; - - return $this; - } - - /** - * @param string $itemClass - * - * @return Factory - * - * @throws \Exception - * @deprecated removed in version 3.0 - */ - public function setItemClass($itemClass) - { - if (!class_exists($itemClass)) { - throw new \Exception("{$itemClass} does not exist"); - } - - $this->itemClass = $itemClass; - - return $this; - } -} diff --git a/Protocol/Parser/FeedContent.php b/Protocol/Parser/FeedContent.php deleted file mode 100644 index 6123eaf..0000000 --- a/Protocol/Parser/FeedContent.php +++ /dev/null @@ -1,273 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\FeedInterface; -use Debril\RssAtomBundle\Protocol\ItemInInterface; - -/** - * A full Feed's content representation, containing both the headers of the feed - * (not the HTTP one) and its news. - * - * This class is meant to be used reading or writing a feed. You will get - * an instance of this class if you grab a RSS or ATOM feed over the internet. - * You will also use this class to publish a feed. - * - * An example of reading implementation is given in the FeedReader's documentation. - * - * You can create a new feed as described below : - * - * <code> - * $feed = new FeedContent; - * - * $feed->setLastModified($lastTimeANewsWasUpdated); - * - * $feed->setTitle('your feed title'); - * $feed->setDescription('the description'); - * $feed->addItem($item); - * </code> - */ - -/** - * Class FeedContent. - * @deprecated removed in version 3.0 - */ -class FeedContent implements FeedInterface -{ - /** - * Atom : feed.entry <feed><entry> - * Rss : rss.channel.item <rss><channel><item>. - * - * @var array[\Debril\RssAtomBundle\Protocol\Parser\Item] - */ - protected $items = array(); - - /** - * Atom : feed.updated <feed><updated> - * Rss : rss.channel.lastBuildDate <rss><channel><lastBuildDate> - * or rss.channel.pubDate <rss><channel><pubDate>. - * - * @var \Datetime - */ - protected $lastModified; - - /** - * Atom : feed.title <feed><title> - * Rss : rss.channel.title <rss><channel><title>. - * - * @var string - */ - protected $title; - - /** - * Atom : feed.subtitle <feed><subtitle> - * Rss : rss.channel.description <rss><channel><description>. - * - * @var string - */ - protected $description; - - /** - * Atom : feed.link <feed><link> - * Rss : rss.channel.link <rss><channel><link>. - * - * @var string - */ - protected $link; - - /** - * Atom : feed.id <feed><id> - * Rss : rss.channel.id <rss><channel><id>. - * - * @var string - */ - protected $publicId; - - /** - * Atom : feed.updated <feed><updated> - * Rss : rss.channel.lastBuildDate <rss><channel><lastBuildDate> - * or rss.channel.pubDate <rss><channel><pubDate>. - * - * @return \DateTime - * @deprecated removed in version 3.0 - */ - public function getLastModified() - { - return $this->lastModified; - } - - /** - * Atom : feed.updated <feed><updated> - * Rss : rss.channel.lastBuildDate <rss><channel><lastBuildDate> - * or rss.channel.pubDate <rss><channel><pubDate>. - * - * @param \DateTime $lastModified - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function setLastModified(\DateTime $lastModified) - { - $this->lastModified = $lastModified; - - return $this; - } - - /** - * Atom : feed.title <feed><title> - * Rss : rss.channel.title <rss><channel><title>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getTitle() - { - return $this->title; - } - - /** - * Atom : feed.title <feed><title> - * Rss : rss.channel.title <rss><channel><title>. - * - * @param string $title - * - * @return \Debril\RssAtomBundle\Protocol\Parser\FeedContent - * @deprecated removed in version 3.0 - */ - public function setTitle($title) - { - $this->title = (string) $title; - - return $this; - } - - /** - * Atom : feed.subtitle <feed><subtitle> - * Rss : rss.channel.description <rss><channel><description>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getDescription() - { - return $this->description; - } - - /** - * Atom : feed.subtitle <feed><subtitle> - * Rss : rss.channel.description <rss><channel><description>. - * - * @param string $description - * - * @return \Debril\RssAtomBundle\Protocol\Parser\FeedContent - * @deprecated removed in version 3.0 - */ - public function setDescription($description) - { - $this->description = (string) $description; - - return $this; - } - - /** - * Atom : feed.link <feed><link> - * Rss : rss.channel.link <rss><channel><link>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getLink() - { - return $this->link; - } - - /** - * Atom : feed.link <feed><link> - * Rss : rss.channel.link <rss><channel><link>. - * - * @param string $link - * - * @return \Debril\RssAtomBundle\Protocol\Parser\FeedContent - * @deprecated removed in version 3.0 - */ - public function setLink($link) - { - $this->link = (string) $link; - - return $this; - } - - /** - * Atom : feed.id <feed><id> - * Rss : rss.channel.id <rss><channel><id>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getPublicId() - { - return $this->publicId; - } - - /** - * Atom : feed.id <feed><id> - * Rss : rss.channel.id <rss><channel><id>. - * - * @param string $id - * - * @return \Debril\RssAtomBundle\Protocol\Parser\FeedContent - * @deprecated removed in version 3.0 - */ - public function setPublicId($id) - { - $this->publicId = (string) $id; - - return $this; - } - - /** - * Number of feed.entry or rss.channel.item in the stream. - * - * @return int - * @deprecated removed in version 3.0 - */ - public function getItemsCount() - { - return count($this->items); - } - - /** - * Atom : feed.entry <feed><entry> - * Rss : rss.channel.item <rss><channel><item>. - * - * @return array[\Debril\RssAtomBundle\Protocol\Item] - * @deprecated removed in version 3.0 - */ - public function getItems() - { - return $this->items; - } - - /** - * Atom : feed.entry <feed><entry> - * Rss : rss.channel.item <rss><channel><item>. - * - * @param \Debril\RssAtomBundle\Protocol\ItemInInterface $item - * - * @return FeedContent - * @deprecated removed in version 3.0 - */ - public function addItem(ItemInInterface $item) - { - $this->items[] = $item; - - return $this; - } -} diff --git a/Protocol/Parser/Item.php b/Protocol/Parser/Item.php deleted file mode 100644 index a5ecce5..0000000 --- a/Protocol/Parser/Item.php +++ /dev/null @@ -1,400 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -use DateTime; -use Debril\RssAtomBundle\Protocol\CategoryInInterface; -use Debril\RssAtomBundle\Protocol\ItemInInterface; -use Debril\RssAtomBundle\Protocol\ItemOutInterface; - -/** - * Class Item. - * @deprecated removed in version 3.0 - */ -class Item implements ItemInInterface, ItemOutInterface -{ - /** - * Atom : feed.entry.title <feed><entry><title> - * Rss : rss.channel.item.title <rss><channel><item><title>. - * - * @var string - */ - protected $title; - - /** - * Atom : feed.entry.summary <feed><entry><summary>. - * - * @var string - */ - protected $summary; - - /** - * Atom : feed.entry.content <feed><entry><content> - * Rss : rss.channel.item.description <rss><channel><item><description>. - * - * @var string - */ - protected $description; - - /** - * Atom : feed.entry.updated <feed><entry><updated> - * Rss : rss.channel.item.pubDate <rss><channel><item><pubDate>. - * - * @var DateTime - */ - protected $updated; - - /** - * Atom : feed.entry.id <feed><entry><id> - * Rss : rss.channel.item.guid <rss><channel><item><guid>. - * - * @var string - */ - protected $publicId; - - /** - * Atom : feed.entry.link <feed><entry><link> - * Rss : rss.channel.item.link <rss><channel><item><link>. - * - * @var string - */ - protected $link; - - /** - * Atom : feed.entry.author.name <feed><entry><author><name> - * Rss : rss.channel.item.author <rss><channel><item><author>. - * - * @var string - */ - protected $author; - - /** - * Rss : rss.channel.item.comment <rss><channel><item><comment>. - * - * @var string - */ - protected $comment; - - /** - * this will take all additional elements from other namespace as array with raw simpleXml - * f.e. MediaRss or FeedBurner additions. - * - * @var array - */ - protected $additional; - - /** - * @var \ArrayIterator - */ - protected $medias; - - /** - * @var Category[] - */ - protected $categories; - - /** - * Constructor. - * @deprecated removed in version 3.0 - */ - public function __construct() - { - $this->categories = array(); - $this->medias = new \ArrayIterator(); - } - - /** - * Atom : feed.entry.title <feed><entry><title> - * Rss : rss.channel.item.title <rss><channel><item><title>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getTitle() - { - return $this->title; - } - - /** - * Atom : feed.entry.title <feed><entry><title> - * Rss : rss.channel.item.title <rss><channel><item><title>. - * - * @param string $title - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setTitle($title) - { - $this->title = (string) $title; - - return $this; - } - - /** - * Atom : feed.entry.id <feed><entry><id> - * Rss : rss.channel.item.guid <rss><channel><item><guid>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getPublicId() - { - return $this->publicId; - } - - /** - * Atom : feed.entry.id <feed><entry><id> - * Rss : rss.channel.item.guid <rss><channel><item><guid>. - * - * @param string $publicId - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setPublicId($publicId) - { - $this->publicId = (string) $publicId; - - return $this; - } - - /** - * Atom : feed.entry.content <feed><entry><content> - * Rss : rss.channel.item.description <rss><channel><item><description>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getDescription() - { - return $this->description; - } - - /** - * Atom : feed.entry.content <feed><entry><content> - * Rss : rss.channel.item.description <rss><channel><item><description>. - * - * @param string $description - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setDescription($description) - { - $this->description = (string) $description; - - return $this; - } - - /** - * Atom : feed.entry.summary <feed><entry><summary>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getSummary() - { - return $this->summary; - } - - /** - * Atom : feed.entry.summary <feed><entry><summary>. - * - * @param string $summary - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setSummary($summary) - { - $this->summary = (string) $summary; - - return $this; - } - - /** - * Atom : feed.entry.updated <feed><entry><updated> - * Rss : rss.channel.item.pubDate <rss><channel><item><pubDate>. - * - * @return \DateTime - * @deprecated removed in version 3.0 - */ - public function getUpdated() - { - return $this->updated; - } - - /** - * Atom : feed.entry.updated <feed><entry><updated> - * Rss : rss.channel.item.pubDate <rss><channel><item><pubDate>. - * - * @param \DateTime $updated - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setUpdated(DateTime $updated) - { - $this->updated = $updated; - - return $this; - } - - /** - * Atom : feed.entry.link <feed><entry><link> - * Rss : rss.channel.item.link <rss><channel><item><link>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getLink() - { - return $this->link; - } - - /** - * Atom : feed.entry.link <feed><entry><link> - * Rss : rss.channel.item.link <rss><channel><item><link>. - * - * @param string $link - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setLink($link) - { - $this->link = (string) $link; - - return $this; - } - - /** - * Atom : feed.entry.author.name <feed><entry><author><name> - * Rss : rss.channel.item.author <rss><channel><item><author>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getAuthor() - { - return $this->author; - } - - /** - * Atom : feed.entry.author.name <feed><entry><author><name> - * Rss : rss.channel.item.author <rss><channel><item><author>. - * - * @param string $author - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setAuthor($author) - { - $this->author = (string) $author; - - return $this; - } - - /** - * Rss : rss.channel.item.comment <rss><channel><item><comment>. - * - * @return string - * @deprecated removed in version 3.0 - */ - public function getComment() - { - return $this->comment; - } - - /** - * Rss : rss.channel.item.comment <rss><channel><item><comment>. - * - * @param string $comment - * - * @return Item - * @deprecated removed in version 3.0 - */ - public function setComment($comment) - { - $this->comment = (string) $comment; - - return $this; - } - - /** - * this will take all additional elements from other namespace as array with raw simpleXml - * f.e. MediaRss or FeedBurner additions. - * - * @param array $additional - * @deprecated removed in version 3.0 - */ - public function setAdditional(array $additional) - { - $this->additional = $additional; - } - - /** - * this will take all additional elements from other namespace as array with raw simpleXml - * f.e. MediaRss or FeedBurner additions. - * - * @return array - * @deprecated removed in version 3.0 - */ - public function getAdditional() - { - return $this->additional; - } - - /** - * @param Media $media - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function addMedia(Media $media) - { - $this->medias->append($media); - - return $this; - } - - /** - * @return \ArrayIterator - * @deprecated removed in version 3.0 - */ - public function getMedias() - { - return $this->medias; - } - - /** - * @param CategoryInInterface $category - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function addCategory(CategoryInInterface $category) - { - $this->categories[] = $category; - - return $this; - } - - /** - * @return Category[] - * @deprecated removed in version 3.0 - */ - public function getCategories() - { - return $this->categories; - } -} diff --git a/Protocol/Parser/Media.php b/Protocol/Parser/Media.php deleted file mode 100644 index 0dab627..0000000 --- a/Protocol/Parser/Media.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -/** - * class Media. - * @deprecated removed in version 3.0 - */ -class Media -{ - /** - * @var string - */ - protected $type; - - /** - * @var string - */ - protected $url; - - /** - * @var int - */ - protected $length; - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getType() - { - return $this->type; - } - - /** - * @param string $type - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function setType($type) - { - $this->type = $type; - - return $this; - } - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function setUrl($url) - { - $this->url = $url; - - return $this; - } - - /** - * @return string - * @deprecated removed in version 3.0 - */ - public function getLength() - { - return $this->length; - } - - /** - * @param string $length - * - * @return $this - * @deprecated removed in version 3.0 - */ - public function setLength($length) - { - $this->length = intval($length); - - return $this; - } -} diff --git a/Protocol/Parser/RdfParser.php b/Protocol/Parser/RdfParser.php deleted file mode 100644 index e848476..0000000 --- a/Protocol/Parser/RdfParser.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\FeedInInterface; -use Debril\RssAtomBundle\Protocol\FeedInterface; -use Debril\RssAtomBundle\Protocol\ItemInInterface; -use Debril\RssAtomBundle\Protocol\Parser; -use SimpleXMLElement; - -/** - * Class RdfParser. - * @deprecated removed in version 3.0 - */ -class RdfParser extends Parser -{ - protected $mandatoryFields = array( - 'channel', - ); - - /** - * - * @deprecated removed in version 3.0 - */ - public function __construct() - { - $this->setdateFormats(array(\DateTime::W3C, 'Y-m-d')); - } - - /** - * @param SimpleXMLElement $xmlBody - * - * @return bool - * @deprecated removed in version 3.0 - */ - public function canHandle(SimpleXMLElement $xmlBody) - { - return 'rdf' === strtolower($xmlBody->getName()); - } - - /** - * @param SimpleXMLElement $xmlBody - * @param FeedInterface $feed - * @param array $filters - * - * @return FeedInInterface - */ - protected function parseBody(SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters) - { - $feed->setPublicId($xmlBody->channel->link); - $feed->setLink($xmlBody->channel->link); - $feed->setTitle($xmlBody->channel->title); - $feed->setDescription($xmlBody->channel->description); - - if (isset($xmlBody->channel->date)) { - $date = $xmlBody->channel->children('dc', true); - $updated = static::convertToDateTime($date[0], $this->guessDateFormat($date[0])); - $feed->setLastModified($updated); - } - - $format = null; - foreach ($xmlBody->item as $xmlElement) { - $item = $this->newItem(); - $date = $xmlElement->children('dc', true); - $format = !is_null($format) ? $format : $this->guessDateFormat($date[0]); - - $item->setTitle($xmlElement->title) - ->setDescription($xmlElement->description) - ->setUpdated(static::convertToDateTime($date[0], $format)) - ->setLink($xmlElement->link); - - $this->addValidItem($feed, $item, $filters); - } - - return $feed; - } - - /** - * RDF format doesn't support enclosures. - * - * @param SimpleXMLElement $element - * @param ItemInInterface $item - * - * @return $this - */ - protected function handleEnclosure(SimpleXMLElement $element, ItemInInterface $item) - { - return $this; - } -} diff --git a/Protocol/Parser/RssParser.php b/Protocol/Parser/RssParser.php deleted file mode 100644 index 1c90af7..0000000 --- a/Protocol/Parser/RssParser.php +++ /dev/null @@ -1,224 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\FeedInterface; -use Debril\RssAtomBundle\Protocol\ItemInInterface; -use Debril\RssAtomBundle\Protocol\Parser; -use SimpleXMLElement; - -/** - * Class RssParser. - * @deprecated removed in version 3.0 - */ -class RssParser extends Parser -{ - protected $mandatoryFields = array( - 'channel', - ); - - /** - * - * @deprecated removed in version 3.0 - */ - public function __construct() - { - $this->setdateFormats(array(\DateTime::RSS)); - } - - /** - * @param SimpleXMLElement $xmlBody - * - * @return bool - * @deprecated removed in version 3.0 - */ - public function canHandle(SimpleXMLElement $xmlBody) - { - return 'rss' === strtolower($xmlBody->getName()); - } - - /** - * @param SimpleXMLElement $xmlBody - * @param FeedInterface $feed - * @param array $filters - * - * @return FeedInterface - */ - protected function parseBody(SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters) - { - $namespaces = $xmlBody->getNamespaces(true); - - $feed->setPublicId($xmlBody->channel->link); - $feed->setLink($xmlBody->channel->link); - $feed->setTitle($xmlBody->channel->title); - $feed->setDescription($xmlBody->channel->description); - - $latest = new \DateTime('@0'); - $date = new \DateTime('now'); - foreach ($xmlBody->channel->item as $xmlElement) { - $item = $this->newItem(); - - if (isset($xmlElement->pubDate)) { - $readDate = trim($xmlElement->pubDate); - - $format = isset($format) ? $format : $this->guessDateFormat($readDate); - $date = static::convertToDateTime($readDate, $format); - } - - $item->setTitle($xmlElement->title) - ->setDescription($xmlElement->description) - ->setPublicId($xmlElement->guid) - ->setUpdated($date) - ->setLink($xmlElement->link) - ->setComment($xmlElement->comments); - - if ($date > $latest) { - $latest = $date; - } - - $this->parseCategories($xmlElement, $item); - - $this->handleAuthor($xmlElement, $item); - $this->handleDescription($xmlElement, $item); - - $item->setAdditional($this->getAdditionalNamespacesElements($xmlElement, $namespaces)); - - $this->handleEnclosure($xmlElement, $item); - $this->handleMediaExtension($xmlElement, $item); - - $this->addValidItem($feed, $item, $filters); - } - - $this->detectAndSetLastModified($xmlBody, $feed, $latest); - - return $feed; - } - - /** - * @param SimpleXMLElement $xmlBody - * @param FeedInterface $feed - * @param $latestItemDate - */ - protected function detectAndSetLastModified(SimpleXMLElement $xmlBody, FeedInterface $feed, $latestItemDate) - { - if (isset($xmlBody->channel->lastBuildDate)) { - $this->setLastModified($feed, $xmlBody->channel->lastBuildDate); - } elseif (isset($xmlBody->channel->pubDate)) { - $this->setLastModified($feed, $xmlBody->channel->pubDate); - } else { - $feed->setLastModified($latestItemDate); - } - } - - /** - * @param FeedInterface $feed - * @param string $rssDate - */ - protected function setLastModified(FeedInterface $feed, $rssDate) - { - $format = $this->guessDateFormat($rssDate); - $updated = static::convertToDateTime($rssDate, $format); - $feed->setLastModified($updated); - } - - /** - * Handles enclosures if any. - * - * @param SimpleXMLElement $element - * @param ItemInInterface $item - * - * @return $this - */ - protected function handleEnclosure(SimpleXMLElement $element, ItemInInterface $item) - { - if (isset($element->enclosure)) { - foreach ($element->enclosure as $enclosure) { - $media = $this->createMedia($enclosure); - $item->addMedia($media); - } - } - - return $this; - } - - /** - * According to RSS specs, either we can have a summary in description ; - * full content in description ; or a summary in description AND full content in content:encoded - * - * @param SimpleXMLElement $xmlElement - * @param ItemInInterface $item - */ - protected function handleDescription(SimpleXMLElement $xmlElement, ItemInInterface $item) - { - $contentChild = $xmlElement->children('http://purl.org/rss/1.0/modules/content/'); - - if (isset($contentChild->encoded)) { - $item->setDescription($contentChild->encoded); - $item->setSummary($xmlElement->description); - } else { - $item->setDescription($xmlElement->description); - } - } - - /** - * Parse elements from Yahoo RSS Media extension - * - * @param SimpleXMLElement $xmlElement - * @param ItemInInterface $item with Media added - */ - protected function handleMediaExtension(SimpleXMLElement $xmlElement, ItemInInterface $item) - { - foreach ($xmlElement->children('http://search.yahoo.com/mrss/') as $xmlMedia) { - $media = new Media(); - $media->setUrl($this->getAttributeValue($xmlMedia, 'url')) - ->setType($this->searchAttributeValue($xmlMedia, array('type', 'medium'))) - ->setLength($this->getAttributeValue($xmlMedia, 'fileSize')) - ; - - $item->addMedia($media); - } - } - - /** - * Parse category elements. - * We may have more than one. - * - * @param SimpleXMLElement $element - * @param ItemInInterface $item - */ - protected function parseCategories(SimpleXMLElement $element, ItemInInterface $item) - { - foreach ($element->category as $xmlCategory) { - $category = new Category(); - $category->setName((string) $xmlCategory); - - $item->addCategory($category); - } - } - - /** - * Parse author: - * first we look at optional dc:creator, which is the author name - * if no, we fallback to the RSS author element which is the author email - * - * @param SimpleXMLElement $element - * @param ItemInInterface $item - */ - protected function handleAuthor(SimpleXMLElement $element, ItemInInterface $item) - { - $dcChild = $element->children('http://purl.org/dc/elements/1.1/'); - - if (isset($dcChild->creator)) { - $item->setAuthor((string) $dcChild->creator); - } else { - $item->setAuthor((string) $element->author); - } - } -} diff --git a/Protocol/Parser/XmlParser.php b/Protocol/Parser/XmlParser.php deleted file mode 100644 index f6aeb80..0000000 --- a/Protocol/Parser/XmlParser.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -/** - * Rss/Atom Bundle for Symfony. - * - * - * @license http://opensource.org/licenses/lgpl-3.0.html LGPL - * @copyright (c) 2013, Alexandre Debril - */ -namespace Debril\RssAtomBundle\Protocol\Parser; - -/** - * Class XmlParser - * - * @deprecated removed in version 3.0 - */ -class XmlParser -{ - /** - * Parse a string and return an XML element - * Pretty much a no-op there, but you may want top override it ti add more - * - * @param string $xmlString - * @return \SimpleXMLElement - * @deprecated removed in version 3.0 - */ - public function parseString($xmlString) - { - return new \SimpleXMLElement($xmlString); - } -} diff --git a/Provider/DoctrineFeedContentProvider.php b/Provider/DoctrineFeedContentProvider.php index 0996ec4..a308c4f 100644 --- a/Provider/DoctrineFeedContentProvider.php +++ b/Provider/DoctrineFeedContentProvider.php @@ -9,7 +9,7 @@ */ namespace Debril\RssAtomBundle\Provider; -use Debril\RssAtomBundle\Protocol\FeedOutInterface; +use FeedIo\FeedInterface; use Doctrine\Bundle\DoctrineBundle\Registry; use Debril\RssAtomBundle\Exception\FeedException\FeedNotFoundException; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -64,7 +64,7 @@ public function setRepositoryName($repositoryName) /** * @param array $options * - * @return FeedOutInterface + * @return FeedInterface * * @throws FeedNotFoundException */ @@ -76,8 +76,8 @@ public function getFeedContent(array $options) ->getRepository($this->getRepositoryName()) ->findOneById($this->getIdFromOptions($options)); - // if the feed is an actual FeedOutInterface instance, then return it - if ($feed instanceof FeedOutInterface) { + // if the feed is an actual FeedInterface instance, then return it + if ($feed instanceof FeedInterface) { return $feed; } diff --git a/Provider/FeedContentProviderInterface.php b/Provider/FeedContentProviderInterface.php index 93d3321..4b0bbda 100644 --- a/Provider/FeedContentProviderInterface.php +++ b/Provider/FeedContentProviderInterface.php @@ -12,7 +12,7 @@ namespace Debril\RssAtomBundle\Provider; use Debril\RssAtomBundle\Exception\FeedException\FeedNotFoundException; -use Debril\RssAtomBundle\Protocol\FeedOutInterface; +use FeedIo\FeedInterface; /** * Interface FeedContentProviderInterface. @@ -24,7 +24,7 @@ interface FeedContentProviderInterface * * @throws FeedNotFoundException * - * @return FeedOutInterface + * @return FeedInterface */ public function getFeedContent(array $options); } diff --git a/Provider/MockProvider.php b/Provider/MockProvider.php index 4206930..6d135a5 100644 --- a/Provider/MockProvider.php +++ b/Provider/MockProvider.php @@ -29,7 +29,7 @@ class MockProvider implements FeedContentProviderInterface */ public function getFeedContent(array $options) { - $content = new Feed(); + $feed = new Feed(); $id = array_key_exists('id', $options) ? $options['id'] : null; @@ -37,13 +37,22 @@ public function getFeedContent(array $options) throw new FeedNotFoundException(); } - $content->setPublicId($id); + $feed->setPublicId($id); - $content->setTitle('thank you for using RssAtomBundle'); - $content->setDescription('this is the mock FeedContent'); - $content->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/'); - $content->setLastModified(new \DateTime()); + $feed->setTitle('thank you for using RssAtomBundle'); + $feed->setDescription('this is the mock FeedContent'); + $feed->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/'); + $feed->setLastModified(new \DateTime()); + return $this->addItem($feed); + } + + /** + * @param Feed $feed + * @return Feed + */ + protected function addItem(Feed $feed) + { $item = new Item(); $item->setPublicId('1'); @@ -52,8 +61,8 @@ public function getFeedContent(array $options) $item->setDescription('this stream was generated using the MockProvider class'); $item->setLastModified(new \DateTime()); - $content->add($item); + $feed->add($item); - return $content; + return $feed; } } diff --git a/Resources/config/services.xml b/Resources/config/services.xml deleted file mode 100644 index f62674c..0000000 --- a/Resources/config/services.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version="1.0" ?> - -<container xmlns="http://symfony.com/schema/dic/services" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - <parameters> - <parameter key="debril.parser.rss.class">Debril\RssAtomBundle\Protocol\Parser\RssParser</parameter> - <parameter key="debril.parser.xml.class">Debril\RssAtomBundle\Protocol\Parser\XmlParser</parameter> - <parameter key="debril.parser.rdf.class">Debril\RssAtomBundle\Protocol\Parser\RdfParser</parameter> - <parameter key="debril.parser.atom.class">Debril\RssAtomBundle\Protocol\Parser\AtomParser</parameter> - <parameter key="debril.parser.factory.class">Debril\RssAtomBundle\Protocol\Parser\Factory</parameter> - <parameter key="debril.parser.feed.class">Debril\RssAtomBundle\Protocol\Parser\FeedContent</parameter> - <parameter key="debril.parser.item.class">Debril\RssAtomBundle\Protocol\Parser\Item</parameter> - <parameter key="debril.reader.class">Debril\RssAtomBundle\Protocol\FeedReader</parameter> - <parameter key="debril.formatter.rss.class">Debril\RssAtomBundle\Protocol\Formatter\FeedRssFormatter</parameter> - <parameter key="debril.formatter.atom.class">Debril\RssAtomBundle\Protocol\Formatter\FeedAtomFormatter</parameter> - <parameter key="debril.http.curl.class">Debril\RssAtomBundle\Driver\HttpCurlDriver</parameter> - <parameter key="debril.http.guzzle_bridge.class">Debril\RssAtomBundle\Driver\GuzzleBridgeDriver</parameter> - <parameter key="debril.file.class">Debril\RssAtomBundle\Driver\FileDriver</parameter> - <parameter key="guzzle.client.class">GuzzleHttp\Client</parameter> - <parameter key="feedio.client.class">FeedIo\Adapter\Guzzle\Client</parameter> - <parameter key="feedio.class">FeedIo\FeedIo</parameter> - <parameter key="debril.provider.mock.class">Debril\RssAtomBundle\Provider\MockProvider</parameter> - <parameter key="debril.provider.default.class">Debril\RssAtomBundle\Provider\MockProvider</parameter> - <parameter key="debril.provider.doctrine.class">Debril\RssAtomBundle\Provider\DoctrineFeedContentProvider</parameter> - </parameters> - <services> - <service id="debril.parser.rss" class="%debril.parser.rss.class%"> - <call method="setDateFormats"> - <argument>%debril_rss_atom.date_formats%</argument> - </call> - </service> - <service id="debril.parser.rdf" class="%debril.parser.rdf.class%"> - <call method="setDateFormats"> - <argument>%debril_rss_atom.date_formats%</argument> - </call> - </service> - <service id="debril.parser.atom" class="%debril.parser.atom.class%"> - <call method="setDateFormats"> - <argument>%debril_rss_atom.date_formats%</argument> - </call> - </service> - - <service id="debril.parser.xml" class="%debril.parser.xml.class%" /> - - <service id="debril.http.curl" class="%debril.http.curl.class%"> - <argument>%debril_rss_atom.curlopt%</argument> - </service> - <service id="debril.http.guzzle_bridge" class="%debril.http.guzzle_bridge.class%" /> - <service id="debril.file" class="%debril.file.class%" /> - - <service id="debril.parser.factory" class="%debril.parser.factory.class%"> - <call method="setFeedClass"> - <argument>%debril.parser.feed.class%</argument> - </call> - <call method="setItemClass"> - <argument>%debril.parser.item.class%</argument> - </call> - </service> - - <service id="debril.reader" class="%debril.reader.class%"> - <argument type="service" id="debril.http.curl"/><!-- ID may be changed by Extension --> - <argument type="service" id="debril.parser.factory"/> - <argument type="service" id="debril.parser.xml"/> - <call method="addParser"> - <argument type="service" id="debril.parser.rss" /> - </call> - <call method="addParser"> - <argument type="service" id="debril.parser.rdf" /> - </call> - <call method="addParser"> - <argument type="service" id="debril.parser.atom" /> - </call> - </service> - - <service id="guzzle.client" class="%guzzle.client.class%" /> - - <service id="feedio.client" class="%feedio.client.class%"> - <argument type="service" id="guzzle.client"/> - </service> - - <service id="feedio" class="%feedio.class%"> - <argument type="service" id="feedio.client"/> - <argument type="service" id="logger"/> - </service> - - <service id="debril.formatter.atom" class="%debril.formatter.atom.class%" /> - <service id="debril.formatter.rss" class="%debril.formatter.rss.class%" /> - - <service id="debril.provider.default" class="%debril.provider.default.class%" /> - <service id="debril.provider.mock" class="%debril.provider.mock.class%" /> - - </services> -</container> diff --git a/Resources/config/services.yml b/Resources/config/services.yml new file mode 100644 index 0000000..1ec3410 --- /dev/null +++ b/Resources/config/services.yml @@ -0,0 +1,22 @@ +parameters: + debril.provider.mock.class: Debril\RssAtomBundle\Provider\MockProvider + debril.provider.default.class: Debril\RssAtomBundle\Provider\MockProvider + debril.provider.doctrine.class: Debril\RssAtomBundle\Provider\DoctrineFeedContentProvider + +services: + guzzle.client: + class: GuzzleHttp\Client + + feedio.client: + class: FeedIo\Adapter\Guzzle\Client + arguments: ["@guzzle.client"] + + feedio: + class: FeedIo\FeedIo + arguments: ["@feedio.client", "@logger"] + + debril.provider.default: + class: %debril.provider.default.class% + + debril.provider.mock: + class: %debril.provider.mock.class% diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000..fe04af2 --- /dev/null +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,17 @@ +<?php + +namespace Debril\RssAtomBundle\DependencyInjection; + +class ConfigurationTest extends \PHPUnit_Framework_TestCase +{ + + public function testGetConfigTreeBuilder() + { + $configuration = new Configuration(); + + $tree = $configuration->getConfigTreeBuilder(); + + $this->assertInstanceOf('\Symfony\Component\Config\Definition\Builder\TreeBuilder', $tree); + } + +} \ No newline at end of file diff --git a/Tests/Driver/FileDriverTest.php b/Tests/Driver/FileDriverTest.php deleted file mode 100644 index 590cdbf..0000000 --- a/Tests/Driver/FileDriverTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Driver; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-26 at 00:32:41. - */ -class FileDriverTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var FileDriver - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new FileDriver(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Driver\FileDriver::getResponse - * - * @todo Implement testGetResponse(). - * @expectedException \Debril\RssAtomBundle\Exception\DriverUnreachableResourceException - */ - public function testGetResponseException() - { - $url = dirname(__FILE__).'/../../Resources/dummy.rss'; - - $this->object->getResponse($url, new \DateTime()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\FileDriver::getResponse - * - * @todo Implement testGetResponse(). - */ - public function testGetResponse() - { - $url = dirname(__FILE__).'/../../Resources/sample-rss.xml'; - - $response = $this->object->getResponse($url, new \DateTime()); - - $this->assertTrue($response instanceof HttpDriverResponse); - - $this->assertInternalType('string', $response->getBody()); - $this->assertGreaterThan(0, strlen($response->getBody())); - } -} diff --git a/Tests/Driver/HttpCurlDriverTest.php b/Tests/Driver/HttpCurlDriverTest.php deleted file mode 100644 index eebd39b..0000000 --- a/Tests/Driver/HttpCurlDriverTest.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Driver; - -use Debril\RssAtomBundle\Exception\DriverUnreachableResourceException; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-06 at 23:48:53. - */ -class HttpCurlDriverTest extends \PHPUnit_Framework_TestCase -{ - const URL = 'https://raw.githubusercontent.com/alexdebril/rss-atom-bundle/master/Resources/sample-atom.xml'; - - /** - * @var HttpCurlDriver - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new HttpCurlDriver(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpCurlDriver::getResponse - */ - public function testGetResponse() - { - $date = \DateTime::createFromFormat('j-M-Y', '10-Feb-2002'); - try { - $response = $this->object->getResponse(self::URL, $date); - - $this->assertInstanceOf('Debril\RssAtomBundle\Driver\HttpDriverResponse', $response); - $this->assertInternalType('integer', $response->getHttpCode()); - - $this->assertInternalType('string', $response->getBody()); - $this->assertGreaterThan(0, strlen($response->getBody())); - } catch (DriverUnreachableResourceException $e) { - $this->markTestIncomplete( - 'This test cannot be run.' - ); - } - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpCurlDriver::getResponse - * @expectedException \Debril\RssAtomBundle\Exception\DriverUnreachableResourceException - */ - public function testGetResponseException() - { - $date = \DateTime::createFromFormat('j-M-Y', '10-Feb-2002'); - $this->object->getResponse('http://idonotexist', $date); - } - - public function testGetHttpResponse() - { - $headers = file_get_contents(dirname(__FILE__).'/../../Resources/tests/curl-200-headers.txt'); - $body = file_get_contents(dirname(__FILE__).'/../../Resources/sample-atom.xml'); - - $response = $this->object->getHttpResponse($headers, $body); - - $this->assertInstanceOf('\Debril\RssAtomBundle\Driver\HttpDriverResponse', $response); - } -} diff --git a/Tests/Driver/HttpDriverResponseTest.php b/Tests/Driver/HttpDriverResponseTest.php deleted file mode 100644 index 8871ec0..0000000 --- a/Tests/Driver/HttpDriverResponseTest.php +++ /dev/null @@ -1,132 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Driver; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-25 at 23:47:50. - */ -class HttpDriverResponseTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var HttpDriverResponse - */ - protected $object; - - /** - * @var array - */ - protected $headers = array(); - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new HttpDriverResponse(); - - $lastModified = new \DateTime(); - $this->headers = array( - 'Last-Modified' => $lastModified->format(\DateTime::RFC2822), - ); - - $this->object->setHeaders($this->headers); - - $this->object->setBody('a long string ...'); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::getHeaders - */ - public function testGetHeaders() - { - $this->assertInternalType(('array'), $this->object->getHeaders()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::setHeaders - */ - public function testSetHeaders() - { - $this->headers['Content-Type'] = 'Content-Type: text/html; charset=utf-8'; - - $this->object->setHeaders($this->headers); - - $this->assertEquals($this->headers, $this->object->getHeaders()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::getBody - * - * @todo Implement testGetBody(). - */ - public function testGetBody() - { - $this->assertInternalType('string', $this->object->getBody()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::setBody - */ - public function testSetBody() - { - $string = 'Lorem Ipsum, some long text'; - $this->object->setBody($string); - - $this->assertEquals($string, $this->object->getBody()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::setHttpCode - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::getHttpCode - */ - public function testSetHttpCode() - { - $this->object->setHttpCode(200); - - $this->assertEquals(200, $this->object->getHttpCode()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::getHttpCodeIsOk - */ - public function testGetHttpCodeIsOk() - { - $this->object->setHttpCode(200); - - $this->assertEquals(true, $this->object->getHttpCodeIsOk()); - - $this->object->setHttpCode(404); - - $this->assertEquals(false, $this->object->getHttpCodeIsOk()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::getHttpVersion - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::setHttpVersion - */ - public function testGetHttpVersion() - { - $this->object->setHttpVersion('1.1'); - $this->assertEquals('1.1', $this->object->getHttpVersion()); - } - - /** - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::getHttpMessage - * @covers Debril\RssAtomBundle\Driver\HttpDriverResponse::setHttpMessage - */ - public function testGetHttpMessage() - { - $message = 'Request ...'; - $this->object->setHttpmessage($message); - $this->assertEquals($message, $this->object->getHttpMessage()); - } -} diff --git a/Tests/Protocol/FeedReaderTest.php b/Tests/Protocol/FeedReaderTest.php deleted file mode 100644 index ec2f7d4..0000000 --- a/Tests/Protocol/FeedReaderTest.php +++ /dev/null @@ -1,364 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol; - -use Debril\RssAtomBundle\Driver\FileDriver; -use Debril\RssAtomBundle\Protocol\Parser\Factory; -use Debril\RssAtomBundle\Protocol\Filter\ModifiedSince; -use Debril\RssAtomBundle\Driver\HttpDriverResponse; -use Debril\RssAtomBundle\Protocol\Parser\XmlParser; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-27 at 00:18:14. - */ -class FeedReaderTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var FeedReader - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new FeedReader(new FileDriver(), new Factory(), new XmlParser()); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::__construct - */ - public function testConstruct() - { - $reader = new FeedReader(new FileDriver(), new Factory(), new XmlParser()); - - $this->assertAttributeInstanceOf('\Debril\RssAtomBundle\Driver\FileDriver', 'driver', $reader); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::addParser - */ - public function testAddParser() - { - $parser = new Parser\AtomParser(); - $this->object->addParser($parser); - - $this->assertAttributeEquals(array($parser), 'parsers', $this->object); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::getDriver - * - * @todo Implement testGetDriver(). - */ - public function testGetDriver() - { - $this->assertInstanceOf( - '\Debril\RssAtomBundle\Driver\HttpDriverInterface', - $this->object->getDriver() - ); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::getFeedContent - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testGetFeedContentException() - { - $url = dirname(__FILE__).'/../../Resources/sample-rss.xml'; - - $this->object->getFeedContent($url, new \DateTime()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::readFeed - * @dataProvider getRssInputs - */ - public function testReadFeed($url, \DateTime $date) - { - $feed = $this->object - ->addParser(new Parser\RssParser()) - ->readFeed($url, new Parser\FeedContent(), $date); - - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::getFeedContent - * @dataProvider getRssInputs - */ - public function testGetRssFeedContent($url, \DateTime $date) - { - $this->object->addParser(new Parser\RssParser()); - $this->validateFeed($this->object->getFeedContent($url, $date)); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::getFeedContent - */ - public function testGetAtomFeedContent() - { - $url = dirname(__FILE__).'/../../Resources/sample-atom.xml'; - $this->object->addParser(new Parser\AtomParser()); - $date = \DateTime::createFromFormat('Y-m-d', '2002-10-10'); - - $this->validateFeed($this->object->getFeedContent($url, $date)); - } - - /** - * @param FeedInInterface $feed - */ - protected function validateFeed(FeedInInterface $feed) - { - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - - $item = current($feed->getItems()); - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\ItemInInterface', $item); - - $this->assertNotNull($item->getPublicId()); - $this->assertNotNull($item->getLink()); - $this->assertNotNull($item->getTitle()); - $this->assertNotNull($item->getDescription()); - $this->assertInstanceOf('\DateTime', $item->getUpdated()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::getResponse - */ - public function testGetResponse() - { - $url = dirname(__FILE__).'/../../Resources/sample-atom.xml'; - $this->object->addParser(new Parser\AtomParser()); - $response = $this->object->getResponse($url, new \DateTime()); - - $this->assertInstanceOf('Debril\RssAtomBundle\Driver\HttpDriverResponse', $response); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - */ - public function testAdditionalNamespacedElements() - { - $url = dirname(__FILE__).'/../../Resources/sample-atom-namespaced.xml'; - $this->object->addParser(new Parser\AtomParser()); - $response = $this->object->getResponse($url, new \DateTime()); - $feed = $this->object->parseBody($response, new Parser\FeedContent()); - $items = $feed->getItems(); - $additional = $items[0]->getAdditional(); - $this->assertEquals('http://original-link.com/item.html', $additional['feedburner']->origLink); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - */ - public function testRssAdditionalNamespacedElements() - { - $url = dirname(__FILE__).'/../../Resources/sample-rss-media.xml'; - $this->object->addParser(new Parser\RssParser()); - $response = $this->object->getResponse($url, new \DateTime()); - $feed = $this->object->parseBody($response, new Parser\FeedContent()); - $items = $feed->getItems(); - $additional = $items[0]->getAdditional(); - $this->assertEquals('Marc', $additional['dc']); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - */ - public function testRssYahooMediaExtension() - { - $url = dirname(__FILE__).'/../../Resources/sample-rss-media.xml'; - $this->object->addParser(new Parser\RssParser()); - $response = $this->object->getResponse($url, new \DateTime()); - $feed = $this->object->parseBody($response, new Parser\FeedContent()); - $items = $feed->getItems(); - $media = $items[0]->getMedias(); - $this->assertEquals('http://media-server.com/image.jpg', $media[0]->getUrl()); - } - - /** - * issue #98 - */ - public function testCallsInLoop() - { - $urls = array( - dirname(__FILE__).'/../../Resources/sample-rss-media.xml', - dirname(__FILE__).'/../../Resources/sample-atom.xml', - ); - $this->object->addParser(new Parser\RssParser()); - $this->object->addParser(new Parser\AtomParser()); - - $count = 0; - foreach( $urls as $url ) { - $feed = $this->object->getFeedContent($url, new \DateTime('@0')); - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - $items = $feed->getItems(); - $this->assertTrue(1 <= count($items)); - $count++; - } - - $this->assertEquals(2, $count); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - */ - public function testParseBody() - { - $url = dirname(__FILE__).'/../../Resources/sample-rss.xml'; - $this->object->addParser(new Parser\RssParser()); - - $date = new \DateTime(); - $response = $this->object->getResponse($url, $date); - - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parseBody($response, new Parser\FeedContent(), $filters); - - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::getAccurateParser - */ - public function testGetAccurateParser() - { - $this->object->addParser(new Parser\RssParser()); - $this->object->addParser(new Parser\RdfParser()); - $this->object->addParser(new Parser\AtomParser()); - - $url = dirname(__FILE__).'/../../Resources/sample-rdf.xml'; - - $rdfBody = $this->object->getResponse($url, new \DateTime())->getBody(); - - $this->assertInstanceOf( - 'Debril\RssAtomBundle\Protocol\Parser\RdfParser', - $this->object->getAccurateParser(new \SimpleXMLElement($rdfBody)) - ); - - $url = dirname(__FILE__).'/../../Resources/sample-rss.xml'; - - $rssBody = $this->object->getResponse($url, new \DateTime())->getBody(); - - $this->assertInstanceOf( - 'Debril\RssAtomBundle\Protocol\Parser\RssParser', - $this->object->getAccurateParser(new \SimpleXMLElement($rssBody)) - ); - - $url = dirname(__FILE__).'/../../Resources/sample-atom.xml'; - - $atomBody = $this->object->getResponse($url, new \DateTime())->getBody(); - - $this->assertInstanceOf( - "Debril\RssAtomBundle\Protocol\Parser\AtomParser", - $this->object->getAccurateParser(new \SimpleXMLElement($atomBody)) - ); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::getAccurateParser - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testGetAccurateParserException() - { - $url = dirname(__FILE__).'/../../Resources/sample-rss.xml'; - $rssBody = $this->object->getResponse($url, new \DateTime())->getBody(); - $this->object->getAccurateParser(new \SimpleXMLElement($rssBody)); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - * @expectedException \Debril\RssAtomBundle\Exception\FeedException\FeedNotModifiedException - */ - public function testParseBody304() - { - $reader = new FeedReader($this->getMockDriver(304), new Factory(), new XmlParser()); - - $reader->getFeedContent('http://afakeurl', new \DateTime()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - * @expectedException \Debril\RssAtomBundle\Exception\FeedException\FeedNotFoundException - */ - public function testParseBody404() - { - $reader = new FeedReader($this->getMockDriver(404), new Factory(), new XmlParser()); - - $reader->getFeedContent('http://afakeurl', new \DateTime()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - * @expectedException \Debril\RssAtomBundle\Exception\FeedException\FeedServerErrorException - */ - public function testParseBody500() - { - $reader = new FeedReader($this->getMockDriver(500), new Factory(), new XmlParser()); - - $reader->getFeedContent('http://afakeurl', new \DateTime()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - * @expectedException \Debril\RssAtomBundle\Exception\FeedException\FeedForbiddenException - */ - public function testParseBody403() - { - $reader = new FeedReader($this->getMockDriver(403), new Factory(), new XmlParser()); - - $reader->getFeedContent('http://afakeurl', new \DateTime()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedReader::parseBody - * @expectedException \Debril\RssAtomBundle\Exception\FeedException\FeedCannotBeReadException - */ - public function testParseBodyUnknownError() - { - $reader = new FeedReader($this->getMockDriver(666), new Factory(), new XmlParser()); - - $reader->getFeedContent('http://afakeurl', new \DateTime()); - } - - /** - * @param $responseHttpCode - * - * @return \Debril\RssAtomBundle\Driver\HttpCurlDriver a mocked instance - */ - public function getMockDriver($responseHttpCode) - { - $mock = $this->createMock('\Debril\RssAtomBundle\Driver\HttpCurlDriver'); - - $response = new HttpDriverResponse(); - $response->setHttpCode($responseHttpCode); - - $mock->expects($this->any()) - ->method('getResponse') - ->will($this->returnValue($response)); - - return $mock; - } - - /** - * @return array - */ - public function getRssInputs() - { - return array( - array( - dirname(__FILE__).'/../../Resources/sample-rss.xml', - \DateTime::createFromFormat('Y-m-d', '2005-10-10'), - ), - ); - } -} diff --git a/Tests/Protocol/Filter/LimitTest.php b/Tests/Protocol/Filter/LimitTest.php deleted file mode 100644 index e8341a3..0000000 --- a/Tests/Protocol/Filter/LimitTest.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Filter; - -use Debril\RssAtomBundle\Protocol\Parser\Item; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-02-12 at 23:05:01. - */ -class LimitTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var Limit - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new Limit(2); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Filter\Limit::isValid - * - * @todo Implement testIsValid(). - */ - public function testIsValid() - { - $item = new Item(); - $this->assertTrue($this->object->isValid($item), 'First one is valid'); - $this->assertTrue($this->object->isValid($item), 'Second one is valid'); - $this->assertFalse($this->object->isValid($item), 'Third one is not valid'); - } -} diff --git a/Tests/Protocol/Filter/ModifiedSinceTest.php b/Tests/Protocol/Filter/ModifiedSinceTest.php deleted file mode 100644 index 18cfa09..0000000 --- a/Tests/Protocol/Filter/ModifiedSinceTest.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Filter; - -use Debril\RssAtomBundle\Protocol\Parser\Item; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-02-12 at 22:48:55. - */ -class ModifiedSinceTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var ModifiedSince - */ - protected $object; - - /** - * @var DateTime - */ - protected $date; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->date = new \DateTime(); - $this->object = new ModifiedSince($this->date); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Filter\ModifiedSince::getDate - * - * @todo Implement testGetDate(). - */ - public function testGetDate() - { - $this->assertInstanceOf('\DateTime', $this->object->getDate()); - $this->assertEquals($this->date, $this->object->getDate()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Filter\ModifiedSince::isValid - * - * @todo Implement testIsValid(). - */ - public function testIsValid() - { - $item = new Item(); - - $date = clone $this->date; - $this->assertFalse($this->object->isValid($item), 'Item must not be valid if no date is specified'); - $item->setUpdated($date->sub(new \DateInterval('P1D'))); - $this->assertFalse($this->object->isValid($item), 'Item must not be valid if its date is prior to modifiedSince'); - $item->setUpdated($date->add(new \DateInterval('P2D'))); - $this->assertTrue($this->object->isValid($item), 'Item must be valid if its date is after modifiedSince'); - } -} diff --git a/Tests/Protocol/Formatter/FeedAtomFormatterTest.php b/Tests/Protocol/Formatter/FeedAtomFormatterTest.php deleted file mode 100644 index a99cc1a..0000000 --- a/Tests/Protocol/Formatter/FeedAtomFormatterTest.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Formatter; - -use Debril\RssAtomBundle\Tests\Protocol\FormatterAbstract; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-12 at 21:51:18. - */ -class FeedAtomFormatterTest extends FormatterAbstract -{ - /** - * @var FeedAtomFormatter - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - parent::setUp(); - $this->object = new FeedAtomFormatter(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedAtomFormatter::toString - */ - public function testToString() - { - $string = $this->object->toString($this->feed); - - $this->assertInternalType('string', $string); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedAtomFormatter::toDom - */ - public function testToDom() - { - $element = $this->object->toDom($this->feed); - - $this->assertInstanceOf('\DomDocument', $element); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedAtomFormatter::getRootElement - */ - public function testGetRootElement() - { - $element = $this->object->getRootElement(); - - $this->assertInstanceOf('\DomDocument', $element); - $this->assertEquals('feed', $element->firstChild->nodeName); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedAtomFormatter::setMetas - */ - public function testSetMetas() - { - $element = $this->object->getRootElement(); - - $this->object->setMetas($element, $this->feed); - $this->assertInstanceOf('\DomDocument', $element); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedAtomFormatter::setEntries - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedAtomFormatter::addEntry - */ - public function testSetEntries() - { - $this->_testSetEntries($this->object); - } -} diff --git a/Tests/Protocol/Formatter/FeedRssFormatterTest.php b/Tests/Protocol/Formatter/FeedRssFormatterTest.php deleted file mode 100644 index c40d12a..0000000 --- a/Tests/Protocol/Formatter/FeedRssFormatterTest.php +++ /dev/null @@ -1,86 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Formatter; - -use Debril\RssAtomBundle\Tests\Protocol\FormatterAbstract; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-12 at 21:51:18. - */ -class FeedRssFormatterTest extends FormatterAbstract -{ - /** - * @var FeedRssFormatter - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - parent::setUp(); - - $this->object = new FeedRssFormatter(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\FeedFormatter::toString - */ - public function testToString() - { - $string = $this->object->toString($this->feed); - - $this->assertInternalType('string', $string); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedRssFormatter::toDom - */ - public function testToDom() - { - $element = $this->object->toDom($this->feed); - - $this->assertInstanceOf('\DomDocument', $element); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedRssFormatter::getRootElement - */ - public function testGetRootElement() - { - $element = $this->object->getRootElement(); - - $this->assertInstanceOf('\DomDocument', $element); - $this->assertEquals('rss', $element->firstChild->nodeName); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedRssFormatter::setMetas - */ - public function testSetMetas() - { - $element = $this->object->getRootElement(); - - $this->object->setMetas($element, $this->feed); - $this->assertInstanceOf('\DomDocument', $element); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedRssFormatter::setEntries - * @covers Debril\RssAtomBundle\Protocol\Formatter\FeedRssFormatter::addEntry - */ - public function testSetEntries() - { - $this->_testSetEntries($this->object); - } -} diff --git a/Tests/Protocol/FormatterAbstract.php b/Tests/Protocol/FormatterAbstract.php deleted file mode 100644 index c77f2b9..0000000 --- a/Tests/Protocol/FormatterAbstract.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Tests\Protocol; - -use Debril\RssAtomBundle\Protocol\Parser\FeedContent; -use Debril\RssAtomBundle\Protocol\Parser\Item; -use Debril\RssAtomBundle\Protocol\Parser\Media; - -/** - * Class FormatterAbstract. - */ -class FormatterAbstract extends \PHPUnit_Framework_TestCase -{ - /** - * @var FeedContent - */ - protected $feed; - - protected function setUp() - { - $this->feed = new FeedContent(); - - $this->feed->setPublicId('feed id'); - $this->feed->setLink('http://example.com'); - $this->feed->setTitle('feed title'); - $this->feed->setDescription('feed subtitle'); - $this->feed->setLastModified(new \DateTime()); - - $item = new Item(); - $item->setPublicId('item id'); - $item->setLink('http://example.com/1'); - $item->setSummary('lorem ipsum'); - $item->setTitle('title 1'); - $item->setUpdated(new \DateTime()); - $item->setComment('http://linktothecomments.com'); - $item->setAuthor('Contributor'); - - $media = new Media(); - $media->setUrl('http://media'); - $media->setUrl('image/jpeg'); - - $item->addMedia($media); - - $this->feed->addItem($item); - } - - /** - * @param $object - */ - protected function _testSetEntries($object) - { - $element = $object->getRootElement(); - - $object->setEntries($element, $this->feed); - - foreach ($element->childNodes as $entry) { - $this->assertInstanceOf('\DomNode', $entry); - } - } -} diff --git a/Tests/Protocol/Parser/AtomParserTest.php b/Tests/Protocol/Parser/AtomParserTest.php deleted file mode 100644 index 726b039..0000000 --- a/Tests/Protocol/Parser/AtomParserTest.php +++ /dev/null @@ -1,178 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\Filter\ModifiedSince; -use Debril\RssAtomBundle\Tests\Protocol\ParserAbstract; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-27 at 00:26:35. - */ -class AtomParserTest extends ParserAbstract -{ - /** - * @var AtomParser - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new AtomParser(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::parse - * @covers Debril\RssAtomBundle\Protocol\Parser\AtomParser::canHandle - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testCannotHandle() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rss.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $this->assertFalse($this->object->canHandle($xmlBody)); - $filters = array(new ModifiedSince(new \DateTime())); - $this->object->parse($xmlBody, new FeedContent(), $filters); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\AtomParser::canHandle - */ - public function testCanHandle() - { - $file = dirname(__FILE__).'/../../../Resources/sample-atom.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $this->assertTrue($this->object->canHandle($xmlBody)); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\AtomParser::checkBodyStructure - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testParseError() - { - $file = dirname(__FILE__).'/../../../Resources/truncated-atom.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $filters = array(new ModifiedSince(new \DateTime())); - $this->object->parse($xmlBody, new FeedContent(), $filters); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::parse - * @covers Debril\RssAtomBundle\Protocol\Parser\AtomParser::parseBody - * @covers Debril\RssAtomBundle\Protocol\Parser\AtomParser::parseContent - * @covers Debril\RssAtomBundle\Protocol\Parser\AtomParser::detectLink - */ - public function testParse() - { - $file = dirname(__FILE__).'/../../../Resources/sample-atom.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2002-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - - $this->assertNotNull($feed->getPublicId(), 'feed->getId() should not return an empty value'); - $this->assertGreaterThan(0, $feed->getItemsCount()); - $this->assertInstanceOf('\DateTime', $feed->getLastModified()); - $this->assertNotNull($feed->getLink()); - $this->assertInternalType('string', $feed->getLink()); - $this->assertInternalType('string', $feed->getDescription()); - $this->assertInternalType('string', $feed->getTitle()); - $this->assertNotNull($feed->getDescription()); - $this->assertNotNull($feed->getTitle()); - - $item = current($feed->getItems()); - $this->assertInternalType('string', $item->getAuthor()); - $this->assertEquals('John Doe', $item->getAuthor()); - - $medias = $item->getMedias(); - $count = 0; - foreach ($medias as $media) { - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\Parser\Media', $media); - ++$count; - } - - $this->assertEquals(1, $count); - - $categories = $item->getCategories(); - $this->assertCount(2, $categories); - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\Parser\Category', $categories[0]); - $this->assertEquals('Category1', $categories[0]->getName()); - $this->assertEquals('Category2', $categories[1]->getName()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::setDateFormats - * @covers Debril\RssAtomBundle\Protocol\Parser\AtomParser::__construct - * @dataProvider getDefaultFormats - */ - public function testSetDateFormats($default) - { - $this->object->setdateFormats($default); - $this->assertEquals($default, $this->readAttribute($this->object, 'dateFormats')); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::guessDateFormat - * @dataProvider getDefaultFormats - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testGuessDateFormatException($default) - { - $this->object->setdateFormats($default); - - $date = '2003-13T18:30:02Z'; - $this->object->guessDateFormat($date); - } - - /** - * - */ - public function testHtmlContent() - { - $file = dirname(__FILE__).'/../../../Resources/sample-atom-html.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2002-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertInstanceOf("Debril\RssAtomBundle\Protocol\FeedInInterface", $feed); - $item = current($feed->getItems()); - - $this->assertTrue(strlen($item->getDescription()) > 0); - } - - /** - * - */ - public function testHtmlSummary() - { - $file = dirname(__FILE__).'/../../../Resources/sample-atom-summary.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2002-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertInstanceOf("Debril\RssAtomBundle\Protocol\FeedInInterface", $feed); - $item = current($feed->getItems()); - - $expected = '<div xmlns="http://www.w3.org/1999/xhtml"><p>sample text</p></div>'; - $this->assertEquals($expected, $item->getSummary()); - } -} diff --git a/Tests/Protocol/Parser/FactoryTest.php b/Tests/Protocol/Parser/FactoryTest.php deleted file mode 100644 index 630660e..0000000 --- a/Tests/Protocol/Parser/FactoryTest.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Parser; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-27 at 00:26:35. - */ -class FactoryTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var Factory - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new Factory(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Factory::newFeed - */ - public function testNewFeed() - { - $feed = $this->object->newFeed(); - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Factory::newItem - */ - public function testNewItem() - { - $item = $this->object->newItem(); - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\ItemInInterface', $item); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Factory::setFeedClass - */ - public function testSetFeedClass() - { - $this->object->setFeedClass('\Debril\RssAtomBundle\Protocol\Parser\FeedContent'); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Factory::setFeedClass - * @expectedException \Exception - */ - public function testSetFeedClassException() - { - $this->object->setFeedClass('\Debril\RssAtomBundle\Protocol\A\Bad\Name'); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Factory::setItemClass - */ - public function testSetItemClass() - { - $this->object->setItemClass('\Debril\RssAtomBundle\Protocol\Parser\Item'); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Factory::setItemClass - * @expectedException \Exception - */ - public function testSetItemClassException() - { - $this->object->setItemClass('Debril\RssAtomBundle\Protocol\A\Bad\Name'); - } -} diff --git a/Tests/Protocol/Parser/FeedContentTest.php b/Tests/Protocol/Parser/FeedContentTest.php deleted file mode 100644 index d909b87..0000000 --- a/Tests/Protocol/Parser/FeedContentTest.php +++ /dev/null @@ -1,208 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Parser; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-26 at 23:10:14. - */ -class FeedContentTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var FeedContent - */ - protected $object; - - const title = 'feed title'; - const subtitle = 'feed subtitle'; - const id = 'feed id'; - const link = 'http://example.com'; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new FeedContent(); - - $this->object->setPublicId(self::id); - $this->object->setLink(self::link); - $this->object->setTitle(self::title); - $this->object->setDescription(self::subtitle); - $this->object->setLastModified(new \DateTime()); - - for ($i = 0; $i < 5; ++$i) { - $item = new Item(); - $item->setPublicId($i); - $this->object->addItem($item); - } - - $lastModified = new \DateTime(); - - $this->object->setLastModified($lastModified); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getLastModified - * - * @todo Implement testGetLastModified(). - */ - public function testGetLastModified() - { - $this->assertInstanceOf('\DateTime', $this->object->getLastModified()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::setLastModified - * - * @todo Implement testSetLastModified(). - */ - public function testSetLastModified() - { - $lastModified = \DateTime::createFromFormat('j-M-Y', '15-Feb-2013'); - - $this->object->setLastModified($lastModified); - - $this->assertEquals($lastModified, $this->object->getLastModified()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getTitle - * - * @todo Implement testGetTitle(). - */ - public function testGetTitle() - { - $this->assertEquals(self::title, $this->object->getTitle()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::setTitle - * - * @todo Implement testSetTitle(). - */ - public function testSetTitle() - { - $newTitle = 'new Feed Title'; - - $this->object->setTitle($newTitle); - - $this->assertEquals($newTitle, $this->object->getTitle()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getDescription - * - * @todo Implement testgetDescription(). - */ - public function testgetDescription() - { - $this->assertEquals(self::subtitle, $this->object->getDescription()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::setDescription - * - * @todo Implement testsetDescription(). - */ - public function testsetDescription() - { - $newSubTitle = 'new subtitle'; - - $this->object->setDescription($newSubTitle); - - $this->assertEquals($newSubTitle, $this->object->getDescription()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getLink - * - * @todo Implement testGetLink(). - */ - public function testGetLink() - { - $this->assertEquals(self::link, $this->object->getLink()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::setLink - * - * @todo Implement testSetLink(). - */ - public function testSetLink() - { - $newLink = 'http://newlink.com'; - - $this->object->setLink($newLink); - - $this->assertEquals($newLink, $this->object->getLink()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getPublicId - */ - public function testGetPublicId() - { - $this->assertEquals(self::id, $this->object->getPublicId()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::setPublicId - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getPublicId - */ - public function testSetPublicId() - { - $newId = '5'; - - $this->object->setPublicId($newId); - - $this->assertEquals($newId, $this->object->getPublicId()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getItems - * - * @todo Implement testGetItemsCount(). - */ - public function testGetItems() - { - $items = $this->object->getItems(); - $item = current($items); - - $this->assertInternalType('array', $items); - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\ItemInInterface', $item); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::getItemsCount - * - * @todo Implement testGetItemsCount(). - */ - public function testGetItemsCount() - { - $count = count($this->object->getItems()); - - $this->assertEquals($count, $this->object->getItemsCount()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\FeedContent::addItem - */ - public function testAddItem() - { - $count = $this->object->getItemsCount(); - - $ret = $this->object->addItem(new Item()); - - $this->assertInstanceOf("Debril\RssAtomBundle\Protocol\Parser\FeedContent", $ret); - $this->assertEquals($count + 1, $this->object->getItemsCount()); - } -} diff --git a/Tests/Protocol/Parser/ItemTest.php b/Tests/Protocol/Parser/ItemTest.php deleted file mode 100644 index 0b9802e..0000000 --- a/Tests/Protocol/Parser/ItemTest.php +++ /dev/null @@ -1,236 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Parser; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-26 at 23:48:58. - */ -class ItemTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var Item - */ - protected $object; - - const title = 'Hello World'; - const id = 1; - const link = 'http://example.com/rss'; - const summary = 'Lorem Ipsum...'; - const description = 'a description'; - const author = 'Contributor'; - const comments = 'http://linktothecomments.com'; - const contentType = 'text'; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new Item(); - - $this->object->setTitle(self::title); - $this->object->setPublicId(self::id); - $this->object->setLink(self::link); - $this->object->setSummary(self::summary); - $this->object->setUpdated(new \DateTime()); - $this->object->setDescription(self::description); - $this->object->setAuthor(self::author); - $this->object->setComment(self::comments); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getTitle - * - * @todo Implement testGetTitle(). - */ - public function testGetTitle() - { - $this->assertEquals(self::title, $this->object->getTitle()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setTitle - * - * @todo Implement testSetTitle(). - */ - public function testSetTitle() - { - $newTitle = 'A brand new title'; - - $this->object->setTitle($newTitle); - $this->assertEquals($newTitle, $this->object->getTitle()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getSummary - * - * @todo Implement testGetSummary(). - */ - public function testGetSummary() - { - $this->assertEquals(self::summary, $this->object->getSummary()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setSummary - * - * @todo Implement testSetSummary(). - */ - public function testSetSummary() - { - $newSummary = 'a brand new summary'; - - $this->object->setSummary($newSummary); - $this->assertEquals($newSummary, $this->object->getSummary()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getUpdated - * - * @todo Implement testGetUpdated(). - */ - public function testGetUpdated() - { - $this->assertInstanceOf('\DateTime', $this->object->getUpdated()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setUpdated - * - * @todo Implement testSetUpdated(). - */ - public function testSetUpdated() - { - $date = \DateTime::createFromFormat('j-M-Y', '15-Feb-2013'); - - $this->object->setUpdated($date); - - $this->assertEquals($date, $this->object->getUpdated()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getLink - */ - public function testGetLink() - { - $this->assertEquals(self::link, $this->object->getLink()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setLink - */ - public function testSetLink() - { - $newLink = 'http://example.com/atom'; - - $this->object->setLink($newLink); - - $this->assertEquals($newLink, $this->object->getLink()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getDescription - */ - public function testGetDescription() - { - $this->assertEquals(self::description, $this->object->getDescription()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setDescription - */ - public function testSetDescription() - { - $newDescription = 'A brand new description'; - - $this->object->setDescription($newDescription); - - $this->assertEquals($newDescription, $this->object->getDescription()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getAuthor - */ - public function testGetAuthor() - { - $this->assertEquals(self::author, $this->object->getAuthor()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setAuthor - */ - public function testSetAuthor() - { - $newAuthor = 'New Contributor'; - - $this->object->setAuthor($newAuthor); - - $this->assertEquals($newAuthor, $this->object->getAuthor()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getComment - */ - public function testGetComment() - { - $this->assertEquals(self::comments, $this->object->getComment()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setComment - */ - public function testSetComment() - { - $newComment = 'http://newlinktothecomments.net'; - - $this->object->setComment($newComment); - - $this->assertEquals($newComment, $this->object->getComment()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setPublicId - * @covers Debril\RssAtomBundle\Protocol\Parser\Item::getPublicId - */ - public function testSetPublicId() - { - $id = uniqid(); - $this->object->setPublicId($id); - - $this->assertEquals($id, $this->object->getPublicId()); - } - - public function testAddMedia() - { - $media = new Media(); - $media->setType('audio/mpeg'); - - $this->object->addMedia($media); - $this->assertAttributeContainsOnly($media, 'medias', $this->object); - } - - public function testGetMedias() - { - $this->object->addMedia(new Media()); - $iterator = $this->object->getMedias(); - - $this->assertInstanceOf('\ArrayIterator', $iterator); - $count = 0; - - foreach ($iterator as $media) { - ++$count; - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\Parser\Media', $media); - } - - $this->assertEquals(1, $count); - } -} diff --git a/Tests/Protocol/Parser/MediaTest.php b/Tests/Protocol/Parser/MediaTest.php deleted file mode 100644 index 2a0d758..0000000 --- a/Tests/Protocol/Parser/MediaTest.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Parser; - -class MediaTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Debril\RssAtomBundle\Protocol\Parser\Media - */ - protected $object; - - protected function setUp() - { - $this->object = new Media(); - } - - public function testSetType() - { - $this->object->setType('image/jpeg'); - $this->assertEquals('image/jpeg', $this->object->getType()); - } - - public function testSetLength() - { - $this->object->setLength('87669'); - $this->assertInternalType('integer', $this->object->getLength()); - $this->assertEquals(87669, $this->object->getLength()); - } - - public function testSetUrl() - { - $this->object->setUrl('http://localhost/'); - $this->assertEquals('http://localhost/', $this->object->getUrl()); - } -} diff --git a/Tests/Protocol/Parser/RdfParserTest.php b/Tests/Protocol/Parser/RdfParserTest.php deleted file mode 100644 index df8fc0d..0000000 --- a/Tests/Protocol/Parser/RdfParserTest.php +++ /dev/null @@ -1,118 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\Filter\ModifiedSince; -use Debril\RssAtomBundle\Tests\Protocol\ParserAbstract; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-27 at 00:26:56. - */ -class RdfParserTest extends ParserAbstract -{ - /** - * @var RdfParser - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new RdfParser(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RdfParser::canHandle - */ - public function testCannotHandle() - { - $file = dirname(__FILE__).'/../../../Resources/sample-atom.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $this->assertFalse($this->object->canHandle($xmlBody)); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RdfParser::canHandle - */ - public function testCanHandle() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rdf.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $this->assertTrue($this->object->canHandle($xmlBody)); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RdfParser::checkBodyStructure - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testParseError() - { - $file = dirname(__FILE__).'/../../../Resources/truncated-rss.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $filters = array(new ModifiedSince(new \DateTime())); - $this->object->parse($xmlBody, new FeedContent(), $filters); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RdfParser::parseBody - */ - public function testParse() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rdf.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2005-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - - $this->assertNotNull($feed->getPublicId(), 'feed->getPublicId() should not return an empty value'); - - $this->assertGreaterThan(0, $feed->getItemsCount()); - - if ( phpversion() < '7' ) { - $this->assertInstanceOf('\DateTime', $feed->getLastModified()); - } - $this->assertInternalType('string', $feed->getLink()); - $this->assertInternalType('string', $feed->getDescription()); - $this->assertInternalType('string', $feed->getTitle()); - $this->assertNotNull($feed->getLink()); - $this->assertNotNull($feed->getTitle()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::setDateFormats - * @dataProvider getDefaultFormats - * @covers Debril\RssAtomBundle\Protocol\Parser\RdfParser::__construct - */ - public function testSetDateFormats($default) - { - $this->object->setdateFormats($default); - $this->assertEquals($default, $this->readAttribute($this->object, 'dateFormats')); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::guessDateFormat - * @dataProvider getDefaultFormats - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testGuessDateFormatException($default) - { - $this->object->setdateFormats($default); - - $date = '2003-13T18:30:02Z'; - $this->object->guessDateFormat($date); - } -} diff --git a/Tests/Protocol/Parser/RssParserTest.php b/Tests/Protocol/Parser/RssParserTest.php deleted file mode 100644 index ed3c168..0000000 --- a/Tests/Protocol/Parser/RssParserTest.php +++ /dev/null @@ -1,217 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol\Parser; - -use Debril\RssAtomBundle\Protocol\Filter\ModifiedSince; -use Debril\RssAtomBundle\Tests\Protocol\ParserAbstract; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-27 at 00:26:56. - */ -class RssParserTest extends ParserAbstract -{ - /** - * @var RssParser - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new RssParser(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::canHandle - */ - public function testCannotHandle() - { - $file = dirname(__FILE__).'/../../../Resources/sample-atom.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $this->assertFalse($this->object->canHandle($xmlBody)); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::canHandle - */ - public function testCanHandle() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rss.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $this->assertTrue($this->object->canHandle($xmlBody)); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::checkBodyStructure - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testParseError() - { - $file = dirname(__FILE__).'/../../../Resources/truncated-rss.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - $filters = array(new ModifiedSince(new \DateTime())); - $this->object->parse($xmlBody, new FeedContent(), $filters); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::parseBody - */ - public function testParse() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rss.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2005-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - - $this->assertNotNull($feed->getPublicId(), 'feed->getPublicId() should not return an empty value'); - - $this->assertGreaterThan(0, $feed->getItemsCount()); - $this->assertInstanceOf('\DateTime', $feed->getLastModified()); - $this->assertInternalType('string', $feed->getLink()); - $this->assertInternalType('string', $feed->getTitle()); - $this->assertNotNull($feed->getLink()); - $this->assertNotNull($feed->getTitle()); - - $item = current($feed->getItems()); - $this->assertInternalType('string', $item->getAuthor()); - $this->assertEquals('john.doe@mail.com', $item->getAuthor()); - - $medias = $item->getMedias(); - $count = 0; - foreach ($medias as $media) { - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\Parser\Media', $media); - ++$count; - } - - $this->assertEquals(1, $count); - - $categories = $item->getCategories(); - $this->assertCount(2, $categories); - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\Parser\Category', $categories[0]); - $this->assertEquals('Category1', $categories[0]->getName()); - $this->assertEquals('Category2', $categories[1]->getName()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::parseBody - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::setLastModified - */ - public function testParseWithoutBuildDate() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rss-pubdate.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2005-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - - $this->assertNotNull($feed->getPublicId(), 'feed->getPublicId() should not return an empty value'); - - $this->assertGreaterThan(0, $feed->getItemsCount()); - $this->assertInstanceOf('\DateTime', $feed->getLastModified()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::parseBody - */ - public function testParseWithoutDate() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rss-nodate.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2005-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\FeedInInterface', $feed); - - $this->assertNotNull($feed->getPublicId(), 'feed->getPublicId() should not return an empty value'); - - $this->assertGreaterThan(0, $feed->getItemsCount()); - $this->assertInstanceOf('\DateTime', $feed->getLastModified()); - $feeds = $feed->getItems(); - $item = next($feeds); - $this->assertEquals($item->getUpdated(), $feed->getLastModified()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::setDateFormats - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::__construct - * @dataProvider getDefaultFormats - */ - public function testSetDateFormats($default) - { - $this->object->setdateFormats($default); - $this->assertEquals($default, $this->readAttribute($this->object, 'dateFormats')); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::guessDateFormat - * @dataProvider getDefaultFormats - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testGuessDateFormatException(array $default) - { - $this->object->setdateFormats($default); - - $date = '2003-13T18:30:02Z'; - $this->object->guessDateFormat($date); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::parseBody - */ - public function testParseWithContentExtension() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rss-content.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2005-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertGreaterThan(0, $feed->getItemsCount()); - - $item = current($feed->getItems()); - - $this->assertEquals('Here is a short summary...', $item->getSummary()); - $this->assertEquals('Here is the real content', $item->getDescription()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser\RssParser::parseBody - */ - public function testParseWithDublinCoreExtension() - { - $file = dirname(__FILE__).'/../../../Resources/sample-rss-creator.xml'; - $xmlBody = new \SimpleXMLElement(file_get_contents($file)); - - $date = \DateTime::createFromFormat('Y-m-d', '2005-10-10'); - $filters = array(new ModifiedSince($date)); - $feed = $this->object->parse($xmlBody, new FeedContent(), $filters); - - $this->assertGreaterThan(0, $feed->getItemsCount()); - - $item = current($feed->getItems()); - - $this->assertInternalType('string', $item->getAuthor()); - $this->assertEquals('John Doe', $item->getAuthor()); - } -} diff --git a/Tests/Protocol/ParserAbstract.php b/Tests/Protocol/ParserAbstract.php deleted file mode 100644 index 926de0d..0000000 --- a/Tests/Protocol/ParserAbstract.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Tests\Protocol; - -use Debril\RssAtomBundle\Protocol\Parser; - -/** - * Class ParserAbstract. - */ -class ParserAbstract extends \PHPUnit_Framework_TestCase -{ - /** - * @var Parser - */ - protected $object; - - /** - * @dataProvider getDefaultFormats - * @covers Debril\RssAtomBundle\Protocol\Parser::guessDateFormat - */ - public function testGuessDateFormat($default) - { - $this->object->setdateFormats($default); - - $date = 'Mon, 06 Sep 2009 16:45:00 GMT'; - $format = $this->object->guessDateFormat($date); - - $this->assertEquals(\DateTime::RSS, $format); - } - - /** - * @return array - */ - public function getDefaultFormats() - { - return - array( - array( - array( - \DateTime::RFC3339, - \DateTime::RSS, - ), - ), - ); - } -} diff --git a/Tests/Protocol/ParserTest.php b/Tests/Protocol/ParserTest.php deleted file mode 100644 index 0a1a6cd..0000000 --- a/Tests/Protocol/ParserTest.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -namespace Debril\RssAtomBundle\Protocol; - -use Debril\RssAtomBundle\Protocol\Parser\AtomParser; -use Debril\RssAtomBundle\Protocol\Parser\Factory; -use Debril\RssAtomBundle\Protocol\Parser\FeedContent; -use Debril\RssAtomBundle\Protocol\Parser\Item; - -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-01-27 at 00:26:35. - */ -class ParserTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var AtomParser - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - date_default_timezone_set('Europe/Paris'); - $this->object = new AtomParser(); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::resetTimezone - */ - public function testResetTimezone() - { - Parser::resetTimezone(); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::getSystemTimezone - */ - public function testGetSystemTimezone() - { - Parser::resetTimezone(); - $tz = Parser::getSystemTimezone(); - - $this->assertInstanceOf('\DateTimeZone', $tz); - $this->assertEquals(date_default_timezone_get(), $tz->getName()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::convertToDateTime - * @expectedException \Debril\RssAtomBundle\Exception\ParserException - */ - public function testConvertToDateTimeException() - { - $string = '09-12-2012'; - Parser::convertToDateTime($string); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::convertToDateTime - */ - public function testConvertToDateTime() - { - $string = '2003-12-13T18:30:02Z'; - $date = Parser::convertToDateTime($string, \DateTime::RFC3339); - - $this->assertInstanceOf('\DateTime', $date); - - $this->assertEquals('13/12/2003', $date->format('d/m/Y')); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::setFactory - */ - public function testSetFactory() - { - $this->object->setFactory(new Factory()); - - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\Parser\Factory', $this->object->getFactory()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::addAcceptableItem - */ - public function testAddAcceptableItem() - { - $feed = new FeedContent(); - $item = new Item(); - $item->setUpdated(\DateTime::createFromFormat('j-M-Y', '17-Feb-2012')); - $ret = $this->object->addAcceptableItem($feed, $item, \DateTime::createFromFormat('j-M-Y', '16-Feb-2012')); - - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\Parser', $ret); - $this->assertEquals(1, $feed->getItemsCount()); - } - - /** - * @covers Debril\RssAtomBundle\Protocol\Parser::addAcceptableItem - */ - public function testAddUnacceptableItem() - { - $feed = new FeedContent(); - $item = new Item(); - $date = new \DateTime(); - $item->setUpdated($date); - $ret = $this->object->addAcceptableItem($feed, $item, $date); - - $this->assertInstanceOf('Debril\RssAtomBundle\Protocol\Parser', $ret); - $this->assertEquals(0, $feed->getItemsCount()); - } - - public function testGetAttributeValue() - { - $xml = new \SimpleXmlElement('<root />'); - $xml->addAttribute('foo', 'bar'); - - $this->assertNull($this->object->getAttributeValue($xml, 'href')); - - $this->assertEquals('bar', $this->object->getAttributeValue($xml, 'foo')); - } - - public function testCreateMedia() - { - $xml = new \SimpleXmlElement('<enclosure />'); - $xml->addAttribute('href', 'http://localhost/'); - $xml->addAttribute('type', 'audio/mpeg'); - $xml->addAttribute('length', '456'); - - $media = $this->object->createMedia($xml); - $this->assertInstanceOf('\Debril\RssAtomBundle\Protocol\Parser\Media', $media); - - $this->assertEquals('http://localhost/', $media->getUrl()); - $this->assertEquals('audio/mpeg', $media->getType()); - $this->assertEquals('456', $media->getLength()); - } - - public function testSearchAttributeValue() - { - $xml = new \SimpleXmlElement('<enclosure />'); - $xml->addAttribute('href', 'http://localhost/'); - $xml->addAttribute('type', 'audio/mpeg'); - $xml->addAttribute('length', '456'); - - $this->assertNull($this->object->searchAttributeValue($xml, array('foo'))); - - $this->assertEquals('http://localhost/', $this->object->searchAttributeValue($xml, array('url', 'href'))); - } -}