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 "TestClassification", self::$TestFieldIds[
'TestTreeField']);
95 "TestControlledName", self::$TestFieldIds[
'TestCNameField']);
97 "TestOptionCName", self::$TestFieldIds[
'TestOptionField']);
99 # Test get and set for each field 100 foreach (self::$TestFieldIds as $FieldName => $FieldId)
104 # whether, before testing equivalence, we need to pop the 105 # returned value out of an array 106 $BeforeTestArrayShift = FALSE;
108 # if we're testing the object return, this is the object we'll compare it to. 111 switch ($Field->Type())
114 $TgtVal =
"A test title";
118 $TgtVal =
"http://testtesttest.com";
122 $TgtVal =
"I am a test paragraph.";
134 $TgtVal = date(
"Y-m-d");
135 $TestObject =
new Date(strval($TgtVal));
136 $TestObjectType =
'Date';
137 $TestFunctionName =
'BeginDate';
138 $TestFunctionArguments = NULL;
142 $TgtVal = date(
"Y-m-d H:i:s");
147 $TgtVal[$TestClassification->Id()] =
"TestClassification";
148 $TestObject = $TestClassification;
149 $TestObjectType =
'Classification';
150 $TestFunctionName =
'FullName';
151 $TestFunctionArguments = NULL;
152 $BeforeTestArrayShift = TRUE;
157 $TgtVal[$TestControlledName->Id()] =
"TestControlledName";
158 $TestObject = $TestControlledName;
159 $TestObjectType =
'ControlledName';
160 $TestFunctionName =
'Name';
161 $TestFunctionArguments = NULL;
162 $BeforeTestArrayShift = TRUE;
167 $TgtVal[$TestOptionCName->Id()] =
"TestOptionCName";
168 $TestObject = $TestOptionCName;
169 $TestObjectType =
'ControlledName';
170 $TestFunctionName =
'Name';
171 $TestFunctionArguments = NULL;
172 $BeforeTestArrayShift = TRUE;
176 $UserId = $GLOBALS[
"G_User"]->Id();
177 $TestObject =
new CWUser($UserId);
178 $TgtVal = array( $UserId => $TestObject->Name() );
179 $TestObjectType =
'CWUser';
180 $TestFunctionName =
'Id';
181 $TestFunctionArguments = NULL;
182 $BeforeTestArrayShift = TRUE;
192 $TestObject = $TestReferenceResource;
194 $TgtVal[$TestReferenceResource->Id()] = $TestReferenceResource->Id();
195 $TestFunctionName =
'Id';
196 $TestObjectType =
'Resource';
197 $TestFunctionArguments = NULL;
198 $BeforeTestArrayShift = TRUE;
202 throw new Exception(
"Data type not handled.");
207 # set the value on the test resource 208 $TestResource->Set($Field, $TgtVal);
210 # assert the default get returns the expected value 212 "MetadataSchema", $Field->Type(),
"MDFTYPE_");
213 $this->assertEquals($TgtVal, $TestResource->Get($Field),
214 "Check that value returned by Get() matches for field type " 217 $RCopy =
new Resource($TestResource->Id());
218 $this->assertEquals($TgtVal, $RCopy->Get($Field),
219 "Check that value returned by Get() matches for field type w/ new resource" 222 if (isset($TestObject))
224 $ReturnedObject = $TestResource->
Get($Field, TRUE);
226 if ($BeforeTestArrayShift)
228 $ReturnedObject = array_shift($ReturnedObject);
231 $array_for_test_object = array($TestObject, $TestFunctionName);
232 $array_for_returned_object = array($ReturnedObject, $TestFunctionName);
234 $this->assertEquals(call_user_func(
235 $array_for_returned_object, $TestFunctionArguments),
236 call_user_func($array_for_test_object, $TestFunctionArguments));
238 $this->assertInstanceOf($TestObjectType, $ReturnedObject);
241 # clear the value from the field 242 $TestResource->Clear($Field);
244 switch ($Field->Type())
271 throw new Exception(
"Data type not handled.");
276 $this->assertEquals($TgtVal, $TestResource->Get($Field));
278 $RCopy =
new Resource($TestResource->Id());
279 $this->assertEquals($TgtVal, $RCopy->Get($Field),
280 "Check that value returned by Get() matches for field type w/ new resource" 284 # Clean up function-specific objects. 286 $TestReferenceResource->Delete();
287 $TestClassification->Delete();
288 $TestControlledName->Delete();
289 $TestOptionCName->Delete();
static tearDownAfterClass()
After to running the tests, this function is run.
static Create($Term, $FieldId)
Create a new empty ControlledName if it's not already present.
SQL database abstraction object with smart query caching.
static Create($Name, $FieldId, $ParentId=NULL)
Add new classification to the hierarchy.
static setUpBeforeClass()
Prior to running any of the tests, this function is run.
CWIS-specific user factory class.
Get($Field, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Retrieve value using field name or field object.
static GetConstantName($ClassName, $Value, $Prefix=NULL)
Get name (string) for constant.
Represents a "resource" in CWIS.
static Create($SchemaId)
Create a new resource.
CWIS-specific user class.
testGetSetClear()
This function exercises the Resource get and set methods for each Metadata types using the fields cre...
Delete()
Remove resource (and accompanying associations) from database and delete any associated files...