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->GetItemByName($FieldName);
40 if ($TmpField === NULL)
42 $TmpField = $Schema->AddField($FieldName, $FieldType);
44 $TmpField->IsTempItem(FALSE);
45 self::$TestFieldIds[$FieldName] = $TmpField->Id();
48 # Resource::Create() expects a user to be logged in, 49 # so log in an admin user 51 $Users = $UFactory->GetUsersWithPrivileges(
52 PRIV_RESOURCEADMIN, PRIV_COLLECTIONADMIN);
53 $UserIds = array_keys($Users);
54 $AdminUserId = array_pop($UserIds);
55 $AdminUser =
new CWUser($AdminUserId);
56 $GLOBALS[
"G_User"]->Login($AdminUser->Name(),
"", TRUE);
65 # construct the schema object 69 # drop all of the test fields 70 foreach (self::$TestFieldIds as $FieldName => $FieldId)
72 $Schema->DropField($FieldId);
74 # remove from OAIFieldMappings too 76 DELETE FROM OAIFieldMappings 77 WHERE SPTFieldId = " . addslashes($FieldId));
87 # Create test-specific objects 89 $TestResource->IsTempResource(FALSE);
91 $TestReferenceResource->IsTempResource(FALSE);
93 self::$TestFieldIds[
'TestTreeField']);
94 $TestControlledName =
new ControlledName(NULL,
"TestControlledName",
95 self::$TestFieldIds[
'TestCNameField']);
97 self::$TestFieldIds[
'TestOptionField']);
99 # Test get and set for each field 100 foreach (self::$TestFields as $FieldName => $FieldType)
102 # whether, before testing equivalence, we need to pop the 103 # returned value out of an array 104 $BeforeTestArrayShift = FALSE;
106 # if we're testing the object return, this is the object we'll compare it to. 112 $TgtVal =
"A test title";
116 $TgtVal =
"http://testtesttest.com";
120 $TgtVal =
"I am a test paragraph.";
132 $TgtVal = date(
"Y-m-d");
133 $TestObject =
new Date(strval($TgtVal));
134 $TestObjectType =
'Date';
135 $TestFunctionName =
'BeginDate';
136 $TestFunctionArguments = NULL;
140 $TgtVal = date(
"Y-m-d H:i:s", strtotime($TgtVal));
145 $TgtVal[$TestClassification->Id()] =
"TestClassification";
146 $TestObject = $TestClassification;
147 $TestObjectType =
'Classification';
148 $TestFunctionName =
'FullName';
149 $TestFunctionArguments = NULL;
150 $BeforeTestArrayShift = TRUE;
155 $TgtVal[$TestControlledName->Id()] =
"TestControlledName";
156 $TestObject = $TestControlledName;
157 $TestObjectType =
'ControlledName';
158 $TestFunctionName =
'Name';
159 $TestFunctionArguments = NULL;
160 $BeforeTestArrayShift = TRUE;
165 $TgtVal[$TestOptionCName->Id()] =
"TestOptionCName";
166 $TestObject = $TestOptionCName;
167 $TestObjectType =
'ControlledName';
168 $TestFunctionName =
'Name';
169 $TestFunctionArguments = NULL;
170 $BeforeTestArrayShift = TRUE;
174 $TestObject =
new CWUser(1);
175 $TgtVal = array( 1 => $TestObject->Name() );
176 $TestObjectType =
'CWUser';
177 $TestFunctionName =
'Id';
178 $TestFunctionArguments = NULL;
179 $BeforeTestArrayShift = TRUE;
189 $TestObject = $TestReferenceResource;
191 $TgtVal[$TestReferenceResource->Id()] = $TestReferenceResource->Id();
192 $TestFunctionName =
'Id';
193 $TestObjectType =
'Resource';
194 $TestFunctionArguments = NULL;
195 $BeforeTestArrayShift = TRUE;
199 throw new Exception(
"Data type not handled.");
204 # set the value on the test resource 205 $TestResource->Set($FieldName, $TgtVal);
207 # assert the default get returns the expected value 208 $this->assertEquals($TgtVal, $TestResource->Get($FieldName));
210 if (isset($TestObject))
212 $ReturnedObject = $TestResource->Get($FieldName, TRUE);
214 if ($BeforeTestArrayShift)
216 $ReturnedObject = array_shift($ReturnedObject);
219 $array_for_test_object = array($TestObject, $TestFunctionName);
220 $array_for_returned_object = array($ReturnedObject, $TestFunctionName);
222 $this->assertEquals(call_user_func(
223 $array_for_returned_object, $TestFunctionArguments),
224 call_user_func($array_for_test_object, $TestFunctionArguments));
226 $this->assertInstanceOf($TestObjectType, $ReturnedObject);
231 # Clean up function-specific objects. 232 $TestResource->Delete();
233 $TestReferenceResource->Delete();
234 $TestClassification->Delete();
235 $TestControlledName->Delete();
236 $TestOptionCName->Delete();
static tearDownAfterClass()
After to running the tests, this function is run.
SQL database abstraction object with smart query caching.
static Create($Name, $FieldId, $ParentId=NULL)
Add new classification to the hierarchy.
Metadata type representing non-hierarchical controlled vocabulary values.
static setUpBeforeClass()
Prior to running any of the tests, this function is run.
CWIS-specific user factory class.
static Create($SchemaId)
Create a new resource.
CWIS-specific user class.
testGetandSet()
This function exercises the Resource get and set methods for each Metadata types using the fields cre...