You are here

public function MoopapiWebTestCase::testMonkeyPatch in Module Object Oriented Programming API 7.2

File

tests/moopapi.test, line 26

Class

MoopapiWebTestCase
Tests that Patchwork library is available, installed and works properly and tests Moopapi interface.

Code

public function testMonkeyPatch() {
  $library = libraries_detect('patchwork');

  // Check Patchwork library.
  if ($this
    ->assertTrue($library, 'Patchwork library is detected')) {
    if ($this
      ->assertTrue(is_array($library) && !empty($library['installed']), 'Patchwork library is installed')) {
      $library = libraries_load('patchwork');
      $this
        ->assertTrue(!empty($library['loaded']), 'Patchwork library is loaded');
    }
    else {
      $message = 'Error while installing Patchwork library';
      if (!empty($library['error'])) {
        $message = 'Library Patchwork is ' . $library['error'];
      }
      if (!empty($library['error message'])) {
        $message .= ': ' . $library['error message'];
      }
      $this
        ->fail($message);
    }
  }

  // Only now we include necessary file to make Patchwork
  // interception work.
  module_load_include('inc', 'moopapi', 'tests/monkey_patch');
  Patchwork\replace("doesMonkeyPatchWork", function () {
    return TRUE;
  });
  $this
    ->assertTrue(doesMonkeyPatchWork(), 'Monkey patching works');
}