diff options
Diffstat (limited to 'demos/sqlmap-sample/tests')
-rw-r--r-- | demos/sqlmap-sample/tests/PersonTest.php | 57 | ||||
-rw-r--r-- | demos/sqlmap-sample/tests/readme.txt | 1 | ||||
-rw-r--r-- | demos/sqlmap-sample/tests/run_tests.php | 33 | ||||
-rw-r--r-- | demos/sqlmap-sample/tests/sqlmap.xml | 13 |
4 files changed, 104 insertions, 0 deletions
diff --git a/demos/sqlmap-sample/tests/PersonTest.php b/demos/sqlmap-sample/tests/PersonTest.php new file mode 100644 index 00000000..c40bffa0 --- /dev/null +++ b/demos/sqlmap-sample/tests/PersonTest.php @@ -0,0 +1,57 @@ +<?php
+
+class PersonTest extends UnitTestCase
+{
+ function testPersonList()
+ {
+ //try it
+ $people = TMapper::instance()->queryForList("SelectAll");
+
+ //test it
+ $this->assertNotNull($people, "Person list is not returned");
+ $this->assertTrue(count($people) > 0, "Person list is empty");
+ $person = $people[0];
+ $this->assertNotNull($person, "Person not returned");
+ }
+
+ function testPersonUpdate()
+ {
+ $expect = "wei";
+ $edited = "Nah";
+
+ //get it;
+ $person = TMapper::instance()->queryForObject("Select", 1);
+
+ //test it
+ $this->assertNotNull($person);
+ $this->assertEqual($expect, $person->FirstName);
+
+ //change it
+ $person->FirstName = $edited;
+ TMapper::instance()->update("Update", $person);
+
+ //get it again
+ $person = TMapper::instance()->queryForObject("Select", 1);
+
+ //test it
+ $this->assertEqual($edited, $person->FirstName);
+
+ //change it back
+ $person->FirstName = $expect;
+ TMapper::instance()->update("Update", $person);
+ }
+
+ function testPersonDelete()
+ {
+ //insert it
+ $person = new Person;
+ $person->ID = -1;
+ TMapper::instance()->insert("Insert", $person);
+
+ //delte it
+ $count = TMapper::instance()->delete("Delete", -1);
+ $this->assertEqual(1, $count);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/tests/readme.txt b/demos/sqlmap-sample/tests/readme.txt new file mode 100644 index 00000000..c0d0afdb --- /dev/null +++ b/demos/sqlmap-sample/tests/readme.txt @@ -0,0 +1 @@ +The ''Data'' directory and ''Data/test.db'' must be writable by PHP for SQLite database to work.
\ No newline at end of file diff --git a/demos/sqlmap-sample/tests/run_tests.php b/demos/sqlmap-sample/tests/run_tests.php new file mode 100644 index 00000000..843d0a79 --- /dev/null +++ b/demos/sqlmap-sample/tests/run_tests.php @@ -0,0 +1,33 @@ +<?php
+
+//define simple test location
+define('SIMPLE_TEST', realpath('../../../tests/UnitTests/simpletest'));
+
+//define prado framework location
+define('PRADO', realpath('../../../framework'));
+
+//define directory that contains business objects
+define('MY_MODELS', realpath('../protected/business-objects'));
+
+require_once(SIMPLE_TEST.'/unit_tester.php');
+require_once(SIMPLE_TEST.'/reporter.php');
+require_once(PRADO.'/prado.php');
+require_once(MY_MODELS.'/Person.php');
+
+//supress strict warnings
+error_reporting(E_ALL);
+
+//import Data mapper
+Prado::using('System.DataAccess.SQLMap.TMapper');
+
+//Add tests
+$test = new GroupTest('SQLMap Tutorial tests');
+$test->addTestFile('PersonTest.php');
+if(SimpleReporter::inCli())
+ $reporter = new TextReporter();
+else
+ $reporter = new HtmlReporter();
+$test->run($reporter);
+
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/tests/sqlmap.xml b/demos/sqlmap-sample/tests/sqlmap.xml new file mode 100644 index 00000000..3968fab4 --- /dev/null +++ b/demos/sqlmap-sample/tests/sqlmap.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?>
+<sqlMapConfig>
+
+ <provider class="TAdodbProvider">
+ <datasource driver="sqlite" host="../protected/person-db/test.db" />
+ </provider>
+
+ <sqlMaps>
+ <sqlMap resource="../protected/person-db/person.xml"/>
+ <sqlMap resource="../protected/person-db/personHelper.xml"/>
+ </sqlMaps>
+
+</sqlMapConfig>
\ No newline at end of file |