aboutsummaryrefslogtreecommitdiff
path: root/engine/tests
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2012-01-25 21:46:20 -0800
committerBrett Profitt <brett.profitt@gmail.com>2012-01-25 21:46:20 -0800
commit4202d7d3087db4f503a7586a1f3fc824ebf45b30 (patch)
tree5c120eb9080425569f322668e1896becd9fb5e5c /engine/tests
parent6a2d3d7c2d22f57f28472d9d023788d20d41f005 (diff)
downloadelgg-4202d7d3087db4f503a7586a1f3fc824ebf45b30.tar.gz
elgg-4202d7d3087db4f503a7586a1f3fc824ebf45b30.tar.bz2
Fixes #4081. Using ElggBatch to delete recursive.
Diffstat (limited to 'engine/tests')
-rw-r--r--engine/tests/api/helpers.php12
-rw-r--r--engine/tests/objects/objects.php49
2 files changed, 55 insertions, 6 deletions
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
index a615be0c0..62e4471e0 100644
--- a/engine/tests/api/helpers.php
+++ b/engine/tests/api/helpers.php
@@ -526,7 +526,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
'offset' => 0,
'limit' => 11
);
- $batch = new ElggBatch(array('ElggCoreHelpersTest', 'test_elgg_batch_callback'), $options,
+ $batch = new ElggBatch(array('ElggCoreHelpersTest', 'elgg_batch_callback_test'), $options,
null, 5);
$j = 0;
foreach ($batch as $e) {
@@ -539,12 +539,12 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertEqual(11, $j);
// no increment, 0 start
- ElggCoreHelpersTest::test_elgg_batch_callback(array(), true);
+ ElggCoreHelpersTest::elgg_batch_callback_test(array(), true);
$options = array(
'offset' => 0,
'limit' => 11
);
- $batch = new ElggBatch(array('ElggCoreHelpersTest', 'test_elgg_batch_callback'), $options,
+ $batch = new ElggBatch(array('ElggCoreHelpersTest', 'elgg_batch_callback_test'), $options,
null, 5);
$batch->setIncrementOffset(false);
@@ -558,12 +558,12 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertEqual(11, $j);
// no increment, 3 start
- ElggCoreHelpersTest::test_elgg_batch_callback(array(), true);
+ ElggCoreHelpersTest::elgg_batch_callback_test(array(), true);
$options = array(
'offset' => 3,
'limit' => 11
);
- $batch = new ElggBatch(array('ElggCoreHelpersTest', 'test_elgg_batch_callback'), $options,
+ $batch = new ElggBatch(array('ElggCoreHelpersTest', 'elgg_batch_callback_test'), $options,
null, 5);
$batch->setIncrementOffset(false);
@@ -578,7 +578,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertEqual(11, $j);
}
- static function test_elgg_batch_callback($options, $reset = false) {
+ static function elgg_batch_callback_test($options, $reset = false) {
static $count = 1;
if ($reset) {
diff --git a/engine/tests/objects/objects.php b/engine/tests/objects/objects.php
index cd507d5ab..915594e0a 100644
--- a/engine/tests/objects/objects.php
+++ b/engine/tests/objects/objects.php
@@ -239,6 +239,55 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
access_show_hidden_entities(false);
}
+ public function testElggRecursiveDelete() {
+ $types = array('ElggGroup', 'ElggObject', 'ElggUser', 'ElggSite');
+ $db_prefix = elgg_get_config('dbprefix');
+
+ foreach ($types as $type) {
+ $parent = new $type();
+ $this->assertTrue($parent->save());
+
+ $child = new ElggObject();
+ $child->container_guid = $parent->guid;
+ $this->assertTrue($child->save());
+
+ $grandchild = new ElggObject();
+ $grandchild->container_guid = $child->guid;
+ $this->assertTrue($grandchild->save());
+
+ $this->assertTrue($parent->delete(true));
+
+ $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $parent->guid";
+ $r = get_data($q);
+ $this->assertFalse($r);
+
+ $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $child->guid";
+ $r = get_data($q);
+ $this->assertFalse($r);
+
+ $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $grandchild->guid";
+ $r = get_data($q);
+ $this->assertFalse($r);
+ }
+
+ // object that owns itself
+ // can't check container_guid because of infinite loops in can_edit_entity()
+ $obj = new ElggObject();
+ $obj->save();
+ $obj->owner_guid = $obj->guid;
+ $obj->save();
+
+ $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $obj->guid";
+ $r = get_data_row($q);
+ $this->assertEqual($obj->guid, $r->owner_guid);
+
+ $this->assertTrue($obj->delete(true));
+
+ $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $obj->guid";
+ $r = get_data_row($q);
+ $this->assertFalse($r);
+ }
+
protected function get_object_row($guid) {
global $CONFIG;
return get_data_row("SELECT * FROM {$CONFIG->dbprefix}objects_entity WHERE guid='$guid'");