You are here

public function CtoolsContextIDTestCase::testNextContextId in Chaos Tool Suite (ctools) 7

Test ctools_context_next_id in various scenarios.

File

tests/context.test, line 127
Test the keyword substitution functionality.

Class

CtoolsContextIDTestCase
@file Test the keyword substitution functionality.

Code

public function testNextContextId() {
  $test_objects = $this
    ->getTestContexts();

  // If no object list or name is given?
  $value = ctools_context_next_id(NULL, NULL);
  $expected = 1;
  $this
    ->assertEqual($value, $expected, 'NULL objects have next id ' . $expected);

  // If no object list is given?
  $value = ctools_context_next_id(NULL, 'bar');
  $expected = 1;
  $this
    ->assertEqual($value, $expected, 'NULL objects have next id ' . $expected);

  // If no object list is given (another way)?
  $value = ctools_context_next_id(array(), 'bar');
  $expected = 1;
  $this
    ->assertEqual($value, $expected, 'Empty objects have next id ' . $expected);

  // The name is empty... which is just another name.
  $value = ctools_context_next_id($test_objects, '');
  $expected = 1;
  $this
    ->assertEqual($value, $expected, 'Unnamed objects have next id ' . $expected . ' (got ' . $value . ')');

  // The value of the id key is not a number.
  $value = ctools_context_next_id($test_objects, 'foo_bar');
  $expected = 1;
  $this
    ->assertEqual($value, $expected, 'Objects with non-integer ids are ignored ' . $expected);

  // One object's id is not a number (ignore) but another is valid.
  $value = ctools_context_next_id($test_objects, 'baz');
  $expected = 16;
  $this
    ->assertEqual($value, $expected, 'Baz\'s objects have next id ' . $expected);

  // An expected case: there is one match and the id is numeric.
  $value = ctools_context_next_id($test_objects, 'foo');
  $expected = 2;
  $this
    ->assertEqual($value, $expected, 'Foo\'s objects have next id ' . $expected);

  // Another expected case: there are multiple numeric IDs.
  $value = ctools_context_next_id($test_objects, 'bar');
  $expected = 100;
  $this
    ->assertEqual($value, $expected, 'Bar\'s objects have next id ' . $expected);
}