Skip to content

Commit

Permalink
add support for testing Mautic 4
Browse files Browse the repository at this point in the history
  • Loading branch information
mollux committed Aug 21, 2023
1 parent cad7ed4 commit 3074e1e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
cp $GITHUB_WORKSPACE/.github/ci-files/local_4.php ./app/config/local.php
php bin/console mautic:install http://localhost/ --force --env=test --mailer_from_name="GitHub Actions" --mailer_from_email="[email protected]"
sed -i "s/('prod',/('test',/g" ./index.php
sed -i 's/env name="MAUTIC_VERSION" value="5"/env name="MAUTIC_VERSION" value="4"/g' ./phpunit.xml.dist
else
cp $GITHUB_WORKSPACE/.github/ci-files/local_5.php ./app/config/local.php
php bin/console mautic:install http://localhost/ --force --env=test
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="MAUTIC_VERSION" value="5"/>
</php>
</phpunit>
8 changes: 7 additions & 1 deletion tests/Api/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class AssetsTest extends MauticApiTestCase
{
protected $skipPayloadAssertion = ['file'];

protected $mediaFolder = 'media';

public function setUp(): void
{
$this->api = $this->getContext('assets');
Expand All @@ -22,6 +24,10 @@ public function setUp(): void
'storageLocation' => 'remote',
'file' => 'https://www.mautic.org/media/logos/logo/Mautic_Logo_DB.pdf',
];

if ('4' == $this->mauticVersion) {
$this->mediaFolder = 'assets';
}
}

public function testGetList()
Expand All @@ -38,7 +44,7 @@ public function testCreateWithLocalFileGetAndDelete()
{
// Upload a testing file
$this->apiFiles = $this->getContext('files');
$this->apiFiles->setFolder('media');
$this->apiFiles->setFolder($this->mediaFolder);
$fileRequest = [
'file' => dirname(__DIR__).'/mauticlogo.png',
];
Expand Down
11 changes: 9 additions & 2 deletions tests/Api/FilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

class FilesTest extends MauticApiTestCase
{
protected $mediaFolder = 'media';

public function setUp(): void
{
$this->api = $this->getContext('files');
$this->testPayload['file'] = dirname(__DIR__).'/mauticlogo.png';

if ('4' == $this->mauticVersion) {
$this->mediaFolder = 'assets';
}

$this->assertTrue(file_exists($this->testPayload['file']), 'A file for test at '.$this->testPayload['file'].' does not exist.');
}

Expand Down Expand Up @@ -46,7 +53,7 @@ public function testGetListSubdir()

public function testGetListMediaFiles()
{
$this->api->setFolder('media');
$this->api->setFolder($this->mediaFolder);
$response = $this->api->getList();
$this->assertErrors($response);
}
Expand Down Expand Up @@ -86,7 +93,7 @@ public function testCreateAndDeleteImageInSubdir()

public function testCreateAndDeleteMedia()
{
$this->api->setFolder('media');
$this->api->setFolder($this->mediaFolder);
$response = $this->api->create($this->testPayload);
$this->assertPayload($response);

Expand Down
3 changes: 3 additions & 0 deletions tests/Api/MauticApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract class MauticApiTestCase extends TestCase
protected $skipPayloadAssertion = [];
protected $testPayload = [];

protected $mauticVersion = null;

/** @var Api */
protected $api;

Expand Down Expand Up @@ -67,6 +69,7 @@ protected function getAuth()

protected function getContext($context)
{
$this->mauticVersion = $_ENV['MAUTIC_VERSION'] ?? '5';
list($auth, $apiUrl) = $this->getAuth();

$api = new MauticApi();
Expand Down
6 changes: 6 additions & 0 deletions tests/Api/StatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public function testGetTables()
'video_hits',
'webhook_logs',
];

if ('4' == $this->mauticVersion) {
$expectedTables[] = 'plugin_citrix_events';
sort($expectedTables);
}

$tables = $this->getTableList();
$this->assertTrue(!empty($tables));
$this->assertSame(
Expand Down

0 comments on commit 3074e1e

Please sign in to comment.