Skip to content

Commit

Permalink
Merge pull request #2977 from ADmad/3.0-merge
Browse files Browse the repository at this point in the history
3.0 merge
  • Loading branch information
markstory committed Mar 9, 2014
2 parents 4f1b262 + be976ed commit 218de22
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 166 deletions.
1 change: 1 addition & 0 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -368,6 +368,7 @@ protected function _unauthenticated(Controller $controller) {
return false;
}
if (!empty($this->ajaxLogin)) {
$controller->response->statusCode(403);
$controller->viewPath = 'Element';
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
$this->_stop();
Expand Down
35 changes: 16 additions & 19 deletions src/Event/EventManager.php
Expand Up @@ -282,30 +282,27 @@ protected function _callListener(callable $listener, Event $event) {
* @return array
*/
public function listeners($eventKey) {
$localListeners = array();
$priorities = array();
if (!$this->_isGlobal) {
$globalListeners = static::instance()->prioritisedListeners($eventKey);
} else {
$globalListeners = $this->prioritisedListeners($eventKey);
$localListeners = $this->prioritisedListeners($eventKey);
$localListeners = empty($localListeners) ? array() : $localListeners;
}
$listeners = array_merge($this->_listeners, self::instance()->_listeners);
$globalListeners = static::instance()->prioritisedListeners($eventKey);
$globalListeners = empty($globalListeners) ? array() : $globalListeners;

if (empty($listeners[$eventKey]) && empty($globalListeners)) {
return [];
}

$listeners = $listeners[$eventKey];
foreach ($globalListeners as $priority => $priorityQ) {
if (!empty($listeners[$priority])) {
$listeners[$priority] = array_merge($priorityQ, $listeners[$priority]);
unset($globalListeners[$priority]);
}
}
$listeners = $listeners + $globalListeners;
$priorities = array_merge(array_keys($globalListeners), array_keys($localListeners));
$priorities = array_unique($priorities);
asort($priorities);

ksort($listeners);
$result = array();
foreach ($listeners as $priorityQ) {
$result = array_merge($result, $priorityQ);
foreach ($priorities as $priority) {
if (isset($globalListeners[$priority])) {
$result = array_merge($result, $globalListeners[$priority]);
}
if (isset($localListeners[$priority])) {
$result = array_merge($result, $localListeners[$priority]);
}
}
return $result;
}
Expand Down
2 changes: 2 additions & 0 deletions src/I18n/L10n.php
Expand Up @@ -141,6 +141,7 @@ class L10n {
/* Kalaallisut (Greenlandic) */ 'kal' => 'kl',
/* Korean */ 'kor' => 'ko',
/* Latvian */ 'lav' => 'lv',
/* Limburgish */ 'lim' => 'li',
/* Lithuanian */ 'lit' => 'lt',
/* Macedonian */ 'mkd' => 'mk',
/* Macedonian - bibliographic */ 'mac' => 'mk',
Expand Down Expand Up @@ -283,6 +284,7 @@ class L10n {
'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'),
'li' => array('language' => 'Limburgish', 'locale' => 'lim', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mkd', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
Expand Down
5 changes: 4 additions & 1 deletion src/Network/Email/MailTransport.php
Expand Up @@ -67,8 +67,11 @@ public function send(Email $email) {
protected function _mail($to, $subject, $message, $headers, $params = null) {
//@codingStandardsIgnoreStart
if (!@mail($to, $subject, $message, $headers, $params)) {
throw new Error\SocketException('Could not send email.');
$error = error_get_last();
$msg = 'Could not send email: ' . isset($error['message']) ? $error['message'] : 'unknown';
throw new SocketException($msg);
}
//@codingStandardsIgnoreEnd
}

}
14 changes: 7 additions & 7 deletions src/basics.php
Expand Up @@ -556,7 +556,7 @@ function __($singular, $args = null) {
$args = array_slice(func_get_args(), 1);
}

$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}

Expand Down Expand Up @@ -587,7 +587,7 @@ function __n($singular, $plural, $count, $args = null) {
$args = array_slice(func_get_args(), 3);
}

$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}

Expand Down Expand Up @@ -615,7 +615,7 @@ function __d($domain, $msg, $args = null) {
$args = array_slice(func_get_args(), 2);
}

$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}

Expand Down Expand Up @@ -647,7 +647,7 @@ function __dn($domain, $singular, $plural, $count, $args = null) {
$args = array_slice(func_get_args(), 4);
}

$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}

Expand Down Expand Up @@ -690,7 +690,7 @@ function __dc($domain, $msg, $category, $args = null) {
$args = array_slice(func_get_args(), 3);
}

$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}

Expand Down Expand Up @@ -737,7 +737,7 @@ function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
$args = array_slice(func_get_args(), 5);
}

$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}

Expand Down Expand Up @@ -776,7 +776,7 @@ function __c($msg, $category, $args = null) {
$args = array_slice(func_get_args(), 2);
}

$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}

Expand Down
140 changes: 140 additions & 0 deletions tests/TestCase/BasicsTest.php
Expand Up @@ -427,6 +427,146 @@ public function testTranslatePercent() {
$this->assertEquals($expected, $result, 'significant-digit placeholder should not be misinterpreted');
}

/**
* testTranslateWithFormatSpecifiers
*
* @return void
*/
public function testTranslateWithFormatSpecifiers() {
$expected = 'Check, one, two, three';
$result = __('Check, %+10s, three', 'one, two');
$this->assertEquals($expected, $result);

$expected = 'Check, +1, two, three';
$result = __('Check, %+5d, two, three', 1);
$this->assertEquals($expected, $result);

$expected = 'Check, @@one, two, three';
$result = __('Check, %\'@+10s, three', 'one, two');
$this->assertEquals($expected, $result);

$expected = 'Check, one, two , three';
$result = __('Check, %-10s, three', 'one, two');
$this->assertEquals($expected, $result);

$expected = 'Check, one, two##, three';
$result = __('Check, %\'#-10s, three', 'one, two');
$this->assertEquals($expected, $result);

$expected = 'Check, one, two, three';
$result = __d('default', 'Check, %+10s, three', 'one, two');
$this->assertEquals($expected, $result);

$expected = 'Check, @@one, two, three';
$result = __d('default', 'Check, %\'@+10s, three', 'one, two');
$this->assertEquals($expected, $result);

$expected = 'Check, one, two , three';
$result = __d('default', 'Check, %-10s, three', 'one, two');
$this->assertEquals($expected, $result);

$expected = 'Check, one, two##, three';
$result = __d('default', 'Check, %\'#-10s, three', 'one, two');
$this->assertEquals($expected, $result);
}

/**
* testTranslateDomainPluralWithFormatSpecifiers
*
* @return void
*/
public function testTranslateDomainPluralWithFormatSpecifiers() {
$result = __dn('core', '%+5d item.', '%+5d items.', 1, 1);
$expected = ' +1 item.';
$this->assertEquals($expected, $result);

$result = __dn('core', '%-5d item.', '%-5d items.', 10, 10);
$expected = '10 items.';
$this->assertEquals($expected, $result);

$result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 1, 1);
$expected = '###+1 item.';
$this->assertEquals($expected, $result);

$result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 90, 90);
$expected = '**+90 items.';
$this->assertEquals($expected, $result);

$result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 9000, 9000);
$expected = '+9000 items.';
$this->assertEquals($expected, $result);
}

/**
* test testTranslatePluralWithFormatSpecifiers
*
* @return void
*/
public function testTranslatePluralWithFormatSpecifiers() {
Configure::write('Config.language', 'rule_1_po');

$result = __n('%-5d = 1', '%-5d = 0 or > 1', 10);
$expected = '%-5d = 0 or > 1 (translated)';
$this->assertEquals($expected, $result);
}

/**
* test testTranslateDomainCategoryWithFormatSpecifiers
*
* @return void
*/
public function testTranslateDomainCategoryWithFormatSpecifiers() {
Configure::write('Config.language', 'rule_1_po');

$result = __dc('default', '%+10s world', 6, 'hello');
$expected = ' hello world';
$this->assertEquals($expected, $result);

$result = __dc('default', '%-10s world', 6, 'hello');
$expected = 'hello world';
$this->assertEquals($expected, $result);

$result = __dc('default', '%\'@-10s world', 6, 'hello');
$expected = 'hello@@@@@ world';
$this->assertEquals($expected, $result);
}

/**
* test testTranslateDomainCategoryPluralWithFormatSpecifiers
*
* @return void
*/
public function testTranslateDomainCategoryPluralWithFormatSpecifiers() {
Configure::write('Config.language', 'rule_1_po');

$result = __dcn('default', '%-5d = 1', '%-5d = 0 or > 1', 0, 6);
$expected = '%-5d = 0 or > 1 (translated)';
$this->assertEquals($expected, $result);

$result = __dcn('default', '%-5d = 1', '%-5d = 0 or > 1', 1, 6);
$expected = '%-5d = 1 (translated)';
$this->assertEquals($expected, $result);
}

/**
* test testTranslateCategoryWithFormatSpecifiers
*
* @return void
*/
public function testTranslateCategoryWithFormatSpecifiers() {
$result = __c('Some string with %+10s', 6, 'arguments');
$expected = 'Some string with arguments';
$this->assertEquals($expected, $result);

$result = __c('Some string with %-10s: args', 6, 'arguments');
$expected = 'Some string with arguments : args';
$this->assertEquals($expected, $result);

$result = __c('Some string with %\'*-10s: args', 6, 'arguments');
$expected = 'Some string with arguments*: args';
$this->assertEquals($expected, $result);
}

/**
* test __n()
*
Expand Down
23 changes: 9 additions & 14 deletions tests/TestCase/Console/ShellDispatcherTest.php
Expand Up @@ -421,14 +421,14 @@ public function testGetShell() {
*/
public function testDispatchShellWithMain() {
$Dispatcher = new TestShellDispatcher();
$Mock = $this->getMock('Cake\Console\Shell', array(), array(), 'MockWithMainShell');
$Shell = $this->getMock('Cake\Console\Shell');

$Mock->expects($this->once())->method('initialize');
$Mock->expects($this->once())->method('runCommand')
$Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('runCommand')
->with(null, array())
->will($this->returnValue(true));

$Dispatcher->TestShell = $Mock;
$Dispatcher->TestShell = $Shell;

$Dispatcher->args = array('mock_with_main');
$result = $Dispatcher->dispatch();
Expand All @@ -443,10 +443,7 @@ public function testDispatchShellWithMain() {
*/
public function testDispatchShellWithoutMain() {
$Dispatcher = new TestShellDispatcher();
$Shell = $this->getMock('Cake\Console\Shell', array(), array(), 'MockWithoutMainShell');

$Shell = new \MockWithoutMainShell();
$this->mockObjects[] = $Shell;
$Shell = $this->getMock('Cake\Console\Shell');

$Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('runCommand')
Expand All @@ -469,7 +466,7 @@ public function testDispatchNotAShellWithMain() {
$Dispatcher = new TestShellDispatcher();
$methods = get_class_methods('Cake\Core\Object');
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
$Shell = $this->getMock('Cake\Core\Object', $methods, array(), 'MockWithMainNotAShell');
$Shell = $this->getMock('Cake\Core\Object', $methods);

$Shell->expects($this->never())->method('initialize');
$Shell->expects($this->once())->method('startup');
Expand All @@ -481,8 +478,7 @@ public function testDispatchNotAShellWithMain() {
$this->assertEquals(0, $result);
$this->assertEquals(array(), $Dispatcher->args);

$Shell = new \MockWithMainNotAShell($Dispatcher);
$this->mockObjects[] = $Shell;
$Shell = $this->getMock('Cake\Core\Object', $methods);
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
$Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
Expand All @@ -501,7 +497,7 @@ public function testDispatchNotAShellWithoutMain() {
$Dispatcher = new TestShellDispatcher();
$methods = get_class_methods('Cake\Core\Object');
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell');
$Shell = $this->getMock('Cake\Core\Object', $methods);

$Shell->expects($this->never())->method('initialize');
$Shell->expects($this->once())->method('startup');
Expand All @@ -513,8 +509,7 @@ public function testDispatchNotAShellWithoutMain() {
$this->assertEquals(0, $result);
$this->assertEquals(array(), $Dispatcher->args);

$Shell = new \MockWithoutMainNotAShell($Dispatcher);
$this->mockObjects[] = $Shell;
$Shell = $this->getMock('Cake\Core\Object', $methods);
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
$Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Controller/Component/AclComponentTest.php
Expand Up @@ -71,11 +71,11 @@ public function testConstrutorException() {
* @return void
*/
public function testAdapter() {
$implementation = new \MockAclImplementation();
$implementation->expects($this->once())->method('initialize')->with($this->Acl);
$this->assertNull($this->Acl->adapter($implementation));
$Adapter = $this->getMock('Cake\Controller\Component\Acl\AclInterface');
$Adapter->expects($this->once())->method('initialize')->with($this->Acl);

$this->assertEquals($this->Acl->adapter(), $implementation, 'Returned object is different %s');
$this->assertNull($this->Acl->adapter($Adapter));
$this->assertEquals($this->Acl->adapter(), $Adapter, 'Returned object is different %s');
}

/**
Expand Down

0 comments on commit 218de22

Please sign in to comment.