Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/post-install-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
43 changes: 43 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: RW Integration Tests
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
integration-tests:
name: Magento 2 Integration Tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_SQL_TO_RUN: 'GRANT ALL ON *.* TO "root"@"%";'
ports:
- 3306:3306
options: --tmpfs /tmp:rw --tmpfs /var/lib/mysql:rw --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
es:
image: docker.io/wardenenv/elasticsearch:7.8
ports:
- 9200:9200
env:
'discovery.type': single-node
'xpack.security.enabled': false
ES_JAVA_OPTS: "-Xms64m -Xmx512m"
options: --health-cmd="curl localhost:9200/_cluster/health?wait_for_status=yellow&timeout=60s" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v4
- name: M2 Integration Tests with Magento 2 (Php8.1)
uses: extdn/github-actions-m2/magento-integration-tests/8.1@master
with:
MAGENTO_PRE_INSTALL_SCRIPT: ./.github/scripts/pre-install-script.sh
MAGENTO_POST_INSTALL_SCRIPT: ./.github/scripts/post-install-script.sh
MODULE_NAME: RocketWeb_CmsImportExport
COMPOSER_NAME: rocketweb/module-cms-import-export
MAGENTO_VERSION: '2.4.5-p5'
PHPUNIT_FILE: './phpunit.rw.xml'
COMPOSER_VERSION: 2
106 changes: 106 additions & 0 deletions Test/Integration/ExportByStoreScopeEntitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

namespace RocketWeb\CmsImportExport\Test\Integration;

use Magento\Framework\Exception\FileSystemException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\App\Filesystem;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
use RocketWeb\CmsImportExport\Model\Service\DumpCmsDataService;

/**
* @magentoAppIsolation disabled
* @magentoDbIsolation disabled
* @magentoAppArea adminhtml
*/
class ExportByStoreScopeEntitiesTest extends TestCase
{
protected ?DumpCmsDataService $exporter;
protected ?string $exportDirPath;
protected ?WriteInterface $varDirectory;

/**
* @return void
* @throws FileSystemException
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$fileSystem = $objectManager->create(Filesystem::class);
$this->exporter = $objectManager->create(DumpCmsDataService::class);
$this->varDirectory = $fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->exportDirPath = $this->varDirectory->getAbsolutePath() . 'sync_cms_data';
$storeManager = $objectManager->create(StoreManagerInterface::class);
if ($storeManager->getStore()->getId() != '0') {
$storeManager->setCurrentStore(0);
}
}

public function getExecuteCases(): array
{
return [
['block', 'imported_cms_block_multistore', ['default', 'second_store_view']],
['page', 'imported_cms_page_multistore', ['default', 'second_store_view']],
];
}

/**
* @param string $type
* @param string $identifier
* @param array $scopes
* @return void
* @throws FileSystemException
* @magentoDataFixture RocketWeb_CmsImportExport::_files/multiple_websites_with_store_groups_stores.php
* @dataProvider getExecuteCases
* @magentoDataFixture RocketWeb_CmsImportExport::_files/multi_store_block.php
* @magentoDataFixture RocketWeb_CmsImportExport::_files/multi_store_page.php
*/
public function testCmsExportedCorrectlyByScope(
string $type,
string $identifier,
array $scopes
) {
$this->exporter->execute([$type], [$identifier], false);
//validate that the export folder exists
self::assertTrue(
$this->varDirectory->isExist($this->exportDirPath),
__CLASS__ . ' Export directory does not exist'
);

$filename = sprintf(
"$identifier---%s.json",
implode('---', $scopes)
);
$filepath = sprintf(
'%s/%s/%s',
$this->exportDirPath,
$type === 'block' ? 'cms/blocks' : 'cms/pages',
$filename
);
//validate file was created successfully
self::assertTrue(
$this->varDirectory->isFile($filepath),
__CLASS__ . " $filename does not exist"
);

$decoded = json_decode(
$this->varDirectory->readFile($filepath),
true
);
//validate file structure was created successfully
self::assertArrayHasKey(
'identifier',
$decoded,
__CLASS__ . " $filename does not have the correct structure"
);
self::assertTrue(
$decoded['identifier'] === $identifier,
__CLASS__ . " Invalid identifiers, file: {$decoded['identifier']}, provided $identifier"
);
}
}
107 changes: 107 additions & 0 deletions Test/Integration/ExportEntitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

declare(strict_types=1);

namespace RocketWeb\CmsImportExport\Test\Integration;

use Magento\Framework\Exception\FileSystemException;
use Magento\TestFramework\App\Filesystem;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
use RocketWeb\CmsImportExport\Model\Service\DumpCmsDataService;

/**
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class ExportEntitiesTest extends TestCase
{
protected ?DumpCmsDataService $exporter;
protected ?string $exportDirPath;
protected ?WriteInterface $varDirectory;

protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$fileSystem = $objectManager->create(Filesystem::class);
$this->exporter = $objectManager->create(DumpCmsDataService::class);
$this->varDirectory = $fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->exportDirPath = $this->varDirectory->getAbsolutePath() . 'sync_cms_data';
}

public function getExecuteCases(): array
{
return [
['block'],
['page'],
];
}

/**
* @return void
* @throws FileSystemException
*/
protected function tearDown(): void
{
if ($this->varDirectory->isExist($this->exportDirPath))
$this->varDirectory->delete($this->exportDirPath);
}

/**
* @param string $type
* @return void
* @throws FileSystemException
* @dataProvider getExecuteCases
* @magentoDataFixture Magento/Cms/_files/block.php
* @magentoDataFixture Magento/Cms/_files/noroute.php
*/
public function testCmsExportedCorrectly(string $type)
{
$this->exporter->execute([$type], null, false);
//validate that the export folder exists
self::assertTrue(
$this->varDirectory->isExist($this->exportDirPath)
);
if ($type === 'block') {
$filepath = sprintf(
'%s/%s/%s',
$this->exportDirPath,
'cms/blocks',
'fixture_block---default.json'
);
//validate file was created successfully
self::assertTrue(
$this->varDirectory->isFile($filepath)
);
$decoded = json_decode(
$this->varDirectory->readFile($filepath),
true
);
//validate file structure was created successfully
self::assertArrayHasKey('identifier', $decoded);
self::assertTrue($decoded['identifier'] === 'fixture_block');
}

if ($type === 'page') {
$filepath = sprintf(
'%s/%s/%s',
$this->exportDirPath,
'cms/pages',
'no-route---_all_.json'
);
//validate file was created successfully
self::assertTrue(
$this->varDirectory->isFile($filepath)
);
$decoded = json_decode(
$this->varDirectory->readFile($filepath),
true
);
//validate file structure was created successfully
self::assertArrayHasKey('identifier', $decoded);
self::assertTrue($decoded['identifier'] === 'no-route');
}
}
}
Loading