diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-13 22:59:36 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-13 22:59:36 +0000 |
commit | 4be522d7544b1aca0e08828bee42a9be7345bf9c (patch) | |
tree | bb1c2ce1f7f177b2de7bb9615c4e87ea58516945 /engine/tests | |
parent | c1c2563fc1cd451afaf735350eb1c576740be2f4 (diff) | |
download | elgg-4be522d7544b1aca0e08828bee42a9be7345bf9c.tar.gz elgg-4be522d7544b1aca0e08828bee42a9be7345bf9c.tar.bz2 |
Refs #2907. DRY'd up and abstracted out a lot of metadata / annotation functions so I can implement #1115 with a clean conscious.
git-svn-id: http://code.elgg.org/elgg/trunk@8207 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests')
-rw-r--r-- | engine/tests/api/metastrings.php | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/engine/tests/api/metastrings.php b/engine/tests/api/metastrings.php new file mode 100644 index 000000000..c18e42eb8 --- /dev/null +++ b/engine/tests/api/metastrings.php @@ -0,0 +1,139 @@ +<?php +/** + * Elgg Metastrings test + * + * @package Elgg.Core + * @subpackage Metastrings.Test + */ +class ElggCoreMetastringsTest extends ElggCoreUnitTest { + + public $metastringTypes = array('metadata', 'annotations'); + + /** + * Called before each test object. + */ + public function __construct() { + parent::__construct(); + + $this->metastrings = array(); + $this->object = new ElggObject(); + $this->object->save(); + } + + public function createAnnotations($max = 1) { + $annotations = array(); + for ($i=0; $i<$max; $i++) { + $name = 'test_annotation_name' . rand(); + $value = 'test_annotation_value' . rand(); + $id = create_annotation($this->object->guid, $name, $value); + $annotations[] = $id; + } + + return $annotations; + } + + public function createMetadata($max = 1) { + $metadata = array(); + for ($i=0; $i<$max; $i++) { + $name = 'test_metadata_name' . rand(); + $value = 'test_metadata_value' . rand(); + $id = create_metadata($this->object->guid, $name, $value); + $metadata[] = $id; + } + + return $metadata; + } + + /** + * 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() { + $this->object->delete(); + + parent::__destruct(); + } + + /** + * A basic test that will be called and fail. + */ + public function testDeleteByID() { + $db_prefix = elgg_get_config('dbprefix'); + $annotations = $this->createAnnotations(1); + $metadata = $this->createMetadata(1); + + foreach ($this->metastringTypes as $type) { + $id = ${$type}[0]; + $table = $db_prefix . $type; + $q = "SELECT * FROM $table WHERE id = $id"; + $test = get_data($q); + + $this->assertEqual($test[0]->id, $id); + $this->assertTrue(elgg_delete_metastring_based_object_by_id($id, $type)); + $this->assertFalse(get_data($q)); + } + } + + public function testGetMetastringObjectByID() { + $db_prefix = elgg_get_config('dbprefix'); + $annotations = $this->createAnnotations(1); + $metadata = $this->createMetadata(1); + + foreach ($this->metastringTypes as $type) { + $id = ${$type}[0]; + $test = elgg_get_metastring_based_object_by_id($id, $type); + + $this->assertEqual($id, $test->id); + } + } + + /** + * A basic test that will be called and fail. + */ + public function testEnableDisableByID() { + $db_prefix = elgg_get_config('dbprefix'); + $annotations = $this->createAnnotations(1); + $metadata = $this->createMetadata(1); + + foreach ($this->metastringTypes as $type) { + $id = ${$type}[0]; + $table = $db_prefix . $type; + $q = "SELECT * FROM $table WHERE id = $id"; + $test = get_data($q); + + // disable + $this->assertEqual($test[0]->enabled, 'yes'); + $this->assertTrue(elgg_set_metastring_based_object_enabled_by_id($id, 'no', $type)); + + $test = get_data($q); + $this->assertEqual($test[0]->enabled, 'no'); + + // enable + $ashe = access_get_show_hidden_status(); + access_show_hidden_entities(true); + flush(); + $this->assertTrue(elgg_set_metastring_based_object_enabled_by_id($id, 'yes', $type)); + + $test = get_data($q); + $this->assertEqual($test[0]->enabled, 'yes'); + + access_show_hidden_entities($ashe); + } + } + + +} |