-
Notifications
You must be signed in to change notification settings - Fork 0
/
ting.test
150 lines (133 loc) · 6.61 KB
/
ting.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Test to ensure that ting objects is available through ding_entity.
*/
class TingEntityTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Ting via Ding entity',
'description' => 'Test that getting a ting object works.',
'group' => 'Ding! - Ting',
);
}
function setUp() {
$this->profile = 'minimal';
parent::setUp(array('ding_entity', 'ting', 'nanosoap'));
variable_set('ting_agency', '100200');
variable_set('ting_search_url', 'http://opensearch.addi.dk/next_2.0/');
variable_set('ting_recommendation_url', 'http://openadhl.addi.dk/1.1/');
variable_set('ting_search_profile', 'opac');
}
/**
* Test that getting a ting object works.
*/
function testTingEntity() {
$exists = module_exists('ding_entity');
// Bit of sanity checking.
$this->assertTrue($exists, 'Ding entity is enabled.');
$type = ding_entity_info('ding_entity');
$this->assertEqual($type['entity_type'], 'ting_object', 'Entity type is right.');
$entity = ding_entity_load('100200:22252852');
$this->assertTrue(is_object($entity), 'Entity is an object.');
$this->assertEqual(get_class($entity), 'TingEntity', 'Entity is a TingEntity.');
$this->assertEqual($entity->title, 'Harry Potter og De Vises Sten', 'Entity has proper title.');
$expected = array(
'150016:rowling00' => array('dbcaddi:hasCreatorDescription', 'Joanne K. Rowling'),
'870976:30179811' => array('dbcaddi:hasReview', 'Lektørudtalelse'),
'870976:3017982X' => array('dbcaddi:hasReview', 'Lektørudtalelse'),
'150012:120447' => array('dbcaddi:hasSubjectDescription', 'magi'),
'_BASEURL_url_ctx_fmt=info:ofi/fmt:kev:mtx:ctx&ctx_ver=Z39.88-2004&rft_val_fmt=info:ofi/fmt:kev:mtx:book&rft.btitle=Harry+Potter+og+De+Vises+Sten&rft.aulast=Rowling&rft.aufirst=Joanne+K.&rft.auinit=JK&rft.date=1998&rft.isbn=87-00-34654-3&rft.pub=Gyldendal&rft.genre=book' => array('dbcaddi:hasOpenUrl', NULL),
'870971:84620998' => array('dbcaddi:hasReview', 'Anmeldelse'),
'870971:84621021' => array('dbcaddi:hasReview', 'Anmeldelse'),
'870971:84732737' => array('dbcaddi:hasReview', 'Anmeldelse'),
'870971:84758469' => array('dbcaddi:hasReview', 'Anmeldelse'),
);
$rels_check = TRUE;
foreach ($entity->relations as $rel) {
if (isset($expected[$rel->uri])) {
$title = NULL;
if (isset($rel->object) && $rel->object->title) {
$title = $rel->object->title;
}
$t = $expected[$rel->uri] == array($rel->type, $title);
if (!$t) {
debug($rel->object->title);
debug(array($expected[$rel->uri], array($rel->type, $title)));
}
$rels_check = $rels_check && $t;
unset($expected[$rel->uri]);
}
else {
$this->fail(t('Unexpected relationship @type @uri', array('@type' => $rel->type, '@uri' => $rel->uri)));
}
}
$this->assertTrue(empty($expected), 'No unexpected relations.');
$this->assertTrue($rels_check, 'Relations look OK.');
}
/**
* Test that getting a ting collection works.
*/
function testTingCollectionEntity() {
$type = ding_entity_info('ding_entity_collection');
$this->assertEqual($type['entity_type'], 'ting_collection', 'Collection type is right.');
$entity = ding_entity_collection_load('100200:22252852');
$this->assertTrue(is_object($entity), 'Collection is an object.');
$this->assertEqual(get_class($entity), 'TingCollection', 'Collection is a TingCollection.');
$this->assertEqual($entity->title, 'Harry Potter og De Vises Sten', 'Collection has proper title.');
$this->assertTrue(is_array($entity->entities), 'Collection has an array.');
// Check entities.
$all_entities = TRUE;
$entities = array();
foreach ($entity->entities as $sub_entity) {
$all_entities = $all_entities && (get_class($sub_entity) == 'TingEntity');
$entities[$sub_entity->id] = $sub_entity;
}
$expected_ids = array (
'100200:22252852',
'100200:22513354',
'100200:22629344',
'100200:23195151',
'100200:24168638',
'100200:27638708',
'100200:42042455',
'100200:42388173',
);
$gotten_ids = array_keys($entities);
sort($gotten_ids);
$this->assertEqual($gotten_ids, $expected_ids, 'Got the expected entity ids.');
// Check random entity properties.
$this->assertEqual($entities['100200:22252852']->title, 'Harry Potter og De Vises Sten', 'Entity title OK.');
$this->assertEqual($entities['100200:22252852']->abstract, 'Den 11-årige forældreløse dreng Harry Potter bliver adopteret af sin onkel og tante som ikke bryder sig om ham. Han har trolddomsblod i årerne og bliver optaget på en skole for trolddomskyndige. Her får han nye venner og fjender', 'Entity abstract OK.');
$this->assertEqual($entities['100200:22629344']->creators, array('Joanne K. Rowling'), 'Entity author OK.');
$this->assertEqual($entities['100200:22629344']->type, 'Bog', 'Entity type OK.');
$this->assertEqual($entities['100200:23195151']->language, 'Dansk', 'Entity language OK.');
$subjects = $entities['100200:23195151']->subjects;
sort($subjects);
$this->assertEqual($subjects, array('eventyrlige fortællinger', 'magi', 'troldmænd' ), 'Entity subjects OK.');
$this->assertEqual($entities['100200:24168638']->title, 'Harry Potter og De Vises Sten', 'Entity title OK.');
$this->assertEqual($entities['100200:24168638']->provider_id, '24168638', 'Entity provider_id OK.');
$this->assertTrue($all_entities, 'Entities is TingEntities.');
}
/**
* Test for regressions.
*/
function testRegression() {
// Bug fixed: Clicking on the lydbog type in a collection would show the
// book object.
// Harry Potter og dødsregalierne
$entity = ding_entity_collection_load('100200:26917921');
$this->assertTrue(is_object($entity), 'Collection is an object.');
$this->assertEqual(get_class($entity), 'TingCollection', 'Collection is a TingCollection.');
$this->assertEqual($entity->title, 'Harry Potter og dødsregalierne', 'We got the proper collection.');
foreach ($entity->entities as $sub_entity) {
$id = $sub_entity->id;
// Clear request cache.
drupal_static_reset('ting_cache_set');
$new_entity = ding_entity_load($id);
// Check that the ids match.
$this->assertEqual($sub_entity->id, $new_entity->id, 'Re-fetching the sub-object returns an object with the same id.');
// Check that the objects is of the same type.
$this->assertEqual($sub_entity->type, $new_entity->type, 'Re-fetching the sub-object returns an object with the same type.');
}
}
}