Skip to content

Commit

Permalink
Add installer for TastyIgniter extensions and themes (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Feb 2, 2021
1 parent df100b0 commit 98b34f8
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ is not needed to install packages with these frameworks:
| Sylius | `sylius-theme`
| symfony1 | **`symfony1-plugin`**
| TAO | `tao-extension`
| TastyIgniter | **`tastyigniter-extension`<br>`tastyigniter-theme`**
| Tusk | `tusk-task`<br>`tusk-command`<br>`tusk-asset`
| TYPO3 Flow | `typo3-flow-package`<br>`typo3-flow-framework`<br>`typo3-flow-plugin`<br>`typo3-flow-site`<br>`typo3-flow-boilerplate`<br>`typo3-flow-build`
| TYPO3 CMS | `typo3-cms-extension` (Deprecated in this package, use the [TYPO3 CMS Installers](https://packagist.org/packages/typo3/cms-composer-installers) instead)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"SyDES",
"Sylius",
"symfony",
"TastyIgniter",
"Thelia",
"TYPO3",
"WHMCS",
Expand Down
1 change: 1 addition & 0 deletions src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Installer extends LibraryInstaller
'fuelphp' => 'FuelphpInstaller',
'grav' => 'GravInstaller',
'hurad' => 'HuradInstaller',
'tastyigniter' => 'TastyIgniterInstaller',
'imagecms' => 'ImageCMSInstaller',
'itop' => 'ItopInstaller',
'joomla' => 'JoomlaInstaller',
Expand Down
32 changes: 32 additions & 0 deletions src/Composer/Installers/TastyIgniterInstaller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Composer\Installers;

class TastyIgniterInstaller extends BaseInstaller
{
protected $locations = array(
'extension' => 'extensions/{$vendor}/{$name}/',
'theme' => 'themes/{$name}/',
);

/**
* Format package name.
*
* Cut off leading 'ti-ext-' or 'ti-theme-' if present.
* Strip vendor name of characters that is not alphanumeric or an underscore
*
*/
public function inflectPackageVars($vars)
{
if ($vars['type'] === 'tastyigniter-extension') {
$vars['vendor'] = preg_replace('/[^a-z0-9_]/i', '', $vars['vendor']);
$vars['name'] = preg_replace('/^ti-ext-/', '', $vars['name']);
}

if ($vars['type'] === 'tastyigniter-theme') {
$vars['name'] = preg_replace('/^ti-theme-/', '', $vars['name']);
}

return $vars;
}
}
4 changes: 4 additions & 0 deletions tests/Composer/Installers/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ public function dataForTestSupport()
array('sydes-theme', true),
array('sylius-theme', true),
array('symfony1-plugin', true),
array('tastyigniter-extension', true),
array('tastyigniter-theme', true),
array('thelia-module', true),
array('thelia-frontoffice-template', true),
array('thelia-backoffice-template', true),
Expand Down Expand Up @@ -435,6 +437,8 @@ public function dataForTestInstallPath()
array('sylius-theme', 'themes/my_theme/', 'shama/my_theme'),
array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sfShamaPlugin'),
array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sf-shama-plugin'),
array('tastyigniter-extension', 'extensions/shama/my_extension/', 'shama/my_extension'),
array('tastyigniter-theme', 'themes/my_theme/', 'shama/my_theme'),
array('thelia-module', 'local/modules/my_module/', 'shama/my_module'),
array('thelia-frontoffice-template', 'templates/frontOffice/my_template_fo/', 'shama/my_template_fo'),
array('thelia-backoffice-template', 'templates/backOffice/my_template_bo/', 'shama/my_template_bo'),
Expand Down
94 changes: 94 additions & 0 deletions tests/Composer/Installers/Test/TastyIgniterInstallerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Composer\Installers\Test;

use Composer\Composer;
use Composer\Installers\TastyIgniterInstaller;
use Composer\Package\Package;
use PHPUnit\Framework\TestCase as BaseTestCase;

class TastyIgniterInstallerTest extends BaseTestCase
{
/**
* @var TastyIgniterInstaller
*/
private $installer;

/**
* setUp
*
* @return void
*/
public function setUp()
{
$this->installer = new TastyIgniterInstaller(
new Package('NyanCat', '4.2', '4.2'),
new Composer()
);
}

/**
* @dataProvider packageNameInflectionProvider
*
* @return void
*/
public function testInflectPackageVars($type, $vendor, $name, $expectedVendor, $expectedName)
{
$this->assertEquals(
$this->installer->inflectPackageVars(array(
'vendor' => $vendor,
'name' => $name,
'type' => $type,
)),
array(
'vendor' => $expectedVendor,
'name' => $expectedName,
'type' => $type
)
);
}

public function packageNameInflectionProvider()
{
return array(
array(
'tastyigniter-extension',
'acme',
'pages',
'acme',
'pages',
),
array(
'tastyigniter-extension',
'acme',
'ti-ext-pages',
'acme',
'pages',
),
// tests vendor name containing a hyphen
array(
'tastyigniter-extension',
'foo-bar-co',
'blog',
'foobarco',
'blog',
),
// tests that exactly one '-theme' is cut off
array(
'tastyigniter-theme',
'acme',
'ti-theme-theme',
'acme',
'theme',
),
// tests that names without '-theme' suffix stay valid
array(
'tastyigniter-theme',
'acme',
'someothertheme',
'acme',
'someothertheme',
),
);
}
}

0 comments on commit 98b34f8

Please sign in to comment.