Skip to content

Commit

Permalink
Adding test case for Model::saveAll for HABTM data with additional fi…
Browse files Browse the repository at this point in the history
…elds saved in join table.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8049 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
jperras committed Feb 19, 2009
1 parent 01340e8 commit 82a8599
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cake/tests/cases/libs/model/model.test.php
Expand Up @@ -3281,6 +3281,44 @@ function testSaveAllHabtm() {
$this->assertEqual(count($result['Comment']), 1);
$this->assertEqual(count($result['Comment'][0]['comment']['Article comment']), 1);
}

function testSaveAllHabtmWithExtraJoinTableFields() {
$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');

$data = array(
'Something' => array(
'id' => 4,
'title' => 'Extra Fields',
'body' => 'Extra Fields Body',
'published' => '1'
),
'SomethingElse' => array(
array('something_else_id' => 1, 'doomed' => '1'),
array('something_else_id' => 2, 'doomed' => '0'),
array('something_else_id' => 3, 'doomed' => '1')
)
);

$Something =& new Something();
$result = $Something->saveAll($data);
$this->assertTrue($result);
$result = $Something->read();

$this->assertEqual(count($result['SomethingElse']), 3);
$this->assertTrue(Set::matches('/Something[id=4]', $result));

$this->assertTrue(Set::matches('/SomethingElse[id=1]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[something_else_id=1]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[doomed=1]', $result));

$this->assertTrue(Set::matches('/SomethingElse[id=2]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[something_else_id=2]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[doomed=0]', $result));

$this->assertTrue(Set::matches('/SomethingElse[id=3]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[something_else_id=3]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[doomed=1]', $result));
}

/**
* testSaveAllHasOne method
Expand Down

0 comments on commit 82a8599

Please sign in to comment.