Fix verification of expected invocations #2919

This commit is contained in:
ndm2 2014-03-01 19:01:36 +01:00
parent a707709e1d
commit 008ad3237c
11 changed files with 235 additions and 208 deletions

View file

@ -436,14 +436,14 @@ class ShellDispatcherTest extends CakeTestCase {
*/ */
public function testDispatchShellWithMain() { public function testDispatchShellWithMain() {
$Dispatcher = new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$Mock = $this->getMock('Shell', array(), array(), 'MockWithMainShell'); $Shell = $this->getMock('Shell');
$Mock->expects($this->once())->method('initialize'); $Shell->expects($this->once())->method('initialize');
$Mock->expects($this->once())->method('runCommand') $Shell->expects($this->once())->method('runCommand')
->with(null, array()) ->with(null, array())
->will($this->returnValue(true)); ->will($this->returnValue(true));
$Dispatcher->TestShell = $Mock; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main'); $Dispatcher->args = array('mock_with_main');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
@ -458,10 +458,7 @@ class ShellDispatcherTest extends CakeTestCase {
*/ */
public function testDispatchShellWithoutMain() { public function testDispatchShellWithoutMain() {
$Dispatcher = new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$Shell = $this->getMock('Shell', array(), array(), 'MockWithoutMainShell'); $Shell = $this->getMock('Shell');
$Shell = new MockWithoutMainShell();
$this->mockObjects[] = $Shell;
$Shell->expects($this->once())->method('initialize'); $Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('runCommand') $Shell->expects($this->once())->method('runCommand')
@ -496,8 +493,7 @@ class ShellDispatcherTest extends CakeTestCase {
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEquals(array(), $Dispatcher->args); $this->assertEquals(array(), $Dispatcher->args);
$Shell = new MockWithMainNotAShell($Dispatcher); $Shell = $this->getMock('Object', $methods, array(), 'MockWithMainNotAShell');
$this->mockObjects[] = $Shell;
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true)); $Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
$Shell->expects($this->once())->method('startup'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell; $Dispatcher->TestShell = $Shell;
@ -528,8 +524,7 @@ class ShellDispatcherTest extends CakeTestCase {
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEquals(array(), $Dispatcher->args); $this->assertEquals(array(), $Dispatcher->args);
$Shell = new MockWithoutMainNotAShell($Dispatcher); $Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell');
$this->mockObjects[] = $Shell;
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true)); $Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
$Shell->expects($this->once())->method('startup'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell; $Dispatcher->TestShell = $Shell;

View file

@ -33,9 +33,7 @@ class AclComponentTest extends CakeTestCase {
*/ */
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
if (!class_exists('MockAclImplementation', false)) { $this->MockAclImplementation = $this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
$this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
}
Configure::write('Acl.classname', 'MockAclImplementation'); Configure::write('Acl.classname', 'MockAclImplementation');
$Collection = new ComponentCollection(); $Collection = new ComponentCollection();
$this->Acl = new AclComponent($Collection); $this->Acl = new AclComponent($Collection);
@ -70,11 +68,10 @@ class AclComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testAdapter() { public function testAdapter() {
$implementation = new MockAclImplementation(); $this->MockAclImplementation->expects($this->once())->method('initialize')->with($this->Acl);
$implementation->expects($this->once())->method('initialize')->with($this->Acl); $this->assertNull($this->Acl->adapter($this->MockAclImplementation));
$this->assertNull($this->Acl->adapter($implementation));
$this->assertEquals($this->Acl->adapter(), $implementation, 'Returned object is different %s'); $this->assertEquals($this->Acl->adapter(), $this->MockAclImplementation, 'Returned object is different %s');
} }
/** /**

View file

@ -35,6 +35,28 @@ class TestAuthComponent extends AuthComponent {
*/ */
public $testStop = false; 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 * stop method
* *
@ -352,7 +374,7 @@ class AuthComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testLogin() { public function testLogin() {
$this->getMock('FormAuthenticate', array(), array(), 'AuthLoginFormAuthenticate', false); $AuthLoginFormAuthenticate = $this->getMock('FormAuthenticate', array(), array(), '', false);
$this->Auth->authenticate = array( $this->Auth->authenticate = array(
'AuthLoginForm' => array( 'AuthLoginForm' => array(
'userModel' => 'AuthUser' 'userModel' => 'AuthUser'
@ -360,8 +382,7 @@ class AuthComponentTest extends CakeTestCase {
); );
$this->Auth->Session = $this->getMock('SessionComponent', array('renew'), array(), '', false); $this->Auth->Session = $this->getMock('SessionComponent', array('renew'), array(), '', false);
$mocks = $this->Auth->constructAuthenticate(); $this->Auth->setAuthenticateObject(0, $AuthLoginFormAuthenticate);
$this->mockObjects[] = $mocks[0];
$this->Auth->request->data = array( $this->Auth->request->data = array(
'AuthUser' => array( 'AuthUser' => array(
@ -375,7 +396,7 @@ class AuthComponentTest extends CakeTestCase {
'username' => 'mark' 'username' => 'mark'
); );
$mocks[0]->expects($this->once()) $AuthLoginFormAuthenticate->expects($this->once())
->method('authenticate') ->method('authenticate')
->with($this->Auth->request) ->with($this->Auth->request)
->will($this->returnValue($user)); ->will($this->returnValue($user));
@ -451,30 +472,26 @@ class AuthComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testIsAuthorizedDelegation() { public function testIsAuthorizedDelegation() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockOneAuthorize', false); $AuthMockOneAuthorize = $this->getMock('BaseAuthorize', array('authorize'), array(), '', false);
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockTwoAuthorize', false); $AuthMockTwoAuthorize = $this->getMock('BaseAuthorize', array('authorize'), array(), '', false);
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockThreeAuthorize', false); $AuthMockThreeAuthorize = $this->getMock('BaseAuthorize', array('authorize'), array(), '', false);
$this->Auth->authorize = array( $this->Auth->setAuthorizeObject(0, $AuthMockOneAuthorize);
'AuthMockOne', $this->Auth->setAuthorizeObject(1, $AuthMockTwoAuthorize);
'AuthMockTwo', $this->Auth->setAuthorizeObject(2, $AuthMockThreeAuthorize);
'AuthMockThree'
);
$mocks = $this->Auth->constructAuthorize();
$request = $this->Auth->request; $request = $this->Auth->request;
$this->assertEquals(3, count($mocks)); $AuthMockOneAuthorize->expects($this->once())
$mocks[0]->expects($this->once())
->method('authorize') ->method('authorize')
->with(array('User'), $request) ->with(array('User'), $request)
->will($this->returnValue(false)); ->will($this->returnValue(false));
$mocks[1]->expects($this->once()) $AuthMockTwoAuthorize->expects($this->once())
->method('authorize') ->method('authorize')
->with(array('User'), $request) ->with(array('User'), $request)
->will($this->returnValue(true)); ->will($this->returnValue(true));
$mocks[2]->expects($this->never()) $AuthMockThreeAuthorize->expects($this->never())
->method('authorize'); ->method('authorize');
$this->assertTrue($this->Auth->isAuthorized(array('User'), $request)); $this->assertTrue($this->Auth->isAuthorized(array('User'), $request));
@ -486,15 +503,15 @@ class AuthComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testIsAuthorizedUsingUserInSession() { public function testIsAuthorizedUsingUserInSession() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockFourAuthorize', false); $AuthMockFourAuthorize = $this->getMock('BaseAuthorize', array('authorize'), array(), '', false);
$this->Auth->authorize = array('AuthMockFour'); $this->Auth->authorize = array('AuthMockFour');
$this->Auth->setAuthorizeObject(0, $AuthMockFourAuthorize);
$user = array('user' => 'mark'); $user = array('user' => 'mark');
$this->Auth->Session->write('Auth.User', $user); $this->Auth->Session->write('Auth.User', $user);
$mocks = $this->Auth->constructAuthorize();
$request = $this->Controller->request; $request = $this->Controller->request;
$mocks[0]->expects($this->once()) $AuthMockFourAuthorize->expects($this->once())
->method('authorize') ->method('authorize')
->with($user, $request) ->with($user, $request)
->will($this->returnValue(true)); ->will($this->returnValue(true));
@ -1223,11 +1240,11 @@ class AuthComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testLogoutTrigger() { public function testLogoutTrigger() {
$this->getMock('BaseAuthenticate', array('authenticate', 'logout'), array(), 'LogoutTriggerMockAuthenticate', false); $LogoutTriggerMockAuthenticate = $this->getMock('BaseAuthenticate', array('authenticate', 'logout'), array(), '', false);
$this->Auth->authenticate = array('LogoutTriggerMock'); $this->Auth->authenticate = array('LogoutTriggerMock');
$mock = $this->Auth->constructAuthenticate(); $this->Auth->setAuthenticateObject(0, $LogoutTriggerMockAuthenticate);
$mock[0]->expects($this->once()) $LogoutTriggerMockAuthenticate->expects($this->once())
->method('logout'); ->method('logout');
$this->Auth->logout(); $this->Auth->logout();
@ -1239,10 +1256,11 @@ class AuthComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testMapActionsDelegation() { public function testMapActionsDelegation() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'MapActionMockAuthorize', false); $MapActionMockAuthorize = $this->getMock('BaseAuthorize', array('authorize', 'mapActions'), array(), '', false);
$this->Auth->authorize = array('MapActionMock'); $this->Auth->authorize = array('MapActionMock');
$mock = $this->Auth->constructAuthorize(); $this->Auth->setAuthorizeObject(0, $MapActionMockAuthorize);
$mock[0]->expects($this->once()) $MapActionMockAuthorize->expects($this->once())
->method('mapActions') ->method('mapActions')
->with(array('create' => array('my_action'))); ->with(array('create' => array('my_action')));
@ -1255,14 +1273,14 @@ class AuthComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testLoginWithRequestData() { public function testLoginWithRequestData() {
$this->getMock('FormAuthenticate', array(), array(), 'RequestLoginMockAuthenticate', false); $RequestLoginMockAuthenticate = $this->getMock('FormAuthenticate', array(), array(), '', false);
$request = new CakeRequest('users/login', false); $request = new CakeRequest('users/login', false);
$user = array('username' => 'mark', 'role' => 'admin'); $user = array('username' => 'mark', 'role' => 'admin');
$this->Auth->request = $request; $this->Auth->request = $request;
$this->Auth->authenticate = array('RequestLoginMock'); $this->Auth->authenticate = array('RequestLoginMock');
$mock = $this->Auth->constructAuthenticate(); $this->Auth->setAuthenticateObject(0, $RequestLoginMockAuthenticate);
$mock[0]->expects($this->once()) $RequestLoginMockAuthenticate->expects($this->once())
->method('authenticate') ->method('authenticate')
->with($request) ->with($request)
->will($this->returnValue($user)); ->will($this->returnValue($user));

View file

@ -443,9 +443,7 @@ class ModelDeleteTest extends BaseModelTest {
*/ */
public function testDeleteAllFailedFind() { public function testDeleteAllFailedFind() {
$this->loadFixtures('Article'); $this->loadFixtures('Article');
$this->getMock('Article', array('find'), array(), 'ArticleDeleteAll'); $TestModel = $this->getMock('Article', array('find'));
$TestModel = new ArticleDeleteAll();
$TestModel->expects($this->once()) $TestModel->expects($this->once())
->method('find') ->method('find')
->will($this->returnValue(null)); ->will($this->returnValue(null));

View file

@ -23,6 +23,80 @@ App::uses('MockAssociatedTransactionDboSource', 'Model/Datasource');
require_once dirname(__FILE__) . DS . 'ModelTestBase.php'; require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
/**
* Helper class for testing with mocked datasources
*/
class TestAuthor extends Author {
public $hasMany = array(
'Post' => array(
'className' => 'Recipe'
)
);
protected $_dataSourceObject;
/**
* Helper method to set a datasource object
*
* @param Object $object The datasource object
*/
public function setDataSourceObject($object) {
$this->_dataSourceObject = $object;
}
/**
* Overwritten in order to return the directly set datasource object if
* available
*
* @return DataSource
*/
public function getDataSource() {
if ($this->_dataSourceObject !== null) {
return $this->_dataSourceObject;
}
return parent::getDataSource();
}
}
/**
* Helper class for testing with mocked datasources
*/
class TestPost extends Post {
public $belongsTo = array(
'Author' => array(
'className' => 'TestAuthor'
)
);
protected $_dataSourceObject;
/**
* Helper method to set a datasource object
*
* @param Object $object The datasource object
*/
public function setDataSourceObject($object) {
$this->_dataSourceObject = $object;
}
/**
* Overwritten in order to return the directly set datasource object if
* available
*
* @return DataSource
*/
public function getDataSource() {
if ($this->_dataSourceObject !== null) {
return $this->_dataSourceObject;
}
return parent::getDataSource();
}
}
/** /**
* ModelWriteTest * ModelWriteTest
* *
@ -4046,17 +4120,15 @@ class ModelWriteTest extends BaseModelTest {
public function testSaveAllManyRowsTransactionNoRollback() { public function testSaveAllManyRowsTransactionNoRollback() {
$this->loadFixtures('Post'); $this->loadFixtures('Post');
$this->getMock('DboSource', array('connect', 'rollback', 'describe'), array(), 'MockTransactionDboSource'); $db = $this->getMock('DboSource', array('begin', 'connect', 'rollback', 'describe'));
$db = ConnectionManager::create('mock_transaction', array(
'datasource' => 'MockTransactionDboSource',
));
$db->expects($this->once()) $db->expects($this->once())
->method('describe') ->method('describe')
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$db->expects($this->once())->method('rollback'); $db->expects($this->once())->method('rollback');
$Post = new Post('mock_transaction'); $Post = new TestPost();
$Post->setDataSourceObject($db);
$Post->validate = array( $Post->validate = array(
'title' => array('rule' => array('notEmpty')) 'title' => array('rule' => array('notEmpty'))
@ -4066,7 +4138,7 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => 'New Fourth Post'), array('author_id' => 1, 'title' => 'New Fourth Post'),
array('author_id' => 1, 'title' => '') array('author_id' => 1, 'title' => '')
); );
$Post->saveAll($data, array('atomic' => true)); $Post->saveAll($data, array('atomic' => true, 'validate' => true));
} }
/** /**
@ -4077,16 +4149,7 @@ class ModelWriteTest extends BaseModelTest {
public function testSaveAllAssociatedTransactionNoRollback() { public function testSaveAllAssociatedTransactionNoRollback() {
$testDb = ConnectionManager::getDataSource('test'); $testDb = ConnectionManager::getDataSource('test');
$this->getMock( $db = $this->getMock('DboSource', array('connect', 'rollback', 'describe', 'create', 'update', 'begin'));
'DboSource',
array('connect', 'rollback', 'describe', 'create', 'update', 'begin'),
array(),
'MockTransactionAssociatedDboSource'
);
$db = ConnectionManager::create('mock_transaction_assoc', array(
'datasource' => 'MockTransactionAssociatedDboSource',
));
$this->mockObjects[] = $db;
$db->columns = $testDb->columns; $db->columns = $testDb->columns;
$db->expects($this->once())->method('rollback'); $db->expects($this->once())->method('rollback');
@ -4098,9 +4161,9 @@ class ModelWriteTest extends BaseModelTest {
'published' => array('type' => 'string') 'published' => array('type' => 'string')
))); )));
$Post = new Post(); $Post = new TestPost();
$Post->useDbConfig = 'mock_transaction_assoc'; $Post->setDataSourceObject($db);
$Post->Author->useDbConfig = 'mock_transaction_assoc'; $Post->Author->setDataSourceObject($db);
$Post->Author->validate = array( $Post->Author->validate = array(
'user' => array('rule' => array('notEmpty')) 'user' => array('rule' => array('notEmpty'))
@ -5490,17 +5553,15 @@ class ModelWriteTest extends BaseModelTest {
public function testSaveManyTransactionNoRollback() { public function testSaveManyTransactionNoRollback() {
$this->loadFixtures('Post'); $this->loadFixtures('Post');
$this->getMock('DboSource', array('connect', 'rollback', 'describe'), array(), 'MockManyTransactionDboSource'); $db = $this->getMock('DboSource', array('begin', 'connect', 'rollback', 'describe'));
$db = ConnectionManager::create('mock_many_transaction', array(
'datasource' => 'MockManyTransactionDboSource',
));
$db->expects($this->once()) $db->expects($this->once())
->method('describe') ->method('describe')
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$db->expects($this->once())->method('rollback'); $db->expects($this->once())->method('rollback');
$Post = new Post('mock_many_transaction'); $Post = new TestPost();
$Post->setDataSourceObject($db);
$Post->validate = array( $Post->validate = array(
'title' => array('rule' => array('notEmpty')) 'title' => array('rule' => array('notEmpty'))
@ -5510,7 +5571,7 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => 'New Fourth Post'), array('author_id' => 1, 'title' => 'New Fourth Post'),
array('author_id' => 1, 'title' => '') array('author_id' => 1, 'title' => '')
); );
$Post->saveMany($data); $Post->saveMany($data, array('validate' => true));
} }
/** /**
@ -5521,17 +5582,7 @@ class ModelWriteTest extends BaseModelTest {
public function testSaveAssociatedTransactionNoRollback() { public function testSaveAssociatedTransactionNoRollback() {
$testDb = ConnectionManager::getDataSource('test'); $testDb = ConnectionManager::getDataSource('test');
$this->getMock( $db = $this->getMock('DboSource', array('connect', 'rollback', 'describe', 'create', 'begin'));
'DboSource',
array('connect', 'rollback', 'describe', 'create', 'begin'),
array(),
'MockAssociatedTransactionDboSource',
false
);
$db = ConnectionManager::create('mock_assoc_transaction', array(
'datasource' => 'MockAssociatedTransactionDboSource',
));
$this->mockObjects[] = $db;
$db->columns = $testDb->columns; $db->columns = $testDb->columns;
$db->expects($this->once())->method('rollback'); $db->expects($this->once())->method('rollback');
@ -5543,9 +5594,9 @@ class ModelWriteTest extends BaseModelTest {
'published' => array('type' => 'string') 'published' => array('type' => 'string')
))); )));
$Post = new Post(); $Post = new TestPost();
$Post->useDbConfig = 'mock_assoc_transaction'; $Post->setDataSourceObject($db);
$Post->Author->useDbConfig = 'mock_assoc_transaction'; $Post->Author->setDataSourceObject($db);
$Post->Author->validate = array( $Post->Author->validate = array(
'user' => array('rule' => array('notEmpty')) 'user' => array('rule' => array('notEmpty'))

View file

@ -42,8 +42,7 @@ class DebugTransportTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testSend() { public function testSend() {
$this->getMock('CakeEmail', array('message'), array(), 'DebugCakeEmail'); $email = $this->getMock('CakeEmail', array('message'), array(), 'DebugCakeEmail');
$email = new DebugCakeEmail();
$email->from('noreply@cakephp.org', 'CakePHP Test'); $email->from('noreply@cakephp.org', 'CakePHP Test');
$email->to('cake@cakephp.org', 'CakePHP'); $email->to('cake@cakephp.org', 'CakePHP');
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso')); $email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
@ -52,7 +51,7 @@ class DebugTransportTest extends CakeTestCase {
$email->subject('Testing Message'); $email->subject('Testing Message');
$date = date(DATE_RFC2822); $date = date(DATE_RFC2822);
$email->setHeaders(array('X-Mailer' => DebugCakeEmail::EMAIL_CLIENT, 'Date' => $date)); $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->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 = "From: CakePHP Test <noreply@cakephp.org>\r\n";
$headers .= "To: CakePHP <cake@cakephp.org>\r\n"; $headers .= "To: CakePHP <cake@cakephp.org>\r\n";

View file

@ -81,10 +81,7 @@ class SmtpTransportTest extends CakeTestCase {
*/ */
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
if (!class_exists('MockSocket')) { $this->socket = $this->getMock('CakeSocket', array('read', 'write', 'connect', 'enableCrypto'));
$this->getMock('CakeSocket', array('read', 'write', 'connect', 'enableCrypto'), array(), 'MockSocket');
}
$this->socket = new MockSocket();
$this->SmtpTransport = new SmtpTestTransport(); $this->SmtpTransport = new SmtpTestTransport();
$this->SmtpTransport->setSocket($this->socket); $this->SmtpTransport->setSocket($this->socket);
@ -122,7 +119,7 @@ class SmtpTransportTest extends CakeTestCase {
$this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n"); $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(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(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(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(10))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 Accepted\r\n")); $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 Accepted\r\n"));
@ -163,7 +160,7 @@ class SmtpTransportTest extends CakeTestCase {
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n"); $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(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(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(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->socket->expects($this->at(7))->method('read')->will($this->returnValue("504 5.7.4 Unrecognized authentication type\r\n"));
$this->SmtpTransport->connect(); $this->SmtpTransport->connect();
@ -232,7 +229,8 @@ class SmtpTransportTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testAuthNoAuth() { public function testAuthNoAuth() {
$this->socket->expects($this->never())->method('write')->with("AUTH LOGIN\r\n"); $this->socket->expects($this->any())->method('write')->with(new PHPUnit_Framework_Constraint_Not("AUTH LOGIN\r\n"));
$this->SmtpTransport->config(array('username' => null, 'password' => null)); $this->SmtpTransport->config(array('username' => null, 'password' => null));
$this->SmtpTransport->auth(); $this->SmtpTransport->auth();
} }
@ -297,8 +295,7 @@ class SmtpTransportTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testSendData() { public function testSendData() {
$this->getMock('CakeEmail', array('message'), array(), 'SmtpCakeEmail'); $email = $this->getMock('CakeEmail', array('message'), array(), 'SmtpCakeEmail');
$email = new SmtpCakeEmail();
$email->from('noreply@cakephp.org', 'CakePHP Test'); $email->from('noreply@cakephp.org', 'CakePHP Test');
$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return'); $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
$email->to('cake@cakephp.org', 'CakePHP'); $email->to('cake@cakephp.org', 'CakePHP');
@ -308,7 +305,7 @@ class SmtpTransportTest extends CakeTestCase {
$email->subject('Testing SMTP'); $email->subject('Testing SMTP');
$date = date(DATE_RFC2822); $date = date(DATE_RFC2822);
$email->setHeaders(array('X-Mailer' => SmtpCakeEmail::EMAIL_CLIENT, 'Date' => $date)); $email->setHeaders(array('X-Mailer' => SmtpCakeEmail::EMAIL_CLIENT, 'Date' => $date));
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); $email->expects($this->once())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
$data = "From: CakePHP Test <noreply@cakephp.org>\r\n"; $data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
$data .= "To: CakePHP <cake@cakephp.org>\r\n"; $data .= "To: CakePHP <cake@cakephp.org>\r\n";

View file

@ -192,13 +192,8 @@ class HttpSocketTest extends CakeTestCase {
*/ */
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
if (!class_exists('MockHttpSocket')) { $this->Socket = $this->getMock('TestHttpSocket', array('read', 'write', 'connect'));
$this->getMock('TestHttpSocket', array('read', 'write', 'connect'), array(), 'MockHttpSocket'); $this->RequestSocket = $this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'));
$this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array(), 'MockHttpSocketRequests');
}
$this->Socket = new MockHttpSocket();
$this->RequestSocket = new MockHttpSocketRequests();
} }
/** /**
@ -635,12 +630,12 @@ class HttpSocketTest extends CakeTestCase {
$this->Socket->reset(); $this->Socket->reset();
$request = array('uri' => 'htpp://www.cakephp.org/'); $request = array('uri' => 'htpp://www.cakephp.org/');
$number = mt_rand(0, 9999999); $number = mt_rand(0, 9999999);
$this->Socket->expects($this->once())->method('connect')->will($this->returnValue(true)); $this->Socket->expects($this->any())->method('connect')->will($this->returnValue(true));
$serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>Hello, your lucky number is " . $number . "</h1>"; $serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>Hello, your lucky number is " . $number . "</h1>";
$this->Socket->expects($this->at(0))->method('write')
->with("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n");
$this->Socket->expects($this->at(0))->method('read')->will($this->returnValue(false)); $this->Socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
$this->Socket->expects($this->once())->method('write')
->with("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n");
$response = (string)$this->Socket->request($request); $response = (string)$this->Socket->request($request);
$this->assertEquals($response, "<h1>Hello, your lucky number is " . $number . "</h1>"); $this->assertEquals($response, "<h1>Hello, your lucky number is " . $number . "</h1>");
} }
@ -684,7 +679,7 @@ class HttpSocketTest extends CakeTestCase {
) )
) )
); );
$http = new MockHttpSocketRequests($request); $http = $this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array($request));
$expected = array('method' => 'GET', 'uri' => '/_test'); $expected = array('method' => 'GET', 'uri' => '/_test');
$http->expects($this->at(0))->method('request')->with($expected); $http->expects($this->at(0))->method('request')->with($expected);
@ -1056,20 +1051,19 @@ class HttpSocketTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testAuth() { public function testAuth() {
$socket = new MockHttpSocket(); $this->Socket->get('http://mark:secret@example.com/test');
$socket->get('http://mark:secret@example.com/test'); $this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
$socket->configAuth(false); $this->Socket->configAuth(false);
$socket->get('http://example.com/test'); $this->Socket->get('http://example.com/test');
$this->assertFalse(strpos($socket->request['header'], 'Authorization:')); $this->assertFalse(strpos($this->Socket->request['header'], 'Authorization:'));
$socket->configAuth('Test', 'mark', 'passwd'); $this->Socket->configAuth('Test', 'mark', 'passwd');
$socket->get('http://example.com/test'); $this->Socket->get('http://example.com/test');
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false); $this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Test mark.passwd') !== false);
$socket->configAuth(false); $this->Socket->configAuth(false);
$socket->request(array( $this->Socket->request(array(
'method' => 'GET', 'method' => 'GET',
'uri' => 'http://example.com/test', 'uri' => 'http://example.com/test',
'auth' => array( 'auth' => array(
@ -1078,8 +1072,8 @@ class HttpSocketTest extends CakeTestCase {
'pass' => 'hunter2' 'pass' => 'hunter2'
) )
)); ));
$this->assertEquals($socket->request['auth'], array('Basic' => array('user' => 'joel', 'pass' => 'hunter2'))); $this->assertEquals($this->Socket->request['auth'], array('Basic' => array('user' => 'joel', 'pass' => 'hunter2')));
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false); $this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false);
} }
/** /**
@ -1088,17 +1082,16 @@ class HttpSocketTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testConsecutiveGetResetsAuthCredentials() { public function testConsecutiveGetResetsAuthCredentials() {
$socket = new MockHttpSocket(); $this->Socket->get('http://mark:secret@example.com/test');
$socket->get('http://mark:secret@example.com/test'); $this->assertEquals('mark', $this->Socket->request['uri']['user']);
$this->assertEquals('mark', $socket->request['uri']['user']); $this->assertEquals('secret', $this->Socket->request['uri']['pass']);
$this->assertEquals('secret', $socket->request['uri']['pass']); $this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
$socket->get('/test2'); $this->Socket->get('/test2');
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); $this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
$socket->get('/test3'); $this->Socket->get('/test3');
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); $this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
} }
/** /**

View file

@ -96,6 +96,27 @@ class GenericObjectCollection extends ObjectCollection {
return $this->_loaded[$name]; 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 CakeTestCase { class ObjectCollectionTest extends CakeTestCase {
@ -188,15 +209,9 @@ class ObjectCollectionTest extends CakeTestCase {
* @return void * @return void
*/ */
protected function _makeMockClasses() { protected function _makeMockClasses() {
if (!class_exists('TriggerMockFirstGenericObject')) { $this->FirstGenericObject = $this->getMock('FirstGenericObject', array(), array(), '', false);
$this->getMock('FirstGenericObject', array(), array(), 'TriggerMockFirstGenericObject', false); $this->SecondGenericObject = $this->getMock('SecondGenericObject', array(), array(), '', false);
} $this->ThirdGenericObject = $this->getMock('ThirdGenericObject', array(), array(), '', false);
if (!class_exists('TriggerMockSecondGenericObject')) {
$this->getMock('SecondGenericObject', array(), array(), 'TriggerMockSecondGenericObject', false);
}
if (!class_exists('TriggerMockThirdGenericObject')) {
$this->getMock('ThirdGenericObject', array(), array(), 'TriggerMockThirdGenericObject', false);
}
} }
/** /**
@ -206,11 +221,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTrigger() { public function testTrigger() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())
->method('callback') ->method('callback')
@ -229,11 +241,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTriggerWithDisabledObjects() { public function testTriggerWithDisabledObjects() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject, array('enabled' => false));
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())
->method('callback') ->method('callback')
@ -242,8 +251,6 @@ class ObjectCollectionTest extends CakeTestCase {
->method('callback') ->method('callback')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$this->Objects->disable('TriggerMockSecond');
$this->assertTrue($this->Objects->trigger('callback', array())); $this->assertTrue($this->Objects->trigger('callback', array()));
} }
@ -254,11 +261,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTriggerWithCollectReturn() { public function testTriggerWithCollectReturn() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())
->method('callback') ->method('callback')
@ -282,11 +286,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTriggerWithBreak() { public function testTriggerWithBreak() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())
->method('callback') ->method('callback')
@ -309,11 +310,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTriggerWithModParams() { public function testTriggerWithModParams() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())
->method('callback') ->method('callback')
@ -341,11 +339,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTriggerModParamsInvalidIndex() { public function testTriggerModParamsInvalidIndex() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->never()) $this->Objects->TriggerMockFirst->expects($this->never())
->method('callback'); ->method('callback');
@ -367,11 +362,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTriggerModParamsNullIgnored() { public function testTriggerModParamsNullIgnored() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())
->method('callback') ->method('callback')
@ -398,11 +390,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testTriggerPriority() { public function testTriggerPriority() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond', array('priority' => 5)); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject, array('priority' => 5));
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->any()) $this->Objects->TriggerMockFirst->expects($this->any())
->method('callback') ->method('callback')
@ -418,8 +407,7 @@ class ObjectCollectionTest extends CakeTestCase {
); );
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$this->Objects->load('TriggerMockThird', array('priority' => 7)); $this->Objects->setObject('TriggerMockThird', $this->ThirdGenericObject, array('priority' => 7));
$this->mockObjects[] = $this->Objects->TriggerMockThird;
$this->Objects->TriggerMockThird->expects($this->any()) $this->Objects->TriggerMockThird->expects($this->any())
->method('callback') ->method('callback')
->will($this->returnValue('3rd')); ->will($this->returnValue('3rd'));
@ -542,11 +530,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testDispatchEventWithSubject() { public function testDispatchEventWithSubject() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$subjectClass = new Object(); $subjectClass = new Object();
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())
@ -570,11 +555,8 @@ class ObjectCollectionTest extends CakeTestCase {
*/ */
public function testDispatchEventNoSubject() { public function testDispatchEventNoSubject() {
$this->_makeMockClasses(); $this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst'); $this->Objects->setObject('TriggerMockFirst', $this->FirstGenericObject);
$this->Objects->load('TriggerMockSecond'); $this->Objects->setObject('TriggerMockSecond', $this->SecondGenericObject);
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$subjectClass = new Object(); $subjectClass = new Object();
$this->Objects->TriggerMockFirst->expects($this->once()) $this->Objects->TriggerMockFirst->expects($this->once())

View file

@ -174,13 +174,8 @@ class JsHelperTest extends CakeTestCase {
protected function _useMock() { protected function _useMock() {
$request = new CakeRequest(null, false); $request = new CakeRequest(null, false);
if (!class_exists('TestJsEngineHelper', false)) {
$this->getMock('JsBaseEngineHelper', array(), array($this->View), 'TestJsEngineHelper');
}
$this->Js = new JsHelper($this->View, array('TestJs')); $this->Js = new JsHelper($this->View, array('TestJs'));
$this->Js->TestJsEngine = new TestJsEngineHelper($this->View); $this->Js->TestJsEngine = $this->getMock('JsBaseEngineHelper', array(), array($this->View));
$this->mockObjects[] = $this->Js->TestJsEngine;
$this->Js->request = $request; $this->Js->request = $request;
$this->Js->Html = new HtmlHelper($this->View); $this->Js->Html = new HtmlHelper($this->View);
$this->Js->Html->request = $request; $this->Js->Html->request = $request;
@ -369,7 +364,7 @@ class JsHelperTest extends CakeTestCase {
Configure::write('Cache.disable', false); Configure::write('Cache.disable', false);
$this->Js->request->webroot = '/'; $this->Js->request->webroot = '/';
$this->Js->JsBaseEngine = new TestJsEngineHelper($this->View); $this->Js->JsBaseEngine = $this->getMock('JsBaseEngineHelper', array(), array($this->View));
$this->Js->buffer('one = 1;'); $this->Js->buffer('one = 1;');
$this->Js->buffer('two = 2;'); $this->Js->buffer('two = 2;');
$result = $this->Js->writeBuffer(array('onDomReady' => false, 'cache' => true)); $result = $this->Js->writeBuffer(array('onDomReady' => false, 'cache' => true));

View file

@ -708,15 +708,17 @@ class ViewTest extends CakeTestCase {
* Test that elements can have callbacks * Test that elements can have callbacks
*/ */
public function testElementCallbacks() { public function testElementCallbacks() {
$this->getMock('Helper', array(), array($this->View), 'ElementCallbackMockHtmlHelper'); $Helper = $this->getMock('Helper', array(), array($this->View), 'ElementCallbackMockHtmlHelper');
$this->View->helpers = array('ElementCallbackMockHtml'); $this->View->helpers = array('ElementCallbackMockHtml');
$this->View->loadHelpers(); $this->View->loadHelpers();
$this->View->Helpers->set('ElementCallbackMockHtml', $Helper);
$this->View->ElementCallbackMockHtml = $Helper;
$this->View->ElementCallbackMockHtml->expects($this->at(0))->method('beforeRender'); $this->View->ElementCallbackMockHtml->expects($this->at(0))->method('beforeRender');
$this->View->ElementCallbackMockHtml->expects($this->at(1))->method('afterRender'); $this->View->ElementCallbackMockHtml->expects($this->at(1))->method('afterRender');
$this->View->element('test_element', array(), array('callbacks' => true)); $this->View->element('test_element', array(), array('callbacks' => true));
$this->mockObjects[] = $this->View->ElementCallbackMockHtml;
} }
/** /**