aboutsummaryrefslogtreecommitdiff
path: root/engine/tests/api/helpers.php
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-31 02:45:08 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-31 02:45:08 +0000
commitcfb5c669bfe6212c25c9ec012e4198eb51a0345b (patch)
tree0c492b821de040169cc6ad03179a8280bdbbe7b7 /engine/tests/api/helpers.php
parent18513b5c7ca4e8392e7ea28ca85978637b9dc4e2 (diff)
downloadelgg-cfb5c669bfe6212c25c9ec012e4198eb51a0345b.tar.gz
elgg-cfb5c669bfe6212c25c9ec012e4198eb51a0345b.tar.bz2
added unit test for previous commit
git-svn-id: http://code.elgg.org/elgg/trunk@7170 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests/api/helpers.php')
-rw-r--r--engine/tests/api/helpers.php92
1 files changed, 91 insertions, 1 deletions
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
index 76b5b38f8..6afcd0ef8 100644
--- a/engine/tests/api/helpers.php
+++ b/engine/tests/api/helpers.php
@@ -28,6 +28,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
public function tearDown() {
// do not allow SimpleTest to interpret Elgg notices as exceptions
$this->swallowErrors();
+
+ global $CONFIG;
+ unset($CONFIG->externals);
}
/**
@@ -40,7 +43,6 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
/**
* Test elgg_instanceof()
- * @return unknown_type
*/
public function testElggInstanceOf() {
$entity = new ElggObject();
@@ -60,6 +62,94 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertFalse(elgg_instanceof($bad_entity));
$this->assertFalse(elgg_instanceof($bad_entity, 'object'));
$this->assertFalse(elgg_instanceof($bad_entity, 'object', 'test_subtype'));
+ }
+
+ /**
+ * Test elgg_register_js()
+ */
+ public function testElggRegisterJS() {
+ global $CONFIG;
+
+ // specify id
+ $result = elgg_register_js('test1', 'key', 'footer');
+ $this->assertTrue($result);
+ $this->assertIdentical('test1', $CONFIG->externals['javascript']['footer']['key']);
+
+ // let Elgg pick id
+ $result = elgg_register_js('test2');
+ $this->assertTrue($result);
+ $this->assertIdentical('test2', $CONFIG->externals['javascript']['head'][0]);
+
+ // send a bad url
+ $result = elgg_register_js();
+ $this->assertFalse($result);
+ }
+
+ /**
+ * Test elgg_register_css()
+ */
+ public function testElggRegisterCSS() {
+ global $CONFIG;
+
+ // specify id
+ $result = elgg_register_css('test1', 'key');
+ $this->assertTrue($result);
+ $this->assertIdentical('test1', $CONFIG->externals['css']['head']['key']);
+
+ // let Elgg pick id
+ $result = elgg_register_css('test2');
+ $this->assertTrue($result);
+ $this->assertIdentical('test2', $CONFIG->externals['css']['head'][1]);
+
+ // send a bad url
+ $result = elgg_register_js();
+ $this->assertFalse($result);
+ }
+
+ /**
+ * Test elgg_unregister_js()
+ */
+ public function testElggUnregisterJS() {
+ global $CONFIG;
+
+ $urls = array('id1' => 'url1', 'id2' => 'url2', 'id3' => 'url3');
+ foreach ($urls as $id => $url) {
+ elgg_register_js($url, $id);
+ }
+
+ $result = elgg_unregister_js('id1');
+ $this->assertTrue($result);
+ $this->assertNULL($CONFIG->externals['javascript']['head']['id1']);
+
+ $result = elgg_unregister_js('', 'url2');
+ $this->assertTrue($result);
+ $this->assertNULL($CONFIG->externals['javascript']['head']['id2']);
+
+ $result = elgg_unregister_js('id1');
+ $this->assertFalse($result);
+ $result = elgg_unregister_js('', 'url2');
+ $this->assertFalse($result);
+
+ $this->assertIdentical('url3', $CONFIG->externals['javascript']['head']['id3']);
+ }
+
+ /**
+ * Test elgg_get_js()
+ */
+ public function testElggGetJS() {
+ global $CONFIG;
+
+ $urls = array('id1' => 'url1', 'id2' => 'url2', 'id3' => 'url3');
+ foreach ($urls as $id => $url) {
+ elgg_register_js($url, $id);
+ }
+
+ $js_urls = elgg_get_js('head');
+ $this->assertIdentical($js_urls[0], $urls['id1']);
+ $this->assertIdentical($js_urls[1], $urls['id2']);
+ $this->assertIdentical($js_urls[2], $urls['id3']);
+ $js_urls = elgg_get_js('footer');
+ $this->assertIdentical(array(), $js_urls);
}
}