Skip to content

Commit

Permalink
Several fixes for testcases.
Browse files Browse the repository at this point in the history
- Ensure correct ordering of find results
- avoid fatal error when testing email transport classes on 5.2
- add skips when running cross db join tests and multiple sqlite configs are defined
  • Loading branch information
ceeram committed Mar 15, 2012
1 parent 9f9c6fd commit 3e0294a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
3 changes: 1 addition & 2 deletions lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php
Expand Up @@ -63,6 +63,7 @@ public function setUp() {
*/
protected function _checkConfigs() {
$config = ConnectionManager::enumConnectionObjects();
$this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.');
$this->skipIf(
!isset($config['test']) || !isset($config['test2']),
'Primary and secondary test databases not configured, skipping cross-database join tests.'
Expand Down Expand Up @@ -95,7 +96,6 @@ public function testModelDatasources() {
*/
public function testHabtmFind() {
$this->loadFixtures('Player', 'Guild', 'GuildsPlayer');

$Player = ClassRegistry::init('Player');

$players = $Player->find('all', array(
Expand Down Expand Up @@ -130,7 +130,6 @@ public function testHabtmFind() {
*/
public function testHabtmSave() {
$this->loadFixtures('Player', 'Guild', 'GuildsPlayer');

$Player = ClassRegistry::init('Player');
$players = $Player->find('count');
$this->assertEquals(4, $players);
Expand Down
15 changes: 9 additions & 6 deletions lib/Cake/Test/Case/Model/ModelDeleteTest.php
Expand Up @@ -316,7 +316,8 @@ public function testDeleteAll() {

$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'user_id', 'title', 'published')
'fields' => array('id', 'user_id', 'title', 'published'),
'order' => array('Article.id' => 'ASC')
));

$expected = array(
Expand Down Expand Up @@ -363,7 +364,8 @@ public function testDeleteAll() {

$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'user_id', 'title', 'published')
'fields' => array('id', 'user_id', 'title', 'published'),
'order' => array('Article.id' => 'ASC')
));
$expected = array(
array('Article' => array(
Expand Down Expand Up @@ -398,7 +400,8 @@ public function testDeleteAll() {

$TestModel->recursive = -1;
$result = $TestModel->find('all', array(
'fields' => array('id', 'user_id', 'title', 'published')
'fields' => array('id', 'user_id', 'title', 'published'),
'order' => array('Article.id' => 'ASC')
));
$expected = array(
array('Article' => array(
Expand Down Expand Up @@ -559,7 +562,7 @@ public function testDeleteDependent() {
'ArticlesTag', 'Comment', 'User', 'Attachment'
);
$Bidding = new Bidding();
$result = $Bidding->find('all');
$result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC')));
$expected = array(
array(
'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'),
Expand All @@ -581,7 +584,7 @@ public function testDeleteDependent() {
$this->assertEquals($expected, $result);

$Bidding->delete(4, true);
$result = $Bidding->find('all');
$result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC')));
$expected = array(
array(
'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'),
Expand All @@ -599,7 +602,7 @@ public function testDeleteDependent() {
$this->assertEquals($expected, $result);

$Bidding->delete(2, true);
$result = $Bidding->find('all');
$result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC')));
$expected = array(
array(
'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'),
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -717,6 +717,7 @@ public function testHABTMKeepExisting() {
*/
public function testHABTMKeepExistingWithThreeDbs() {
$config = ConnectionManager::enumConnectionObjects();
$this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.');
$this->skipIf(
!isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']),
'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.'
Expand Down Expand Up @@ -835,7 +836,7 @@ public static function timeProvider() {
array('hour' => '', 'min' => '', 'sec' => ''),
''
),
// set and empty merdian
// set and empty merdian
array(
array('hour' => '1', 'min' => '00', 'meridian' => ''),
''
Expand Down
20 changes: 14 additions & 6 deletions lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -1006,7 +1006,10 @@ public function testSaveWithSet() {
$this->assertEquals($expected, $result);

$TestModel->recursive = -1;
$result = $TestModel->find('all', array('fields' => array('id', 'title')));
$result = $TestModel->find('all', array(
'fields' => array('id', 'title'),
'order' => array('Article.id' => 'ASC')
));
$expected = array(
array('Article' => array('id' => 1, 'title' => 'First Article')),
array('Article' => array('id' => 2, 'title' => 'Second Article')),
Expand Down Expand Up @@ -3075,7 +3078,8 @@ public function testSaveAllDeepAssociated() {
'First new comment',
'Second new comment'
);
$this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment'));
$result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
$this->assertEquals($expected, $result);

$result = $TestModel->Comment->User->field('id', array('user' => 'newuser', 'password' => 'newuserpass'));
$this->assertEquals(5, $result);
Expand All @@ -3097,7 +3101,8 @@ public function testSaveAllDeepAssociated() {
'Third new comment',
'Fourth new comment'
);
$this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment'));
$result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
$this->assertEquals($expected, $result);

$result = $TestModel->Comment->Attachment->field('id', array('attachment' => 'deepsaved'));
$this->assertEquals(2, $result);
Expand Down Expand Up @@ -3848,7 +3853,8 @@ public function testSaveAllHasMany() {
'First new comment',
'Second new comment'
);
$this->assertEquals(Set::extract($result['Comment'], '{n}.comment'), $expected);
$result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
$this->assertEquals($expected, $result);

$result = $TestModel->saveAll(
array(
Expand All @@ -3871,7 +3877,8 @@ public function testSaveAllHasMany() {
'Second new comment',
'Third new comment'
);
$this->assertEquals(Set::extract($result['Comment'], '{n}.comment'), $expected);
$result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
$this->assertEquals($expected, $result);

$TestModel->beforeSaveReturn = false;
$result = $TestModel->saveAll(
Expand All @@ -3895,7 +3902,8 @@ public function testSaveAllHasMany() {
'Second new comment',
'Third new comment'
);
$this->assertEquals(Set::extract($result['Comment'], '{n}.comment'), $expected);
$result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
$this->assertEquals($expected, $result);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Network/Email/DebugTransportTest.php
Expand Up @@ -50,7 +50,7 @@ public function testSend() {
$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
$email->subject('Testing Message');
$date = date(DATE_RFC2822);
$email->setHeaders(array('X-Mailer' => $email::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', '')));

$headers = "From: CakePHP Test <noreply@cakephp.org>\r\n";
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php
Expand Up @@ -221,7 +221,7 @@ public function testSendData() {
$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
$email->subject('Testing SMTP');
$date = date(DATE_RFC2822);
$email->setHeaders(array('X-Mailer' => $email::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', '')));

$data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
Expand Down

0 comments on commit 3e0294a

Please sign in to comment.