Commit 5e356081 authored by Ghislain Loas's avatar Ghislain Loas

Merge branch 'dev#56034_3455contractuel_renommer_module_formation' into 'master'

Dev#56034 3455contractuel renommer module formation

See merge request !20
parents bcc363ad 455ad18f
Pipeline #1235 passed with stage
in 7 seconds
......@@ -29,20 +29,18 @@ THE SOFTWARE.
* Used to generate on-the-fly method names and attributes for Storm_Model_Abstract mainly
*/
class Storm_Inflector {
protected static $_singular = [
'/eux$/i' => 'eu',
'/aux$/i' => 'al',
'/s$/i' => ''
];
protected static $_plural = [
'/eu$/i'=> 'eux',
'/al$/i'=> 'aux',
'/s$/i'=> 's',
'/$/'=> 's'
];
protected static
protected static $_singular = ['/activities$/i' => 'activity',
'/eux$/i' => 'eu',
'/aux$/i' => 'al',
'/s$/i' => ''];
protected static $_plural = ['/eu$/i'=> 'eux',
'/al$/i'=> 'aux',
'/y$/i' => 'ies',
'/s$/i'=> 's',
'/$/'=> 's'];
protected static
$_uncountable = ['avis'],
$_underscorize_cache = [],
$_camelize_cache = [];
......@@ -51,14 +49,14 @@ class Storm_Inflector {
/**
* Returns given_word as CamelCased
*
* @param string $word
* @param string $word
* @return string
*/
public static function camelize($word) {
if (isset(self::$_camelize_cache[$word]))
return self::$_camelize_cache[$word];
return self::$_camelize_cache[$word] = str_replace(' ',
'',
'',
ucwords(preg_replace('/[^A-Z^a-z^0-9]+/',' ',strtolower($word))));
}
......@@ -66,14 +64,14 @@ class Storm_Inflector {
/**
* Returns GivenWord as variable_name_with_underscores
*
* @param string $word
* @param string $word
* @return string
*/
public static function underscorize($word) {
if (isset(self::$_underscorize_cache[$word]))
return self::$_underscorize_cache[$word];
return self::$_underscorize_cache[$word] = strtolower(
preg_replace(['/([A-Z])([A-Z])/', '/([^A-Z_])([A-Z])/'],
preg_replace(['/([A-Z])([A-Z])/', '/([^A-Z_])([A-Z])/'],
'$1_$2',
$word)
);
......@@ -88,12 +86,12 @@ class Storm_Inflector {
if (self::_isUncountable($word))
return $word;
foreach (self::$_singular as $rule => $replacement) {
if ($word != ($singular = preg_replace($rule, $replacement, $word)))
return $singular;
}
return $word;
}
......@@ -105,7 +103,7 @@ class Storm_Inflector {
public static function pluralize($word) {
if (self::_isUncountable($word))
return $word;
foreach (self::$_plural as $rule => $replacement) {
if ($word !== ($plural = preg_replace($rule, $replacement, $word)))
return $plural;
......
<?php
/*
STORM is under the MIT License (MIT)
STORM is under the MIT License (MIT)
Copyright (c) 2010-2011 Agence Française Informatique http://www.afi-sa.fr
Copyright (c) 2010-2011 Agence Française Informatique http://www.afi-sa.fr
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:
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 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.
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.
*/
......@@ -33,38 +33,71 @@ abstract class InflectorTestCase extends PHPUnit_Framework_TestCase {
class InflectorPluralizeFrenchTest extends InflectorTestCase {
public function datas() {
class InflectorPluralizeTest extends InflectorTestCase {
public function frensh() {
return [['cheval', 'chevaux'],
['Lieu', 'Lieux'],
['categorie', 'categories'],
['avis', 'avis']];
}
/**
* @test
* @dataProvider datas
public function english() {
return [['item', 'items'],
['category', 'categories']];
}
/**
* @test
* @dataProvider frensh
*/
public function pluralizeShouldReturnPlural($singular, $plural) {
public function pluralizeFrenshShouldReturnPlural($singular, $plural) {
$this->assertEquals($plural, Storm_Inflector::pluralize($singular));
}
/**
* @test
* @dataProvider english
*/
public function pluralizEnglishShouldReturnPlural($singular, $plural) {
$this->assertEquals($plural, Storm_Inflector::pluralize($singular));
}
}
class InflectorSinguralizeFrenchTest extends InflectorTestCase {
public function datas() {
public function frensh() {
return [['chevaux', 'cheval'],
['zork', 'zork'],
['categories', 'categorie'],
['avis', 'avis']];
}
/**
* @test
* @dataProvider datas
public function english() {
return [['activities', 'activity'],
['items', 'item']];
}
/**
* @test
* @dataProvider frensh
*/
public function singuralizeFrenshShouldReturnSingular($plural, $singular) {
$this->assertEquals($singular, Storm_Inflector::singularize($plural));
}
/**
* @test
* @dataProvider english
*/
public function singuralizeShouldReturnSingular($plural, $singular) {
public function singuralizeEnglishShouldReturnSingular($plural, $singular) {
$this->assertEquals($singular, Storm_Inflector::singularize($plural));
}
}
......@@ -77,8 +110,8 @@ class InflectorCamelizeFrenchTest extends InflectorTestCase {
['ID_NEWS', 'IdNews']];
}
/**
* @test
/**
* @test
* @dataProvider datas
*/
public function camelizeNEWSShouldReturnNews($value, $camelized) {
......@@ -96,8 +129,8 @@ class InflectorUnderscorizeFrenchTest extends InflectorTestCase {
['ABoireEtAManger', 'a_boire_et_a_manger']];
}
/**
* @test
/**
* @test
* @dataProvider datas
*/
public function underscorizeShouldReturnUnderscorized($value, $expected) {
......
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