From c3cbea030adb2201e29897915bfae19f1628c967 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 21 Aug 2010 19:37:19 +0000 Subject: Merging r6517:6520 from 1.7 branch git-svn-id: http://code.elgg.org/elgg/trunk@6839 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/metadata.php | 2 +- engine/lib/upgrades/2010061501.php | 4 +- engine/tests/api/entity_getter_functions.php | 135 +++++++++++++++++++++++++++ mod/search/start.php | 2 + 4 files changed, 140 insertions(+), 3 deletions(-) diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index d28999a77..74ea6858a 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -677,7 +677,7 @@ function elgg_get_entity_metadata_where_sql($e_table, $n_table, $names = NULL, $ && (!$values && $values !== 0) && (!$pairs && $pairs !== 0) && (!$owner_guids && $owner_guids !== 0) - && !isset($order_by_metadata)) { + && !$order_by_metadata) { return ''; } diff --git a/engine/lib/upgrades/2010061501.php b/engine/lib/upgrades/2010061501.php index 19d6467ed..2b65cc5c7 100644 --- a/engine/lib/upgrades/2010061501.php +++ b/engine/lib/upgrades/2010061501.php @@ -30,9 +30,9 @@ if ($dbversion < 2009100701) { $qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity DISABLE KEYS"; $qs[] = "REPLACE INTO {$CONFIG->dbprefix}users_entity (guid, name, username, password, salt, email, language, code, - banned, last_action, prev_last_action, last_login, prev_last_login) + banned, admin, last_action, prev_last_action, last_login, prev_last_login) SELECT guid, name, unhex(hex(convert(username using latin1))), password, salt, email, language, code, - banned, last_action, prev_last_action, last_login, prev_last_login + banned, admin, last_action, prev_last_action, last_login, prev_last_login FROM {$CONFIG->dbprefix}users_entity"; $qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ENABLE KEYS"; diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php index 9fcc6fe01..faa91db34 100644 --- a/engine/tests/api/entity_getter_functions.php +++ b/engine/tests/api/entity_getter_functions.php @@ -2041,4 +2041,139 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { } } } + + // Make sure metadata doesn't affect getting entities by relationship. See #2274 + public function testElggApiGettersEntityRelationshipWithMetadata() { + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->save(); + $guids[] = $obj2->guid; + + add_entity_relationship($guids[0], 'test', $guids[1]); + + $options = array( + 'relationship' => 'test', + 'relationship_guid' => $guids[0] + ); + + $es = elgg_get_entities_from_relationship($options); + $this->assertTrue(is_array($es)); + $this->assertTrue(count($es), 1); + + foreach ($es as $e) { + $this->assertEqual($guids[1], $e->guid); + } + + foreach ($guids as $guid) { + $e = get_entity($guid); + $e->delete(); + } + } + + public function testElggApiGettersEntityRelationshipWithOutMetadata() { + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->save(); + $guids[] = $obj2->guid; + + add_entity_relationship($guids[0], 'test', $guids[1]); + + $options = array( + 'relationship' => 'test', + 'relationship_guid' => $guids[0] + ); + + $es = elgg_get_entities_from_relationship($options); + $this->assertTrue(is_array($es)); + $this->assertTrue(count($es), 1); + + foreach ($es as $e) { + $this->assertEqual($guids[1], $e->guid); + } + + foreach ($guids as $guid) { + $e = get_entity($guid); + $e->delete(); + } + } + + public function testElggApiGettersEntityRelationshipWithMetadataIncludingRealMetadata() { + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->save(); + $guids[] = $obj2->guid; + + add_entity_relationship($guids[0], 'test', $guids[1]); + + $options = array( + 'relationship' => 'test', + 'relationship_guid' => $guids[0], + 'metadata_name' => 'test_md', + 'metadata_value' => 'test', + ); + + $es = elgg_get_entities_from_relationship($options); + $this->assertTrue(is_array($es)); + $this->assertTrue(count($es), 1); + + foreach ($es as $e) { + $this->assertEqual($guids[1], $e->guid); + } + + foreach ($guids as $guid) { + $e = get_entity($guid); + $e->delete(); + } + } + + public function testElggApiGettersEntityRelationshipWithMetadataIncludingFakeMetadata() { + $guids = array(); + + $obj1 = new ElggObject(); + $obj1->test_md = 'test'; + $obj1->save(); + $guids[] = $obj1->guid; + + $obj2 = new ElggObject(); + $obj2->test_md = 'test'; + $obj2->save(); + $guids[] = $obj2->guid; + + add_entity_relationship($guids[0], 'test', $guids[1]); + + $options = array( + 'relationship' => 'test', + 'relationship_guid' => $guids[0], + 'metadata_name' => 'test_md', + 'metadata_value' => 'invalid', + ); + + $es = elgg_get_entities_from_relationship($options); + + $this->assertTrue(empty($es)); + + foreach ($guids as $guid) { + $e = get_entity($guid); + $e->delete(); + } + } } diff --git a/mod/search/start.php b/mod/search/start.php index 3467420b7..781afb8ec 100644 --- a/mod/search/start.php +++ b/mod/search/start.php @@ -259,6 +259,8 @@ function search_highlight_words($words, $string) { ); foreach ($words as $word) { + // escape the delimiter and any other regexp special chars + $word = preg_quote($word, '/'); $search = "/($word)/i"; // must replace with placeholders in case one of the search terms is -- cgit v1.2.3