11 parent::__construct($MockItemId);
16 $MockItemValues = array(
17 "MockItemName" =>
"Fake Item",
18 "DateCreated" =>
"1989-01-23 12:34:56",
20 "DateLastModified" =>
"1998-07-06 05:04:32",
21 "LastModifiedBy" => 1);
23 $MockItem = parent::CreateWithValues($MockItemValues);
38 # construct MockItem with invalid Id 42 $this->assertTrue(FALSE,
"Exception not thrown on invalid Id");
46 $this->assertEquals(get_class($E),
"InvalidArgumentException",
47 "Testing constructing MockItem with invalid Id");
52 $this->assertEquals($Mock->Id(), 1,
"Testing Id()");
53 $this->assertEquals($Mock->GetCanonicalId($Mock->Id()), 1,
54 "Testing GetCanonicalId()");
56 $this->assertEquals($Mock->Name(),
"Fake Item",
"Testing getting Name()");
57 $this->assertEquals($Mock->Name(
"New Name"),
"New Name",
58 "Testing setting Name()");
60 $this->assertEquals($Mock->DateCreated(),
"1989-01-23 12:34:56",
61 "Testing getting DateCreated()");
62 $this->assertEquals($Mock->DateCreated(
"1901-12-31 12:59:45"),
63 "1901-12-31 12:59:45",
"Testing setting DateCreated()");
65 $this->assertEquals($Mock->CreatedBy(), 1,
"Testing getting CreatedBy()");
66 $this->assertEquals($Mock->CreatedBy(2), 2,
"Testing setting CreatedBy()");
69 $this->assertEquals($Mock->DateLastModified(),
"1998-07-06 05:04:32",
70 "Testing getting DateLastModified()");
71 $this->assertEquals($Mock->DateLastModified($DateNow),
72 $DateNow,
"Testing setting DateLastModified()");
74 $this->assertEquals($Mock->LastModifiedBy(), 1,
75 "Testing getting LastModifiedBy()");
76 $this->assertEquals($Mock->LastModifiedBy(2), 2,
77 "Testing setting LastModifiedBy()");
79 $this->assertEquals($Mock->ItemExists(NULL), FALSE,
80 "Testing ItemExists() with input NULL");
81 $this->assertEquals($Mock->ItemExists($Mock->Id()), TRUE,
82 "Testing ItemExists() with valid Id");
83 $this->assertEquals($Mock->ItemExists($Mock->Id() + 1), FALSE,
84 "Testing ItemExists() with invalid Id");
85 $this->assertEquals($Mock->ItemExists($Mock), TRUE,
86 "Testing ItemExists() with ItemMock object");
88 # test ItemExists() for a non-Item object 91 $Directory = dir(
"objects/tests");
93 $this->assertTrue(FALSE,
94 "Exception not thrown on invalid ItemExists() call");
98 $this->assertEquals(get_class($E),
"Exception",
99 "Testing ItemExists() in ItemMock with Directory object");
102 # test ItemExists() for another Item child type 106 $this->assertTrue(FALSE,
107 "Exception not thrown on invalid ItemExists() call");
111 $this->assertEquals(get_class($E),
"Exception",
112 "Testing ItemExists() in ItemMockTwo with ItemMock object");
115 $MockItemId = $Mock->Id();
117 $this->assertEquals($Mock->ItemExists($MockItemId), FALSE,
118 "Testing ItemExists() with deleted object");
127 $DB->Query(
"CREATE TABLE MockItems ( 128 MockItemId INT NOT NULL AUTO_INCREMENT, 130 DateCreated DATETIME, 132 DateLastModified DATETIME, 134 INDEX Index_I (MockItemId) 138 $DB->Query(
"CREATE TABLE MockItemTwos ( 139 MockItemTwoId INT NOT NULL AUTO_INCREMENT, 140 MockItemTwoName TEXT, 141 DateCreated DATETIME, 143 DateLastModified DATETIME, 145 INDEX Index_I (MockItemTwoId) 157 $DB->Query(
"DROP TABLE MockItems");
158 $DB->Query(
"DROP TABLE MockItemTwos");
static tearDownAfterClass()
Destroy tables created for testing.
SQL database abstraction object with smart query caching.
Create a MockItem extending Item for testing because Item is an abstract class.
Common base class for persistent items store in database.
const SQL_DATE_FORMAT
Format to feed to date() to get SQL-compatible date/time string.
static setUpBeforeClass()
Create tables for MockItem before testing.
static ItemExists($Id)
Check whether an item exists with the specified ID.