diff --git a/.travis.yml b/.travis.yml index 83ec37de7f16f32b00f51e266cd34263e1e1390c..461a4c85152ee7092a6fe2711e0ec8bde46cfc48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,7 @@ before_install: install: - cd /tmp/magento - composer install --no-interaction + - composer require --dev mikey179/vfsstream script: - php /tmp/magento/vendor/bin/phpunit -c /tmp/magento/app/code/Firegento/ContentProvisioning/Test/Integration/phpunit.travis.xml diff --git a/Test/Integration/Model/BlockInstallerTest.php b/Test/Integration/Model/BlockInstallerTest.php deleted file mode 100644 index 829123ee8ba63062354102f9b5d2b0cfedb59bea..0000000000000000000000000000000000000000 --- a/Test/Integration/Model/BlockInstallerTest.php +++ /dev/null @@ -1,168 +0,0 @@ -<?php -declare(strict_types=1); - -namespace Firegento\ContentProvisioning\Test\Integration\Model; - -use Firegento\ContentProvisioning\Api\Data\BlockEntryInterface; -use Firegento\ContentProvisioning\Api\Data\BlockEntryInterfaceFactory; -use Firegento\ContentProvisioning\Model\BlockInstaller; -use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList; -use Firegento\ContentProvisioning\Model\Query\GetFirstBlockByBlockEntry; -use Magento\Cms\Api\Data\BlockInterface; -use Magento\Framework\App\ResourceConnection; -use Magento\Store\Model\StoreManagerInterface; -use PHPUnit\Framework\MockObject\MockObject; -use Magento\TestFramework\Helper\Bootstrap; - -class BlockInstallerTest extends \PHPUnit\Framework\TestCase -{ - /** - * @var BlockInstaller - */ - private $installer; - - /** - * @var GetBlockEntryList|MockObject - */ - private $getBlockEntryListMock; - - /** - * @var BlockEntryInterfaceFactory - */ - private $blockEntryInterfaceFactory; - - /** - * @var StoreManagerInterface - */ - private $storeManager; - - /** - * @var BlockEntryInterface[] - */ - private $blockEntries = []; - - /** - * @var GetFirstBlockByBlockEntry - */ - private $getFirstBlockByBlockEntry; - - protected function setUp() - { - parent::setUp(); - - $this->getBlockEntryListMock = self::getMockBuilder(GetBlockEntryList::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->installer = Bootstrap::getObjectManager() - ->create(BlockInstaller::class, ['getAllBlockEntries' => $this->getBlockEntryListMock]); - - $this->blockEntryInterfaceFactory = Bootstrap::getObjectManager() - ->create(BlockEntryInterfaceFactory::class); - - $this->storeManager = Bootstrap::getObjectManager() - ->create(StoreManagerInterface::class); - - $this->getFirstBlockByBlockEntry = Bootstrap::getObjectManager() - ->create(GetFirstBlockByBlockEntry::class); - } - - protected function tearDown() - { - parent::tearDown(); - - $connection = Bootstrap::getObjectManager()->get(ResourceConnection::class); - $connection->getConnection()->delete( - $connection->getTableName('cms_block'), - [ - 'identifier LIKE ?' => 'firegento-content-provisioning-test-%', - ] - ); - } - - private function initBlockEntries() - { - $this->blockEntries[1] = $this->blockEntryInterfaceFactory->create(['data' => [ - BlockEntryInterface::TITLE => 'Test Block 1', - BlockEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', - BlockEntryInterface::KEY => 'test.block.1', - BlockEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-1', - BlockEntryInterface::IS_ACTIVE => false, - BlockEntryInterface::IS_MAINTAINED => true, - BlockEntryInterface::STORES => ['admin'], - ]]); - - $this->blockEntries[2] = $this->blockEntryInterfaceFactory->create(['data' => [ - BlockEntryInterface::TITLE => 'Test Block 2', - BlockEntryInterface::CONTENT => file_get_contents(__DIR__ . '/_files/dummy-content.html'), - BlockEntryInterface::KEY => 'test.block.2', - BlockEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-2', - BlockEntryInterface::IS_ACTIVE => true, - BlockEntryInterface::IS_MAINTAINED => false, - BlockEntryInterface::STORES => ['default', 'admin'], - ]]); - - $this->getBlockEntryListMock->method('get')->willReturn($this->blockEntries); - } - - private function compareBlockWithEntryForStore($entryIndex) - { - $entry = $this->blockEntries[$entryIndex]; - $block = $this->getBlockByBlockEntry($entry); - - $this->assertSame($block->getTitle(), $entry->getTitle()); - $this->assertSame($block->getContent(), $entry->getContent()); - $this->assertSame($block->isActive(), $entry->isActive()); - } - - /** - * @param BlockEntryInterface $entry - * @return BlockInterface - * @throws \Magento\Framework\Exception\NoSuchEntityException - * @throws \Magento\Framework\Exception\LocalizedException - */ - private function getBlockByBlockEntry(BlockEntryInterface $entry): BlockInterface - { - return $this->getFirstBlockByBlockEntry->execute($entry); - } - - public function testInstall() - { - $this->initBlockEntries(); - - $this->installer->install(); - - // Verify, that block are in database like defined - $this->compareBlockWithEntryForStore(1); - $this->compareBlockWithEntryForStore(2); - } - - public function testInstallUpdateMaintainedBlocks() - { - $this->initBlockEntries(); - - $this->installer->install(); - - // Change block entry values - $this->blockEntries[1]->setTitle('Changed Block 1'); - $this->blockEntries[1]->setIsActive(true); - $this->blockEntries[1]->setContent('New Content'); - - $this->blockEntries[2]->setTitle('Changed Block 2'); - $this->blockEntries[2]->setIsActive(true); - $this->blockEntries[2]->setContent('New Content'); - - // Execute installer a second time - $this->installer->install(); - - // Verify that first block was updated - $this->compareBlockWithEntryForStore(1); - - // Verify that second block did not change - $entry = $this->blockEntries[2]; - $block = $this->getBlockByBlockEntry($entry); - - $this->assertNotSame($block->getTitle(), $entry->getTitle()); - $this->assertNotSame($block->getContent(), $entry->getContent()); - } -} diff --git a/Test/Integration/Model/PageInstallerTest.php b/Test/Integration/Model/PageInstallerTest.php deleted file mode 100644 index b2f109ada2e22a904f0a7beb8ac3c584ba217709..0000000000000000000000000000000000000000 --- a/Test/Integration/Model/PageInstallerTest.php +++ /dev/null @@ -1,217 +0,0 @@ -<?php -declare(strict_types=1); - -namespace Firegento\ContentProvisioning\Test\Integration\Model; - -use Firegento\ContentProvisioning\Api\Data\PageEntryInterface; -use Firegento\ContentProvisioning\Api\Data\PageEntryInterfaceFactory; -use Firegento\ContentProvisioning\Model\PageInstaller; -use Firegento\ContentProvisioning\Model\Query\GetFirstPageByPageEntry; -use Firegento\ContentProvisioning\Model\Query\GetPageEntryList; -use Magento\Cms\Api\Data\PageInterface; -use Magento\Framework\App\ResourceConnection; -use Magento\Store\Model\StoreManagerInterface; -use PHPUnit\Framework\MockObject\MockObject; -use Magento\TestFramework\Helper\Bootstrap; - -class PageInstallerTest extends \PHPUnit\Framework\TestCase -{ - /** - * @var StoreManagerInterface - */ - private $storeManager; - - /** - * @var GetPageEntryList|MockObject - */ - private $getPageEntryListMock; - - /** - * @var PageInstaller - */ - private $installer; - - /** - * @var PageEntryInterfaceFactory - */ - private $pageEntryInterfaceFactory; - - /** - * @var PageEntryInterface[] - */ - private $pageEntries; - - /** - * @var GetFirstPageByPageEntry - */ - private $getFisrtPageByPageEntry; - - - protected function setUp() - { - parent::setUp(); - - $this->getPageEntryListMock = self::getMockBuilder(GetPageEntryList::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->installer = Bootstrap::getObjectManager() - ->create(PageInstaller::class, ['getAllPageEntries' => $this->getPageEntryListMock]); - - $this->pageEntryInterfaceFactory = Bootstrap::getObjectManager() - ->create(PageEntryInterfaceFactory::class); - - $this->storeManager = Bootstrap::getObjectManager() - ->create(StoreManagerInterface::class); - - $this->getFisrtPageByPageEntry = Bootstrap::getObjectManager() - ->create(GetFirstPageByPageEntry::class); - } - - protected function tearDown() - { - parent::tearDown(); - - $connection = Bootstrap::getObjectManager()->get(ResourceConnection::class); - $connection->getConnection()->delete( - $connection->getTableName('cms_page'), - [ - 'identifier LIKE ?' => 'firegento-content-provisioning-test-%', - ] - ); - $connection->getConnection()->delete( - $connection->getTableName('url_rewrite'), - [ - 'request_path LIKE ?' => 'firegento-content-provisioning-test-%', - 'entity_type = ?' => 'cms-page', - ] - ); - } - - private function initEntries() - { - $this->pageEntries[1] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Test Page 1', - PageEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', - PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', - PageEntryInterface::KEY => 'test.page.1', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-1', - PageEntryInterface::IS_ACTIVE => false, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['admin'], - PageEntryInterface::META_DESCRIPTION => 'Some seo description', - PageEntryInterface::META_KEYWORDS => 'Some, seo, keywords', - PageEntryInterface::META_TITLE => 'Seo title', - PageEntryInterface::PAGE_LAYOUT => '3columns', - PageEntryInterface::LAYOUT_UPDATE_XML => '<foo>bar</foo>', - PageEntryInterface::CUSTOM_THEME => 3, - PageEntryInterface::CUSTOM_THEME_FROM => '2019-03-29', - PageEntryInterface::CUSTOM_THEME_TO => '2019-05-29', - PageEntryInterface::CUSTOM_ROOT_TEMPLATE => '3columns', - ]]); - - $this->pageEntries[2] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Test Page 2', - PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/_files/dummy-content.html'), - PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', - PageEntryInterface::KEY => 'test.page.2', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-2', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => false, - PageEntryInterface::STORES => ['default', 'admin'], - ]]); - - $this->pageEntries[3] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Test Page 3', - PageEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', - PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', - PageEntryInterface::KEY => 'test.page.3', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-3', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['default'], - PageEntryInterface::META_DESCRIPTION => 'Some seo description', - PageEntryInterface::META_KEYWORDS => 'Some, seo, keywords', - PageEntryInterface::META_TITLE => 'Seo title', - PageEntryInterface::PAGE_LAYOUT => '3columns', - PageEntryInterface::LAYOUT_UPDATE_XML => '<foo>bar</foo>' - ]]); - - $this->getPageEntryListMock->method('get')->willReturn($this->pageEntries); - } - - private function comparePageWithEntryForStore($entryIndex) - { - $entry = $this->pageEntries[$entryIndex]; - $block = $this->getPageByPageEntry($entry); - - $this->assertSame($block->getTitle(), $entry->getTitle()); - $this->assertSame($block->getContent(), $entry->getContent()); - $this->assertSame($block->isActive(), $entry->isActive()); - $this->assertSame($block->getMetaDescription(), $entry->getMetaDescription()); - $this->assertSame($block->getMetaKeywords(), $entry->getMetaKeywords()); - $this->assertSame($block->getMetaTitle(), $entry->getMetaTitle()); - $this->assertSame($block->getCustomLayoutUpdateXml(), $entry->getCustomLayoutUpdateXml()); - $this->assertSame($block->getPageLayout(), $entry->getPageLayout()); - $this->assertSame($block->getContentHeading(), $entry->getContentHeading()); - } - - /** - * @param PageEntryInterface $entry - * @return PageInterface - * @throws \Magento\Framework\Exception\NoSuchEntityException - * @throws \Magento\Framework\Exception\LocalizedException - */ - private function getPageByPageEntry(PageEntryInterface $entry): PageInterface - { - return $this->getFisrtPageByPageEntry->execute($entry); - } - - public function testInstall() - { - $this->initEntries(); - - $this->installer->install(); - - // Verify, that pages are in database like defined - $this->comparePageWithEntryForStore(1); - $this->comparePageWithEntryForStore(2); - $this->comparePageWithEntryForStore(3); - } - - public function testInstallUpdateMaintainedPages() - { - $this->initEntries(); - - $this->installer->install(); - - // Change page entry values - $this->pageEntries[1]->setTitle('Changed Page 1'); - $this->pageEntries[1]->setIsActive(true); - $this->pageEntries[1]->setContent('New Content'); - - $this->pageEntries[2]->setTitle('Changed Page 2'); - $this->pageEntries[2]->setIsActive(true); - $this->pageEntries[2]->setContent('New Content'); - - $this->pageEntries[3]->setTitle('Changed Page 3'); - $this->pageEntries[3]->setContent('New Content 333'); - $this->pageEntries[3]->setMetaDescription('New Meta description'); - $this->pageEntries[3]->setPageLayout('1column'); - $this->pageEntries[3]->setContentHeading('Another Content Heading'); - - // Execute installer a second time - $this->installer->install(); - - // Verify that first and third page was updated - $this->comparePageWithEntryForStore(1); - $this->comparePageWithEntryForStore(3); - - // Verify that second page did not change - $entry = $this->pageEntries[2]; - $block = $this->getPageByPageEntry($entry); - - $this->assertNotSame($block->getTitle(), $entry->getTitle()); - $this->assertNotSame($block->getContent(), $entry->getContent()); - } -}