updated login-destination, libraries
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains LibrariesAdminWebTest.
|
||||
*
|
||||
* Simpletest automatically discovers test files using PSR-4. We cannot,
|
||||
* however, declare a namespace for this class, as that would require PHP 5.3.
|
||||
* To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
|
||||
* split each test class into its own file and use the correct base name, but
|
||||
* for now use the 'test' extension and register them explicitly in
|
||||
* libraries.info.
|
||||
*
|
||||
* @see simpletest_test_get_all()
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the administrative interface for libraries.
|
||||
*/
|
||||
class LibrariesAdminWebTest extends LibrariesWebTestBase {
|
||||
|
||||
/**
|
||||
* Provides metadata about this test.
|
||||
*
|
||||
* @return array
|
||||
* An array of test metadata with the following keys:
|
||||
* - name: The name of the test.
|
||||
* - description: The description of the test.
|
||||
* - group: The group of the test.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Libraries administration',
|
||||
'description' => 'Tests the administrative interface for libraries.',
|
||||
'group' => 'Libraries API',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the libraries report at /admin/reports/libraries.
|
||||
*/
|
||||
public function testLibrariesReportOverview() {
|
||||
$this->getWithPermissions(array('access site reports'), 'admin/reports/libraries');
|
||||
$this->assertRaw('Libraries');
|
||||
|
||||
// Make sure that all the libraries are listed.
|
||||
$libraries = libraries_info();
|
||||
$this->assertTrue($libraries);
|
||||
foreach ($libraries as $library) {
|
||||
$this->assertText($library['name']);
|
||||
$this->assertLinkByHref('admin/reports/libraries/' . $library['machine name']);
|
||||
}
|
||||
|
||||
// Make sure that all possible statuses are displayed.
|
||||
$this->assertText('OK');
|
||||
$this->assertText('Not found');
|
||||
$this->assertText('Not detected');
|
||||
$this->assertText('Not supported');
|
||||
$this->assertText('Missing dependency');
|
||||
$this->assertText('Incompatible dependency');
|
||||
|
||||
// Make sure that the providers are displayed.
|
||||
$this->assertRaw('<em class="placeholder">Libraries test module</em> module');
|
||||
$this->assertRaw('<em class="placeholder">Libraries test theme</em> theme');
|
||||
$this->assertRaw('<em class="placeholder">example_info_file.libraries.info</em> info file');
|
||||
|
||||
// Make sure that homepage and download links are displayed.
|
||||
$this->assertLinkByHref('http://example.com');
|
||||
$this->assertLinkByHref('http://example.com/download');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the libraries report for an installed library.
|
||||
*/
|
||||
public function testLibrariesReportInstalled() {
|
||||
$this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_files');
|
||||
$this->assertRaw('Status report for library <em class="placeholder">Example files</em>');
|
||||
$this->assertRaw('The <em class="placeholder">Example files</em> library is installed correctly.');
|
||||
// Check that the information in the status report is displayed.
|
||||
$this->assertText('Example files');
|
||||
$this->assertText('example_files');
|
||||
$this->assertRaw('<em class="placeholder">Libraries test module</em> module');
|
||||
$this->assertText(drupal_get_path('module', 'libraries') . '/tests/libraries/example');
|
||||
$this->assertText('1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the libraries report for a missing library.
|
||||
*/
|
||||
public function testLibrariesReportMissing() {
|
||||
$this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_missing');
|
||||
$this->assertRaw('Status report for library <em class="placeholder">Example missing</em>');
|
||||
$this->assertRaw('The <em class="placeholder">Example missing</em> library could not be found.');
|
||||
// Check that the download link is being displayed.
|
||||
$this->assertLinkByHref('http://example.com/download');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the libraries report for a missing library.
|
||||
*/
|
||||
public function testLibrariesReportNotDetected() {
|
||||
$this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_undetected_version');
|
||||
$this->assertRaw('Status report for library <em class="placeholder">Example undetected version</em>');
|
||||
$this->assertRaw('The version of the <em class="placeholder">Example undetected version</em> library could not be detected.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the libraries report for a missing library.
|
||||
*/
|
||||
public function testLibrariesReportNotSupported() {
|
||||
$this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_unsupported_version');
|
||||
$this->assertRaw('Status report for library <em class="placeholder">Example unsupported version</em>');
|
||||
$this->assertRaw('The installed version <em class="placeholder">1</em> of the <em class="placeholder">Example unsupported version</em> library is not supported.');
|
||||
// Check that the download link is being displayed.
|
||||
$this->assertLinkByHref('http://example.com/download');
|
||||
}
|
||||
|
||||
}
|
@@ -2,67 +2,29 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for Libraries API.
|
||||
* Contains LibrariesLoadWebTest.
|
||||
*
|
||||
* Simpletest automatically discovers test files using PSR-4. We cannot,
|
||||
* however, declare a namespace for this class, as that would require PHP 5.3.
|
||||
* To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
|
||||
* place the test files in the correct directory already, but for now register
|
||||
* them explicitly in libraries.info
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests basic Libraries API functions.
|
||||
*/
|
||||
class LibrariesUnitTestCase extends DrupalUnitTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Libraries API unit tests',
|
||||
'description' => 'Tests basic functions provided by Libraries API.',
|
||||
'group' => 'Libraries API',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
drupal_load('module', 'libraries');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests libraries_get_path().
|
||||
*/
|
||||
function testLibrariesGetPath() {
|
||||
// Note that, even though libraries_get_path() doesn't find the 'example'
|
||||
// library, we are able to make it 'installed' by specifying the 'library
|
||||
// path' up-front. This is only used for testing purposed and is strongly
|
||||
// discouraged as it defeats the purpose of Libraries API in the first
|
||||
// place.
|
||||
$this->assertEqual(libraries_get_path('example'), FALSE, 'libraries_get_path() returns FALSE for a missing library.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests libraries_prepare_files().
|
||||
*/
|
||||
function testLibrariesPrepareFiles() {
|
||||
$expected = array(
|
||||
'files' => array(
|
||||
'js' => array('example.js' => array()),
|
||||
'css' => array('example.css' => array()),
|
||||
'php' => array('example.php' => array()),
|
||||
),
|
||||
);
|
||||
$library = array(
|
||||
'files' => array(
|
||||
'js' => array('example.js'),
|
||||
'css' => array('example.css'),
|
||||
'php' => array('example.php'),
|
||||
),
|
||||
);
|
||||
libraries_prepare_files($library, NULL, NULL);
|
||||
$this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests basic detection and loading of libraries.
|
||||
*/
|
||||
class LibrariesTestCase extends DrupalWebTestCase {
|
||||
protected $profile = 'testing';
|
||||
class LibrariesLoadWebTest extends LibrariesWebTestBase {
|
||||
|
||||
/**
|
||||
* Provides metadata about this test.
|
||||
*
|
||||
* @return array
|
||||
* An array of test metadata with the following keys:
|
||||
* - name: The name of the test.
|
||||
* - description: The description of the test.
|
||||
* - group: The group of the test.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Libraries detection and loading',
|
||||
@@ -71,15 +33,10 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('libraries', 'libraries_test_module');
|
||||
theme_enable(array('libraries_test_theme'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests libraries_detect_dependencies().
|
||||
*/
|
||||
function testLibrariesDetectDependencies() {
|
||||
public function testLibrariesDetectDependencies() {
|
||||
$library = array(
|
||||
'name' => 'Example',
|
||||
'dependencies' => array('example_missing'),
|
||||
@@ -158,7 +115,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Tests libraries_scan_info_files().
|
||||
*/
|
||||
function testLibrariesScanInfoFiles() {
|
||||
public function testLibrariesScanInfoFiles() {
|
||||
$expected = array('example_info_file' => (object) array(
|
||||
'uri' => drupal_get_path('module', 'libraries') . '/tests/libraries/example_info_file.libraries.info',
|
||||
'filename' => 'example_info_file.libraries.info',
|
||||
@@ -171,7 +128,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Tests libraries_info().
|
||||
*/
|
||||
function testLibrariesInfo() {
|
||||
public function testLibrariesInfo() {
|
||||
// Test that modules can provide and alter library information.
|
||||
$info = libraries_info();
|
||||
$this->assertTrue(isset($info['example_module']));
|
||||
@@ -226,7 +183,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Tests libraries_detect().
|
||||
*/
|
||||
function testLibrariesDetect() {
|
||||
public function testLibrariesDetect() {
|
||||
// Test missing library.
|
||||
$library = libraries_detect('example_missing');
|
||||
$this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
|
||||
@@ -306,10 +263,24 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
$this->assertEqual($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests libraries_detect() without a $name parameter.
|
||||
*/
|
||||
public function testLibrariesDetectAll() {
|
||||
// Test that an array with all library information is returned and that the
|
||||
// libraries are properly detected.
|
||||
$libraries = libraries_detect();
|
||||
$this->verbose('<pre>' . var_export($libraries, TRUE) . '</pre>');
|
||||
$this->assertEqual($libraries['example_missing']['error'], 'not found');
|
||||
$this->assertEqual($libraries['example_undetected_version']['error'], 'not detected');
|
||||
$this->assertEqual($libraries['example_unsupported_version']['error'], 'not supported');
|
||||
$this->assertEqual($libraries['example_supported_version']['installed'], TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests libraries_load().
|
||||
*/
|
||||
function testLibrariesLoad() {
|
||||
public function testLibrariesLoad() {
|
||||
// Test dependencies.
|
||||
$library = libraries_load('example_dependency_missing');
|
||||
$this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
|
||||
@@ -334,7 +305,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Tests the applying of callbacks.
|
||||
*/
|
||||
function testCallbacks() {
|
||||
public function testCallbacks() {
|
||||
$expected = array(
|
||||
'name' => 'Example callback',
|
||||
'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
|
||||
@@ -453,7 +424,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
*
|
||||
* @see _libraries_test_module_load()
|
||||
*/
|
||||
function testLibrariesOutput() {
|
||||
public function testLibrariesOutput() {
|
||||
// Test loading of a simple library with a top-level files property.
|
||||
$this->drupalGet('libraries-test-module/files');
|
||||
$this->assertLibraryFiles('example_1', 'File loading');
|
||||
@@ -527,7 +498,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
* (optional) The expected file extensions of $name. Defaults to
|
||||
* array('js', 'css', 'php').
|
||||
*/
|
||||
function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) {
|
||||
public function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) {
|
||||
$label = ($label !== '' ? "$label: " : '');
|
||||
|
||||
// Test that the wrong files are not loaded...
|
||||
@@ -570,4 +541,3 @@ class LibrariesTestCase extends DrupalWebTestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains LibrariesUnitTest.
|
||||
*
|
||||
* Simpletest automatically discovers test files using PSR-4. We cannot,
|
||||
* however, declare a namespace for this class, as that would require PHP 5.3.
|
||||
* To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
|
||||
* place the test files in the correct directory already, but for now register
|
||||
* them explicitly in libraries.info.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests basic Libraries API functions.
|
||||
*/
|
||||
class LibrariesUnitTest extends DrupalUnitTestCase {
|
||||
|
||||
/**
|
||||
* Provides metadata about this test.
|
||||
*
|
||||
* @return array
|
||||
* An array of test metadata with the following keys:
|
||||
* - name: The name of the test.
|
||||
* - description: The description of the test.
|
||||
* - group: The group of the test.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Libraries API unit tests',
|
||||
'description' => 'Tests basic functions provided by Libraries API.',
|
||||
'group' => 'Libraries API',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
drupal_load('module', 'libraries');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests libraries_get_path().
|
||||
*/
|
||||
public function testLibrariesGetPath() {
|
||||
// Note that, even though libraries_get_path() doesn't find the 'example'
|
||||
// library, we are able to make it 'installed' by specifying the 'library
|
||||
// path' up-front. This is only used for testing purposed and is strongly
|
||||
// discouraged as it defeats the purpose of Libraries API in the first
|
||||
// place.
|
||||
$this->assertEqual(libraries_get_path('example'), FALSE, 'libraries_get_path() returns FALSE for a missing library.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests libraries_prepare_files().
|
||||
*/
|
||||
public function testLibrariesPrepareFiles() {
|
||||
$expected = array(
|
||||
'files' => array(
|
||||
'js' => array('example.js' => array()),
|
||||
'css' => array('example.css' => array()),
|
||||
'php' => array('example.php' => array()),
|
||||
),
|
||||
);
|
||||
$library = array(
|
||||
'files' => array(
|
||||
'js' => array('example.js'),
|
||||
'css' => array('example.css'),
|
||||
'php' => array('example.php'),
|
||||
),
|
||||
);
|
||||
libraries_prepare_files($library, NULL, NULL);
|
||||
$this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.');
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains LibrariesWebTestBase.
|
||||
*
|
||||
* Simpletest automatically discovers test files using PSR-4. We cannot,
|
||||
* however, declare a namespace for this class, as that would require PHP 5.3.
|
||||
* To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
|
||||
* place the test files in the correct directory already, but for now register
|
||||
* them explicitly in libraries.info
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for Libraries API web tests.
|
||||
*/
|
||||
abstract class LibrariesWebTestBase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $profile = 'testing';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp('libraries', 'libraries_test_module');
|
||||
theme_enable(array('libraries_test_theme'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a path making sure a set of permissions is required to access it.
|
||||
*
|
||||
* After calling this method, a user with the given permissions is logged in
|
||||
* and the retrieved page is loaded into the internal browser.
|
||||
*
|
||||
* @param array $permissions
|
||||
* An array of permission names to assign to user. Note that the user always
|
||||
* has the default permissions derived from the "authenticated users" role.
|
||||
* @param string $path
|
||||
* Drupal path or URL to load into the internal browser.
|
||||
* @param array $options
|
||||
* Options to be forwarded to url().
|
||||
* @param array $headers
|
||||
* An array containing additional HTTP request headers, each formatted as
|
||||
* "name: value".
|
||||
*
|
||||
* @return string
|
||||
* The retrieved HTML string, also available as $this->drupalGetContent().
|
||||
*
|
||||
* @see \DrupalWebTestCase::drupalGet()
|
||||
* @see \DrupalWebTestCase::drupalCreateUser()
|
||||
*/
|
||||
protected function getWithPermissions(array $permissions, $path, array $options = array(), array $headers = array()) {
|
||||
$this->drupalGet($path, $options, $headers);
|
||||
$this->assertResponse(403);
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser($permissions));
|
||||
$this->drupalGet($path, $options, $headers);
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
}
|
@@ -2,9 +2,9 @@
|
||||
name = Example info file
|
||||
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-02-09
|
||||
version = "7.x-2.2"
|
||||
; Information added by Drupal.org packaging script on 2016-05-12
|
||||
version = "7.x-2.3"
|
||||
core = "7.x"
|
||||
project = "libraries"
|
||||
datestamp = "1391965716"
|
||||
datestamp = "1463077450"
|
||||
|
||||
|
@@ -5,9 +5,9 @@ package = Testing
|
||||
dependencies[] = libraries
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-02-09
|
||||
version = "7.x-2.2"
|
||||
; Information added by Drupal.org packaging script on 2016-05-12
|
||||
version = "7.x-2.3"
|
||||
core = "7.x"
|
||||
project = "libraries"
|
||||
datestamp = "1391965716"
|
||||
datestamp = "1463077450"
|
||||
|
||||
|
@@ -18,6 +18,9 @@ function libraries_test_module_libraries_info() {
|
||||
// Test library detection.
|
||||
$libraries['example_missing'] = array(
|
||||
'name' => 'Example missing',
|
||||
// Provide a vendor and download URL to test that the UI links to it.
|
||||
'vendor url' => 'http://example.com',
|
||||
'download url' => 'http://example.com/download',
|
||||
'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/missing',
|
||||
);
|
||||
$libraries['example_undetected_version'] = array(
|
||||
@@ -28,6 +31,8 @@ function libraries_test_module_libraries_info() {
|
||||
);
|
||||
$libraries['example_unsupported_version'] = array(
|
||||
'name' => 'Example unsupported version',
|
||||
// Provide a download URL to test that the UI links to it.
|
||||
'download url' => 'http://example.com/download',
|
||||
'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
|
||||
'version callback' => '_libraries_test_module_return_version',
|
||||
'version arguments' => array('1'),
|
||||
|
@@ -3,9 +3,9 @@ description = Tests that themes can provide and alter library information.
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-02-09
|
||||
version = "7.x-2.2"
|
||||
; Information added by Drupal.org packaging script on 2016-05-12
|
||||
version = "7.x-2.3"
|
||||
core = "7.x"
|
||||
project = "libraries"
|
||||
datestamp = "1391965716"
|
||||
datestamp = "1463077450"
|
||||
|
||||
|
Reference in New Issue
Block a user