CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ControlledName--Test.php
Go to the documentation of this file.
1 <?PHP
2
3 class ControlledName_Test extends PHPUnit_Framework_TestCase
4 {
5 protected static $TestFieldIds;
6 protected static $TestFields;
7
14 public static function setUpBeforeClass()
15 {
16 # construct the schema object
17 $Schema = new MetadataSchema(
18 MetadataSchema::SCHEMAID_DEFAULT);
19
20 self::$TestFieldIds = array();
21
22 # outline fields to be created
23 self::$TestFields = array(
24 "ControlledNameTestField" => MetadataSchema::MDFTYPE_TREE,
25 );
26
27 # create the fields
28 foreach (self::$TestFields as $FieldName => $FieldType)
29 {
30 $TmpField = $Schema->GetItemByName($FieldName);
31 if ($TmpField === NULL)
32 {
33 $TmpField = $Schema->AddField($FieldName, $FieldType);
34 }
35 $TmpField->IsTempItem(FALSE);
36 self::$TestFieldIds[$FieldName] = $TmpField->Id();
37 }
38
39 }
40
45 public static function tearDownAfterClass()
46 {
47 # construct the schema object
48 $Schema = new MetadataSchema(
49 MetadataSchema::SCHEMAID_DEFAULT);
50 $Database = new Database();
51
52 # drop all of the test fields
53 foreach (self::$TestFieldIds as $FieldName => $FieldId)
54 {
55 $Schema->DropField($FieldId);
56
57 # remove from OAIFieldMappings too
58 $Database->Query("
59 DELETE FROM OAIFieldMappings
60 WHERE SPTFieldId = " . addslashes($FieldId));
61 }
62 }
63
64
65 public function testClassification()
66 {
67 $MyId = self::$TestFieldIds['ControlledNameTestField'];
68
69 # Create a new name
70 $TestName = new ControlledName(
71 NULL, "TestName", $MyId);
72 $this->assertInstanceOf(
73 ControlledName::class, $TestName);
74 $this->assertEquals(
75 $TestName->FieldId(), $MyId);
76 $this->assertEquals(
77 $TestName->Name(), "TestName");
78 $this->assertEquals(
79 $TestName->Status(), ControlledName::STATUS_OK);
80 $this->assertEquals(
81 $TestName->InUse(), 0);
82 $this->assertEquals(
83 $TestName->GetAssociatedResources(), array() );
84
85 # look up CNID
86 $this->assertEquals(
87 array($TestName->Id()),
88 ControlledName::SearchForControlledName(
89 "TestName", $MyId));
90
91 # Create a duplicate of the name
92 $TestDup = new ControlledName(
93 NULL, "TestName", $MyId);
94 $this->assertEquals(
95 $TestDup->Status(), ControlledName::STATUS_EXISTS);
96 $this->assertEquals(
97 $TestDup->Id(), $TestName->Id() );
98
99 # Create an invalid name
100 $TestInv = new ControlledName(-5000);
101 $this->assertEquals(
102 $TestInv->Status(), ControlledName::STATUS_INVALID_ID);
103
104 # Delete a name
105 $TestName->Delete(TRUE);
106 }
107 }
MetadataSchema
Metadata schema (in effect a Factory class for MetadataField).
Definition: MetadataSchema.php:13
ControlledName\SearchForControlledName
static SearchForControlledName($ControlledName, $FieldId)
Check if the given controlled name already exists for a given field ID.
Definition: ControlledName.php:245
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
MetadataSchema\MDFTYPE_TREE
const MDFTYPE_TREE
Definition: MetadataSchema.php:27
ControlledName
Metadata type representing non-hierarchical controlled vocabulary values.
Definition: ControlledName.php:14
PHP
PHP
Definition: RSSClient--Test.php:12
MetadataSchema\SCHEMAID_DEFAULT
const SCHEMAID_DEFAULT
Definition: MetadataSchema.php:53
ControlledName_Test
Definition: ControlledName--Test.php:3
ControlledName\STATUS_OK
const STATUS_OK
Successful execution.
Definition: ControlledName.php:21
ControlledName_Test\$TestFieldIds
static $TestFieldIds
Definition: ControlledName--Test.php:5
ControlledName_Test\$TestFields
static $TestFields
Definition: ControlledName--Test.php:6
ControlledName\STATUS_INVALID_ID
const STATUS_INVALID_ID
No ControlledName exists with specified ID.
Definition: ControlledName.php:23
ControlledName_Test\tearDownAfterClass
static tearDownAfterClass()
After to running the tests, this function is run.
Definition: ControlledName--Test.php:45
ControlledName\STATUS_EXISTS
const STATUS_EXISTS
ControlledName already exists with this term.
Definition: ControlledName.php:25
ControlledName_Test\testClassification
testClassification()
Definition: ControlledName--Test.php:65
ControlledName_Test\setUpBeforeClass
static setUpBeforeClass()
Prior to running any of the tests, this function is run.
Definition: ControlledName--Test.php:14