Skip to content

Commit

Permalink
Add test for Model::getID(), simplify return and remove dated @see link
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Dec 14, 2011
1 parent d831159 commit 060e225
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 1 addition & 5 deletions lib/Cake/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -3164,11 +3164,7 @@ public function getID($list = 0) {
return false;
}

foreach ($this->id as $id) {
return $id;
}

return false;
return current($this->id);
}

/**
Expand Down
25 changes: 24 additions & 1 deletion lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,6 @@ public function testCreation() {

/**
* testEscapeField to prove it escapes the field well even when it has part of the alias on it
* @see ttp://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/473-escapefield-doesnt-consistently-prepend-modelname
*
* @return void
*/
Expand Down Expand Up @@ -2052,6 +2051,30 @@ public function testEscapeField() {
ConnectionManager::drop('mock');
}

/**
* testGetID
*
* @return void
*/
public function testGetID() {
$TestModel = new Test();

$result = $TestModel->getID();
$this->assertFalse($result);

$TestModel->id = 9;
$result = $TestModel->getID();
$this->assertEquals(9, $result);

$TestModel->id = array(10, 9, 8, 7);
$result = $TestModel->getID(2);
$this->assertEquals(8, $result);

$TestModel->id = array(array(), 1, 2, 3);
$result = $TestModel->getID();
$this->assertFalse($result);
}

/**
* test that model->hasMethod checks self and behaviors.
*
Expand Down

0 comments on commit 060e225

Please sign in to comment.