Skip to content

Commit

Permalink
Hardcode language translations since K24 now does it totally differen…
Browse files Browse the repository at this point in the history
…tly. This forks the code, but it's reached the end of its development path and we should replace it with phpunit anyway
  • Loading branch information
bharat committed Dec 21, 2009
1 parent 6f063ac commit 91e39f7
Showing 1 changed file with 69 additions and 27 deletions.
96 changes: 69 additions & 27 deletions modules/unit_test/libraries/Unit_Test.php
Expand Up @@ -20,6 +20,48 @@ class Unit_Test_Core {
// Statistics for every test class
protected $stats = array();

public static $lang = array(
'class' => 'Class',
'method' => 'Method',
'invalid_test_path' => 'Failed to open test path: %s.',
'duplicate_test_class' => 'Duplicate test class named %s found in %s.',
'test_class_not_found' => 'No test class by the name of %s found in %s.',
'test_class_extends' => '%s must extend Unit_Test_Case.',
'no_tests_found' => 'No tests found',
'score' => 'Score',
'total' => 'Total',
'passed' => 'Passed',
'failed' => 'Failed',
'error' => 'Error',
'errors' => 'Errors',
'line' => 'line',
'assert_true' => 'assert_true: Expected true, but was given (%s) %s.',
'assert_true_strict' => 'assert_true_strict: Expected (boolean) true, but was given (%s) %s.',
'assert_false' => 'assert_false: Expected false, but was given (%s) %s.',
'assert_false_strict' => 'assert_false_strict: Expected (boolean) false, but was given (%s) %s.',
'assert_equal' => 'assert_equal: Expected (%s) %s, but was given (%s) %s.',
'assert_not_equal' => 'assert_not_equal: Expected not (%s) %s, but was given (%s) %s.',
'assert_same' => 'assert_same: Expected (%s) %s, but was given (%s) %s.',
'assert_not_same' => 'assert_not_same: Expected not (%s) %s, but was given (%s) %s.',
'assert_boolean' => 'assert_boolean: Expected a boolean, but was given (%s) %s.',
'assert_not_boolean' => 'assert_not_boolean: Expected not a boolean, but was given (%s) %s.',
'assert_integer' => 'assert_integer: Expected an integer, but was given (%s) %s.',
'assert_not_integer' => 'assert_not_integer: Expected not an integer, but was given (%s) %s.',
'assert_float' => 'assert_float: Expected a float, but was given (%s) %s.',
'assert_not_float' => 'assert_not_float: Expected not a float, but was given (%s) %s.',
'assert_array' => 'assert_array: Expected an array, but was given (%s) %s.',
'assert_array_key' => 'assert_array_key: Expected a valid key, but was given (%s) %s.',
'assert_in_array' => 'assert_in_array: Expected a valid value, but was given (%s) %s.',
'assert_not_array' => 'assert_not_array: Expected not an array, but was given (%s) %s.',
'assert_object' => 'assert_object: Expected an object, but was given (%s) %s.',
'assert_not_object' => 'assert_not_object: Expected not an object, but was given (%s) %s.',
'assert_null' => 'assert_null: Expected null, but was given (%s) %s.',
'assert_not_null' => 'assert_not_null: Expected not null, but was given (%s) %s.',
'assert_empty' => 'assert_empty: Expected an empty value, but was given (%s) %s.',
'assert_not_empty' => 'assert_not_empty: Expected not an empty value, but was given (%s) %s.',
'assert_pattern' => 'assert_pattern: Expected %s to match %s.',
'assert_not_pattern' => 'assert_not_pattern: Expected %s to not match %s.'
);
/**
* Sets the test path(s), runs the tests inside and stores the results.
*
Expand Down Expand Up @@ -207,7 +249,7 @@ public function report($hide_passed = NULL)
{
// No tests found
if (empty($this->results))
return Kohana::lang('unit_test.no_tests_found');
return sprintf(self::$lang['unit_test.no_tests_found']);

// Hide passed tests from the report?
$hide_passed = (bool) (($hide_passed !== NULL) ? $hide_passed : Kohana::config('unit_test.hide_passed', FALSE, FALSE));
Expand Down Expand Up @@ -259,127 +301,127 @@ abstract class Unit_Test_Case {
public function assert_true($value, $debug = NULL)
{
if ($value != TRUE)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_true'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_true_strict($value, $debug = NULL)
{
if ($value !== TRUE)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true_strict', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_true_strict'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_false($value, $debug = NULL)
{
if ($value != FALSE)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_false'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_false_strict($value, $debug = NULL)
{
if ($value !== FALSE)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false_strict', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_false_strict'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_equal($expected, $actual, $debug = NULL)
{
if ($expected != $actual)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_equal', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);

return $this;
}

public function assert_not_equal($expected, $actual, $debug = NULL)
{
if ($expected == $actual)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_equal', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);

return $this;
}

public function assert_same($expected, $actual, $debug = NULL)
{
if ($expected !== $actual)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_same', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);

return $this;
}

public function assert_not_same($expected, $actual, $debug = NULL)
{
if ($expected === $actual)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_same', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug);

return $this;
}

public function assert_boolean($value, $debug = NULL)
{
if ( ! is_bool($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_boolean', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_boolean'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_not_boolean($value, $debug = NULL)
{
if (is_bool($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_boolean', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_boolean'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_integer($value, $debug = NULL)
{
if ( ! is_int($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_integer', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_integer'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_not_integer($value, $debug = NULL)
{
if (is_int($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_integer', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_integer'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_float($value, $debug = NULL)
{
if ( ! is_float($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_float', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_float'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_not_float($value, $debug = NULL)
{
if (is_float($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_float', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_float'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_array($value, $debug = NULL)
{
if ( ! is_array($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_array', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_array'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_array_key($key, $array, $debug = NULL)
{
if ( ! array_key_exists($key, $array)) {
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_array_key', gettype($key), var_export($key, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_array_key'], gettype($key), var_export($key, TRUE)), $debug);
}

return $this;
Expand All @@ -388,7 +430,7 @@ public function assert_array_key($key, $array, $debug = NULL)
public function assert_in_array($value, $array, $debug = NULL)
{
if ( ! in_array($value, $array)) {
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_in_array', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_in_array'], gettype($value), var_export($value, TRUE)), $debug);
}

return $this;
Expand All @@ -397,71 +439,71 @@ public function assert_in_array($value, $array, $debug = NULL)
public function assert_not_array($value, $debug = NULL)
{
if (is_array($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_array', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_array'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_object($value, $debug = NULL)
{
if ( ! is_object($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_object', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_object'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_not_object($value, $debug = NULL)
{
if (is_object($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_object', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_object'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_null($value, $debug = NULL)
{
if ($value !== NULL)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_null', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_null'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_not_null($value, $debug = NULL)
{
if ($value === NULL)
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_null', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_null'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_empty($value, $debug = NULL)
{
if ( ! empty($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_empty'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_not_empty($value, $debug = NULL)
{
if (empty($value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_empty'], gettype($value), var_export($value, TRUE)), $debug);

return $this;
}

public function assert_pattern($value, $regex, $debug = NULL)
{
if ( ! is_string($value) OR ! is_string($regex) OR ! preg_match($regex, $value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug);

return $this;
}

public function assert_not_pattern($value, $regex, $debug = NULL)
{
if ( ! is_string($value) OR ! is_string($regex) OR preg_match($regex, $value))
throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug);
throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug);

return $this;
}
Expand Down

0 comments on commit 91e39f7

Please sign in to comment.