Skip to content

Commit

Permalink
Fixes #398, #397: Use strict mode when generating view folder name
Browse files Browse the repository at this point in the history
  • Loading branch information
machour authored and samdark committed Feb 17, 2019
1 parent bfe6044 commit 505c92d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ before_script:
fi
script:
- phpunit $PHPUNIT_FLAGS
- ./vendor/bin/phpunit $PHPUNIT_FLAGS

after_script:
- |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 gii extension Change Log
2.1.0 under development
-----------------------

- Bug #398, #397: Use strict mode when generating view folder name (machour)
- Enh #390, Bug #260: Create (bootstrap)-independent version (simialbi)
- Enh #395: Made `yii\gii\CodeFile` indepdendent of controller context, do not apply `$newDirMode` and `$newFileMode` if module is not available (CeBe)

Expand Down
7 changes: 6 additions & 1 deletion src/generators/crud/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class Generator extends \yii\gii\Generator
* @since 2.0.5
*/
public $enablePjax = false;
/**
* @var bool whether to use strict inflection for controller IDs (insert a separator between two consecutive uppercase chars)
* @since 2.1.0
*/
public $strictInflector = true;


/**
Expand Down Expand Up @@ -195,7 +200,7 @@ public function getControllerID()
$pos = strrpos($this->controllerClass, '\\');
$class = substr(substr($this->controllerClass, $pos + 1), 0, -10);

return Inflector::camel2id($class);
return Inflector::camel2id($class, '-', $this->strictInflector);
}

/**
Expand Down
30 changes: 29 additions & 1 deletion tests/generators/CrudGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,32 @@ public function testGenerateColumnFormat()
$c = new ColumnSchema(['phpType' => 'string', 'type' => 'string', 'name' => 'url_lalala']);
$this->assertEquals('url', $g->generateColumnFormat($c));
}
}

public function testGeneratedControllerId()
{
$g = new Generator();
$g->controllerClass = '\app\controllers\TestController';
$this->assertEquals('test', $g->getControllerID());

$g = new Generator();
$g->controllerClass = '\app\controllers\SomeTestController';
$this->assertEquals('some-test', $g->getControllerID());

$g = new Generator();
$g->controllerClass = '\app\controllers\ATestController';
$this->assertEquals('a-test', $g->getControllerID());

$g = new Generator();
$g->controllerClass = '\app\controllers\YoTestController';
$this->assertEquals('yo-test', $g->getControllerID());

$g = new Generator();
$g->controllerClass = '\app\controllers\ABCTestController';
$this->assertEquals('a-b-c-test', $g->getControllerID());

$g = new Generator();
$g->controllerClass = '\app\controllers\XYTestController';
$this->assertEquals('x-y-test', $g->getControllerID());
}

}

0 comments on commit 505c92d

Please sign in to comment.