summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoralex <>2005-11-13 09:16:34 +0000
committeralex <>2005-11-13 09:16:34 +0000
commit3d81c30a35b1b7d83f24adcfd27e390f98390096 (patch)
tree0f0162a07c499af3754dae24a7112092e6584685 /tests
parent44e58c12eaf7444bc6d109b5a8aaf6fc52b0cfdd (diff)
Finished tests cases for TPropertyValue. Some tests cases fail!
Diffstat (limited to 'tests')
-rw-r--r--tests/UnitTests/framework/common.php36
-rw-r--r--tests/UnitTests/framework/utComponent.php36
2 files changed, 67 insertions, 5 deletions
diff --git a/tests/UnitTests/framework/common.php b/tests/UnitTests/framework/common.php
index 71d6949e..bcff7a89 100644
--- a/tests/UnitTests/framework/common.php
+++ b/tests/UnitTests/framework/common.php
@@ -23,4 +23,40 @@ function __autoload($className)
error_reporting(E_ALL);
restore_error_handler();
+
+/**
+ * PradoTestCase class.
+ *
+ * Extends the simpletest UnitTestCase class to provide some fairly generic extra functionality.
+ *
+ * @author Alex Flint <alex@linium.net>
+ */
+
+class PradoUnitTestCase extends UnitTestCase {
+
+ /**
+ * Tests whether the given code results in an appropriate exception being raised.
+ * @param string the PHP code to execute. must end with a semi-colon.
+ * @param string the type of exception that should be raised.
+ * @return boolean true
+ */
+ public function assertException(string $code, string $exception) {
+ $pass = false;
+ $code = "
+try {
+ $code
+} catch ($exception \$e) {
+ \$pass = true;
+}";
+ eval($code);
+ if ($pass) {
+ $this->pass();
+ } else {
+ $this->fail("Code did not produce correct exception (wanted $exception, got something else");
+ }
+ }
+}
+
+
+
?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/utComponent.php b/tests/UnitTests/framework/utComponent.php
index 5f6248b0..b47c3de9 100644
--- a/tests/UnitTests/framework/utComponent.php
+++ b/tests/UnitTests/framework/utComponent.php
@@ -281,7 +281,10 @@ class utComponent extends UnitTestCase
*/
public function testEnsureArray()
{
-
+ $this->assertEqual(TPropertyValue::ensureArray(array()), array());
+ $this->assertEqual(TPropertyValue::ensureArray(array(1,2,3)), array(1,2,3));
+ $this->assertEqual(TPropertyValue::ensureArray("(1,2,3)"), array(1,2,3));
+ $this->assertEqual(TPropertyValue::ensureArray(""), array());
}
/**
@@ -289,7 +292,10 @@ class utComponent extends UnitTestCase
*/
public function testEnsureObject()
{
-
+ $this->assertEqual(TPropertyValue::ensureObject($this->component), $this->component);
+ $this->assertNull(TPropertyValue::ensureObject(array(1,2,3)));
+ $this->assertNull(TPropertyValue::ensureObject(1));
+ $this->assertNull(TPropertyValue::ensureObject("foo"));
}
/**
@@ -297,10 +303,30 @@ class utComponent extends UnitTestCase
*/
public function testEnsureEnum()
{
-
+ $this->assertEqual(TPropertyValue::ensureEnum("foo", array("foo", "bar", "BAR")), "foo");
+ $this->assertEqual(TPropertyValue::ensureEnum("bar", array("foo", "bar", "BAR")), "bar");
+ $this->assertEqual(TPropertyValue::ensureEnum("BAR", array("foo", "bar", "BAR")), "BAR");
+ $pass = false;
+ try {
+ $this->assertEqual(TPropertyValue::ensureEnum("xxx", array("foo", "bar", "BAR")), "BAR");
+ } catch (TInvalidDataValueException $e) {
+ $this->pass();
+ $pass = true;
+ }
+ if (!$pass) {
+ $this->fail("ensureEnun didn't raise a TInvalidDataValueException when it should have");
+ }
+ $pass = false;
+ try {
+ $this->assertEqual(TPropertyValue::ensureEnum("FOO", array("foo", "bar", "BAR")), "BAR");
+ } catch (TInvalidDataValueException $e) {
+ $this->pass();
+ $pass = true;
+ }
+ if (!$pass) {
+ $this->fail("ensureEnun didn't raise a TInvalidDataValueException when it should have");
+ }
}
-
-
}
?> \ No newline at end of file