aboutsummaryrefslogtreecommitdiff
path: root/engine/tests/objects
diff options
context:
space:
mode:
Diffstat (limited to 'engine/tests/objects')
-rw-r--r--engine/tests/objects/entities.php245
-rw-r--r--engine/tests/objects/metadata.php106
-rw-r--r--engine/tests/objects/objects.php125
-rw-r--r--engine/tests/objects/sites.php33
-rw-r--r--engine/tests/objects/users.php85
5 files changed, 372 insertions, 222 deletions
diff --git a/engine/tests/objects/entities.php b/engine/tests/objects/entities.php
index 018f7aa02..bac72079e 100644
--- a/engine/tests/objects/entities.php
+++ b/engine/tests/objects/entities.php
@@ -26,16 +26,16 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
*/
public function testElggEntityAttributes() {
$test_attributes = array();
- $test_attributes['guid'] = '';
- $test_attributes['type'] = '';
- $test_attributes['subtype'] = '';
- $test_attributes['owner_guid'] = get_loggedin_userid();
- $test_attributes['container_guid'] = get_loggedin_userid();
- $test_attributes['site_guid'] = 0;
+ $test_attributes['guid'] = NULL;
+ $test_attributes['type'] = NULL;
+ $test_attributes['subtype'] = NULL;
+ $test_attributes['owner_guid'] = elgg_get_logged_in_user_guid();
+ $test_attributes['container_guid'] = elgg_get_logged_in_user_guid();
+ $test_attributes['site_guid'] = NULL;
$test_attributes['access_id'] = ACCESS_PRIVATE;
- $test_attributes['time_created'] = '';
- $test_attributes['time_updated'] = '';
- $test_attributes['last_action'] = '';
+ $test_attributes['time_created'] = NULL;
+ $test_attributes['time_updated'] = NULL;
+ $test_attributes['last_action'] = NULL;
$test_attributes['enabled'] = 'yes';
$test_attributes['tables_split'] = 1;
$test_attributes['tables_loaded'] = 0;
@@ -77,7 +77,7 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->assertIdentical($this->entity->getGUID(), $this->entity->guid );
$this->assertIdentical($this->entity->getType(), $this->entity->type );
$this->assertIdentical($this->entity->getSubtype(), $this->entity->subtype );
- $this->assertIdentical($this->entity->getOwner(), $this->entity->owner_guid );
+ $this->assertIdentical($this->entity->getOwnerGUID(), $this->entity->owner_guid );
$this->assertIdentical($this->entity->getAccessID(), $this->entity->access_id );
$this->assertIdentical($this->entity->getTimeCreated(), $this->entity->time_created );
$this->assertIdentical($this->entity->getTimeUpdated(), $this->entity->time_updated );
@@ -89,25 +89,25 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->assertFalse(isset($this->entity->non_existent));
// create metadata
- $this->assertTrue($this->entity->non_existent = 'testing');
+ $this->entity->existent = 'testing';
+ $this->assertIdentical($this->entity->existent, 'testing');
// check metadata set
- $this->assertTrue(isset($this->entity->non_existent));
- $this->assertIdentical($this->entity->non_existent, 'testing');
- $this->assertIdentical($this->entity->getMetaData('non_existent'), 'testing');
+ $this->assertTrue(isset($this->entity->existent));
+ $this->assertIdentical($this->entity->getMetaData('existent'), 'testing');
// check internal metadata array
$metadata = $this->entity->expose_metadata();
- $this->assertIdentical($metadata['non_existent'], 'testing');
+ $this->assertIdentical($metadata['existent'], array('testing'));
}
public function testElggEnityGetAndSetAnnotations() {
$this->assertFalse(array_key_exists('non_existent', $this->entity->expose_annotations()));
- $this->assertFalse($this->entity->getAnnotations('non_existent'));
+ $this->assertIdentical($this->entity->getAnnotations('non_existent'), array());
// set and check temp annotation
$this->assertTrue($this->entity->annotate('non_existent', 'testing'));
- $this->assertIdentical($this->entity->getAnnotations('non_existent'), 'testing');
+ $this->assertIdentical($this->entity->getAnnotations('non_existent'), array('testing'));
$this->assertTrue(array_key_exists('non_existent', $this->entity->expose_annotations()));
// save entity and check for annotation
@@ -118,30 +118,27 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->assertIsA($annotations[0], 'ElggAnnotation');
$this->assertIdentical($annotations[0]->name, 'non_existent');
$this->assertEqual($this->entity->countAnnotations('non_existent'), 1);
-
- $this->assertIdentical($annotations, get_annotations($this->entity->getGUID()));
- $this->assertIdentical($annotations, get_annotations($this->entity->getGUID(), 'site'));
- $this->assertIdentical($annotations, get_annotations($this->entity->getGUID(), 'site', 'testing'));
- $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID(), 'site', 'fail'));
+
+ $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID())));
+ $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site')));
+ $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site', 'subtype' => 'testing')));
+ $this->assertIdentical(FALSE, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site', 'subtype' => 'fail')));
// clear annotation
- $this->assertTrue($this->entity->clearAnnotations());
+ $this->assertTrue($this->entity->deleteAnnotations());
$this->assertEqual($this->entity->countAnnotations('non_existent'), 0);
-
- $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID()));
- $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID(), 'site'));
- $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID(), 'site', 'testing'));
+
+ $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID())));
+ $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site')));
+ $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site', 'subtype' => 'testing')));
// clean up
$this->assertTrue($this->entity->delete());
+ remove_subtype('site', 'testing');
}
public function testElggEntityCache() {
global $ENTITY_CACHE;
- $ENTITY_CACHE = NULL;
-
- $this->assertNull($ENTITY_CACHE);
- initialise_entity_cache();
$this->assertIsA($ENTITY_CACHE, 'array');
}
@@ -181,7 +178,7 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->AssertEqual($this->entity->get('non_existent'), 'testing');
// clean up with delete
- $this->assertTrue($this->entity->delete());
+ $this->assertIdentical(true, $this->entity->delete());
}
public function testElggEntityDisableAndEnable() {
@@ -190,19 +187,104 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
// ensure enabled
$this->assertTrue($this->entity->isEnabled());
- // false on disable
+ // false on disable because it's not saved yet.
$this->assertFalse($this->entity->disable());
// save and disable
$this->save_entity();
+
+ // add annotations and metadata to check if they're disabled.
+ $annotation_id = create_annotation($this->entity->guid, 'test_annotation_' . rand(), 'test_value_' . rand());
+ $metadata_id = create_metadata($this->entity->guid, 'test_metadata_' . rand(), 'test_value_' . rand());
+
$this->assertTrue($this->entity->disable());
// ensure disabled by comparing directly with database
$entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'");
$this->assertIdentical($entity->enabled, 'no');
+ $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '$annotation_id'");
+ $this->assertIdentical($annotation->enabled, 'no');
+
+ $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '$metadata_id'");
+ $this->assertIdentical($metadata->enabled, 'no');
+
// re-enable for deletion to work
$this->assertTrue($this->entity->enable());
+
+ // check enabled
+ // check annotations and metadata enabled.
+ $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'");
+ $this->assertIdentical($entity->enabled, 'yes');
+
+ $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '$annotation_id'");
+ $this->assertIdentical($annotation->enabled, 'yes');
+
+ $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '$metadata_id'");
+ $this->assertIdentical($metadata->enabled, 'yes');
+
+ $this->assertTrue($this->entity->delete());
+ }
+
+ public function testElggEntityRecursiveDisableAndEnable() {
+ global $CONFIG;
+
+ $this->save_entity();
+ $obj1 = new ElggObject();
+ $obj1->container_guid = $this->entity->getGUID();
+ $obj1->save();
+ $obj2 = new ElggObject();
+ $obj2->container_guid = $this->entity->getGUID();
+ $obj2->save();
+
+ // disable $obj2 before disabling the container
+ $this->assertTrue($obj2->disable());
+
+ // disable entities container by $this->entity
+ $this->assertTrue($this->entity->disable());
+ $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'");
+ $this->assertIdentical($entity->enabled, 'no');
+
+ // enable entities that were disabled with the container (but not $obj2)
+ $this->assertTrue($this->entity->enable());
+ $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'");
+ $this->assertIdentical($entity->enabled, 'yes');
+ $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj2->guid}'");
+ $this->assertIdentical($entity->enabled, 'no');
+
+ // cleanup
+ $this->assertTrue($obj2->enable());
+ $this->assertTrue($obj2->delete());
+ $this->assertTrue($obj1->delete());
+ $this->assertTrue($this->entity->delete());
+ }
+
+ public function testElggEntityMetadata() {
+ // let's delete a non-existent metadata
+ $this->assertFalse($this->entity->deleteMetadata('important'));
+
+ // let's add the metadata
+ $this->entity->important = 'indeed!';
+ $this->assertIdentical('indeed!', $this->entity->important);
+ $this->entity->less_important = 'true, too!';
+ $this->assertIdentical('true, too!', $this->entity->less_important);
+ $this->save_entity();
+
+ // test deleting incorrectly
+ // @link https://github.com/elgg/elgg/issues/2273
+ $this->assertNull($this->entity->deleteMetadata('impotent'));
+ $this->assertEqual($this->entity->important, 'indeed!');
+
+ // get rid of one metadata
+ $this->assertEqual($this->entity->important, 'indeed!');
+ $this->assertTrue($this->entity->deleteMetadata('important'));
+ $this->assertNull($this->entity->important);
+
+ // get rid of all metadata
+ $this->assertTrue($this->entity->deleteMetadata());
+ $this->assertNull($this->entity->less_important);
+
+ // clean up database
$this->assertTrue($this->entity->delete());
}
@@ -221,8 +303,101 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->assertIdentical($exportables, $this->entity->getExportableValues());
}
- protected function save_entity($type='site')
- {
+ public function testElggEntityMultipleMetadata() {
+ foreach (array(false, true) as $save) {
+ if ($save) {
+ $this->save_entity();
+ }
+ $md = array('brett', 'bryan', 'brad');
+ $name = 'test_md_' . rand();
+
+ $this->entity->$name = $md;
+
+ $this->assertEqual($md, $this->entity->$name);
+
+ if ($save) {
+ $this->assertTrue($this->entity->delete());
+ }
+ }
+ }
+
+ public function testElggEntitySingleElementArrayMetadata() {
+ foreach (array(false, true) as $save) {
+ if ($save) {
+ $this->save_entity();
+ }
+ $md = array('test');
+ $name = 'test_md_' . rand();
+
+ $this->entity->$name = $md;
+
+ $this->assertEqual($md[0], $this->entity->$name);
+
+ if ($save) {
+ $this->assertTrue($this->entity->delete());
+ }
+ }
+ }
+
+ public function testElggEntityAppendMetadata() {
+ foreach (array(false, true) as $save) {
+ if ($save) {
+ $this->save_entity();
+ }
+ $md = 'test';
+ $name = 'test_md_' . rand();
+
+ $this->entity->$name = $md;
+ $this->entity->setMetaData($name, 'test2', '', true);
+
+ $this->assertEqual(array('test', 'test2'), $this->entity->$name);
+
+ if ($save) {
+ $this->assertTrue($this->entity->delete());
+ }
+ }
+ }
+
+ public function testElggEntitySingleElementArrayAppendMetadata() {
+ foreach (array(false, true) as $save) {
+ if ($save) {
+ $this->save_entity();
+ }
+ $md = 'test';
+ $name = 'test_md_' . rand();
+
+ $this->entity->$name = $md;
+ $this->entity->setMetaData($name, array('test2'), '', true);
+
+ $this->assertEqual(array('test', 'test2'), $this->entity->$name);
+
+ if ($save) {
+ $this->assertTrue($this->entity->delete());
+ }
+ }
+ }
+
+ public function testElggEntityArrayAppendMetadata() {
+ foreach (array(false, true) as $save) {
+ if ($save) {
+ $this->save_entity();
+ }
+ $md = array('brett', 'bryan', 'brad');
+ $md2 = array('test1', 'test2', 'test3');
+ $name = 'test_md_' . rand();
+
+ $this->entity->$name = $md;
+ $this->entity->setMetaData($name, $md2, '', true);
+
+ $this->assertEqual(array_merge($md, $md2), $this->entity->$name);
+
+ if ($save) {
+ $this->assertTrue($this->entity->delete());
+ }
+ }
+ }
+
+ protected function save_entity($type='site') {
$this->entity->type = $type;
$this->assertNotEqual($this->entity->save(), 0);
}
diff --git a/engine/tests/objects/metadata.php b/engine/tests/objects/metadata.php
deleted file mode 100644
index b5b9aba02..000000000
--- a/engine/tests/objects/metadata.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-/**
- * Elgg Test ElggMetadata
- *
- * @package Elgg
- * @subpackage Test
- */
-class ElggCoreMetadataTest extends ElggCoreUnitTest {
- protected $metastrings;
-
- /**
- * Called before each test method.
- */
- public function setUp() {
- $this->metastrings = array();
- $this->object = new ElggObject();
- }
-
- /**
- * Called after each test method.
- */
- public function tearDown() {
- // do not allow SimpleTest to interpret Elgg notices as exceptions
- $this->swallowErrors();
-
- unset($this->object);
- }
-
- public function testGetMetastringById() {
- foreach (array('metaUnitTest', 'metaunittest', 'METAUNITTEST') as $string) {
- $this->create_metastring($string);
- }
-
- // lookup metastring id
- $cs_ids = get_metastring_id('metaUnitTest', TRUE);
- $this->assertEqual($cs_ids, $this->metastrings['metaUnitTest']);
-
- // lookup all metastrings, ignoring case
- $cs_ids = get_metastring_id('metaUnitTest', FALSE);
- $this->assertEqual(count($cs_ids), 3);
- $this->assertEqual(count($cs_ids), count($this->metastrings));
- foreach ($cs_ids as $string )
- {
- $this->assertTrue(in_array($string, $this->metastrings));
- }
-
- // clean up
- $this->delete_metastrings();
- }
-
- public function testElggGetEntitiesFromMetadata() {
- global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
- $METASTRINGS_CACHE = $METASTRINGS_DEADNAME_CACHE = array();
-
- $this->object->title = 'Meta Unit Test';
- $this->object->save();
- $this->create_metastring('metaUnitTest');
- $this->create_metastring('tested');
-
- // create_metadata returns id of metadata on success
- $this->assertTrue(create_metadata($this->object->guid, 'metaUnitTest', 'tested'));
-
- // check value with improper case
- $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'Tested', 'limit' => 10, 'metadata_case_sensitive' => TRUE);
- $this->assertFalse(elgg_get_entities_from_metadata($options));
-
- // compare forced case with ignored case
- $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'tested', 'limit' => 10, 'metadata_case_sensitive' => TRUE);
- $case_true = elgg_get_entities_from_metadata($options);
- $this->assertIsA($case_true, 'array');
-
- $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'Tested', 'limit' => 10, 'metadata_case_sensitive' => FALSE);
- $case_false = elgg_get_entities_from_metadata($options);
- $this->assertIsA($case_false, 'array');
-
- $this->assertIdentical($case_true, $case_false);
-
- // check deprecated get_entities_from_metadata() function
- $deprecated = get_entities_from_metadata('metaUnitTest', 'tested', '', '', 0, 10, 0, '', 0, FALSE, TRUE);
- $this->assertIdentical($deprecated, $case_true);
-
- // check entity list
- //$this->dump(list_entities_from_metadata('metaUnitTest', 'Tested', '', '', 0, 10, TRUE, TRUE, TRUE, FALSE));
-
- // clean up
- $this->delete_metastrings();
- $this->object->delete();
- }
-
-
- protected function create_metastring($string) {
- global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
- $METASTRINGS_CACHE = $METASTRINGS_DEADNAME_CACHE = array();
-
- mysql_query("INSERT INTO {$CONFIG->dbprefix}metastrings (string) VALUES ('$string')");
- $this->metastrings[$string] = mysql_insert_id();
- }
-
- protected function delete_metastrings() {
- global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
- $METASTRINGS_CACHE = $METASTRINGS_DEADNAME_CACHE = array();
-
- $strings = implode(', ', $this->metastrings);
- mysql_query("DELETE FROM {$CONFIG->dbprefix}metastrings WHERE id IN ($strings)");
- }
-}
diff --git a/engine/tests/objects/objects.php b/engine/tests/objects/objects.php
index 40c3c635a..263ab2414 100644
--- a/engine/tests/objects/objects.php
+++ b/engine/tests/objects/objects.php
@@ -38,21 +38,21 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
public function testElggObjectConstructor() {
$attributes = array();
- $attributes['guid'] = '';
+ $attributes['guid'] = NULL;
$attributes['type'] = 'object';
- $attributes['subtype'] = '';
- $attributes['owner_guid'] = get_loggedin_userid();
- $attributes['container_guid'] = get_loggedin_userid();
- $attributes['site_guid'] = 0;
+ $attributes['subtype'] = NULL;
+ $attributes['owner_guid'] = elgg_get_logged_in_user_guid();
+ $attributes['container_guid'] = elgg_get_logged_in_user_guid();
+ $attributes['site_guid'] = NULL;
$attributes['access_id'] = ACCESS_PRIVATE;
- $attributes['time_created'] = '';
- $attributes['time_updated'] = '';
- $attributes['last_action'] = '';
+ $attributes['time_created'] = NULL;
+ $attributes['time_updated'] = NULL;
+ $attributes['last_action'] = NULL;
$attributes['enabled'] = 'yes';
$attributes['tables_split'] = 2;
$attributes['tables_loaded'] = 0;
- $attributes['title'] = '';
- $attributes['description'] = '';
+ $attributes['title'] = NULL;
+ $attributes['description'] = NULL;
ksort($attributes);
$entity_attributes = $this->entity->expose_attributes();
@@ -87,11 +87,11 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
public function testElggObjectLoad() {
// fail on wrong type
try {
- $error = new ElggObjectTest(get_loggedin_userid());
+ $error = new ElggObjectTest(elgg_get_logged_in_user_guid());
$this->assertTrue(FALSE);
} catch (Exception $e) {
$this->assertIsA($e, 'InvalidClassException');
- $message = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), get_loggedin_userid(), 'ElggObject');
+ $message = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), elgg_get_logged_in_user_guid(), 'ElggObject');
$this->assertIdentical($e->getMessage(), $message);
}
}
@@ -144,18 +144,15 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
}
public function testElggObjectContainer() {
- $this->assertEqual($this->entity->getContainer(), get_loggedin_userid());
-
- // fals when container not a group
- $this->assertFalse($this->entity->getContainerEntity());
+ $this->assertEqual($this->entity->getContainerGUID(), elgg_get_logged_in_user_guid());
// create and save to group
$group = new ElggGroup();
$guid = $group->save();
- $this->assertTrue($this->entity->setContainer($guid));
+ $this->assertTrue($this->entity->setContainerGUID($guid));
// check container
- $this->assertEqual($this->entity->getContainer(), $guid);
+ $this->assertEqual($this->entity->getContainerGUID(), $guid);
$this->assertIdentical($group, $this->entity->getContainerEntity());
// clean up
@@ -197,7 +194,99 @@ class ElggCoreObjectTest extends ElggCoreUnitTest {
$old = elgg_set_ignore_access(true);
}
+ // see https://github.com/elgg/elgg/issues/1196
+ public function testElggEntityRecursiveDisableWhenLoggedOut() {
+ $e1 = new ElggObject();
+ $e1->access_id = ACCESS_PUBLIC;
+ $e1->owner_guid = 0;
+ $e1->container_guid = 0;
+ $e1->save();
+ $guid1 = $e1->getGUID();
+
+ $e2 = new ElggObject();
+ $e2->container_guid = $guid1;
+ $e2->access_id = ACCESS_PUBLIC;
+ $e2->owner_guid = 0;
+ $e2->save();
+ $guid2 = $e2->getGUID();
+
+ // fake being logged out
+ $user = $_SESSION['user'];
+ unset($_SESSION['user']);
+ $ia = elgg_set_ignore_access(true);
+
+ $this->assertTrue(disable_entity($guid1, null, true));
+
+ // "log in" original user
+ $_SESSION['user'] = $user;
+ elgg_set_ignore_access($ia);
+
+ $this->assertFalse(get_entity($guid1));
+ $this->assertFalse(get_entity($guid2));
+
+ $db_prefix = get_config('dbprefix');
+ $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $guid1";
+ $r = get_data_row($q);
+ $this->assertEqual('no', $r->enabled);
+
+ $q = "SELECT * FROM {$db_prefix}entities WHERE guid = $guid2";
+ $r = get_data_row($q);
+ $this->assertEqual('no', $r->enabled);
+
+ access_show_hidden_entities(true);
+ delete_entity($guid1);
+ delete_entity($guid2);
+ 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;
diff --git a/engine/tests/objects/sites.php b/engine/tests/objects/sites.php
index d8c458bc4..a01a661e3 100644
--- a/engine/tests/objects/sites.php
+++ b/engine/tests/objects/sites.php
@@ -18,7 +18,7 @@ class ElggCoreSiteTest extends ElggCoreUnitTest {
* Called before each test method.
*/
public function setUp() {
- $this->site = new ElggSiteTest;
+ $this->site = new ElggSiteTest();
}
/**
@@ -36,27 +36,24 @@ class ElggCoreSiteTest extends ElggCoreUnitTest {
parent::__destruct();
}
- /**
- * A basic test that will be called and fail.
- */
public function testElggSiteConstructor() {
$attributes = array();
- $attributes['guid'] = '';
+ $attributes['guid'] = NULL;
$attributes['type'] = 'site';
- $attributes['subtype'] = '';
- $attributes['owner_guid'] = get_loggedin_userid();
- $attributes['container_guid'] = get_loggedin_userid();
- $attributes['site_guid'] = 0;
+ $attributes['subtype'] = NULL;
+ $attributes['owner_guid'] = elgg_get_logged_in_user_guid();
+ $attributes['container_guid'] = elgg_get_logged_in_user_guid();
+ $attributes['site_guid'] = NULL;
$attributes['access_id'] = ACCESS_PRIVATE;
- $attributes['time_created'] = '';
- $attributes['time_updated'] = '';
- $attributes['last_action'] = '';
+ $attributes['time_created'] = NULL;
+ $attributes['time_updated'] = NULL;
+ $attributes['last_action'] = NULL;
$attributes['enabled'] = 'yes';
$attributes['tables_split'] = 2;
$attributes['tables_loaded'] = 0;
- $attributes['name'] = '';
- $attributes['description'] = '';
- $attributes['url'] = '';
+ $attributes['name'] = NULL;
+ $attributes['description'] = NULL;
+ $attributes['url'] = NULL;
ksort($attributes);
$entity_attributes = $this->site->expose_attributes();
@@ -66,8 +63,10 @@ class ElggCoreSiteTest extends ElggCoreUnitTest {
}
public function testElggSiteSaveAndDelete() {
- $this->assertTrue($this->site->save());
- $this->assertTrue($this->site->delete());
+ $guid = $this->site->save();
+ $this->assertIsA($guid, 'int');
+ $this->assertTrue($guid > 0);
+ $this->assertIdentical(true, $this->site->delete());
}
}
diff --git a/engine/tests/objects/users.php b/engine/tests/objects/users.php
index fe5b48b03..8a1033ac4 100644
--- a/engine/tests/objects/users.php
+++ b/engine/tests/objects/users.php
@@ -41,33 +41,33 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
parent::__destruct();
}
- /**
- * A basic test that will be called and fail.
- */
public function testElggUserConstructor() {
$attributes = array();
- $attributes['guid'] = '';
+ $attributes['guid'] = NULL;
$attributes['type'] = 'user';
- $attributes['subtype'] = '';
- $attributes['owner_guid'] = get_loggedin_userid();
- $attributes['container_guid'] = get_loggedin_userid();
- $attributes['site_guid'] = 0;
+ $attributes['subtype'] = NULL;
+ $attributes['owner_guid'] = elgg_get_logged_in_user_guid();
+ $attributes['container_guid'] = elgg_get_logged_in_user_guid();
+ $attributes['site_guid'] = NULL;
$attributes['access_id'] = ACCESS_PRIVATE;
- $attributes['time_created'] = '';
- $attributes['time_updated'] = '';
- $attributes['last_action'] = '';
+ $attributes['time_created'] = NULL;
+ $attributes['time_updated'] = NULL;
+ $attributes['last_action'] = NULL;
$attributes['enabled'] = 'yes';
$attributes['tables_split'] = 2;
$attributes['tables_loaded'] = 0;
- $attributes['name'] = '';
- $attributes['username'] = '';
- $attributes['password'] = '';
- $attributes['salt'] = '';
- $attributes['email'] = '';
- $attributes['language'] = '';
- $attributes['code'] = '';
+ $attributes['name'] = NULL;
+ $attributes['username'] = NULL;
+ $attributes['password'] = NULL;
+ $attributes['salt'] = NULL;
+ $attributes['email'] = NULL;
+ $attributes['language'] = NULL;
+ $attributes['code'] = NULL;
$attributes['banned'] = 'no';
$attributes['admin'] = 'no';
+ $attributes['prev_last_action'] = NULL;
+ $attributes['last_login'] = NULL;
+ $attributes['prev_last_login'] = NULL;
ksort($attributes);
$entity_attributes = $this->user->expose_attributes();
@@ -98,7 +98,7 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
}
public function testElggUserConstructorByGuid() {
- $user = new ElggUser(get_loggedin_userid());
+ $user = new ElggUser(elgg_get_logged_in_user_guid());
$this->assertIdentical($user, $_SESSION['user']);
// fail with garbage
@@ -113,13 +113,13 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
}
public function testElggUserConstructorByDbRow() {
- $row = $this->fetchUser(get_loggedin_userid());
+ $row = $this->fetchUser(elgg_get_logged_in_user_guid());
$user = new ElggUser($row);
$this->assertIdentical($user, $_SESSION['user']);
}
public function testElggUserConstructorByUsername() {
- $row = $this->fetchUser(get_loggedin_userid());
+ $row = $this->fetchUser(elgg_get_logged_in_user_guid());
$user = new ElggUser($row->username);
$this->assertIdentical($user, $_SESSION['user']);
}
@@ -138,14 +138,14 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
$guid = $this->user->save();
// delete object
- $this->assertTrue($this->user->delete());
+ $this->assertIdentical(true, $this->user->delete());
// check GUID not in database
$this->assertFalse($this->fetchUser($guid));
}
public function testElggUserNameCache() {
- // Trac #1305
+ // issue https://github.com/elgg/elgg/issues/1305
// very unlikely a user would have this username
$name = (string)time();
@@ -159,6 +159,22 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
$this->assertFalse($user);
}
+ public function testGetUserByUsernameAcceptsUrlEncoded() {
+ $username = (string)time();
+ $this->user->username = $username;
+ $guid = $this->user->save();
+
+ // percent encode first letter
+ $first_letter = $username[0];
+ $first_letter = str_pad('%' . dechex(ord($first_letter)), 2, '0', STR_PAD_LEFT);
+ $username = $first_letter . substr($username, 1);
+
+ $user = get_user_by_username($username);
+ $this->assertTrue((bool) $user);
+ $this->assertEqual($guid, $user->guid);
+
+ $this->user->delete();
+ }
public function testElggUserMakeAdmin() {
global $CONFIG;
@@ -220,29 +236,6 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
$this->user->delete();
}
- // remove in 1.9
- public function testElggUserIsAdminLegacy() {
- $this->user->save();
- $this->user->makeAdmin();
-
- $this->assertTrue($this->user->admin);
- $this->assertTrue($this->user->siteadmin);
-
- $this->user->removeAdmin();
- $this->user->delete();
- }
-
- public function testElggUserIsNotAdminLegacy() {
- $this->user->save();
- $this->user->removeAdmin();
-
- $this->assertFalse($this->user->admin);
- $this->assertFalse($this->user->siteadmin);
-
- $this->user->removeAdmin();
- $this->user->delete();
- }
-
protected function fetchUser($guid) {
global $CONFIG;