You are here

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

Same name and namespace in other branches
  1. 6.2 tests/moopapi.test \MoopapiWebTestCase::testWrap()
  2. 6 tests/moopapi.test \MoopapiWebTestCase::testWrap()
  3. 7 tests/moopapi.test \MoopapiWebTestCase::testWrap()

File

tests/moopapi.test, line 123

Class

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

Code

public function testWrap() {
  $use_cases = array(
    'lowercase',
    'uppercase',
    'camelcase',
    'decorators_null',
  );
  foreach ($use_cases as $use_case) {
    switch ($use_case) {

      // Formatting.
      case 'lowercase':
        $app = 'exampleapp';
        $method = 'examplemethod';
        $decorators = array(
          'testdecorator',
        );
        break;
      case 'uppercase':
        $app = 'EXAMPLEAPP';
        $method = 'EXAMPLEMETHOD';
        $decorators = array(
          'TESTDECORATOR',
        );
        break;
      case 'camelcase':
        $app = 'ExampleApp';
        $method = 'ExampleMethod';
        $decorators = array(
          'TestDecorator',
        );
        break;

      // Business logic.
      case 'decorators_null':
        $app = 'ExampleApp';
        $method = 'exampleMethod';
        $decorators = array();
        break;
      case 'app_absent':

        // @todo Moopapi::absent(): Implement app_absent use case.
        break;
      case 'class_absent':

        // @todo Moopapi::absent(): Implement class_absent use case.
        break;
      case 'method_absent':

        // @todo Moopapi::absent(): Implement method_absent use case.
        break;
    }

    // Prepare workspace.
    static $objects;
    $objects = array();
    module_load_include('inc', 'moopapi', 'tests/monkey_patch');

    // Test interface function.
    moopapi_wrap($app, $method, $decorators);

    // Check result.
    if ($use_case === 'decorators_null') {
      $decorator = $app;
    }
    else {
      $decorator = reset($decorators);
    }
    $function_name = "{$app}_{$method}";
    if ($this
      ->assertTrue(function_exists($function_name), "{$use_case}: {$function_name} function was created")) {
      $function_result = call_user_func($function_name);
      $this
        ->assertTrue(strcasecmp($function_result, $decorator) == 0, "{$use_case}: Calling {$app}::{$method} wrapped as {$function_name} brings {$function_result}, which is the same as {$decorator}");
    }

    // Clear workspace.
    unset($result);
    $objects = array();
  }
}