From b73d1c8f7bebb55fa7a6d7d953bd63b37be13d40 Mon Sep 17 00:00:00 2001 From: Ben Batschelet Date: Tue, 13 Mar 2018 09:33:39 -0500 Subject: [PATCH] Replace ZF1 Zend_Feed with ZF2 Zend\Feed --- app/code/Magento/Rss/Model/Rss.php | 5 +- .../Controller/Adminhtml/Feed/IndexTest.php | 3 +- .../Test/Unit/Controller/Feed/IndexTest.php | 3 +- .../Magento/Rss/Test/Unit/Model/RssTest.php | 6 +- composer.json | 1 + composer.lock | 63 ++++++++++++++++++- .../Test/Legacy/_files/obsolete_classes.php | 1 + 7 files changed, 74 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Rss/Model/Rss.php b/app/code/Magento/Rss/Model/Rss.php index 7461c780fb230..96f71133cb832 100644 --- a/app/code/Magento/Rss/Model/Rss.php +++ b/app/code/Magento/Rss/Model/Rss.php @@ -8,6 +8,7 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\App\Rss\DataProviderInterface; use Magento\Framework\Serialize\SerializerInterface; +use Zend\Feed\Writer\FeedFactory; /** * Provides functionality to work with RSS feeds @@ -92,7 +93,7 @@ public function setDataProvider(DataProviderInterface $dataProvider) */ public function createRssXml() { - $rssFeedFromArray = \Zend_Feed::importArray($this->getFeeds(), 'rss'); - return $rssFeedFromArray->saveXML(); + $feed = FeedFactory::factory($this->getFeeds()); + return $feed->export('rss'); } } diff --git a/app/code/Magento/Rss/Test/Unit/Controller/Adminhtml/Feed/IndexTest.php b/app/code/Magento/Rss/Test/Unit/Controller/Adminhtml/Feed/IndexTest.php index 32aab6ffb92bc..58fd541bab8cb 100644 --- a/app/code/Magento/Rss/Test/Unit/Controller/Adminhtml/Feed/IndexTest.php +++ b/app/code/Magento/Rss/Test/Unit/Controller/Adminhtml/Feed/IndexTest.php @@ -6,6 +6,7 @@ namespace Magento\Rss\Test\Unit\Controller\Adminhtml\Feed; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Zend\Feed\Writer\Exception\InvalidArgumentException; /** * Class IndexTest @@ -110,7 +111,7 @@ public function testExecuteWithException() $this->rssFactory->expects($this->once())->method('create')->will($this->returnValue($rssModel)); $this->rssManager->expects($this->once())->method('getProvider')->will($this->returnValue($dataProvider)); - $this->expectException('\Zend_Feed_Builder_Exception'); + $this->expectException(InvalidArgumentException::class); $this->controller->execute(); } } diff --git a/app/code/Magento/Rss/Test/Unit/Controller/Feed/IndexTest.php b/app/code/Magento/Rss/Test/Unit/Controller/Feed/IndexTest.php index 71802deee0a8d..e8f7a85382f27 100644 --- a/app/code/Magento/Rss/Test/Unit/Controller/Feed/IndexTest.php +++ b/app/code/Magento/Rss/Test/Unit/Controller/Feed/IndexTest.php @@ -6,6 +6,7 @@ namespace Magento\Rss\Test\Unit\Controller\Feed; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Zend\Feed\Writer\Exception\InvalidArgumentException; /** * Class IndexTest @@ -97,7 +98,7 @@ public function testExecuteWithException() $this->rssFactory->expects($this->once())->method('create')->will($this->returnValue($rssModel)); $this->rssManager->expects($this->once())->method('getProvider')->will($this->returnValue($dataProvider)); - $this->expectException('\Zend_Feed_Builder_Exception'); + $this->expectException(InvalidArgumentException::class); $this->controller->execute(); } } diff --git a/app/code/Magento/Rss/Test/Unit/Model/RssTest.php b/app/code/Magento/Rss/Test/Unit/Model/RssTest.php index 6f98b9f202e30..34f9940556a93 100644 --- a/app/code/Magento/Rss/Test/Unit/Model/RssTest.php +++ b/app/code/Magento/Rss/Test/Unit/Model/RssTest.php @@ -119,11 +119,11 @@ public function testCreateRssXml() $this->rss->setDataProvider($dataProvider); $result = $this->rss->createRssXml(); $this->assertContains('', $result); - $this->assertContains('<![CDATA[Feed Title]]>', $result); - $this->assertContains('<![CDATA[Feed 1 Title]]>', $result); + $this->assertContains('Feed Title', $result); + $this->assertContains('Feed 1 Title', $result); $this->assertContains('http://magento.com/rss/link', $result); $this->assertContains('http://magento.com/rss/link/id/1', $result); - $this->assertContains('', $result); + $this->assertContains('Feed Description', $result); $this->assertContains('', $result); } } diff --git a/composer.json b/composer.json index 212322ee2300c..6fbf296e1fbae 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,7 @@ "zendframework/zend-db": "^2.8.2", "zendframework/zend-di": "^2.6.1", "zendframework/zend-eventmanager": "^2.6.3", + "zendframework/zend-feed": "^2.9.0", "zendframework/zend-form": "^2.10.0", "zendframework/zend-http": "^2.6.0", "zendframework/zend-i18n": "^2.7.3", diff --git a/composer.lock b/composer.lock index d86ab3e509178..8509554e81739 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "19f6c01c03032849ec8101511a02d174", + "content-hash": "03ece269ddc8227e813e176dad41a986", "packages": [ { "name": "braintree/braintree_php", @@ -2433,6 +2433,67 @@ ], "time": "2017-12-12T17:48:56+00:00" }, + { + "name": "zendframework/zend-feed", + "version": "2.9.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-feed.git", + "reference": "abe88686124d492e0a2a84656f15e5482bfbe030" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-feed/zipball/abe88686124d492e0a2a84656f15e5482bfbe030", + "reference": "abe88686124d492e0a2a84656f15e5482bfbe030", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0", + "zendframework/zend-escaper": "^2.5.2", + "zendframework/zend-stdlib": "^2.7.7 || ^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.23 || ^6.4.3", + "psr/http-message": "^1.0.1", + "zendframework/zend-cache": "^2.7.2", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-db": "^2.8.2", + "zendframework/zend-http": "^2.7", + "zendframework/zend-servicemanager": "^2.7.8 || ^3.3", + "zendframework/zend-validator": "^2.10.1" + }, + "suggest": { + "psr/http-message": "PSR-7 ^1.0.1, if you wish to use Zend\\Feed\\Reader\\Http\\Psr7ResponseDecorator", + "zendframework/zend-cache": "Zend\\Cache component, for optionally caching feeds between requests", + "zendframework/zend-db": "Zend\\Db component, for use with PubSubHubbub", + "zendframework/zend-http": "Zend\\Http for PubSubHubbub, and optionally for use with Zend\\Feed\\Reader", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component, for easily extending ExtensionManager implementations", + "zendframework/zend-validator": "Zend\\Validator component, for validating email addresses used in Atom feeds and entries when using the Writer subcomponent" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.9-dev", + "dev-develop": "2.10-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Feed\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "provides functionality for consuming RSS and Atom feeds", + "keywords": [ + "ZendFramework", + "feed", + "zf" + ], + "time": "2017-12-04T17:59:38+00:00" + }, { "name": "zendframework/zend-filter", "version": "2.7.2", diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index dea45d5f7f860..939b98cabc3de 100755 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -4220,4 +4220,5 @@ ['Magento\Framework\MessageQueue\Config\Reader', 'Magento\Framework\MessageQueue\Config\Reader\Xml'], ['Magento\Framework\MessageQueue\PublisherFactory'], ['Magento\Framework\MessageQueue\PublisherProxy'], + ['Zend_Feed', 'Zend\Feed'], ];