Unverified Commit 91ddec71 authored by Roumen Damianoff's avatar Roumen Damianoff
Browse files

misc updates

parents 33cdea92 2453a61f
......@@ -4,16 +4,16 @@
* Feed generator class for laravel-feed package.
*
* @author Roumen Damianoff <roumen@damianoff.com>
* @version 3.1
* @version 6.0.1
* @link https://laravelium.com
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
use Illuminate\Cache\Repository as CacheRepository;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Filesystem\Filesystem as Filesystem;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactory;
use Illuminate\View\Factory as ViewFactory;
use Illuminate\Contracts\View\Factory as ViewFactory;
class Feed
{
......@@ -289,27 +289,29 @@ class Feed
*/
public function render($format = null, $cache = null, $key = null)
{
if (null == $format) {
if (null === $format) {
$format = "atom";
}
if (0 == $cache || (null == $cache && 0 == $this->caching)) {
if (0 === $cache || (null === $cache && 0 === $this->caching)) {
$this->clearCache();
} else {
}
if (0 < $cache) {
$this->caching = $cache;
}
if (null != $key) {
if (null !== $key) {
$this->cacheKey = $key;
}
if (null != $this->customView) {
if (null !== $this->customView) {
$view = $this->customView;
} else {
$view = 'feed::'.$format;
}
if (null != $this->getCtype()) {
if (null !== $this->getCtype()) {
$ctype = $this->getCtype();
} else {
$ctype = ($format == 'atom') ? 'application/atom+xml' : 'application/rss+xml';
......
<?php namespace Laravelium\Feed;
<?php
namespace Laravelium\Feed;
use Illuminate\Support\ServiceProvider;
use Laravelium\Feed\Feed;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Routing\ResponseFactory;
class FeedServiceProvider extends ServiceProvider
class FeedServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Bootstrap the application events.
*
......@@ -42,7 +38,7 @@ class FeedServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->bind('feed', function ($app) {
$this->app->bind('feed', function (Container $app) {
$config = config('feed');
return new Feed(
......@@ -50,7 +46,7 @@ class FeedServiceProvider extends ServiceProvider
$app['Illuminate\Cache\Repository'],
$app['config'],
$app['files'],
$app['Illuminate\Contracts\Routing\ResponseFactory'],
$app[ResponseFactory::class],
$app['view']
);
});
......
......@@ -255,6 +255,75 @@ class FeedTest extends TestCase
$this->assertEquals(false, $this->feed->IsCached());
}
public function testCacheIsNotClearedWhenSet()
{
$this->feed->setCache(69, 'TestKey');
$this->feed->addItem([
'title' => 'FirstTitle',
'author' => 'TestAuthor',
'link' => 'TestUrl',
'pubdate' => '2014-02-29 00:00:00',
'description' => '<p>TestResume</p>',
'content' => '<p>TestContent</p>',
'category' => 'testCategory',
'enclosure' => ['url'=>'http://foobar.dev/someThing.jpg', 'type' => 'image/jpeg'],
'duration' => '00:00:00'
]);
$response = $this->feed->render();
$this->assertTrue(strpos($response, 'FirstTitle') >= 0);
$this->assertFalse(strpos($response, 'SecondTitle'));
$this->feed->addItem([
'title' => 'SecondTitle',
'author' => 'TestAuthor',
'link' => 'TestUrl',
'pubdate' => '2014-02-29 00:00:00',
'description' => '<p>TestResume</p>',
'content' => '<p>TestContent</p>',
'category' => 'testCategory',
'enclosure' => ['url'=>'http://foobar.dev/someThing.jpg', 'type' => 'image/jpeg'],
'duration' => '00:00:00'
]);
$response = $this->feed->render();
$this->assertTrue(strpos($response, 'FirstTitle') >= 0);
$this->assertFalse(strpos($response, 'SecondTitle'));
}
public function testCacheIsClearedWhenNotSet()
{
$this->feed->addItem([
'title' => 'FirstTitle',
'author' => 'TestAuthor',
'link' => 'TestUrl',
'pubdate' => '2014-02-29 00:00:00',
'description' => '<p>TestResume</p>',
'content' => '<p>TestContent</p>',
'category' => 'testCategory',
'enclosure' => ['url'=>'http://foobar.dev/someThing.jpg', 'type' => 'image/jpeg'],
'duration' => '00:00:00'
]);
$response = $this->feed->render();
$this->assertTrue(strpos($response, 'FirstTitle') >= 0);
$this->assertFalse(strpos($response, 'SecondTitle'));
$this->feed->addItem([
'title' => 'SecondTitle',
'author' => 'TestAuthor',
'link' => 'TestUrl',
'pubdate' => '2014-02-29 00:00:00',
'description' => '<p>TestResume</p>',
'content' => '<p>TestContent</p>',
'category' => 'testCategory',
'enclosure' => ['url'=>'http://foobar.dev/someThing.jpg', 'type' => 'image/jpeg'],
'duration' => '00:00:00'
]);
$response = $this->feed->render();
$this->assertTrue(strpos($response, 'FirstTitle') >= 0);
$this->assertTrue(strpos($response, 'SecondTitle') >= 0);
}
public function testGetRssLink()
{
$this->assertEquals('http://localhost', $this->feed->getRssLink());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment