You are here

function libraries_test_module_libraries_info in Libraries API 7.3

Same name and namespace in other branches
  1. 7.2 tests/modules/libraries_test_module/libraries_test_module.module \libraries_test_module_libraries_info()

Implements hook_libraries_info().

File

tests/modules/libraries_test_module/libraries_test_module.module, line 11
Tests the library detection and loading.

Code

function libraries_test_module_libraries_info() {

  // Test library information gathering.
  $libraries['example_module'] = array(
    'name' => 'Example module',
    'module_altered' => FALSE,
  );

  // Test library detection.
  $libraries['example_missing'] = array(
    'name' => 'Example missing',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/missing',
  );
  $libraries['example_undetected_version'] = array(
    'name' => 'Example undetected version',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version callback' => '_libraries_test_module_return_version',
    'version arguments' => array(
      FALSE,
    ),
  );
  $libraries['example_unsupported_version'] = array(
    'name' => 'Example unsupported version',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version callback' => '_libraries_test_module_return_version',
    'version arguments' => array(
      '1',
    ),
    'versions' => array(
      '2' => array(),
    ),
  );
  $libraries['example_supported_version'] = array(
    'name' => 'Example supported version',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version callback' => '_libraries_test_module_return_version',
    'version arguments' => array(
      '1',
    ),
    'versions' => array(
      '1' => array(),
    ),
  );

  // Test the default version callback.
  $libraries['example_default_version_callback'] = array(
    'name' => 'Example default version callback',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version arguments' => array(
      'file' => 'README.txt',
      // Version 1
      'pattern' => '/Version (\\d+)/',
      'lines' => 5,
    ),
  );

  // Test a multiple-parameter version callback.
  $libraries['example_multiple_parameter_version_callback'] = array(
    'name' => 'Example multiple parameter version callback',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    // Version 1
    'version callback' => '_libraries_test_module_get_version',
    'version arguments' => array(
      'README.txt',
      '/Version (\\d+)/',
      5,
    ),
  );

  // Test a top-level files property.
  $libraries['example_files'] = array(
    'name' => 'Example files',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'files' => array(
      'js' => array(
        'example_1.js',
      ),
      'css' => array(
        'example_1.css',
      ),
      'php' => array(
        'example_1.php',
      ),
    ),
  );

  // Test loading of integration files.
  // Normally added by the corresponding module via hook_libraries_info_alter(),
  // these files should be automatically loaded when the library is loaded.
  $libraries['example_module_integration_files'] = array(
    'name' => 'Example module integration files',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'integration files' => array(
      'libraries_test_module' => array(
        'js' => array(
          'libraries_test_module.js',
        ),
        'css' => array(
          'libraries_test_module.css',
        ),
        'php' => array(
          'libraries_test_module.inc',
        ),
      ),
    ),
  );

  // Test version overloading.
  $libraries['example_versions'] = array(
    'name' => 'Example versions',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '2',
    'versions' => array(
      '1' => array(
        'files' => array(
          'js' => array(
            'example_1.js',
          ),
          'css' => array(
            'example_1.css',
          ),
          'php' => array(
            'example_1.php',
          ),
        ),
      ),
      '2' => array(
        'files' => array(
          'js' => array(
            'example_2.js',
          ),
          'css' => array(
            'example_2.css',
          ),
          'php' => array(
            'example_2.php',
          ),
        ),
      ),
    ),
  );

  // Test variant detection.
  $libraries['example_variant_missing'] = array(
    'name' => 'Example variant missing',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'variants' => array(
      'example_variant' => array(
        'files' => array(
          'js' => array(
            'example_3.js',
          ),
          'css' => array(
            'example_3.css',
          ),
          'php' => array(
            'example_3.php',
          ),
        ),
        'variant callback' => '_libraries_test_module_return_installed',
        'variant arguments' => array(
          FALSE,
        ),
      ),
    ),
  );
  $libraries['example_variant'] = array(
    'name' => 'Example variant',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'variants' => array(
      'example_variant' => array(
        'files' => array(
          'js' => array(
            'example_3.js',
          ),
          'css' => array(
            'example_3.css',
          ),
          'php' => array(
            'example_3.php',
          ),
        ),
        'variant callback' => '_libraries_test_module_return_installed',
        'variant arguments' => array(
          TRUE,
        ),
      ),
    ),
  );

  // Test correct behaviour with multiple versions and multiple variants.
  $libraries['example_versions_and_variants'] = array(
    'name' => 'Example versions and variants',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '2',
    'versions' => array(
      '1' => array(
        'variants' => array(
          'example_variant_1' => array(
            'files' => array(
              'js' => array(
                'example_1.js',
              ),
              'css' => array(
                'example_1.css',
              ),
              'php' => array(
                'example_1.php',
              ),
            ),
            'variant callback' => '_libraries_test_module_return_installed',
            'variant arguments' => array(
              TRUE,
            ),
          ),
          'example_variant_2' => array(
            'files' => array(
              'js' => array(
                'example_2.js',
              ),
              'css' => array(
                'example_2.css',
              ),
              'php' => array(
                'example_2.php',
              ),
            ),
            'variant callback' => '_libraries_test_module_return_installed',
            'variant arguments' => array(
              TRUE,
            ),
          ),
        ),
      ),
      '2' => array(
        'variants' => array(
          'example_variant_1' => array(
            'files' => array(
              'js' => array(
                'example_3.js',
              ),
              'css' => array(
                'example_3.css',
              ),
              'php' => array(
                'example_3.php',
              ),
            ),
            'variant callback' => '_libraries_test_module_return_installed',
            'variant arguments' => array(
              TRUE,
            ),
          ),
          'example_variant_2' => array(
            'files' => array(
              'js' => array(
                'example_4.js',
              ),
              'css' => array(
                'example_4.css',
              ),
              'php' => array(
                'example_4.php',
              ),
            ),
            'variant callback' => '_libraries_test_module_return_installed',
            'variant arguments' => array(
              TRUE,
            ),
          ),
        ),
      ),
    ),
  );

  // Test dependency loading.
  // We add one file to each library to be able to verify if it was loaded with
  // libraries_load().
  // This library acts as a dependency for the libraries below.
  $libraries['example_dependency'] = array(
    'name' => 'Example dependency',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1.1',
    'files' => array(
      'js' => array(
        'example_1.js',
      ),
    ),
  );
  $libraries['example_dependency_missing'] = array(
    'name' => 'Example dependency missing',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'dependencies' => array(
      'example_missing',
    ),
    'files' => array(
      'js' => array(
        'example_1.js',
      ),
    ),
  );
  $libraries['example_dependency_incompatible'] = array(
    'name' => 'Example dependency incompatible',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'dependencies' => array(
      'example_dependency (>1.1)',
    ),
    'files' => array(
      'js' => array(
        'example_1.js',
      ),
    ),
  );
  $libraries['example_dependency_compatible'] = array(
    'name' => 'Example dependency compatible',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'dependencies' => array(
      'example_dependency (>=1.1)',
    ),
    'files' => array(
      'js' => array(
        'example_1.js',
      ),
    ),
  );

  // Test the applying of callbacks.
  $libraries['example_callback'] = array(
    'name' => 'Example callback',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'versions' => array(
      '1' => array(
        'variants' => array(
          'example_variant' => array(
            // These keys are for testing purposes only.
            'info callback' => 'not applied',
            'pre-detect callback' => 'not applied',
            'post-detect callback' => 'not applied',
            'pre-dependencies-load callback' => 'not applied',
            'pre-load callback' => 'not applied',
            'post-load callback' => 'not applied',
          ),
        ),
        // These keys are for testing purposes only.
        'info callback' => 'not applied',
        'pre-detect callback' => 'not applied',
        'post-detect callback' => 'not applied',
        'pre-dependencies-load callback' => 'not applied',
        'pre-load callback' => 'not applied',
        'post-load callback' => 'not applied',
      ),
    ),
    'variants' => array(
      'example_variant' => array(
        // These keys are for testing purposes only.
        'info callback' => 'not applied',
        'pre-detect callback' => 'not applied',
        'post-detect callback' => 'not applied',
        'pre-dependencies-load callback' => 'not applied',
        'pre-load callback' => 'not applied',
        'post-load callback' => 'not applied',
      ),
    ),
    'callbacks' => array(
      'info' => array(
        '_libraries_test_module_info_callback',
      ),
      'pre-detect' => array(
        '_libraries_test_module_pre_detect_callback',
      ),
      'post-detect' => array(
        '_libraries_test_module_post_detect_callback',
      ),
      'pre-dependencies-load' => array(
        '_libraries_test_module_pre_dependencies_load_callback',
      ),
      'pre-load' => array(
        '_libraries_test_module_pre_load_callback',
      ),
      'post-load' => array(
        '_libraries_test_module_post_load_callback',
      ),
    ),
    // These keys are for testing purposes only.
    'info callback' => 'not applied',
    'pre-detect callback' => 'not applied',
    'post-detect callback' => 'not applied',
    'pre-dependencies-load callback' => 'not applied',
    'pre-load callback' => 'not applied',
    'post-load callback' => 'not applied',
  );
  $libraries['example_path_variable_override'] = array(
    'name' => 'Example path variable override',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'files' => array(
      'php' => array(
        'example_1.php',
        'example_2.php',
      ),
    ),
  );
  return $libraries;
}