Skip to content
Snippets Groups Projects
Commit 2846605c authored by Vadim Justus's avatar Vadim Justus
Browse files

Refactore integration tests structure

parent c1c13b10
No related branches found
No related tags found
1 merge request!14Introduce logic for handling with media files
Showing
with 575 additions and 1 deletion
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Test\Integration\Model\BlockInstaller;
class InstallTest extends TestCase
{
public function testInstall()
{
$this->initBlockEntries();
$this->installer->install();
// Verify, that block are in database like defined
$this->compareBlockWithEntryForStore(1);
$this->compareBlockWithEntryForStore(2);
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Test\Integration\Model\BlockInstaller;
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 TestCase extends \PHPUnit\Framework\TestCase
{
/**
* @var BlockInstaller
*/
protected $installer;
/**
* @var GetBlockEntryList|MockObject
*/
protected $getBlockEntryListMock;
/**
* @var BlockEntryInterfaceFactory
*/
protected $blockEntryInterfaceFactory;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var BlockEntryInterface[]
*/
protected $blockEntries = [];
/**
* @var GetFirstBlockByBlockEntry
*/
protected $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-%',
]
);
}
protected 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/content/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);
}
protected 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
*/
protected function getBlockByBlockEntry(BlockEntryInterface $entry): BlockInterface
{
return $this->getFirstBlockByBlockEntry->execute($entry);
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Test\Integration\Model\BlockInstaller;
class UpdateMaintainedTest extends TestCase
{
public function testInstall()
{
$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());
}
}
......@@ -21,7 +21,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
public function testConverter()
{
$pathFiles = __DIR__ . '/_files';
$pathFiles = __DIR__ . '/../../_files';
$expectedResult = require $pathFiles . '/result.php';
$path = $pathFiles . '/content_provisioning.xml';
$domDocument = new \DOMDocument();
......
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Test\Integration\Model\PageInstaller;
class InstallTest extends TestCase
{
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);
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Test\Integration\Model\PageInstaller;
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 TestCase extends \PHPUnit\Framework\TestCase
{
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var GetPageEntryList|MockObject
*/
protected $getPageEntryListMock;
/**
* @var PageInstaller
*/
protected $installer;
/**
* @var PageEntryInterfaceFactory
*/
protected $pageEntryInterfaceFactory;
/**
* @var PageEntryInterface[]
*/
protected $pageEntries;
/**
* @var GetFirstPageByPageEntry
*/
protected $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',
]
);
}
protected 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/content/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);
}
protected 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
*/
protected function getPageByPageEntry(PageEntryInterface $entry): PageInterface
{
return $this->getFisrtPageByPageEntry->execute($entry);
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Test\Integration\Model\PageInstaller;
class UpdateMaintainedTest extends TestCase
{
public function testInstall()
{
$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());
}
}
<h5>Some foobar</h5>
<p>Foobar: <a href="{{media url=&quot;image-1.png&quot;}}">Link zu einem Bilder</a></p>
<p>Dummy content...</p>
<p>Image:&nbsp;<img src="{{media url=&quot;some-test-image.png&quot;}}" alt="fooo" width="300"></p>
<p>Image 2:&nbsp;<img src="{{media url=&quot;foobar/test.png&quot;}}" alt="" width="450" height="150"></p>
\ No newline at end of file
<h1>Dummy Content</h1>
<p>
Some test block content
</p>
\ No newline at end of file
<p>
Some test page content
</p>
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Firegento/ContentProvisioning/etc/content_provisioning.xsd">
<page key="test.page.1" identifier="test-page-1" maintained="true" active="true">
<title>Test Page 1</title>
<content type="file">Firegento_ContentProvisioning::Test/Integration/_files/content/file-1.html</content>
</page>
<page key="test.page.2" identifier="test-page-2" active="false">
<title>Title 2</title>
<content heading="New Page Heading 2" type="file">Firegento_ContentProvisioning::Test/Integration/_files/content/file-1.html</content>
<stores>
<store code="default" />
<store code="admin" />
</stores>
<seo>
<title>SEO Page Title</title>
<keywords>Some, SEO, keywords</keywords>
<description>SEO description</description>
</seo>
<design>
<layout>3columns</layout>
<layout_xml><![CDATA[<foo>bar</foo>]]></layout_xml>
</design>
<custom_design>
<from>2019-03-03</from>
<to>2019-03-29</to>
<layout>3columns</layout>
<theme_id>3</theme_id>
</custom_design>
</page>
<page key="test.page.3" identifier="test-page-3" active="true" maintained="true">
<title>Page With Images</title>
<content type="file">Firegento_ContentProvisioning::Test/Integration/_files/content/content-with-images-1.html</content>
<media_directory>Firegento_ContentProvisioning::Test/Integration/_files/content/media</media_directory>
</page>
<block key="test.block.1" identifier="test-block-1" maintained="true" active="true">
<title>Test Block 1</title>
<content><![CDATA[<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>]]></content>
</block>
<block key="test.block.2" identifier="test-block-2" maintained="false" active="true">
<title>Test Block 2</title>
<content type="file">Firegento_ContentProvisioning::Test/Integration/_files/content/file-1.html</content>
<stores>
<store code="default" />
<store code="admin" />
</stores>
</block>
<block key="test.block.3" identifier="test-block-3" maintained="true" active="true">
<title>Block With Images</title>
<content type="file">Firegento_ContentProvisioning::Test/Integration/_files/content/content-with-images-1.html</content>
<media_directory>Firegento_ContentProvisioning::Test/Integration/_files/content/media</media_directory>
</block>
</config>
\ No newline at end of file
<?php
use \Firegento\ContentProvisioning\Api\Data\PageEntryInterface;
use \Firegento\ContentProvisioning\Api\Data\BlockEntryInterface;
return [
'pages' => [
'test.page.1' => [
PageEntryInterface::TITLE => 'Test Page 1',
PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/content/file-1.html'),
PageEntryInterface::KEY => 'test.page.1',
PageEntryInterface::IDENTIFIER => 'test-page-1',
PageEntryInterface::IS_ACTIVE => true,
PageEntryInterface::IS_MAINTAINED => true,
PageEntryInterface::STORES => ['admin'],
PageEntryInterface::CONTENT_HEADING => '',
PageEntryInterface::MEDIA_DIRECTORY => null,
PageEntryInterface::MEDIA_FILES => [],
],
'test.page.2' => [
PageEntryInterface::TITLE => 'Title 2',
PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/content/file-1.html'),
PageEntryInterface::KEY => 'test.page.2',
PageEntryInterface::IDENTIFIER => 'test-page-2',
PageEntryInterface::IS_ACTIVE => false,
PageEntryInterface::IS_MAINTAINED => false,
PageEntryInterface::STORES => ['default', 'admin'],
PageEntryInterface::CONTENT_HEADING => 'New Page Heading 2',
PageEntryInterface::META_TITLE => 'SEO Page Title',
PageEntryInterface::META_KEYWORDS => 'Some, SEO, keywords',
PageEntryInterface::META_DESCRIPTION => 'SEO description',
PageEntryInterface::PAGE_LAYOUT => '3columns',
PageEntryInterface::LAYOUT_UPDATE_XML => '<foo>bar</foo>',
PageEntryInterface::CUSTOM_THEME_FROM => '2019-03-03',
PageEntryInterface::CUSTOM_THEME_TO => '2019-03-29',
PageEntryInterface::CUSTOM_THEME => '3',
PageEntryInterface::CUSTOM_ROOT_TEMPLATE => '3columns',
PageEntryInterface::MEDIA_DIRECTORY => null,
PageEntryInterface::MEDIA_FILES => [],
],
'test.page.3' => [
PageEntryInterface::TITLE => 'Page With Images',
PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/content/content-with-images-1.html'),
PageEntryInterface::KEY => 'test.page.3',
PageEntryInterface::IDENTIFIER => 'test-page-3',
PageEntryInterface::IS_ACTIVE => true,
PageEntryInterface::IS_MAINTAINED => true,
PageEntryInterface::STORES => ['admin'],
PageEntryInterface::CONTENT_HEADING => '',
PageEntryInterface::MEDIA_DIRECTORY => __DIR__ . '/content/media',
PageEntryInterface::MEDIA_FILES => [
'image-1.png',
'some-test-image.png',
'foobar/test.png',
],
]
],
'blocks' => [
'test.block.1' => [
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 => 'test-block-1',
BlockEntryInterface::IS_ACTIVE => true,
BlockEntryInterface::IS_MAINTAINED => true,
BlockEntryInterface::STORES => ['admin'],
BlockEntryInterface::MEDIA_DIRECTORY => null,
BlockEntryInterface::MEDIA_FILES => [],
],
'test.block.2' => [
BlockEntryInterface::TITLE => 'Test Block 2',
BlockEntryInterface::CONTENT => file_get_contents(__DIR__ . '/content/file-1.html'),
BlockEntryInterface::KEY => 'test.block.2',
BlockEntryInterface::IDENTIFIER => 'test-block-2',
BlockEntryInterface::IS_ACTIVE => true,
BlockEntryInterface::IS_MAINTAINED => false,
BlockEntryInterface::STORES => ['default', 'admin'],
BlockEntryInterface::MEDIA_DIRECTORY => null,
BlockEntryInterface::MEDIA_FILES => [],
],
'test.block.3' => [
BlockEntryInterface::TITLE => 'Block With Images',
BlockEntryInterface::CONTENT => file_get_contents(__DIR__ . '/content/content-with-images-1.html'),
BlockEntryInterface::KEY => 'test.block.3',
BlockEntryInterface::IDENTIFIER => 'test-block-3',
BlockEntryInterface::IS_ACTIVE => true,
BlockEntryInterface::IS_MAINTAINED => true,
BlockEntryInterface::STORES => ['admin'],
BlockEntryInterface::MEDIA_DIRECTORY => __DIR__ . '/content/media',
BlockEntryInterface::MEDIA_FILES => [
'image-1.png',
'some-test-image.png',
'foobar/test.png',
],
],
],
];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment