You are here

public function ContextUnitTest::test in Context 7.3

Same name and namespace in other branches
  1. 6.3 tests/context.test \ContextUnitTest::test()

File

tests/context.test, line 18

Class

ContextUnitTest

Code

public function test() {

  // define possible data types
  $set_types = array(
    'bool' => TRUE,
    'int' => 1,
    'string' => 'lorem',
    'array' => array(
      'lorem',
    ),
    'object' => new stdClass(),
  );
  $id_types = array(
    'int',
    'string',
  );

  // NAMESPACE
  foreach ($set_types as $type => $val) {
    $set = context_set($val);

    // Test return value of context_set()
    if (in_array($type, $id_types)) {

      // test set integrity
      $this
        ->assertIdentical(true, $set, 'Space set successful.');

      // test get integrity
      $this
        ->assertIdentical(array(), context_get($val), 'Namespace get successful.');
      $this
        ->assertIdentical(true, context_exists($val), 'Namespace exists successful.');
    }
    else {
      $this
        ->assertIdentical(false, $set, 'Prohibited namespace not established.');
    }
    context_clear();
  }

  // NAMESPACE+ATTRIBUTE
  foreach ($set_types as $type => $val) {
    foreach ($set_types as $type2 => $val2) {

      // test set integrity
      $set = context_set($val, $val2);
      if (in_array($type, $id_types)) {

        // test set integrity
        if ($type2 != 'bool') {
          $this
            ->assertIdentical(true, $set, 'Namespace and attribute set successful.');
        }
        else {
          $this
            ->assertIdentical(false, $set);
        }

        // test get + exists integrity
        if (in_array($type2, $id_types)) {
          $this
            ->assertIdentical(true, context_get($val, $val2) == $val2, 'Namespace and attribute get successful.');
          $this
            ->assertIdentical(true, context_exists($val, $val2), 'Namespace and attribute exists.');
        }
        elseif (in_array($type2, array(
          'array',
          'object',
        ))) {
          $this
            ->assertIdentical(true, context_get($val) == $val2, 'Namespace and attribute get successful.');
          $this
            ->assertIdentical(true, context_exists($val), 'Namespace and attribute exists.');
        }
      }
    }
    context_clear();
  }

  // NAMESPACE+ATTRIBUTE+VALUE, o lord
  foreach ($set_types as $type => $val) {
    foreach ($set_types as $type2 => $val2) {
      foreach ($set_types as $type3 => $val3) {
        $set = context_set($val, $val2, $val3);
        if (in_array($type, $id_types)) {
          if (in_array($type2, $id_types)) {
            $this
              ->assertIdentical(true, context_get($val, $val2, $val3) == $val3, 'Namespace, attribute and value get successful.');
            $this
              ->assertIdentical(true, context_exists($val, $val2, $val3), 'Namespace, attribute and value exists.');
          }
        }
        context_clear();
      }
    }
  }
}