From 355363b46fdf99364027fffac2801d7242242703 Mon Sep 17 00:00:00 2001 From: nickw Date: Wed, 21 Oct 2009 16:11:26 +0000 Subject: 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 --- engine/tests/objects/metadata.php | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 engine/tests/objects/metadata.php (limited to 'engine/tests/objects') 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 @@ +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)"); + } +} -- cgit v1.2.3