mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	Fix #18660: Check name if backslash appears
This commit is contained in:
		@ -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)
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user