Skip to content

Commit

Permalink
Update MauticInstaller to allow plugins & themes (#484)
Browse files Browse the repository at this point in the history
* Update MauticInstaller to allow plugins & themes with custom directory names

Update MauticInstaller to allow plugins & themes with custom directory names - Please do not merge yet

* Update MauticInstaller.php

* Update README.md

* Update MauticInstaller.php

* Adding mautic composer installer tests

* Fixing tests and making it compatible with PHP 5.3
  • Loading branch information
nickveenhof committed Apr 28, 2021
1 parent 0f4a400 commit 844fcbc
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 7 deletions.
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'
)
)
)
);
}
}

0 comments on commit 844fcbc

Please sign in to comment.