Merge branch '2.6' into 2.7

This commit is contained in:
mark_story 2015-06-07 15:45:26 -04:00
commit c47196fe08
4 changed files with 98 additions and 14 deletions

View file

@ -295,6 +295,8 @@ class CakeRequest implements ArrayAccess {
if (!$baseUrl) { if (!$baseUrl) {
$base = dirname(env('PHP_SELF')); $base = dirname(env('PHP_SELF'));
// Clean up additional / which cause following code to fail..
$base = preg_replace('#/+#', '/', $base);
$indexPos = strpos($base, '/webroot/index.php'); $indexPos = strpos($base, '/webroot/index.php');
if ($indexPos !== false) { if ($indexPos !== false) {

View file

@ -1423,6 +1423,24 @@ class CakeRequestTest extends CakeTestCase {
$this->assertEquals('/cakephp/bananas/eat/tasty_banana', $request->here); $this->assertEquals('/cakephp/bananas/eat/tasty_banana', $request->here);
} }
/**
* Test that even if mod_rewrite is on, and the url contains index.php
* and there are numerous //s that the base/webroot is calculated correctly.
*
* @return void
*/
public function testBaseUrlWithModRewriteAndExtraSlashes() {
$_SERVER['REQUEST_URI'] = '/cakephp/webroot///index.php/bananas/eat';
$_SERVER['PHP_SELF'] = '/cakephp/webroot///index.php/bananas/eat';
$_SERVER['PATH_INFO'] = '/bananas/eat';
$request = new CakeRequest();
$this->assertEquals('/cakephp', $request->base);
$this->assertEquals('/cakephp/', $request->webroot);
$this->assertEquals('bananas/eat', $request->url);
$this->assertEquals('/cakephp/bananas/eat', $request->here);
}
/** /**
* Test base, webroot, and URL parsing when there is no URL rewriting * Test base, webroot, and URL parsing when there is no URL rewriting
* *

View file

@ -183,6 +183,29 @@ class InflectorTest extends CakeTestCase {
$this->assertEquals(Inflector::singularize(''), ''); $this->assertEquals(Inflector::singularize(''), '');
} }
/**
* Test that overlapping irregulars don't collide.
*
* @return void
*/
public function testSingularizeMultiWordIrregular() {
Inflector::rules('singular', array(
'irregular' => array(
'preguntas_frecuentes' => 'pregunta_frecuente',
'categorias_preguntas_frecuentes' => 'categoria_pregunta_frecuente',
)
));
$this->assertEquals('pregunta_frecuente', Inflector::singularize('preguntas_frecuentes'));
$this->assertEquals(
'categoria_pregunta_frecuente',
Inflector::singularize('categorias_preguntas_frecuentes')
);
$this->assertEquals(
'faq_categoria_pregunta_frecuente',
Inflector::singularize('faq_categorias_preguntas_frecuentes')
);
}
/** /**
* testInflectingPlurals method * testInflectingPlurals method
* *
@ -256,6 +279,29 @@ class InflectorTest extends CakeTestCase {
$this->assertEquals(Inflector::pluralize(''), ''); $this->assertEquals(Inflector::pluralize(''), '');
} }
/**
* Test that overlapping irregulars don't collide.
*
* @return void
*/
public function testPluralizeMultiWordIrregular() {
Inflector::rules('plural', array(
'irregular' => array(
'pregunta_frecuente' => 'preguntas_frecuentes',
'categoria_pregunta_frecuente' => 'categorias_preguntas_frecuentes',
)
));
$this->assertEquals('preguntas_frecuentes', Inflector::pluralize('pregunta_frecuente'));
$this->assertEquals(
'categorias_preguntas_frecuentes',
Inflector::pluralize('categoria_pregunta_frecuente')
);
$this->assertEquals(
'faq_categorias_preguntas_frecuentes',
Inflector::pluralize('faq_categoria_pregunta_frecuente')
);
}
/** /**
* testInflectingMultiWordIrregulars * testInflectingMultiWordIrregulars
* *
@ -414,6 +460,20 @@ class InflectorTest extends CakeTestCase {
$this->assertSame(Inflector::underscore(false), ''); $this->assertSame(Inflector::underscore(false), '');
} }
/**
* Test camelize()
*
* @return void
*/
public function testCamelize() {
$this->assertSame('BlogArticles', Inflector::camelize('blog_articles'));
$this->assertSame('BlogArticles', Inflector::camelize('blog articles'));
$this->assertSame('MyPlugin.MyClass', Inflector::camelize('MyPlugin.MyClass'));
$this->assertSame('MyPlugin.MyClass', Inflector::camelize('my_plugin.MyClass'));
$this->assertSame('MyPlugin.myClass', Inflector::camelize('MyPlugin.my_class'));
}
/** /**
* testVariableNaming method * testVariableNaming method
* *
@ -444,10 +504,10 @@ class InflectorTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testTableNaming() { public function testTableNaming() {
$this->assertEquals(Inflector::tableize('ArtistsGenre'), 'artists_genres'); $this->assertEquals('artists_genres', Inflector::tableize('ArtistsGenre'));
$this->assertEquals(Inflector::tableize('FileSystem'), 'file_systems'); $this->assertEquals('file_systems', Inflector::tableize('FileSystem'));
$this->assertEquals(Inflector::tableize('News'), 'news'); $this->assertEquals('news', Inflector::tableize('News'));
$this->assertEquals(Inflector::tableize('Bureau'), 'bureaus'); $this->assertEquals('bureaus', Inflector::tableize('Bureau'));
} }
/** /**
@ -456,11 +516,12 @@ class InflectorTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testHumanization() { public function testHumanization() {
$this->assertEquals(Inflector::humanize('posts'), 'Posts'); $this->assertEquals('Posts', Inflector::humanize('posts'));
$this->assertEquals(Inflector::humanize('posts_tags'), 'Posts Tags'); $this->assertEquals('Posts Tags', Inflector::humanize('posts_tags'));
$this->assertEquals(Inflector::humanize('file_systems'), 'File Systems'); $this->assertEquals('File Systems', Inflector::humanize('file_systems'));
$this->assertEquals(Inflector::humanize('hello_wörld'), 'Hello Wörld'); $this->assertEquals('FiLe SysTems', Inflector::humanize('FiLe_SysTems'));
$this->assertEquals(Inflector::humanize('福岡_city'), '福岡 City'); $this->assertEquals('Hello Wörld', Inflector::humanize('hello_wörld'));
$this->assertEquals('福岡 City', Inflector::humanize('福岡_city'));
} }
/** /**

View file

@ -386,8 +386,10 @@ class Inflector {
self::$_plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_plural['merged']['irregular'])) . ')'; self::$_plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_plural['merged']['irregular'])) . ')';
} }
if (preg_match('/(.*(?:\\b|_))(' . self::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) { if (preg_match('/(.*?(?:\\b|_))(' . self::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
self::$_cache['pluralize'][$word] = $regs[1] . substr($regs[2], 0, 1) . substr(self::$_plural['merged']['irregular'][strtolower($regs[2])], 1); self::$_cache['pluralize'][$word] = $regs[1] .
substr($regs[2], 0, 1) .
substr(self::$_plural['merged']['irregular'][strtolower($regs[2])], 1);
return self::$_cache['pluralize'][$word]; return self::$_cache['pluralize'][$word];
} }
@ -435,8 +437,10 @@ class Inflector {
self::$_singular['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_singular['merged']['irregular'])) . ')'; self::$_singular['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_singular['merged']['irregular'])) . ')';
} }
if (preg_match('/(.*(?:\\b|_))(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) { if (preg_match('/(.*?(?:\\b|_))(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
self::$_cache['singularize'][$word] = $regs[1] . substr($regs[2], 0, 1) . substr(self::$_singular['merged']['irregular'][strtolower($regs[2])], 1); self::$_cache['singularize'][$word] = $regs[1] .
substr($regs[2], 0, 1) .
substr(self::$_singular['merged']['irregular'][strtolower($regs[2])], 1);
return self::$_cache['singularize'][$word]; return self::$_cache['singularize'][$word];
} }
@ -496,7 +500,6 @@ class Inflector {
*/ */
public static function humanize($lowerCaseAndUnderscoredWord) { public static function humanize($lowerCaseAndUnderscoredWord) {
if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) { if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
$lowerCaseAndUnderscoredWord = self::underscore($lowerCaseAndUnderscoredWord);
$result = explode(' ', str_replace('_', ' ', $lowerCaseAndUnderscoredWord)); $result = explode(' ', str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
foreach ($result as &$word) { foreach ($result as &$word) {
$word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1); $word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1);