12 class RssTest extends \PHPUnit\Framework\TestCase
23 'title' =>
'Feed Title',
24 'link' =>
'http://magento.com/rss/link',
25 'description' =>
'Feed Description',
29 'title' =>
'Feed 1 Title',
30 'link' =>
'http://magento.com/rss/link/id/1',
31 'description' =>
'Feed 1 Description',
39 private $feedXml =
'<?xml version="1.0" encoding="UTF-8"?> 40 <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> 42 <title><![CDATA[Feed Title]]></title> 43 <link>http://magento.com/rss/link</link> 44 <description><![CDATA[Feed Description]]></description> 45 <pubDate>Sat, 22 Apr 2017 13:21:12 +0200</pubDate> 46 <generator>Zend\Feed</generator> 47 <docs>http://blogs.law.harvard.edu/tech/rss</docs> 49 <title><![CDATA[Feed 1 Title]]></title> 50 <link>http://magento.com/rss/link/id/1</link> 51 <description><![CDATA[Feed 1 Description]]></description> 52 <pubDate>Sat, 22 Apr 2017 13:21:12 +0200</pubDate> 70 private $feedFactoryMock;
80 private $serializerMock;
84 $this->cacheMock = $this->createMock(\
Magento\Framework\
App\CacheInterface::class);
85 $this->serializerMock = $this->createMock(SerializerInterface::class);
86 $this->feedFactoryMock = $this->createMock(\
Magento\Framework\
App\FeedFactoryInterface::class);
87 $this->feedMock = $this->createMock(\
Magento\Framework\
App\FeedInterface::class);
89 $this->objectManagerHelper =
new ObjectManagerHelper($this);
90 $this->rss = $this->objectManagerHelper->getObject(
93 'cache' => $this->cacheMock,
94 'feedFactory' => $this->feedFactoryMock,
95 'serializer' => $this->serializerMock
102 $dataProvider = $this->createMock(\
Magento\Framework\
App\Rss\DataProviderInterface::class);
103 $dataProvider->expects($this->any())->method(
'getCacheKey')->will($this->returnValue(
'cache_key'));
104 $dataProvider->expects($this->any())->method(
'getCacheLifetime')->will($this->returnValue(100));
105 $dataProvider->expects($this->any())->method(
'getRssData')->will($this->returnValue($this->feedData));
107 $this->rss->setDataProvider($dataProvider);
109 $this->cacheMock->expects($this->once())
112 ->will($this->returnValue(
false));
113 $this->cacheMock->expects($this->once())
115 ->with(
'serializedData')
116 ->will($this->returnValue(
true));
117 $this->serializerMock->expects($this->once())
118 ->method(
'serialize')
119 ->with($this->feedData)
120 ->willReturn(
'serializedData');
122 $this->assertEquals($this->feedData, $this->rss->getFeeds());
127 $dataProvider = $this->createMock(\
Magento\Framework\
App\Rss\DataProviderInterface::class);
128 $dataProvider->expects($this->any())->method(
'getCacheKey')->will($this->returnValue(
'cache_key'));
129 $dataProvider->expects($this->any())->method(
'getCacheLifetime')->will($this->returnValue(100));
130 $dataProvider->expects($this->never())->method(
'getRssData');
132 $this->rss->setDataProvider($dataProvider);
134 $this->cacheMock->expects($this->once())
137 ->will($this->returnValue(
'serializedData'));
138 $this->serializerMock->expects($this->once())
139 ->method(
'unserialize')
140 ->with(
'serializedData')
141 ->willReturn($this->feedData);
142 $this->cacheMock->expects($this->never())->method(
'save');
144 $this->assertEquals($this->feedData, $this->rss->getFeeds());
149 $dataProvider = $this->createMock(\
Magento\Framework\
App\Rss\DataProviderInterface::class);
150 $dataProvider->expects($this->any())->method(
'getCacheKey')->will($this->returnValue(
'cache_key'));
151 $dataProvider->expects($this->any())->method(
'getCacheLifetime')->will($this->returnValue(100));
152 $dataProvider->expects($this->any())->method(
'getRssData')->will($this->returnValue($this->feedData));
154 $this->feedMock->expects($this->once())
155 ->method(
'getFormattedContent')
156 ->willReturn($this->feedXml);
158 $this->feedFactoryMock->expects($this->once())
160 ->with($this->feedData, \
Magento\Framework\
App\FeedFactoryInterface::FORMAT_RSS)
161 ->will($this->returnValue($this->feedMock));
163 $this->rss->setDataProvider($dataProvider);
164 $this->assertNotNull($this->rss->createRssXml());