Browse Source

Merge branch '2.5' into 3.0-merge

Conflicts:
	app/Config/Schema/db_acl.php
	app/Config/core.php
	build.xml
	lib/Cake/Test/Case/Model/ModelDeleteTest.php
	lib/Cake/Test/Case/Model/ModelWriteTest.php
	lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
	lib/Cake/Test/Case/View/Helper/FormHelperTest.php
	lib/Cake/Test/Case/View/Helper/JsHelperTest.php
	lib/Cake/View/Helper/FormHelper.php
	src/Controller/Component/AuthComponent.php
	src/Event/EventManager.php
	src/Network/Email/MailTransport.php
	tests/TestCase/Console/ShellDispatcherTest.php
	tests/TestCase/Controller/Component/AclComponentTest.php
	tests/TestCase/Controller/Component/AuthComponentTest.php
	tests/TestCase/Event/EventManagerTest.php
	tests/TestCase/Network/Email/DebugTransportTest.php
	tests/TestCase/Network/Email/SmtpTransportTest.php
	tests/TestCase/Utility/ObjectCollectionTest.php
	tests/TestCase/View/ViewTest.php
ADmad 12 years ago
parent
commit
be976edefa

+ 1 - 0
src/Controller/Component/AuthComponent.php

@@ -368,6 +368,7 @@ class AuthComponent extends Component {
 			return false;
 		}
 		if (!empty($this->ajaxLogin)) {
+			$controller->response->statusCode(403);
 			$controller->viewPath = 'Element';
 			echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
 			$this->_stop();

+ 16 - 19
src/Event/EventManager.php

@@ -282,30 +282,27 @@ class EventManager {
  * @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;
 	}

+ 2 - 0
src/I18n/L10n.php

@@ -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',
@@ -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'),

+ 4 - 1
src/Network/Email/MailTransport.php

@@ -67,8 +67,11 @@ class MailTransport extends AbstractTransport {
 	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
 	}
 
 }

+ 7 - 7
src/basics.php

@@ -556,7 +556,7 @@ if (!function_exists('__')) {
 			$args = array_slice(func_get_args(), 1);
 		}
 
-		$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
+		$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
 		return vsprintf($translated, $args);
 	}
 
@@ -587,7 +587,7 @@ if (!function_exists('__n')) {
 			$args = array_slice(func_get_args(), 3);
 		}
 
-		$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
+		$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
 		return vsprintf($translated, $args);
 	}
 
@@ -615,7 +615,7 @@ if (!function_exists('__d')) {
 			$args = array_slice(func_get_args(), 2);
 		}
 
-		$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
+		$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
 		return vsprintf($translated, $args);
 	}
 
@@ -647,7 +647,7 @@ if (!function_exists('__dn')) {
 			$args = array_slice(func_get_args(), 4);
 		}
 
-		$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
+		$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
 		return vsprintf($translated, $args);
 	}
 
@@ -690,7 +690,7 @@ if (!function_exists('__dc')) {
 			$args = array_slice(func_get_args(), 3);
 		}
 
-		$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
+		$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
 		return vsprintf($translated, $args);
 	}
 
@@ -737,7 +737,7 @@ if (!function_exists('__dcn')) {
 			$args = array_slice(func_get_args(), 5);
 		}
 
-		$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
+		$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
 		return vsprintf($translated, $args);
 	}
 
@@ -776,7 +776,7 @@ if (!function_exists('__c')) {
 			$args = array_slice(func_get_args(), 2);
 		}
 
-		$translated = preg_replace('/(?<!%)%(?![%bcdeEfFgGosuxX\d\.])/', '%%', $translated);
+		$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
 		return vsprintf($translated, $args);
 	}
 

+ 140 - 0
tests/TestCase/BasicsTest.php

@@ -428,6 +428,146 @@ class BasicsTest extends TestCase {
 	}
 
 /**
+ * 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()
  *
  * @return void

+ 9 - 14
tests/TestCase/Console/ShellDispatcherTest.php

@@ -421,14 +421,14 @@ class ShellDispatcherTest extends TestCase {
  */
 	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();
@@ -443,10 +443,7 @@ class ShellDispatcherTest extends TestCase {
  */
 	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')
@@ -469,7 +466,7 @@ class ShellDispatcherTest extends TestCase {
 		$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');
@@ -481,8 +478,7 @@ class ShellDispatcherTest extends TestCase {
 		$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;
@@ -501,7 +497,7 @@ class ShellDispatcherTest extends TestCase {
 		$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');
@@ -513,8 +509,7 @@ class ShellDispatcherTest extends TestCase {
 		$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;

+ 4 - 4
tests/TestCase/Controller/Component/AclComponentTest.php

@@ -71,11 +71,11 @@ class AclComponentTest extends TestCase {
  * @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');
 	}
 
 /**

+ 64 - 42
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -138,17 +138,21 @@ class AuthComponentTest extends TestCase {
  * @return void
  */
 	public function testLogin() {
-		$this->getMock('Cake\Controller\Component\Auth\FormAuthenticate', array(), array(), 'AuthLoginFormAuthenticate', false);
-		class_alias('AuthLoginFormAuthenticate', 'Cake\Controller\Component\Auth\AuthLoginFormAuthenticate');
+		$AuthLoginFormAuthenticate = $this->getMock(
+			'Cake\Controller\Componenent\Auth\FormAuthenticate',
+			array('authenticate'), array(), '', false
+		);
 		$this->Auth->authenticate = array(
 			'AuthLoginForm' => array(
 				'userModel' => 'AuthUsers'
 			)
 		);
-		$this->Auth->Session = $this->getMock('Cake\Controller\Component\SessionComponent', array('renew'), array(), '', false);
+		$this->Auth->Session = $this->getMock(
+			'Cake\Controller\Component\SessionComponent',
+			array('renew'), array(), '', false
+		);
 
-		$mocks = $this->Auth->constructAuthenticate();
-		$this->mockObjects[] = $mocks[0];
+		$this->Auth->setAuthenticateObject(0, $AuthLoginFormAuthenticate);
 
 		$this->Auth->request->data = array(
 			'AuthUsers' => array(
@@ -162,7 +166,7 @@ class AuthComponentTest extends TestCase {
 			'username' => 'mark'
 		);
 
-		$mocks[0]->expects($this->once())
+		$AuthLoginFormAuthenticate->expects($this->once())
 			->method('authenticate')
 			->with($this->Auth->request)
 			->will($this->returnValue($user));
@@ -240,34 +244,35 @@ class AuthComponentTest extends TestCase {
  * @return void
  */
 	public function testIsAuthorizedDelegation() {
-		$this->getMock('Cake\Controller\Component\Auth\BaseAuthorize', array('authorize'), array(), 'AuthMockOneAuthorize', false);
-		$this->getMock('Cake\Controller\Component\Auth\BaseAuthorize', array('authorize'), array(), 'AuthMockTwoAuthorize', false);
-		$this->getMock('Cake\Controller\Component\Auth\BaseAuthorize', array('authorize'), array(), 'AuthMockThreeAuthorize', false);
-
-		class_alias('AuthMockOneAuthorize', 'Cake\Controller\Component\Auth\AuthMockOneAuthorize');
-		class_alias('AuthMockTwoAuthorize', 'Cake\Controller\Component\Auth\AuthMockTwoAuthorize');
-		class_alias('AuthMockThreeAuthorize', 'Cake\Controller\Component\Auth\AuthMockThreeAuthorize');
-
-		$this->Auth->authorize = array(
-			'AuthMockOne',
-			'AuthMockTwo',
-			'AuthMockThree'
+		$AuthMockOneAuthorize = $this->getMock(
+			'Cake\Controller\Component\BaseAuthorize',
+			array('authorize'), array(), '', false
+		);
+		$AuthMockTwoAuthorize = $this->getMock(
+			'Cake\Controller\Component\Auth\BaseAuthorize',
+			array('authorize'), array(), '', false
 		);
-		$mocks = $this->Auth->constructAuthorize();
+		$AuthMockThreeAuthorize = $this->getMock(
+			'Cake\Controller\Component\Auth\BaseAuthorize',
+			array('authorize'), array(), '', false
+		);
+
+		$this->Auth->setAuthorizeObject(0, $AuthMockOneAuthorize);
+		$this->Auth->setAuthorizeObject(1, $AuthMockTwoAuthorize);
+		$this->Auth->setAuthorizeObject(2, $AuthMockThreeAuthorize);
 		$request = $this->Auth->request;
 
-		$this->assertEquals(3, count($mocks));
-		$mocks[0]->expects($this->once())
+		$AuthMockOneAuthorize->expects($this->once())
 			->method('authorize')
 			->with(array('User'), $request)
 			->will($this->returnValue(false));
 
-		$mocks[1]->expects($this->once())
+		$AuthMockTwoAuthorize->expects($this->once())
 			->method('authorize')
 			->with(array('User'), $request)
 			->will($this->returnValue(true));
 
-		$mocks[2]->expects($this->never())
+		$AuthMockThreeAuthorize->expects($this->never())
 			->method('authorize');
 
 		$this->assertTrue($this->Auth->isAuthorized(array('User'), $request));
@@ -279,16 +284,18 @@ class AuthComponentTest extends TestCase {
  * @return void
  */
 	public function testIsAuthorizedUsingUserInSession() {
-		$this->getMock('Cake\Controller\Component\Auth\BaseAuthorize', array('authorize'), array(), 'AuthMockFourAuthorize', false);
-		class_alias('AuthMockFourAuthorize', 'Cake\Controller\Component\Auth\AuthMockFourAuthorize');
+		$AuthMockFourAuthorize = $this->getMock(
+			'Cake\Controller\Component\Auth\BaseAuthorize',
+			array('authorize'), array(), '', false
+		);
 		$this->Auth->authorize = array('AuthMockFour');
+		$this->Auth->setAuthorizeObject(0, $AuthMockFourAuthorize);
 
 		$user = array('user' => 'mark');
 		$this->Auth->Session->write('Auth.User', $user);
-		$mocks = $this->Auth->constructAuthorize();
 		$request = $this->Controller->request;
 
-		$mocks[0]->expects($this->once())
+		$AuthMockFourAuthorize->expects($this->once())
 			->method('authorize')
 			->with($user, $request)
 			->will($this->returnValue(true));
@@ -677,7 +684,10 @@ class AuthComponentTest extends TestCase {
 
 		$this->Auth->Session->write('Auth.User.id', '1');
 		$this->Auth->authenticate = array('Form');
-		$this->getMock('BaseAuthorize', array('authorize'), array(), 'NoLoginRedirectMockAuthorize', false);
+		$this->getMock(
+			'Cake\Controller\Component\Auth\BaseAuthorize',
+			array('authorize'), array(), 'NoLoginRedirectMockAuthorize', false
+		);
 		$this->Auth->authorize = array('NoLoginRedirectMockAuthorize');
 		$this->Auth->loginAction = array('controller' => 'auth_test', 'action' => 'login');
 
@@ -896,10 +906,12 @@ class AuthComponentTest extends TestCase {
 			'url' => '/ajax_auth/add',
 			'environment' => ['HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']
 		]);
+		$response = new Response();
 		$Dispatcher = new Dispatcher();
-		$Dispatcher->dispatch($request, new Response(), array('return' => 1));
+		$Dispatcher->dispatch($request, $response, array('return' => 1));
 		$result = ob_get_clean();
 
+		$this->assertEquals(403, $response->statusCode());
 		$this->assertEquals("Ajax!\nthis is the test element", str_replace("\r\n", "\n", $result));
 	}
 
@@ -1014,12 +1026,14 @@ class AuthComponentTest extends TestCase {
  * @return void
  */
 	public function testLogoutTrigger() {
-		$this->getMock('Cake\Controller\Component\Auth\BaseAuthenticate', array('authenticate', 'logout'), array(), 'LogoutTriggerMockAuthenticate', false);
-		class_alias('LogoutTriggerMockAuthenticate', 'Cake\Controller\Component\Auth\LogoutTriggerMockAuthenticate');
+		$LogoutTriggerMockAuthenticate = $this->getMock(
+			'Cake\Controller\Component\Auth\BaseAuthenticate',
+			array('authenticate', 'logout'), array(), '', false
+		);
 
 		$this->Auth->authenticate = array('LogoutTriggerMock');
-		$mock = $this->Auth->constructAuthenticate();
-		$mock[0]->expects($this->once())
+		$this->Auth->setAuthenticateObject(0, $LogoutTriggerMockAuthenticate);
+		$LogoutTriggerMockAuthenticate->expects($this->once())
 			->method('logout');
 
 		$this->Auth->logout();
@@ -1031,11 +1045,14 @@ class AuthComponentTest extends TestCase {
  * @return void
  */
 	public function testMapActionsDelegation() {
-		$this->getMock('Cake\Controller\Component\Auth\BaseAuthorize', array('authorize'), array(), 'MapActionMockAuthorize', false);
-		class_alias('MapActionMockAuthorize', 'Cake\Controller\Component\Auth\MapActionMockAuthorize');
+		$MapActionMockAuthorize = $this->getMock(
+			'Cake\Controller\Component\Auth\BaseAuthorize',
+			array('authorize', 'mapActions'), array(), '', false
+		);
+
 		$this->Auth->authorize = array('MapActionMock');
-		$mock = $this->Auth->constructAuthorize();
-		$mock[0]->expects($this->once())
+		$this->Auth->setAuthorizeObject(0, $MapActionMockAuthorize);
+		$MapActionMockAuthorize->expects($this->once())
 			->method('mapActions')
 			->with(array('create' => array('my_action')));
 
@@ -1048,15 +1065,17 @@ class AuthComponentTest extends TestCase {
  * @return void
  */
 	public function testLoginWithRequestData() {
-		$this->getMock('Cake\Controller\Component\Auth\FormAuthenticate', array(), array(), 'RequestLoginMockAuthenticate', false);
-		class_alias('RequestLoginMockAuthenticate', 'Cake\Controller\Component\Auth\RequestLoginMockAuthenticate');
+		$RequestLoginMockAuthenticate = $this->getMock(
+			'Cake\Controller\Componenent\Auth\FormAuthenticate',
+			array('authenticate'), array(), '', false
+		);
 		$request = new Request('users/login');
 		$user = array('username' => 'mark', 'role' => 'admin');
 
 		$this->Auth->request = $request;
 		$this->Auth->authenticate = array('RequestLoginMock');
-		$mock = $this->Auth->constructAuthenticate();
-		$mock[0]->expects($this->once())
+		$this->Auth->setAuthenticateObject(0, $RequestLoginMockAuthenticate);
+		$RequestLoginMockAuthenticate->expects($this->once())
 			->method('authenticate')
 			->with($request)
 			->will($this->returnValue($user));
@@ -1090,7 +1109,10 @@ class AuthComponentTest extends TestCase {
  * @return void
  */
 	public function testFlashSettings() {
-		$this->Auth->Session = $this->getMock('Cake\Controller\Component\SessionComponent', array(), array(), '', false);
+		$this->Auth->Session = $this->getMock(
+			'Cake\Controller\Component\SessionComponent',
+			array(), array(), '', false
+		);
 		$this->Auth->Session->expects($this->once())
 			->method('setFlash')
 			->with('Auth failure', 'custom', array(1), 'auth-key');

+ 18 - 4
tests/TestCase/Event/EventManagerTest.php

@@ -1,9 +1,5 @@
 <?php
 /**
- * EventMangerTest file
- *
- * Test Case for EventManager class
- *
  * CakePHP : Rapid Development Framework (http://cakephp.org)
  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  *
@@ -496,4 +492,22 @@ class EventManagerTest extends TestCase {
 		$this->assertEquals('ok', $event->data['callback']);
 	}
 
+/**
+ * Test that events are dispatched properly when there are global and local
+ * listeners at the same priority.
+ *
+ * @return void
+ */
+	public function testDispatchWithGlobalAndLocalEvents() {
+		$listener = new CustomTestEventListener();
+		EventManager::instance()->attach($listener);
+		$listener2 = new EventTestListener();
+		$manager = new EventManager();
+		$manager->attach(array($listener2, 'listenerFunction'), 'fake.event');
+
+		$manager->dispatch(new Event('fake.event', $this));
+		$this->assertEquals(array('listenerFunction'), $listener->callStack);
+		$this->assertEquals(array('listenerFunction'), $listener2->callStack);
+	}
+
 }

+ 3 - 4
tests/TestCase/Network/Email/DebugTransportTest.php

@@ -42,8 +42,7 @@ class DebugTransportTest extends TestCase {
  * @return void
  */
 	public function testSend() {
-		$this->getMock('Cake\Network\Email\Email', array('message'), array(), 'DebugCakeEmail');
-		$email = new \DebugCakeEmail();
+		$email = $this->getMock('Cake\Network\Email\Email', array('message'));
 		$email->from('noreply@cakephp.org', 'CakePHP Test');
 		$email->to('cake@cakephp.org', 'CakePHP');
 		$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
@@ -51,8 +50,8 @@ class DebugTransportTest extends TestCase {
 		$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
 		$email->subject('Testing Message');
 		$date = date(DATE_RFC2822);
-		$email->setHeaders(array('X-Mailer' => \DebugCakeEmail::EMAIL_CLIENT, 'Date' => $date));
-		$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
+		$email->setHeaders(array('X-Mailer' => Email::EMAIL_CLIENT, 'Date' => $date));
+		$email->expects($this->once())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
 
 		$headers = "From: CakePHP Test <noreply@cakephp.org>\r\n";
 		$headers .= "To: CakePHP <cake@cakephp.org>\r\n";

+ 9 - 8
tests/TestCase/Network/Email/SmtpTransportTest.php

@@ -82,10 +82,10 @@ class SmtpTransportTest extends TestCase {
  */
 	public function setUp() {
 		parent::setUp();
-		if (!class_exists('MockSocket')) {
-			$this->getMock('Cake\Network\Socket', array('read', 'write', 'connect', 'enableCrypto'), array(), 'MockSocket');
-		}
-		$this->socket = new \MockSocket();
+		$this->socket = $this->getMock(
+			'Cake\Network\Socket',
+			array('read', 'write', 'connect', 'enableCrypto')
+		);
 
 		$this->SmtpTransport = new SmtpTestTransport();
 		$this->SmtpTransport->setSocket($this->socket);
@@ -123,7 +123,7 @@ class SmtpTransportTest extends TestCase {
 		$this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n");
 		$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
 		$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("220 Server ready\r\n"));
-		$this->socket->expects($this->at(8))->method('other')->with('tls')->will($this->returnValue(true));
+		$this->socket->expects($this->at(8))->method('enableCrypto')->with('tls')->will($this->returnValue(true));
 		$this->socket->expects($this->at(9))->method('write')->with("EHLO localhost\r\n");
 		$this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
 		$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 Accepted\r\n"));
@@ -164,7 +164,7 @@ class SmtpTransportTest extends TestCase {
 		$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
 		$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
-		$this->socket->expects($this->at(5))->method('read')->with("AUTH LOGIN\r\n");
+		$this->socket->expects($this->at(5))->method('write')->with("AUTH LOGIN\r\n");
 		$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
 		$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("504 5.7.4 Unrecognized authentication type\r\n"));
 		$this->SmtpTransport->connect();
@@ -233,7 +233,8 @@ class SmtpTransportTest extends TestCase {
  * @return void
  */
 	public function testAuthNoAuth() {
-		$this->socket->expects($this->never())->method('write')->with("AUTH LOGIN\r\n");
+		$this->socket->expects($this->any())->method('write')->with($this->logicalNot($this->stringContains('AUTH LOGIN')));
+
 		$this->SmtpTransport->config(array('username' => null, 'password' => null));
 		$this->SmtpTransport->auth();
 	}
@@ -308,7 +309,7 @@ class SmtpTransportTest extends TestCase {
 		$email->subject('Testing SMTP');
 		$date = date(DATE_RFC2822);
 		$email->setHeaders(array('X-Mailer' => Email::EMAIL_CLIENT, 'Date' => $date));
-		$email->expects($this->any())
+		$email->expects($this->once())
 			->method('message')
 			->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
 

+ 54 - 63
tests/TestCase/Utility/ObjectCollectionTest.php

@@ -101,6 +101,27 @@ class GenericObjectCollection extends ObjectCollection {
 		return $this->_loaded[$name];
 	}
 
+/**
+ * Helper method for adding/overwriting enabled objects including
+ * settings
+ *
+ * @param string $name Name of the object
+ * @param Object $object The object to use
+ * @param array $settings Settings to apply for the object
+ * @return array Loaded objects
+ */
+	public function setObject($name, $object, $settings = array()) {
+		$this->_loaded[$name] = $object;
+		if (isset($settings['priority'])) {
+			$this->setPriority($name, $settings['priority']);
+		}
+		$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
+		if ($enable === true) {
+			$this->enable($name);
+		}
+		return $this->_loaded;
+	}
+
 }
 
 class ObjectCollectionTest extends TestCase {
@@ -193,15 +214,18 @@ class ObjectCollectionTest extends TestCase {
  * @return void
  */
 	protected function _makeMockClasses() {
-		if (!class_exists('TriggerMockFirstGenericObject')) {
-			$this->getMock(__NAMESPACE__ . '\FirstGenericObject', array(), array(), 'TriggerMockFirstGenericObject', false);
-		}
-		if (!class_exists('TriggerMockSecondGenericObject')) {
-			$this->getMock(__NAMESPACE__ . '\SecondGenericObject', array(), array(), 'TriggerMockSecondGenericObject', false);
-		}
-		if (!class_exists('TriggerMockThirdGenericObject')) {
-			$this->getMock(__NAMESPACE__ . '\ThirdGenericObject', array(), array(), 'TriggerMockThirdGenericObject', false);
-		}
+		$this->FirstGenericObject = $this->getMock(
+			__NAMESPACE__ . '\FirstGenericObject',
+			array(), array(), '', false
+		);
+		$this->SecondGenericObject = $this->getMock(
+			__NAMESPACE__ . '\SecondGenericObject',
+			array(), array(), '', false
+		);
+		$this->ThirdGenericObject = $this->getMock(
+			__NAMESPACE__ . '\ThirdGenericObject',
+			array(), array(), '', false
+		);
 	}
 
 /**
@@ -211,11 +235,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTrigger() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$this->Objects->TriggerMockFirst->expects($this->once())
 			->method('callback')
@@ -234,11 +255,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTriggerWithDisabledObjects() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject, array('enabled' => false));
 
 		$this->Objects->TriggerMockFirst->expects($this->once())
 			->method('callback')
@@ -247,8 +265,6 @@ class ObjectCollectionTest extends TestCase {
 			->method('callback')
 			->will($this->returnValue(true));
 
-		$this->Objects->disable('TriggerMockSecond');
-
 		$this->assertTrue($this->Objects->trigger('callback', array()));
 	}
 
@@ -259,11 +275,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTriggerWithCollectReturn() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$this->Objects->TriggerMockFirst->expects($this->once())
 			->method('callback')
@@ -287,11 +300,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTriggerWithBreak() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$this->Objects->TriggerMockFirst->expects($this->once())
 			->method('callback')
@@ -314,11 +324,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTriggerWithModParams() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$this->Objects->TriggerMockFirst->expects($this->once())
 			->method('callback')
@@ -346,11 +353,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTriggerModParamsInvalidIndex() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$this->Objects->TriggerMockFirst->expects($this->never())
 			->method('callback');
@@ -372,11 +376,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTriggerModParamsNullIgnored() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$this->Objects->TriggerMockFirst->expects($this->once())
 			->method('callback')
@@ -403,11 +404,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testTriggerPriority() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond', array('priority' => 5));
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject, array('priority' => 5));
 
 		$this->Objects->TriggerMockFirst->expects($this->any())
 			->method('callback')
@@ -423,8 +421,7 @@ class ObjectCollectionTest extends TestCase {
 		);
 		$this->assertEquals($expected, $result);
 
-		$this->Objects->load('TriggerMockThird', array('priority' => 7));
-		$this->mockObjects[] = $this->Objects->TriggerMockThird;
+		$this->Objects->setObject('TriggerMockThird', $this->ThirdGenericObject, array('priority' => 7));
 		$this->Objects->TriggerMockThird->expects($this->any())
 			->method('callback')
 			->will($this->returnValue('3rd'));
@@ -547,11 +544,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testDispatchEventWithSubject() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$subjectClass = new Object();
 		$this->Objects->TriggerMockFirst->expects($this->once())
@@ -575,11 +569,8 @@ class ObjectCollectionTest extends TestCase {
  */
 	public function testDispatchEventNoSubject() {
 		$this->_makeMockClasses();
-		$this->Objects->load('TriggerMockFirst');
-		$this->Objects->load('TriggerMockSecond');
-
-		$this->mockObjects[] = $this->Objects->TriggerMockFirst;
-		$this->mockObjects[] = $this->Objects->TriggerMockSecond;
+		$this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
+		$this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
 
 		$subjectClass = new Object();
 		$this->Objects->TriggerMockFirst->expects($this->once())

+ 22 - 0
tests/test_app/TestApp/Controller/Component/TestAuthComponent.php

@@ -33,6 +33,28 @@ class TestAuthComponent extends AuthComponent {
 	public $testStop = false;
 
 /**
+ * Helper method to add/set an authenticate object instance
+ *
+ * @param integer $index The index at which to add/set the object
+ * @param Object $object The object to add/set
+ * @return void
+ */
+	public function setAuthenticateObject($index, $object) {
+		$this->_authenticateObjects[$index] = $object;
+	}
+
+/**
+ * Helper method to add/set an authorize object instance
+ *
+ * @param integer $index The index at which to add/set the object
+ * @param Object $object The object to add/set
+ * @return void
+ */
+	public function setAuthorizeObject($index, $object) {
+		$this->_authorizeObjects[$index] = $object;
+	}
+
+/**
  * stop method
  *
  * @return void

+ 2 - 0
tests/test_app/TestApp/Locale/rule_13_po/LC_MESSAGES/core.po

@@ -22,3 +22,5 @@ msgstr[1] "%d is 0 or ends in 01-10 (from core translated)"
 msgstr[2] "%d ends in 11-20 (from core translated)"
 msgstr[3] "%d everything else (from core translated)"
 
+msgid "%+5d = 1 (from core)"
+msgid_plural "%+5d = 0 or > 1 (from core)"

+ 5 - 0
tests/test_app/TestApp/Locale/rule_1_po/LC_MESSAGES/default.po

@@ -20,6 +20,11 @@ msgid_plural "%d = 0 or > 1"
 msgstr[0] "%d = 1 (translated)"
 msgstr[1] "%d = 0 or > 1 (translated)"
 
+msgid "%-5d = 1"
+msgid_plural "%-5d = 0 or > 1"
+msgstr[0] "%-5d = 1 (translated)"
+msgstr[1] "%-5d = 0 or > 1 (translated)"
+
 #~ msgid "Plural-Forms 1"
 #~ msgstr "Plural-Forms 1 (translated)"