Skip to content

Commit

Permalink
Add tests/e2e/AddManagedEntityTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Oct 4, 2023
1 parent 06bc8b0 commit e4c6ec4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/e2e/AddManagedEntityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace E2E;

use ProcessHelper\ProcessHelper;

class AddManagedEntityTest extends \PHPUnit\Framework\TestCase {

use CivixProjectTestTrait;

public static $key = 'civix_exportmgd';

public function setUp(): void {
chdir(static::getWorkspacePath());
static::cleanDir(static::getKey());
$this->civixGenerateModule(static::getKey());
chdir(static::getKey());

$this->assertFileGlobs([
'info.xml' => 1,
'civix_exportmgd.php' => 1,
'civix_exportmgd.civix.php' => 1,
]);
$this->civixMixin(['--disable-all' => TRUE]);
}

public function testAddMgd(): void {
$this->assertMixinStatuses(['mgd-php@1' => 'off']);
$this->assertFileGlobs(['managed/OptionGroup_preferred_communication_method.mgd.php' => 0]);

$tester = static::civix('generate:managed');
$tester->execute(['<EntityName>' => 'OptionGroup', '<EntityId>' => 1]);
if ($tester->getStatusCode() !== 0) {
throw new \RuntimeException(sprintf("Failed to generate mgd (%s)", static::getKey()));
}

$this->assertMixinStatuses(['mgd-php@1' => 'on']);
$this->assertFileGlobs(['managed/OptionGroup_preferred_communication_method.mgd.php' => 1]);

ProcessHelper::runOk('php -l managed/OptionGroup_preferred_communication_method.mgd.php');
$expectPhrases = [
"use CRM_CivixExportmgd_ExtensionUtil as E;",
"'title' => E::ts('Preferred Communication Method')",
"'option_group_id.name' => 'preferred_communication_method'",
"'label' => E::ts('Phone')",
"'value' => '1'",
"'label' => E::ts('Email')",
"'value' => '2'",
];
$this->assertStringSequence($expectPhrases, file_get_contents('managed/OptionGroup_preferred_communication_method.mgd.php'));
}

}
17 changes: 17 additions & 0 deletions tests/e2e/CivixProjectTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ public function civixInfoSet(string $xpath, string $value): CommandTester {
return $tester;
}

/**
* Update the mixin settings by calling `civix mixin`.
*
* @param array $options
* Ex: ['--disable-all' => TRUE]
* Ex: ['--enable' => 'foo@1']
* @return \Symfony\Component\Console\Tester\CommandTester
*/
public function civixMixin(array $options): CommandTester {
$tester = static::civix('mixin');
$tester->execute($options);
if ($tester->getStatusCode() !== 0) {
throw new \RuntimeException(sprintf("Failed to call \"civix mixin\" with options: %s", json_encode($options)));
}
return $tester;
}

/**
* Run the 'upgrade' command (non-interactively; all default choices).
*
Expand Down

0 comments on commit e4c6ec4

Please sign in to comment.