Commit 59a52d88 by Alexander Makarov

Fixes #4556: Gii was incorrectly generating labels

parent c1cf48cf
......@@ -197,7 +197,7 @@ class Generator extends \yii\gii\Generator
$labels[$column->name] = 'ID';
} else {
$label = Inflector::camel2words($column->name);
if (!empty($label) && substr_compare($label, ' id', -3, 3, true)) {
if (!empty($label) && substr_compare($label, ' id', -3, 3, true) === 0) {
$label = substr($label, 0, -3) . ' ID';
}
$labels[$column->name] = $label;
......
<?php
namespace yiiunit\extensions\gii;
use yii\gii\CodeFile;
use yii\gii\generators\controller\Generator as ControllerGenerator;
use yii\gii\generators\crud\Generator as CRUDGenerator;
use yii\gii\generators\extension\Generator as ExtensionGenerator;
......@@ -53,7 +54,11 @@ class GeneratorsTest extends GiiTestCase
$generator->modelClass = 'Profile';
if ($generator->validate()) {
$generator->generate();
$files = $generator->generate();
$modelCode = $files[0]->content;
$this->assertTrue(strpos($modelCode, "'id' => 'ID'") !== false, "ID label should be there:\n" . $modelCode);
$this->assertTrue(strpos($modelCode, "'description' => 'Description',") !== false, "Description label should be there:\n" . $modelCode);
} else {
print_r($generator->getErrors());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment