Browse Source

Fix #18660: Check name if backslash appears

tags/2.0.44
irice 3 years ago committed by GitHub
parent
commit
02fe7f42c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/console/controllers/MigrateController.php
  3. 41
      tests/framework/console/controllers/MigrateControllerTest.php

1
framework/CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.44 under development
------------------------
- Bug #18660: Check name if backslash appears (iridance)
- Enh #13105: Add yiiActiveForm validate_only property for skipping form auto-submission (ptolomaues)
- Enh #18967: Use proper attribute names for tabular data in `yii\widgets\ActiveField::addAriaAttributes()` (AnkIF)
- Bug #18798: Fix `StringHelper::dirname()` when passing string with a trailing slash (perlexed)

2
framework/console/controllers/MigrateController.php

@ -406,7 +406,7 @@ class MigrateController extends BaseMigrateController
$name = $params['name'];
if ($params['namespace']) {
$name = substr($name, strrpos($name, '\\') + 1);
$name = substr($name, (strrpos($name, '\\') ?: -1) + 1);
}
$templateFile = $this->templateFile;

41
tests/framework/console/controllers/MigrateControllerTest.php

@ -78,6 +78,22 @@ class MigrateControllerTest extends TestCase
$this->assertFileContent($expectedFile, $class, $table, $namespace);
}
/**
* Check config namespace but without input namespace
* @param mixed $expectedFile
* @param mixed $migrationName
* @param mixed $table
* @param array $params
*/
protected function assertCommandCreatedFileWithoutNamespaceInput($expectedFile, $migrationName, $table, $params = [])
{
$params[0] = $migrationName;
list($config, $namespace, $class) = $this->prepareMigrationNameData($this->migrationNamespace . '\\' . $migrationName);
$this->runMigrateControllerAction('create', $params, $config);
$this->assertFileContent($expectedFile, $class, $table, $namespace);
}
public function assertFileContentJunction($expectedFile, $class, $junctionTable, $firstTable, $secondTable, $namespace = null)
{
if ($namespace) {
@ -101,6 +117,23 @@ class MigrateControllerTest extends TestCase
$this->assertFileContentJunction($expectedFile, $class, $junctionTable, $firstTable, $secondTable, $namespace);
}
/**
* Check config namespace but without input namespace
* @param mixed $expectedFile
* @param mixed $migrationName
* @param mixed $junctionTable
* @param mixed $firstTable
* @param mixed $secondTable
*/
protected function assertCommandCreatedJunctionFileWithoutNamespaceInput($expectedFile, $migrationName, $junctionTable, $firstTable, $secondTable)
{
list($config, $namespace, $class) = $this->prepareMigrationNameData($this->migrationNamespace . '\\' . $migrationName);
$this->runMigrateControllerAction('create', [$migrationName], $config);
$this->assertSame(ExitCode::OK, $this->getExitCode());
$this->assertFileContentJunction($expectedFile, $class, $junctionTable, $firstTable, $secondTable, $namespace);
}
protected function prepareMigrationNameData($migrationName)
{
$config = [];
@ -318,6 +351,7 @@ class MigrateControllerTest extends TestCase
$table,
$params
);
$this->assertCommandCreatedFileWithoutNamespaceInput($expectedFile, $migrationName, $table, $params);
}
/**
@ -369,6 +403,13 @@ class MigrateControllerTest extends TestCase
$firstTable,
$secondTable
);
$this->assertCommandCreatedJunctionFileWithoutNamespaceInput(
'junction_test',
$migrationName,
$junctionTable,
$firstTable,
$secondTable
);
}
public function testUpdatingLongNamedMigration()

Loading…
Cancel
Save