You are here

function SkinrApiTest::testSkinrImplements in Skinr 8.2

Test module_implements().

File

src/Tests/SkinrApiTest.php, line 107
Contains \Drupal\skinr\Tests\SkinrApiTest.

Class

SkinrApiTest
Tests Skinr API functionality.

Namespace

Drupal\skinr\Tests

Code

function testSkinrImplements() {

  // Test clearing cache.
  \Drupal::cache('bootstrap')
    ->invalidate('skinr_implements');
  $this
    ->assertFalse(\Drupal::cache('bootstrap')
    ->get('skinr_implements'), t('The skinr implements cache is empty.'));
  $this
    ->drupalGet('');
  $this
    ->assertTrue(\Drupal::cache('bootstrap')
    ->get('skinr_implements'), t('The skinr implements cache is populated after requesting a page.'));

  // Test clearing cache with an authenticated user.
  $this->user = $this
    ->drupalCreateUser(array());
  $this
    ->drupalLogin($this->user);
  \Drupal::cache('bootstrap')
    ->invalidate('skinr_implements');
  $this
    ->drupalGet('');
  $this
    ->assertTrue(\Drupal::cache('bootstrap')
    ->get('skinr_implements'), t('The skinr implements cache is populated after requesting a page.'));

  // Make sure $module.skinr.inc files (both in the module root, which are
  // auto-loaded by drupal, and in custom paths and themes, which are
  // loaded by skinr_implements()) are loaded when the hook is called. Also
  // ensure only module that implement the current Skinr API are loaded.
  $modules = skinr_implements('skinr_skin_info');

  // Ensure the hook is found in includes.
  $this
    ->assertTrue(in_array('skinr_test', $modules), 'Hook found in $module.skinr.inc file auto-loaded by module_hook().');
  $this
    ->assertTrue(in_array('skinr_test_subtheme', $modules), 'Hook found in $module.skinr.inc file in custom path.');

  // Ensure that skinr_test_incompatible is not included.
  $this
    ->assertTrue(!in_array('skinr_test_incompatible', $modules), 'Hook in incompatible module not found.');
}