mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding another test for #250.
This commit is contained in:
parent
500550faef
commit
9992cff96c
2 changed files with 46 additions and 0 deletions
|
@ -708,4 +708,32 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
// Removing Article #2 from Tag #1 is all that should have happened.
|
||||
$this->assertEqual(count($before[0]["Tag"]), count($after[0]["Tag"]));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that deleting records inside the beforeDelete doesn't truncate the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testBeforeDeleteWipingTable() {
|
||||
$this->loadFixtures('Comment');
|
||||
|
||||
$Comment =& new BeforeDeleteComment();
|
||||
// Delete 3 records.
|
||||
$Comment->delete(4);
|
||||
$result = $Comment->find('count');
|
||||
|
||||
$this->assertTrue($result > 1, 'Comments are all gone.');
|
||||
$Comment->create(array(
|
||||
'article_id' => 1,
|
||||
'user_id' => 2,
|
||||
'comment' => 'new record',
|
||||
'published' => 'Y'
|
||||
));
|
||||
$Comment->save();
|
||||
|
||||
$Comment->delete(5);
|
||||
$result = $Comment->find('count');
|
||||
|
||||
$this->assertTrue($result > 1, 'Comments are all gone.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -282,6 +282,24 @@ class Article extends CakeTestModel {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Model stub for beforeDelete testing
|
||||
*
|
||||
* @see #250
|
||||
* @package cake.tests
|
||||
*/
|
||||
class BeforeDeleteComment extends CakeTestModel {
|
||||
var $name = 'BeforeDeleteComment';
|
||||
|
||||
var $useTable = 'comments';
|
||||
|
||||
function beforeDelete($cascade = true) {
|
||||
$db =& $this->getDataSource();
|
||||
$db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NumericArticle class
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue