Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MauticInstaller to allow plugins & themes #484

Merged
merged 6 commits into from
Apr 28, 2021
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ is not needed to install packages with these frameworks:
| majima | `majima-plugin`
| Mako | `mako-package`
| MantisBT | `mantisbt-plugin`
| Mautic | `mautic-plugin`<br>`mautic-theme`
| Mautic | `mautic-core`<br>`mautic-plugin`<br>`mautic-theme`
| Maya | `maya-module`
| MODX | `modx-extra`
| MODX Evo | `modxevo-snippet`<br>`modxevo-plugin`<br>`modxevo-module`<br>`modxevo-template`<br>`modxevo-lib`
Expand Down
35 changes: 29 additions & 6 deletions src/Composer/Installers/MauticInstaller.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
<?php
namespace Composer\Installers;

use Composer\Package\PackageInterface;

class MauticInstaller extends BaseInstaller
{
protected $locations = array(
'plugin' => 'plugins/{$name}/',
'theme' => 'themes/{$name}/',
'plugin' => 'plugins/{$name}/',
'theme' => 'themes/{$name}/',
'core' => 'app/',
);

private function getDirectoryName()
{
$extra = $this->package->getExtra();
if (!empty($extra['install-directory-name'])) {
return $extra['install-directory-name'];
}

return $this->toCamelCase($this->package->getPrettyName());
}

/**
* @param string $packageName
*
* @return string
*/
private function toCamelCase($packageName)
{
return str_replace(' ', '', ucwords(str_replace('-', ' ', basename($packageName))));
}

/**
* Format package name of mautic-plugins to CamelCase
*/
public function inflectPackageVars($vars)
{
if ($vars['type'] == 'mautic-plugin') {
$vars['name'] = preg_replace_callback('/(-[a-z])/', function ($matches) {
return strtoupper($matches[0][1]);
}, ucfirst($vars['name']));

if ($vars['type'] == 'mautic-plugin' || $vars['type'] == 'mautic-theme') {
$directoryName = $this->getDirectoryName();
$vars['name'] = $directoryName;
}

return $vars;
Expand Down
116 changes: 116 additions & 0 deletions tests/Composer/Installers/Test/MauticInstallerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
namespace Composer\Installers\Test;

use Composer\Installers\MauticInstaller;
use Composer\Package\Package;
use Composer\Composer;

class MauticInstallerTest extends TestCase
{
/**
* @var MauticInstaller
*/
private $installer;

/**
* @var \Composer\Composer
*/
protected $composer;

public function setUp()
{
$this->composer = new Composer();
}

/**
* @param string[] $vars
* @param string[] $expectedVars
*
* @covers ::inflectPackageVars
*
* @dataProvider provideExpectedInflectionResults
*/
final public function testInflectPackageVars($vars, $expectedVars)
{
$package = new Package($vars['name'], '1.0.0', '1.0.0');
$package->setType($vars['type']);
if (isset($vars['extra'])) {
$package->setExtra((array) $vars['extra']);
}

$installer = new MauticInstaller(
$package,
$this->composer
);

$actual = $installer->inflectPackageVars($vars);
$this->assertEquals($actual, $expectedVars);
}

/**
* Provides various parameters for packages and the expected result after
* inflection
*
* @return array
*/
final public function provideExpectedInflectionResults()
{
return array(
//check bitrix-dir is correct
array(
array(
'name' => 'mautic/grapes-js-builder-bundle',
'type' => 'mautic-plugin'
),
array(
'name' => 'GrapesJsBuilderBundle',
'type' => 'mautic-plugin'
)
),
// Check if composer renames the name based on the given
// installation directory
array(
array(
'name' => 'mautic/grapes-js-builder-bundle',
'type' => 'mautic-plugin',
'extra' => array(
'install-directory-name' => 'GrapesJsBuilderPlugin'
)
),
array(
'name' => 'GrapesJsBuilderPlugin',
'type' => 'mautic-plugin',
'extra' => array(
'install-directory-name' => 'GrapesJsBuilderPlugin'
)
)
),
array(
array(
'name' => 'mautic/theme-blank-grapejs',
'type' => 'mautic-theme'
),
array(
'name' => 'ThemeBlankGrapejs',
'type' => 'mautic-theme'
)
),
array(
array(
'name' => 'mautic/theme-blank-grapejs',
'type' => 'mautic-theme',
'extra' => array(
'install-directory-name' => 'blank-grapejs'
)
),
array(
'name' => 'blank-grapejs',
'type' => 'mautic-theme',
'extra' => array(
'install-directory-name' => 'blank-grapejs'
)
)
)
);
}
}