LibrariesUnitTest.test 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Contains LibrariesUnitTest.
  5. *
  6. * Simpletest automatically discovers test files using PSR-4. We cannot,
  7. * however, declare a namespace for this class, as that would require PHP 5.3.
  8. * To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
  9. * place the test files in the correct directory already, but for now register
  10. * them explicitly in libraries.info.
  11. */
  12. /**
  13. * Tests basic Libraries API functions.
  14. */
  15. class LibrariesUnitTest extends DrupalUnitTestCase {
  16. /**
  17. * Provides metadata about this test.
  18. *
  19. * @return array
  20. * An array of test metadata with the following keys:
  21. * - name: The name of the test.
  22. * - description: The description of the test.
  23. * - group: The group of the test.
  24. */
  25. public static function getInfo() {
  26. return array(
  27. 'name' => 'Libraries API unit tests',
  28. 'description' => 'Tests basic functions provided by Libraries API.',
  29. 'group' => 'Libraries API',
  30. );
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. protected function setUp() {
  36. drupal_load('module', 'libraries');
  37. parent::setUp();
  38. }
  39. /**
  40. * Tests libraries_get_path().
  41. */
  42. public function testLibrariesGetPath() {
  43. // Note that, even though libraries_get_path() doesn't find the 'example'
  44. // library, we are able to make it 'installed' by specifying the 'library
  45. // path' up-front. This is only used for testing purposed and is strongly
  46. // discouraged as it defeats the purpose of Libraries API in the first
  47. // place.
  48. $this->assertEqual(libraries_get_path('example'), FALSE, 'libraries_get_path() returns FALSE for a missing library.');
  49. }
  50. /**
  51. * Tests libraries_prepare_files().
  52. */
  53. public function testLibrariesPrepareFiles() {
  54. $expected = array(
  55. 'files' => array(
  56. 'js' => array('example.js' => array()),
  57. 'css' => array('example.css' => array()),
  58. 'php' => array('example.php' => array()),
  59. ),
  60. );
  61. $library = array(
  62. 'files' => array(
  63. 'js' => array('example.js'),
  64. 'css' => array('example.css'),
  65. 'php' => array('example.php'),
  66. ),
  67. );
  68. libraries_prepare_files($library, NULL, NULL);
  69. $this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.');
  70. }
  71. }