Initial commit: apps.supersam24.ru

This commit is contained in:
root committed 2026-10-22 00:04:27 +03:00
commit e955e1da36
6566 files changed
+1271095

No files matched your search

@@ -0,0 +1,9 @@
# Define the line ending behavior of the different file extensions
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto
* text eol=lf
# Remove files for archives generated using `git archive`
.editorconfig export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
@@ -0,0 +1,2 @@
/vendor
/composer.lock
+28
View File
@@ -0,0 +1,28 @@
The MIT License
CakePHP(tm) : The Rapid Development PHP Framework (http://cakephp.org)
Copyright (c) 2005-present, Cake Software Foundation, Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Cake Software Foundation, Inc.
1785 E. Sahara Avenue,
Suite 490-204
Las Vegas, Nevada 89104,
United States of America.
+83
View File
@@ -0,0 +1,83 @@
# CakePHP Plugin Installer
A composer installer for installing CakePHP 3.0+ plugins.
This installer ensures your application is aware of CakePHP plugins installed
by composer in `vendor/`.
## Usage
Your CakePHP application should already depend on `cakephp/plugin-installer`, if
not in your CakePHP application run:
```
composer require cakephp/plugin-installer:*
```
Your plugins themselves do **not** need to require `cakephp/plugin-installer`. They
only need to specify the `type` in their composer config:
```json
"type": "cakephp-plugin"
```
## Multiple Plugin Paths
If your application uses multiple plugin paths. In addition to configuring your
application settings you will also need to update your `composer.json` to ensure
the generated `cakephp-plugins.php` file is correct:
```
// Define the list of plugin-paths your application uses.
"extra": {
"plugin-paths": ["plugins", "extra_plugins"]
}
```
## Plugin Setup
For the installer to work properly ensure that your plugin's composer config
file has a proper autoload section. Assuming your plugin's namespace is "MyPlugin"
the autoload section would be like:
```json
"autoload": {
"psr-4": {
"MyPlugin\\": "src"
}
}
```
Not strictly necessary for the working of the installer but ideally you would
also have an "autoload-dev" section for loading test files:
```json
"autoload": {
"psr-4": {
"MyPlugin\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"MyPlugin\\Test\\": "tests",
"Cake\\Test\\" : "vendor/cakephp/cakephp/test"
}
}
```
If your top level namespace is a vendor name then your namespace to path mapping
would be like:
```json
"autoload": {
"psr-4": {
"MyVendor\\MyPlugin\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"MyVendor\\MyPlugin\\Test\\": "tests",
"Cake\\Test\\" : "vendor/cakephp/cakephp/test"
}
}
```
+30
View File
@@ -0,0 +1,30 @@
{
"name": "cakephp/plugin-installer",
"description": "A composer installer for CakePHP 3.0+ plugins.",
"type": "composer-installer",
"license": "MIT",
"authors": [
{
"name": "CakePHP Community",
"homepage": "https://cakephp.org"
}
],
"require-dev": {
"composer/composer": "^1.0",
"phpunit/phpunit": "^4.8|^5.7|^6.0",
"cakephp/cakephp-codesniffer": "dev-master"
},
"autoload": {
"psr-4": {
"Cake\\Composer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Cake\\Test\\Composer\\": "tests/"
}
},
"extra": {
"class": "Cake\\Composer\\Installer\\PluginInstaller"
}
}
@@ -0,0 +1,473 @@
<?php
namespace Cake\Composer\Installer;
use Composer\Composer;
use Composer\Installer\LibraryInstaller;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Script\Event;
use Composer\Util\Filesystem;
use RuntimeException;
class PluginInstaller extends LibraryInstaller
{
/**
* A flag to check usage - once
*
* @var bool
*/
protected static $checkUsage = true;
/**
* Check usage upon construction
*
* @param IOInterface $io composer object
* @param Composer $composer composer object
* @param string $type what are we loading
* @param Filesystem $filesystem composer object
*/
public function __construct(IOInterface $io, Composer $composer, $type = 'library', Filesystem $filesystem = null)
{
parent::__construct($io, $composer, $type, $filesystem);
$this->checkUsage($composer);
}
/**
* Check that the root composer.json file use the post-autoload-dump hook
*
* If not, warn the user they need to update their application's composer file.
* Do nothing if the main project is not a project (if it's a plugin in development).
*
* @param Composer $composer object
* @return void
*/
public function checkUsage(Composer $composer)
{
if (static::$checkUsage === false) {
return;
}
static::$checkUsage = false;
$package = $composer->getPackage();
if (!$package || $package->getType() !== 'project') {
return;
}
$scripts = $composer->getPackage()->getScripts();
$postAutoloadDump = 'Cake\Composer\Installer\PluginInstaller::postAutoloadDump';
if (!isset($scripts['post-autoload-dump']) ||
!in_array($postAutoloadDump, $scripts['post-autoload-dump'])
) {
$this->warnUser(
'Action required!',
'The CakePHP plugin installer has been changed, please update your' .
' application composer.json file to add the post-autoload-dump hook.' .
' See the changes in https://github.com/cakephp/app/pull/216 for more' .
' info.'
);
}
}
/**
* Warn the developer of action they need to take
*
* @param string $title Warning title
* @param string $text warning text
*
* @return void
*/
public function warnUser($title, $text)
{
$wrap = function ($text, $width = 75) {
return '<error> ' . str_pad($text, $width) . '</error>';
};
$messages = [
'',
'',
$wrap(''),
$wrap($title),
$wrap(''),
];
$lines = explode("\n", wordwrap($text, 68));
foreach ($lines as $line) {
$messages[] = $wrap($line);
}
$messages = array_merge($messages, [$wrap(''), '', '']);
$this->io->write($messages);
}
/**
* Called whenever composer (re)generates the autoloader
*
* Recreates CakePHP's plugin path map, based on composer information
* and available app-plugins.
*
* @param Event $event the composer event object
* @return void
*/
public static function postAutoloadDump(Event $event)
{
$composer = $event->getComposer();
$config = $composer->getConfig();
$vendorDir = realpath($config->get('vendor-dir'));
$packages = $composer->getRepositoryManager()->getLocalRepository()->getPackages();
$extra = $event->getComposer()->getPackage()->getExtra();
if (empty($extra['plugin-paths'])) {
$pluginsDir = dirname($vendorDir) . DIRECTORY_SEPARATOR . 'plugins';
} else {
$pluginsDir = $extra['plugin-paths'];
}
$plugins = static::determinePlugins($packages, $pluginsDir, $vendorDir);
$configFile = static::_configFile($vendorDir);
static::writeConfigFile($configFile, $plugins);
}
/**
* Find all plugins available
*
* Add all composer packages of type cakephp-plugin, and all plugins located
* in the plugins directory to a plugin-name indexed array of paths
*
* @param array $packages an array of \Composer\Package\PackageInterface objects
* @param string|array $pluginsDir the path to the plugins dir
* @param string $vendorDir the path to the vendor dir
* @return array plugin-name indexed paths to plugins
*/
public static function determinePlugins($packages, $pluginsDir = 'plugins', $vendorDir = 'vendor')
{
$plugins = [];
foreach ($packages as $package) {
if ($package->getType() !== 'cakephp-plugin') {
continue;
}
$ns = static::primaryNamespace($package);
$path = $vendorDir . DIRECTORY_SEPARATOR . $package->getPrettyName();
$plugins[$ns] = $path;
}
foreach ((array)$pluginsDir as $path) {
$path = static::fullpath($path, $vendorDir);
if (is_dir($path)) {
$dir = new \DirectoryIterator($path);
foreach ($dir as $info) {
if (!$info->isDir() || $info->isDot()) {
continue;
}
$name = $info->getFilename();
if ($name[0] === '.') {
continue;
}
$plugins[$name] = $path . DIRECTORY_SEPARATOR . $name;
}
}
}
ksort($plugins);
return $plugins;
}
/**
* Turns relative paths in full paths.
*
* @param string $path Path
* @param string $vendorDir The path to the vendor dir
* @return string
*/
protected static function fullpath($path, $vendorDir)
{
if (preg_match('{^(?:/|[a-z]:|[a-z0-9.]+://)}i', $path)) {
return rtrim($path, '/');
}
if (substr($path, 0, 2) === './') {
$path = substr($path, 2);
}
return rtrim(dirname($vendorDir) . DIRECTORY_SEPARATOR . $path);
}
/**
* Rewrite the config file with a complete list of plugins
*
* @param string $configFile the path to the config file
* @param array $plugins of plugins
* @param string|null $root The root directory. Defaults to a value generated from $configFile
* @return void
*/
public static function writeConfigFile($configFile, $plugins, $root = null)
{
$root = $root ?: dirname(dirname($configFile));
$data = [];
foreach ($plugins as $name => $pluginPath) {
// Normalize to *nix paths.
$pluginPath = str_replace('\\', '/', $pluginPath);
$pluginPath .= '/';
$pluginPath = str_replace(
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
$pluginPath
);
// Namespaced plugins should use /
$name = str_replace('\\', '/', $name);
$data[] = sprintf(" '%s' => '%s'", $name, $pluginPath);
}
$data = implode(",\n", $data);
$contents = <<<'PHP'
<?php
$baseDir = dirname(dirname(__file__));
return [
'plugins' => [
%s
]
];
PHP;
$contents = sprintf($contents, $data);
// Gross hacks to work around composer smashing `__FILE__` in this
// PHP file when it runs the code through eval()
$uppercase = function ($matches) {
return strtoupper($matches[0]);
};
$contents = preg_replace_callback('/__file__/', $uppercase, $contents);
$root = str_replace(
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
$root
);
// Normalize to *nix paths.
$root = str_replace('\\', '/', $root);
$contents = str_replace('\'' . $root, '$baseDir . \'', $contents);
file_put_contents($configFile, $contents);
}
/**
* Path to the plugin config file
*
* @param string $vendorDir path to composer-vendor dir
* @return string absolute file path
*/
protected static function _configFile($vendorDir)
{
return $vendorDir . DIRECTORY_SEPARATOR . 'cakephp-plugins.php';
}
/**
* Get the primary namespace for a plugin package.
*
* @param \Composer\Package\PackageInterface $package composer object
* @return string The package's primary namespace.
* @throws \RuntimeException When the package's primary namespace cannot be determined.
*/
public static function primaryNamespace($package)
{
$primaryNs = null;
$autoLoad = $package->getAutoload();
foreach ($autoLoad as $type => $pathMap) {
if ($type !== 'psr-4') {
continue;
}
$count = count($pathMap);
if ($count === 1) {
$primaryNs = key($pathMap);
break;
}
$matches = preg_grep('#^(\./)?src/?$#', $pathMap);
if ($matches) {
$primaryNs = key($matches);
break;
}
foreach (['', '.'] as $path) {
$key = array_search($path, $pathMap, true);
if ($key !== false) {
$primaryNs = $key;
}
}
break;
}
if (!$primaryNs) {
throw new RuntimeException(
sprintf(
"Unable to get primary namespace for package %s." .
"\nEnsure you have added proper 'autoload' section to your plugin's config" .
" as stated in README on https://github.com/cakephp/plugin-installer",
$package->getName()
)
);
}
return trim($primaryNs, '\\');
}
/**
* Decides if the installer supports the given type.
*
* This installer only supports package of type 'cakephp-plugin'.
*
* @return bool
*/
public function supports($packageType)
{
return 'cakephp-plugin' === $packageType;
}
/**
* Installs specific plugin.
*
* After the plugin is installed, app's `cakephp-plugins.php` config file is updated with
* plugin namespace to path mapping.
*
* @param \Composer\Repository\InstalledRepositoryInterface $repo Repository in which to check.
* @param \Composer\Package\PackageInterface $package Package instance.
* @deprecated superceeded by the post-autoload-dump hook
*/
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
parent::install($repo, $package);
$path = $this->getInstallPath($package);
$ns = static::primaryNamespace($package);
$this->updateConfig($ns, $path);
}
/**
* Updates specific plugin.
*
* After the plugin is installed, app's `cakephp-plugins.php` config file is updated with
* plugin namespace to path mapping.
*
* @param \Composer\Repository\InstalledRepositoryInterface $repo Repository in which to check.
* @param \Composer\Package\PackageInterface $initial Already installed package version.
* @param \Composer\Package\PackageInterface $target Updated version.
* @deprecated superceeded by the post-autoload-dump hook
*
* @throws \InvalidArgumentException if $initial package is not installed
*/
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
parent::update($repo, $initial, $target);
$ns = static::primaryNamespace($initial);
$this->updateConfig($ns, null);
$path = $this->getInstallPath($target);
$ns = static::primaryNamespace($target);
$this->updateConfig($ns, $path);
}
/**
* Uninstalls specific package.
*
* @param \Composer\Repository\InstalledRepositoryInterface $repo Repository in which to check.
* @param \Composer\Package\PackageInterface $package Package instance.
* @deprecated superceeded by the post-autoload-dump hook
*/
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
parent::uninstall($repo, $package);
$path = $this->getInstallPath($package);
$ns = static::primaryNamespace($package);
$this->updateConfig($ns, null);
}
/**
* Update the plugin path for a given package.
*
* @param string $name The plugin name being installed.
* @param string $path The path, the plugin is being installed into.
*/
public function updateConfig($name, $path)
{
$name = str_replace('\\', '/', $name);
$configFile = static::_configFile($this->vendorDir);
$this->_ensureConfigFile($configFile);
$return = include $configFile;
if (is_array($return) && empty($config)) {
$config = $return;
}
if (!isset($config)) {
$this->io->write(
'ERROR - `vendor/cakephp-plugins.php` file is invalid. ' .
'Plugin path configuration not updated.'
);
return;
}
if (!isset($config['plugins'])) {
$config['plugins'] = [];
}
if ($path == null) {
unset($config['plugins'][$name]);
} else {
$config['plugins'][$name] = $path;
}
$root = dirname($this->vendorDir);
static::writeConfigFile($configFile, $config['plugins'], $root);
}
/**
* Ensure that the vendor/cakephp-plugins.php file exists.
*
* If config/plugins.php is found - copy it to the vendor folder
*
* @param string $path the config file path.
* @return void
*/
protected function _ensureConfigFile($path)
{
if (file_exists($path)) {
if ($this->io->isVerbose()) {
$this->io->write('vendor/cakephp-plugins.php exists.');
}
return;
}
$oldPath = dirname(dirname($path)) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'plugins.php';
if (file_exists($oldPath)) {
copy($oldPath, $path);
if ($this->io->isVerbose()) {
$this->io->write('config/plugins.php found and copied to vendor/cakephp-plugins.php.');
}
return;
}
if (!is_dir(dirname($path))) {
mkdir(dirname($path));
}
$root = dirname($this->vendorDir);
static::writeConfigFile($path, [], $root);
if ($this->io->isVerbose()) {
$this->io->write('Created vendor/cakephp-plugins.php');
}
}
}
@@ -0,0 +1,25 @@
<?php
namespace Cake\Test\Composer\Installer;
use Cake\Composer\Installer\PluginInstaller as PluginInstallerSrc;
/**
* Test double for static methods in PluginInstaller
*/
class PluginInstaller extends PluginInstallerSrc
{
/**
* Overriden to return a test-config file
*
* @param string $vendorDir
* @return string path to test plugins config file
*/
public static function configFile($vendorDir)
{
$root = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'plugin-installer-test';
return $root . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'cakephp-plugins.php';
}
}
@@ -0,0 +1,418 @@
<?php
namespace Cake\Test\TestCase\Composer\Installer;
use Cake\Test\Composer\Installer\PluginInstaller;
use Composer\Composer;
use Composer\Package\Package;
use Composer\Repository\RepositoryManager;
use PHPUnit\Framework\TestCase;
class PluginInstallerTest extends TestCase
{
public $package;
public $installer;
/**
* Directories used during tests
*
* @var string
*/
protected $testDirs = [
'',
'vendor',
'plugins',
'plugins/Foo',
'plugins/Fee',
'plugins/Foe',
'plugins/Fum',
'app_plugins',
'app_plugins/Bar',
];
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->package = new Package('CamelCased', '1.0', '1.0');
$this->package->setType('cakephp-plugin');
$this->path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'plugin-installer-test';
foreach ($this->testDirs as $dir) {
if (!is_dir($this->path . '/' . $dir)) {
mkdir($this->path . '/' . $dir);
}
}
$composer = new Composer();
$config = $this->getMockBuilder('Composer\Config')->getMock();
$config->expects($this->any())
->method('get')
->will($this->returnValue($this->path . '/vendor'));
$composer->setConfig($config);
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$rm = new RepositoryManager(
$this->io,
$config
);
$composer->setRepositoryManager($rm);
$this->installer = new PluginInstaller($this->io, $composer);
}
public function tearDown()
{
parent::tearDown();
$dirs = array_reverse($this->testDirs);
if (is_file($this->path . '/vendor/cakephp-plugins.php')) {
unlink($this->path . '/vendor/cakephp-plugins.php');
}
foreach ($dirs as $dir) {
if (is_dir($this->path . '/' . $dir)) {
rmdir($this->path . '/' . $dir);
}
}
}
/**
* Sanity test
*
* The test double should return a path to a test file, where
* the containing folder
*
* @return void
*/
public function testConfigFile()
{
$path = PluginInstaller::configFile("");
$this->assertFileExists(dirname($path));
}
/**
* Ensure that primary namespace detection works.
*
* @return void
*/
public function testPrimaryNamespace()
{
$autoload = [
'psr-4' => [
'FOC\\Authenticate' => ''
]
];
$this->package->setAutoload($autoload);
$ns = PluginInstaller::primaryNamespace($this->package);
$this->assertEquals('FOC\Authenticate', $ns);
$autoload = [
'psr-4' => [
'FOC\Acl\Test' => './tests',
'FOC\Acl' => ''
]
];
$this->package->setAutoload($autoload);
$ns = PluginInstaller::primaryNamespace($this->package);
$this->assertEquals('FOC\Acl', $ns);
$autoload = [
'psr-4' => [
'Foo\Bar' => 'foo',
'Acme\Plugin' => './src'
]
];
$this->package->setAutoload($autoload);
$ns = PluginInstaller::primaryNamespace($this->package);
$this->assertEquals('Acme\Plugin', $ns);
$autoload = [
'psr-4' => [
'Foo\Bar' => 'bar',
'Foo\\' => ''
]
];
$this->package->setAutoload($autoload);
$ns = PluginInstaller::primaryNamespace($this->package);
$this->assertEquals('Foo', $ns);
$autoload = [
'psr-4' => [
'Foo\Bar' => 'bar',
'Foo' => '.'
]
];
$this->package->setAutoload($autoload);
$ns = PluginInstaller::primaryNamespace($this->package);
$this->assertEquals('Foo', $ns);
$autoload = [
'psr-4' => [
'Acme\Foo\Bar' => 'bar',
'Acme\Foo\\' => ''
]
];
$this->package->setAutoload($autoload);
$ns = PluginInstaller::primaryNamespace($this->package);
$this->assertEquals('Acme\Foo', $ns);
$autoload = [
'psr-4' => [
'Acme\Foo\Bar' => '',
'Acme\Foo' => 'src'
]
];
$this->package->setAutoload($autoload);
$name = PluginInstaller::primaryNamespace($this->package);
$this->assertEquals('Acme\Foo', $name);
}
public function testDeterminePlugins()
{
$plugin1 = new Package('cakephp/the-thing', '1.0', '1.0');
$plugin1->setType('cakephp-plugin');
$plugin1->setAutoload([
'psr-4' => [
'TheThing' => 'src/'
]
]);
$plugin2 = new Package('cakephp/princess', '1.0', '1.0');
$plugin2->setType('cakephp-plugin');
$plugin2->setAutoload([
'psr-4' => [
'Princess' => 'src/'
]
]);
$packages = [
$plugin1,
new Package('SomethingElse', '1.0', '1.0'),
$plugin2
];
$return = PluginInstaller::determinePlugins(
$packages,
$this->path . '/doesnt-exist',
$this->path . '/vendor'
);
$expected = [
'Princess' => $this->path . '/vendor/cakephp/princess',
'TheThing' => $this->path . '/vendor/cakephp/the-thing'
];
$this->assertSame($expected, $return, 'Only composer-loaded plugins should be listed');
$return = PluginInstaller::determinePlugins(
$packages,
$this->path . '/plugins',
$this->path . '/vendor'
);
$expected = [
'Fee' => $this->path . '/plugins/Fee',
'Foe' => $this->path . '/plugins/Foe',
'Foo' => $this->path . '/plugins/Foo',
'Fum' => $this->path . '/plugins/Fum',
'Princess' => $this->path . '/vendor/cakephp/princess',
'TheThing' => $this->path . '/vendor/cakephp/the-thing'
];
$this->assertSame($expected, $return, 'Composer and application plugins should be listed');
$return = PluginInstaller::determinePlugins(
$packages,
[$this->path . '/plugins', $this->path . '/app_plugins'],
$this->path . '/vendor'
);
$expected = [
'Bar' => $this->path . '/app_plugins/Bar',
'Fee' => $this->path . '/plugins/Fee',
'Foe' => $this->path . '/plugins/Foe',
'Foo' => $this->path . '/plugins/Foo',
'Fum' => $this->path . '/plugins/Fum',
'Princess' => $this->path . '/vendor/cakephp/princess',
'TheThing' => $this->path . '/vendor/cakephp/the-thing'
];
$this->assertSame($expected, $return, 'Composer and application plugins should be listed');
}
public function testWriteConfigFile()
{
$plugins = [
'Fee' => $this->path . '/plugins/Fee',
'Foe' => $this->path . '/plugins/Foe',
'Foo' => $this->path . '/plugins/Foo',
'Fum' => $this->path . '/plugins/Fum',
'OddOneOut' => '/some/other/path',
'Princess' => $this->path . '/vendor/cakephp/princess',
'TheThing' => $this->path . '/vendor/cakephp/the-thing',
'Vendor\Plugin' => $this->path . '/vendor/vendor/plugin'
];
$path = $this->path . '/vendor/cakephp-plugins.php';
PluginInstaller::writeConfigFile($path, $plugins);
$this->assertFileExists($path);
$contents = file_get_contents($path);
$this->assertContains('<?php', $contents);
$this->assertContains('$baseDir = dirname(dirname(__FILE__));', $contents);
$this->assertContains(
"'Fee' => \$baseDir . '/plugins/Fee/'",
$contents,
'paths should be relative for app-plugins'
);
$this->assertContains(
"'Princess' => \$baseDir . '/vendor/cakephp/princess/'",
$contents,
'paths should be relative for vendor-plugins'
);
$this->assertContains(
"'OddOneOut' => '/some/other/path/'",
$contents,
'paths should stay absolute if it\'s not under the application root'
);
$this->assertContains(
"'Vendor/Plugin' => \$baseDir . '/vendor/vendor/plugin/'",
$contents,
'Plugin namespaces should use forward slash'
);
// Ensure all plugin paths are slash terminated
foreach ($plugins as &$plugin) {
$plugin .= '/';
}
unset($plugin);
$result = require $path;
$expected = [
'plugins' => $plugins
];
$expected['plugins']['Vendor/Plugin'] = $expected['plugins']['Vendor\Plugin'];
unset($expected['plugins']['Vendor\Plugin']);
$this->assertSame($expected, $result, 'The evaluated result should be the same as the input except for namespaced plugin');
}
public function testUpdateConfigNoConfigFile()
{
$this->installer->updateConfig('DebugKit', '/vendor/cakephp/DebugKit');
$this->assertFileExists($this->path . '/vendor/cakephp-plugins.php');
$contents = file_get_contents($this->path . '/vendor/cakephp-plugins.php');
$this->assertContains('<?php', $contents);
$this->assertContains("'plugins' =>", $contents);
$this->assertContains("'DebugKit' => '/vendor/cakephp/DebugKit/'", $contents);
}
public function testUpdateConfigAddPathInvalidFile()
{
file_put_contents($this->path . '/vendor/cakephp-plugins.php', '<?php $foo = "DERP";');
$this->io->expects($this->once())
->method('write');
$this->installer->updateConfig('DebugKit', '/vendor/cakephp/DebugKit');
}
public function testUpdateConfigAddPathFileExists()
{
file_put_contents(
$this->path . '/vendor/cakephp-plugins.php',
'<?php $config = ["plugins" => ["Bake" => "/some/path"]];'
);
$this->installer->updateConfig('DebugKit', '/vendor/cakephp/DebugKit');
$contents = file_get_contents($this->path . '/vendor/cakephp-plugins.php');
$this->assertContains('<?php', $contents);
$this->assertContains("'plugins' =>", $contents);
$this->assertContains("'DebugKit' => '/vendor/cakephp/DebugKit/'", $contents);
$this->assertContains("'Bake' => '/some/path/'", $contents);
}
/**
* testUpdateConfigAddRootPath
*
* @return void
*/
public function testUpdateConfigAddRootPath()
{
file_put_contents(
$this->path . '/vendor/cakephp-plugins.php',
'<?php return ["plugins" => ["Bake" => "/some/path"]];'
);
$this->installer->updateConfig('DebugKit', $this->path . '/vendor/cakephp/debugkit');
$contents = file_get_contents($this->path . '/vendor/cakephp-plugins.php');
$this->assertContains('<?php', $contents);
$this->assertContains('$baseDir = dirname(dirname(__FILE__));', $contents);
$this->assertContains("'DebugKit' => \$baseDir . '/vendor/cakephp/debugkit/'", $contents);
$this->assertContains("'Bake' => '/some/path/'", $contents);
}
/**
* testUpdateConfigAddPath
*
* @return void
*/
public function testUpdateConfigAddPath()
{
file_put_contents(
$this->path . '/vendor/cakephp-plugins.php',
'<?php return ["plugins" => ["Bake" => "/some/path"]];'
);
$this->installer->updateConfig('DebugKit', '/vendor/cakephp/debugkit');
$this->installer->updateConfig('ADmad\JwtAuth', '/vendor/admad/cakephp-jwt-auth');
$contents = file_get_contents($this->path . '/vendor/cakephp-plugins.php');
$this->assertContains('<?php', $contents);
$this->assertContains("'DebugKit' => '/vendor/cakephp/debugkit/'", $contents);
$this->assertContains("'Bake' => '/some/path/'", $contents);
$this->assertContains("'ADmad/JwtAuth' => '/vendor/admad/cakephp-jwt-auth/'", $contents);
}
/**
* test adding windows paths.
*
* @return void
*/
public function testUpdateConfigAddPathWindows()
{
file_put_contents(
$this->path . '/vendor/cakephp-plugins.php',
'<?php return ["plugins" => ["Bake" => "/some/path"]];'
);
$this->installer->updateConfig('DebugKit', '\vendor\cakephp\debugkit');
$contents = file_get_contents($this->path . '/vendor/cakephp-plugins.php');
$this->assertContains('<?php', $contents);
$this->assertContains("'DebugKit' => '/vendor/cakephp/debugkit/'", $contents);
}
/**
* testUpdateConfigRemovePath
*
* @return void
*/
public function testUpdateConfigRemovePath()
{
file_put_contents(
$this->path . '/vendor/cakephp-plugins.php',
'<?php $config = ["plugins" => ["Bake" => "/some/path"]];'
);
$this->installer->updateConfig('Bake', '');
$contents = file_get_contents($this->path . '/vendor/cakephp-plugins.php');
$this->assertContains('<?php', $contents);
$this->assertContains("'plugins' =>", $contents);
$this->assertNotContains("Bake", $contents);
}
}
+4
View File
@@ -0,0 +1,4 @@
<?php
$loader = require __DIR__ . '/../vendor/autoload.php';
$loader->add('Cake\Test\TestCase\Composer', __DIR__ . 'TestCase');