aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt8
-rw-r--r--engine/lib/elgglib.php3
-rw-r--r--engine/lib/entities.php22
-rw-r--r--engine/tests/api/helpers.php67
4 files changed, 99 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 574d1effd..8e0af58b3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,11 @@
+Version 1.8.0
+(??? from http://code.elgg.org/branches/1.8/)
+
+ API changes:
+ * added elgg_instanceof().
+
+
+
Version 1.7.0
(March 2, 2010 from http://code.elgg.org/elgg/trunk/)
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 3c95ef2be..42d6ffc6f 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -2757,6 +2757,7 @@ function elgg_boot() {
function elgg_api_test($hook, $type, $value, $params) {
global $CONFIG;
$value[] = $CONFIG->path . 'engine/tests/api/entity_getter_functions.php';
+ $value[] = $CONFIG->path . 'engine/tests/api/helpers.php';
$value[] = $CONFIG->path . 'engine/tests/regression/trac_bugs.php';
return $value;
}
@@ -2775,4 +2776,4 @@ define('ELGG_ENTITIES_NO_VALUE', 0);
register_elgg_event_handler('init', 'system', 'elgg_init');
register_elgg_event_handler('boot', 'system', 'elgg_boot', 1000);
-register_plugin_hook('unit_test', 'system', 'elgg_api_test');
+register_plugin_hook('unit_test', 'system', 'elgg_api_test'); \ No newline at end of file
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index af5b140d9..17bc0aa1e 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -3631,6 +3631,28 @@ function recursive_delete_permissions_check($hook, $entity_type, $returnvalue, $
}
/**
+ * Checks if $entity is an ElggEntity and optionally for type and subtype.
+ *
+ * @param $entity
+ * @param $type
+ * @param $subtype
+ * @return Bool
+ */
+function elgg_instanceof($entity, $type = NULL, $subtype = NULL) {
+ $return = ($entity instanceof ElggEntity);
+
+ if ($type) {
+ $return = $return && ($entity->getType() == $type);
+ }
+
+ if ($subtype) {
+ $return = $return && ($entity->getSubtype() == $subtype);
+ }
+
+ return $return;
+}
+
+/**
* Garbage collect stub and fragments from any broken delete/create calls
*
* @param unknown_type $hook
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
new file mode 100644
index 000000000..a2152a0ef
--- /dev/null
+++ b/engine/tests/api/helpers.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Elgg Test helper functions
+ *
+ *
+ * @package Elgg
+ * @subpackage Test
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+class ElggCoreHelpersTest extends ElggCoreUnitTest {
+
+ /**
+ * Called before each test object.
+ */
+ public function __construct() {
+ parent::__construct();
+ }
+
+ /**
+ * Called before each test method.
+ */
+ public function setUp() {
+
+ }
+
+ /**
+ * Called after each test method.
+ */
+ public function tearDown() {
+ // do not allow SimpleTest to interpret Elgg notices as exceptions
+ $this->swallowErrors();
+ }
+
+ /**
+ * Called after each test object.
+ */
+ public function __destruct() {
+ // all __destruct() code should go above here
+ parent::__destruct();
+ }
+
+ /**
+ * Test elgg_instanceof()
+ * @return unknown_type
+ */
+ public function testElggInstanceOf() {
+ $entity = new ElggObject();
+ $entity->subtype = 'test_subtype';
+ $entity->save();
+
+ $this->assertTrue(elgg_instanceof($entity));
+ $this->assertTrue(elgg_instanceof($entity, 'object'));
+ $this->assertTrue(elgg_instanceof($entity, 'object', 'test_subtype'));
+
+ $this->assertFalse(elgg_instanceof($entity, 'object', 'invalid_subtype'));
+ $this->assertFalse(elgg_instanceof($entity, 'user', 'test_subtype'));
+
+ $entity->delete();
+
+ $bad_entity = FALSE;
+ $this->assertFalse(elgg_instanceof($bad_entity));
+ $this->assertFalse(elgg_instanceof($bad_entity, 'object'));
+ $this->assertFalse(elgg_instanceof($bad_entity, 'object', 'test_subtype'));
+
+ }
+}