aboutsummaryrefslogtreecommitdiff
path: root/engine/tests
diff options
context:
space:
mode:
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-21 16:11:26 +0000
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-21 16:11:26 +0000
commit355363b46fdf99364027fffac2801d7242242703 (patch)
tree251747dab31ddd2a5e511d6e90b367917a6b9eb2 /engine/tests
parent734e8279272e81a27fec8ef1327e8eab38dc07ce (diff)
downloadelgg-355363b46fdf99364027fffac2801d7242242703.tar.gz
elgg-355363b46fdf99364027fffac2801d7242242703.tar.bz2
Allowing entities to be retrieved by case-insensitive search.
Adding a new unit test for ElggMetadata. git-svn-id: http://code.elgg.org/elgg/trunk@3568 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests')
-rw-r--r--engine/tests/objects/metadata.php92
1 files changed, 92 insertions, 0 deletions
diff --git a/engine/tests/objects/metadata.php b/engine/tests/objects/metadata.php
new file mode 100644
index 000000000..eb635db4a
--- /dev/null
+++ b/engine/tests/objects/metadata.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * Elgg Test ElggMetadata
+ *
+ * @package Elgg
+ * @subpackage Test
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+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 testGetEntitiesFromMetadata() {
+ $this->object->title = 'Meta Unit Test';
+ $this->object->save();
+ $this->create_metastring('metaUnitTest');
+ $this->create_metastring('tested');
+ $this->assertTrue(create_metadata($this->object->guid, 'metaUnitTest', 'tested'));
+
+ // check value with improper case
+ $this->assertFalse(get_entities_from_metadata('metaUnitTest', 'Tested', '', '', 0, 10, 0, '', 0, FALSE, TRUE));
+
+ // compare forced case with ignored case
+ $case_true = get_entities_from_metadata('metaUnitTest', 'tested', '', '', 0, 10, 0, '', 0, FALSE, TRUE);
+ $case_false = get_entities_from_metadata('metaUnitTest', 'Tested', '', '', 0, 10, 0, '', 0, FALSE, FALSE);
+ $this->assertIsA($case_true, 'array');
+ $this->assertIsA($case_false, 'array');
+ $this->assertIdentical($case_true, $case_false);
+
+ // 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;
+
+ mysql_query("INSERT INTO {$CONFIG->dbprefix}metastrings (string) VALUES ('$string')");
+ $this->metastrings[$string] = mysql_insert_id();
+ }
+
+ protected function delete_metastrings() {
+ global $CONFIG;
+
+ $strings = implode(', ', $this->metastrings);
+ mysql_query("DELETE FROM {$CONFIG->dbprefix}metastrings WHERE id IN ($strings)");
+ }
+}