16 # construct the schema object 19 self::$TestFieldIds = array();
21 # outline fields to be created 22 self::$TestFields = array(
37 foreach (self::$TestFields as $FieldName => $FieldType)
39 $TmpField = $Schema->AddField($FieldName, $FieldType);
40 $TmpField->IsTempItem(FALSE);
41 self::$TestFieldIds[$FieldName] = $TmpField->Id();
44 # Resource::Create() expects a user to be logged in, 46 $AdminUser =
new CWUser(1);
48 $GLOBALS[
"G_User"]->Login($AdminUser->Name(),
"", TRUE);
57 # construct the schema object 61 # drop all of the test fields 62 foreach (self::$TestFieldIds as $FieldName => $FieldId)
64 $Schema->DropField($FieldId);
66 # remove from OAIFieldMappings too 68 DELETE FROM OAIFieldMappings 69 WHERE SPTFieldId = " . addslashes($FieldId));
79 # Create test-specific objects 81 $TestResource->IsTempResource(FALSE);
83 $TestReferenceResource->IsTempResource(FALSE);
84 $TestClassification =
new Classification(NULL,
"TestClassification",
85 self::$TestFieldIds[
'TestTreeField']);
86 $TestControlledName =
new ControlledName(NULL,
"TestControlledName",
87 self::$TestFieldIds[
'TestCNameField']);
89 self::$TestFieldIds[
'TestOptionField']);
91 # Test get and set for each field 92 foreach (self::$TestFields as $FieldName => $FieldType)
94 # whether, before testing equivalence, we need to pop the 95 # returned value out of an array 96 $BeforeTestArrayShift = FALSE;
98 # if we're testing the object return, this is the object we'll compare it to. 104 $TgtVal =
"A test title";
108 $TgtVal =
"http://testtesttest.com";
112 $TgtVal =
"I am a test paragraph.";
124 $TgtVal = date(
"Y-m-d");
125 $TestObject =
new Date(strval($TgtVal));
126 $TestObjectType =
'Date';
127 $TestFunctionName =
'BeginDate';
128 $TestFunctionArguments = NULL;
132 $TgtVal = date(
"Y-m-d H:i:s", strtotime($TgtVal));
137 $TgtVal[$TestClassification->Id()] =
"TestClassification";
138 $TestObject = $TestClassification;
139 $TestObjectType =
'Classification';
140 $TestFunctionName =
'FullName';
141 $TestFunctionArguments = NULL;
142 $BeforeTestArrayShift = TRUE;
147 $TgtVal[$TestControlledName->Id()] =
"TestControlledName";
148 $TestObject = $TestControlledName;
149 $TestObjectType =
'ControlledName';
150 $TestFunctionName =
'Name';
151 $TestFunctionArguments = NULL;
152 $BeforeTestArrayShift = TRUE;
157 $TgtVal[$TestOptionCName->Id()] =
"TestOptionCName";
158 $TestObject = $TestOptionCName;
159 $TestObjectType =
'ControlledName';
160 $TestFunctionName =
'Name';
161 $TestFunctionArguments = NULL;
162 $BeforeTestArrayShift = TRUE;
166 $TestObject =
new CWUser(1);
167 $TgtVal = array( 1 => $TestObject->Name() );
168 $TestObjectType =
'CWUser';
169 $TestFunctionName =
'Id';
170 $TestFunctionArguments = NULL;
171 $BeforeTestArrayShift = TRUE;
181 $TestObject = $TestReferenceResource;
183 $TgtVal[$TestReferenceResource->Id()] = $TestReferenceResource->Id();
184 $TestFunctionName =
'Id';
185 $TestObjectType =
'Resource';
186 $TestFunctionArguments = NULL;
187 $BeforeTestArrayShift = TRUE;
191 throw new Exception(
"Data type not handled.");
196 # set the value on the test resource 197 $TestResource->Set($FieldName, $TgtVal);
199 # assert the default get returns the expected value 200 $this->assertEquals($TgtVal, $TestResource->Get($FieldName));
202 if (isset($TestObject))
204 $ReturnedObject = $TestResource->Get($FieldName, TRUE);
206 if ($BeforeTestArrayShift)
208 $ReturnedObject = array_shift($ReturnedObject);
211 $array_for_test_object = array($TestObject, $TestFunctionName);
212 $array_for_returned_object = array($ReturnedObject, $TestFunctionName);
214 $this->assertEquals(call_user_func($array_for_returned_object, $TestFunctionArguments),
215 call_user_func($array_for_test_object, $TestFunctionArguments));
217 $this->assertInstanceOf($TestObjectType, $ReturnedObject);
222 # Clean up function-specific objects. 223 $TestResource->Delete();
224 $TestReferenceResource->Delete();
225 $TestClassification->Delete();
226 $TestControlledName->Delete();
227 $TestOptionCName->Delete();
static tearDownAfterClass()
After to running the tests, this function is run.
SQL database abstraction object with smart query caching.
Metadata type representing non-hierarchical controlled vocabulary values.
static setUpBeforeClass()
Prior to running any of the tests, this function is run.
static Create($SchemaId)
Create a new resource.
Metadata type representing hierarchical ("Tree") controlled vocabulary values.
CWIS-specific user class.
testGetandSet()
This function exercises the Resource get and set methods for each Metadata types using the fields cre...