summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/common.test61
-rw-r--r--modules/simpletest/tests/common_test.module32
2 files changed, 89 insertions, 4 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index d4a07be73..1c418a26b 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -435,7 +435,7 @@ class JavaScriptTestCase extends DrupalWebTestCase {
/**
* Store configured value for JavaScript preprocessing.
*/
- var $preprocess_js = NULL;
+ protected $preprocess_js = NULL;
public static function getInfo() {
return array(
@@ -447,14 +447,15 @@ class JavaScriptTestCase extends DrupalWebTestCase {
function setUp() {
// Enable Locale and SimpleTest in the test environment.
- parent::setUp('locale', 'simpletest');
+ parent::setUp('locale', 'simpletest', 'common_test');
// Disable preprocessing
$this->preprocess_js = variable_get('preprocess_js', 0);
variable_set('preprocess_js', 0);
- // Reset drupal_add_js() before each test.
+ // Reset drupal_add_js() and drupal_add_library() statics before each test.
drupal_static_reset('drupal_add_js');
+ drupal_static_reset('drupal_add_library');
}
function tearDown() {
@@ -562,7 +563,7 @@ class JavaScriptTestCase extends DrupalWebTestCase {
* Test rendering the JavaScript with a file's weight above jQuery's.
*/
function testRenderDifferentWeight() {
- drupal_add_js('misc/collapse.js', array('weight' => JS_LIBRARY - 10));
+ drupal_add_js('misc/collapse.js', array('weight' => JS_LIBRARY - 21));
$javascript = drupal_get_js();
$this->assertTrue(strpos($javascript, 'misc/collapse.js') < strpos($javascript, 'misc/jquery.js'), t('Rendering a JavaScript file above jQuery.'));
}
@@ -583,6 +584,58 @@ class JavaScriptTestCase extends DrupalWebTestCase {
$javascript = drupal_get_js();
$this->assertTrue(strpos($javascript, 'simpletest.js') < strpos($javascript, 'misc/tableselect.js'), t('Altering JavaScript weight through the alter hook.'));
}
+
+ /**
+ * Adds a library to the page and tests for both its JavaScript and its CSS.
+ */
+ function testLibraryRender() {
+ $result = drupal_add_library('system', 'farbtastic');
+ $this->assertTrue($result !== FALSE, t('Library was added without errors.'));
+ $scripts = drupal_get_js();
+ $styles = drupal_get_css();
+ $this->assertTrue(strpos($scripts, 'misc/farbtastic/farbtastic.js'), t('JavaScript of library was added to the page.'));
+ $this->assertTrue(strpos($styles, 'misc/farbtastic/farbtastic.css'), t('Stylesheet of library was added to the page.'));
+ }
+
+ /**
+ * Adds a JavaScript library to the page and alters it.
+ *
+ * @see common_test_library_alter()
+ */
+ function testLibraryAlter() {
+ // Verify that common_test altered the title of Farbtastic.
+ $library = drupal_get_library('system', 'farbtastic');
+ $this->assertEqual($library['title'], 'Farbtastic: Altered Library', t('Registered libraries were altered.'));
+
+ // common_test_library_alter() also added a dependency on jQuery Form.
+ drupal_add_library('system', 'farbtastic');
+ $scripts = drupal_get_js();
+ $this->assertTrue(strpos($scripts, 'misc/jquery.form.js'), t('Altered library dependencies are added to the page.'));
+ }
+
+ /**
+ * Tests that multiple modules can implement the same library.
+ *
+ * @see common_test_library()
+ */
+ function testLibraryNameConflicts() {
+ $farbtastic = drupal_get_library('common_test', 'farbtastic');
+ $this->assertEqual($farbtastic['title'], 'Custom Farbtastic Library', t('Alternative libraries can be added to the page.'));
+ }
+
+ /**
+ * Tests non-existing libraries.
+ */
+ function testLibraryUnknown() {
+ $result = drupal_get_library('unknown', 'unknown');
+ $this->assertFalse($result, t('Unknown library returned FALSE.'));
+ drupal_static_reset('drupal_get_library');
+
+ $result = drupal_add_library('unknown', 'unknown');
+ $this->assertFalse($result, t('Unknown library returned FALSE.'));
+ $scripts = drupal_get_js();
+ $this->assertTrue(strpos($scripts, 'unknown') === FALSE, t('Unknown library was not added to the page.'));
+ }
}
/**
diff --git a/modules/simpletest/tests/common_test.module b/modules/simpletest/tests/common_test.module
index 71d384d10..c1a8b7917 100644
--- a/modules/simpletest/tests/common_test.module
+++ b/modules/simpletest/tests/common_test.module
@@ -23,3 +23,35 @@ function common_test_theme() {
function theme_common_test_foo($foo, $bar) {
return $foo . $bar;
}
+
+/**
+ * Implementation of hook_library_alter().
+ */
+function common_test_library_alter(&$libraries, $module) {
+ if ($module == 'system' && isset($libraries['farbtastic'])) {
+ // Change the title of Farbtastic to "Farbtastic: Altered Library".
+ $libraries['farbtastic']['title'] = 'Farbtastic: Altered Library';
+ // Make Farbtastic depend on jQuery Form to test library dependencies.
+ $libraries['farbtastic']['dependencies'][] = array('system', 'form');
+ }
+}
+
+/**
+ * Implementation of hook_library().
+ *
+ * Adds Farbtastic in a different version.
+ */
+function common_test_library() {
+ $libraries['farbtastic'] = array(
+ 'title' => 'Custom Farbtastic Library',
+ 'website' => 'http://code.google.com/p/farbtastic/',
+ 'version' => '5.3',
+ 'js' => array(
+ 'misc/farbtastic/farbtastic.js' => array(),
+ ),
+ 'css' => array(
+ 'misc/farbtastic/farbtastic.css' => array(),
+ ),
+ );
+ return $libraries;
+}