From e8b4f147d8ad9f5f6f6e960dce9a56c288fd483e Mon Sep 17 00:00:00 2001 From: Bartosz Kubicki Date: Sat, 13 Jun 2020 13:54:50 +0200 Subject: [PATCH] Porting changes for integration testssuite decomposition --- .../Adminhtml/Notification/MarkAsReadTest.php | 13 +++-- .../Notification/MassMarkAsReadTest.php | 17 ++++-- .../Adminhtml/Notification/MassRemoveTest.php | 17 ++++-- .../Adminhtml/Notification/RemoveTest.php | 26 +++++++++ .../Inbox/Collection/CriticalTest.php | 42 ++++++++++++++ .../Test/Integration/_files/notifications.php | 57 +++++++++++++++++++ .../Controller/Feed/IndexTest.php | 47 ++++++++++----- .../Adminhtml/Notification/RemoveTest.php | 16 ------ .../Inbox/Collection/CriticalTest.php | 30 ---------- .../_files/notifications.php | 50 ---------------- 10 files changed, 192 insertions(+), 123 deletions(-) rename {dev/tests/integration/testsuite/Magento/AdminNotification => app/code/Magento/AdminNotification/Test/Integration}/Controller/Adminhtml/Notification/MarkAsReadTest.php (63%) rename {dev/tests/integration/testsuite/Magento/AdminNotification => app/code/Magento/AdminNotification/Test/Integration}/Controller/Adminhtml/Notification/MassMarkAsReadTest.php (53%) rename {dev/tests/integration/testsuite/Magento/AdminNotification => app/code/Magento/AdminNotification/Test/Integration}/Controller/Adminhtml/Notification/MassRemoveTest.php (54%) create mode 100644 app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/RemoveTest.php create mode 100644 app/code/Magento/AdminNotification/Test/Integration/Model/ResourceModel/Inbox/Collection/CriticalTest.php create mode 100644 app/code/Magento/AdminNotification/Test/Integration/_files/notifications.php rename {dev/tests/integration/testsuite/Magento/Rss => app/code/Magento/Rss/Test/Integration}/Controller/Feed/IndexTest.php (62%) delete mode 100644 dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/RemoveTest.php delete mode 100644 dev/tests/integration/testsuite/Magento/AdminNotification/Model/ResourceModel/Inbox/Collection/CriticalTest.php delete mode 100644 dev/tests/integration/testsuite/Magento/AdminNotification/_files/notifications.php diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsReadTest.php b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MarkAsReadTest.php similarity index 63% rename from dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsReadTest.php rename to app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MarkAsReadTest.php index ca2033b2efda2..dc52e60c3b4c2 100644 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MarkAsReadTest.php +++ b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MarkAsReadTest.php @@ -1,24 +1,29 @@ resource = 'Magento_AdminNotification::mark_as_read'; $this->uri = 'backend/admin/notification/markasread'; - parent::setUp(); } } diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MassMarkAsReadTest.php similarity index 53% rename from dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php rename to app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MassMarkAsReadTest.php index ea5fd8ec72ab1..b0155ae985e22 100644 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassMarkAsReadTest.php +++ b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MassMarkAsReadTest.php @@ -1,19 +1,28 @@ resource = 'Magento_AdminNotification::mark_as_read'; $this->uri = 'backend/admin/notification/massmarkasread'; $this->httpMethod = HttpRequest::METHOD_POST; - parent::setUp(); } } diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MassRemoveTest.php similarity index 54% rename from dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php rename to app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MassRemoveTest.php index 06ccf4bb8a4af..ba9e9cf01e971 100644 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemoveTest.php +++ b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/MassRemoveTest.php @@ -1,19 +1,28 @@ resource = 'Magento_AdminNotification::adminnotification_remove'; $this->uri = 'backend/admin/notification/massremove'; $this->httpMethod = HttpRequest::METHOD_POST; - parent::setUp(); } } diff --git a/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/RemoveTest.php b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/RemoveTest.php new file mode 100644 index 0000000000000..98cb38afa6dfc --- /dev/null +++ b/app/code/Magento/AdminNotification/Test/Integration/Controller/Adminhtml/Notification/RemoveTest.php @@ -0,0 +1,26 @@ +resource = 'Magento_AdminNotification::adminnotification_remove'; + $this->uri = 'backend/admin/notification/remove'; + } +} diff --git a/app/code/Magento/AdminNotification/Test/Integration/Model/ResourceModel/Inbox/Collection/CriticalTest.php b/app/code/Magento/AdminNotification/Test/Integration/Model/ResourceModel/Inbox/Collection/CriticalTest.php new file mode 100644 index 0000000000000..5bf6a27675d74 --- /dev/null +++ b/app/code/Magento/AdminNotification/Test/Integration/Model/ResourceModel/Inbox/Collection/CriticalTest.php @@ -0,0 +1,42 @@ +model = Bootstrap::getObjectManager()->create( + Critical::class + ); + } + + /** + * @magentoDataFixture Magento_AdminNotification::Test/Integration/_files/notifications.php + * + * @return void + */ + public function testCollectionContainsLastUnreadCriticalItem(): void + { + $items = array_values($this->model->getItems()); + $this->assertEquals('Unread Critical 3', $items[0]->getTitle()); + } +} diff --git a/app/code/Magento/AdminNotification/Test/Integration/_files/notifications.php b/app/code/Magento/AdminNotification/Test/Integration/_files/notifications.php new file mode 100644 index 0000000000000..d62914d6902de --- /dev/null +++ b/app/code/Magento/AdminNotification/Test/Integration/_files/notifications.php @@ -0,0 +1,57 @@ +create(Inbox::class); +$message + ->setSeverity(MessageInterface::SEVERITY_CRITICAL) + ->setTitle('Unread Critical 1') + ->save(); + +$message = $om->create(Inbox::class); +$message + ->setSeverity(MessageInterface::SEVERITY_MAJOR) + ->setTitle('Unread Major 1') + ->save(); + +$message = $om->create(Inbox::class); +$message + ->setSeverity(MessageInterface::SEVERITY_CRITICAL) + ->setTitle('Unread Critical 2') + ->save(); + +$message = $om->create(Inbox::class); +$message + ->setSeverity(MessageInterface::SEVERITY_CRITICAL) + ->setTitle('Unread Critical 3') + ->save(); + +$message = $om->create(Inbox::class); +$message + ->setSeverity(MessageInterface::SEVERITY_CRITICAL) + ->setTitle('Read Critical 1') + ->setIsRead(1) + ->save(); + +$message = $om->create(Inbox::class); +$message + ->setSeverity(MessageInterface::SEVERITY_MAJOR) + ->setTitle('Unread Major 2') + ->save(); + +$message = $om->create(Inbox::class); +$message + ->setSeverity(MessageInterface::SEVERITY_CRITICAL) + ->setTitle('Removed Critical 1') + ->setIsRemove(1) + ->save(); diff --git a/dev/tests/integration/testsuite/Magento/Rss/Controller/Feed/IndexTest.php b/app/code/Magento/Rss/Test/Integration/Controller/Feed/IndexTest.php similarity index 62% rename from dev/tests/integration/testsuite/Magento/Rss/Controller/Feed/IndexTest.php rename to app/code/Magento/Rss/Test/Integration/Controller/Feed/IndexTest.php index 991914460c61b..19b09433ef790 100644 --- a/dev/tests/integration/testsuite/Magento/Rss/Controller/Feed/IndexTest.php +++ b/app/code/Magento/Rss/Test/Integration/Controller/Feed/IndexTest.php @@ -5,22 +5,29 @@ */ declare(strict_types=1); -namespace Magento\Rss\Controller\Feed; +namespace Magento\Rss\Test\Integration\Controller\Feed; -class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Model\Session; +use Magento\Framework\Exception\AuthenticationException; +use Magento\Rss\Model\UrlBuilder; +use Magento\TestFramework\TestCase\AbstractBackendController; +use Magento\Wishlist\Model\Wishlist; + +class IndexTest extends AbstractBackendController { /** - * @var \Magento\Rss\Model\UrlBuilder + * @var UrlBuilder */ private $urlBuilder; /** - * @var \Magento\Customer\Api\CustomerRepositoryInterface + * @var CustomerRepositoryInterface */ private $customerRepository; /** - * @var \Magento\Wishlist\Model\Wishlist + * @var Wishlist */ private $wishlist; @@ -29,15 +36,19 @@ class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendControlle */ private $customerSession; + /** + * @return void + * @throws AuthenticationException + */ protected function setUp(): void { parent::setUp(); - $this->urlBuilder = $this->_objectManager->get(\Magento\Rss\Model\UrlBuilder::class); + $this->urlBuilder = $this->_objectManager->get(UrlBuilder::class); $this->customerRepository = $this->_objectManager->get( - \Magento\Customer\Api\CustomerRepositoryInterface::class + CustomerRepositoryInterface::class ); - $this->wishlist = $this->_objectManager->get(\Magento\Wishlist\Model\Wishlist::class); - $this->customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class); + $this->wishlist = $this->_objectManager->get(Wishlist::class); + $this->customerSession = $this->_objectManager->get(Session::class); } /** @@ -48,13 +59,13 @@ protected function setUp(): void * @magentoConfigFixture current_store rss/wishlist/active 1 * @magentoConfigFixture current_store rss/config/active 1 */ - public function testRssResponse() + public function testRssResponse(): void { $firstCustomerId = 1; $this->customerSession->setCustomerId($firstCustomerId); $customer = $this->customerRepository->getById($firstCustomerId); $customerEmail = $customer->getEmail(); - $wishlistId = $this->wishlist->loadByCustomerId($firstCustomerId)->getId(); + $wishlistId = (int) $this->wishlist->loadByCustomerId($firstCustomerId)->getId(); $this->dispatch($this->getLink($firstCustomerId, $customerEmail, $wishlistId)); $body = $this->getResponse()->getBody(); $this->assertStringContainsString('John Smith\'s Wishlist', $body); @@ -68,22 +79,28 @@ public function testRssResponse() * @magentoConfigFixture current_store rss/wishlist/active 1 * @magentoConfigFixture current_store rss/config/active 1 */ - public function testRssResponseWithIncorrectWishlistId() + public function testRssResponseWithIncorrectWishlistId(): void { $firstCustomerId = 1; $secondCustomerId = 2; $this->customerSession->setCustomerId($firstCustomerId); $customer = $this->customerRepository->getById($firstCustomerId); $customerEmail = $customer->getEmail(); - $wishlistId = $this->wishlist->loadByCustomerId($secondCustomerId, true)->getId(); + $wishlistId = (int) $this->wishlist->loadByCustomerId($secondCustomerId, true)->getId(); $this->dispatch($this->getLink($firstCustomerId, $customerEmail, $wishlistId)); $body = $this->getResponse()->getBody(); $this->assertStringContainsString('404 Not Found', $body); } - private function getLink($customerId, $customerEmail, $wishlistId) + /** + * @param int $customerId + * @param string $customerEmail + * @param int $wishlistId + * + * @return string + */ + private function getLink(int $customerId, string $customerEmail, int $wishlistId): string { - return 'rss/feed/index/type/wishlist/data/' . base64_encode($customerId . ',' . $customerEmail) . '/wishlist_id/' . $wishlistId; diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/RemoveTest.php b/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/RemoveTest.php deleted file mode 100644 index 0ffdbdd570f9c..0000000000000 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Controller/Adminhtml/Notification/RemoveTest.php +++ /dev/null @@ -1,16 +0,0 @@ -resource = 'Magento_AdminNotification::adminnotification_remove'; - $this->uri = 'backend/admin/notification/remove'; - parent::setUp(); - } -} diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/Model/ResourceModel/Inbox/Collection/CriticalTest.php b/dev/tests/integration/testsuite/Magento/AdminNotification/Model/ResourceModel/Inbox/Collection/CriticalTest.php deleted file mode 100644 index 218bb5089ce3f..0000000000000 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/Model/ResourceModel/Inbox/Collection/CriticalTest.php +++ /dev/null @@ -1,30 +0,0 @@ -_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Critical::class - ); - } - - /** - * @magentoDataFixture Magento/AdminNotification/_files/notifications.php - */ - public function testCollectionContainsLastUnreadCriticalItem() - { - $items = array_values($this->_model->getItems()); - $this->assertEquals('Unread Critical 3', $items[0]->getTitle()); - } -} diff --git a/dev/tests/integration/testsuite/Magento/AdminNotification/_files/notifications.php b/dev/tests/integration/testsuite/Magento/AdminNotification/_files/notifications.php deleted file mode 100644 index 0a8f2670b5740..0000000000000 --- a/dev/tests/integration/testsuite/Magento/AdminNotification/_files/notifications.php +++ /dev/null @@ -1,50 +0,0 @@ -create(Inbox::class); -$messageResource = $objectManager->create(InboxResource::class); - -$message->setSeverity(MessageInterface::SEVERITY_CRITICAL)->setTitle('Unread Critical 1'); -$messageResource->save($message); - -$message = $objectManager->create(Inbox::class); -$message->setSeverity(MessageInterface::SEVERITY_MAJOR)->setTitle('Unread Major 1'); -$messageResource->save($message); - -$message = $objectManager->create(Inbox::class); -$message->setSeverity(MessageInterface::SEVERITY_CRITICAL)->setTitle('Unread Critical 2'); -$messageResource->save($message); - -$message = $objectManager->create(Inbox::class); -$message->setSeverity(MessageInterface::SEVERITY_CRITICAL)->setTitle('Unread Critical 3'); -$messageResource->save($message); - -$message = $objectManager->create(Inbox::class); -$message->setSeverity(MessageInterface::SEVERITY_CRITICAL)->setTitle('Read Critical 1')->setIsRead(1); -$messageResource->save($message); - -$message = $objectManager->create(Inbox::class); -$message->setSeverity(MessageInterface::SEVERITY_MAJOR)->setTitle('Unread Major 2'); -$messageResource->save($message); - -$message = $objectManager->create(Inbox::class); -$message->setSeverity(MessageInterface::SEVERITY_CRITICAL)->setTitle('Removed Critical 1')->setIsRemove(1); -$messageResource->save($message);