-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathStatementBaseTest.php
More file actions
174 lines (139 loc) · 5.51 KB
/
Copy pathStatementBaseTest.php
File metadata and controls
174 lines (139 loc) · 5.51 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/*
Copyright 2016 Rustici Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace TinCanTest;
use PHPUnit\Framework\TestCase;
use TinCan\StatementBase;
use TinCan\SubStatement;
use TinCan\Verb;
use TinCan\Agent;
use TinCan\Context;
use TinCan\Result;
class StubStatementBase extends StatementBase {}
class StatementBaseTest extends TestCase {
public function testInstantiation() {
$obj = new StubStatementBase();
}
public function testSetTargetAsSAgent() {
$obj = new StubStatementBase();
$ss = [
'objectType' => 'Agent'
];
$obj->setTarget($ss);
$this->assertInstanceOf('TinCan\Agent', $obj->getTarget());
}
public function testSetTargetAsGroup() {
$obj = new StubStatementBase();
$ss = [
'objectType' => 'Group'
];
$obj->setTarget($ss);
$this->assertInstanceOf('TinCan\Group', $obj->getTarget());
}
public function testSetTargetAsSubStatement() {
$obj = new StubStatementBase();
$ss = [
'objectType' => 'SubStatement'
];
$obj->setTarget($ss);
$this->assertInstanceOf('TinCan\SubStatement', $obj->getTarget());
}
public function testSetTargetInvalidArgumentException() {
$badObjectType = 'imABadObjectType';
$this->setExpectedException(
"InvalidArgumentException",
"arg1 must implement the StatementTargetInterface objectType not recognized:$badObjectType"
);
$obj = new StubStatementBase();
$ss = [
'objectType' => $badObjectType
];
$obj->setTarget($ss);
}
public function testSetActorAsGroup() {
$obj = new StubStatementBase();
$ss = [
'objectType' => 'Group'
];
$obj->setActor($ss);
$this->assertInstanceOf('TinCan\Group', $obj->getActor());
}
public function testSetTimestampInvalidArgumentException() {
$this->setExpectedException(
"InvalidArgumentException",
'type of arg1 must be string or DateTime'
);
$obj = new StubStatementBase();
$obj->setTimestamp(1);
}
/**
* @dataProvider statementPropertyValueProvider
*/
public function testCompareWithSignaturePropertyMissing($property, $value) {
$signature = new \stdClass;
$setMethodName = 'set' . ucfirst($property);
$obj = new StubStatementBase();
$obj->$setMethodName($value);
$result = $obj->compareWithSignature($signature);
$this->assertFalse($result['success']);
$this->assertEquals("Comparison of $property failed: value not in signature", $result['reason']);
$obj = new StubStatementBase();
$signature->$property = $value;
$result = $obj->compareWithSignature($signature);
$this->assertFalse($result['success']);
$this->assertEquals("Comparison of $property failed: value not in this", $result['reason']);
}
public function statementPropertyValueProvider() {
return [
['actor', new Agent()],
['verb', new Verb()],
['target', new Agent()],
['context', new Context()],
['result', new Result()],
];
}
public function testCompareWithSignatureTimestampMissing() {
$timestamp = "2004-02-12T15:19:21+00:00";
$signature = new \stdClass;
$obj = new StubStatementBase();
$obj->setTimestamp($timestamp);
$result = $obj->compareWithSignature($signature);
$this->assertFalse($result['success']);
$this->assertEquals("Comparison of timestamp failed: value not in signature", $result['reason']);
$obj = new StubStatementBase();
$signature->timestamp = $timestamp;
$result = $obj->compareWithSignature($signature);
$this->assertFalse($result['success']);
$this->assertEquals("Comparison of timestamp failed: value not in this", $result['reason']);
}
public function testCompareWithSignatureTimestampNotEqual() {
$timestamp = "2004-02-12T15:19:21+00:00";
$signature = new \stdClass;
$obj = new StubStatementBase();
$obj->setTimestamp($timestamp);
$signature->timestamp = "2005-02-12T15:19:21+00:00";
$result = $obj->compareWithSignature($signature);
$this->assertFalse($result['success']);
$this->assertEquals("Comparison of timestamp failed: value is not the same", $result['reason']);
//Now check with microseconds.
$timestamp = "2012-07-08 11:14:15.638276";
$obj = new StubStatementBase();
$obj->setTimestamp($timestamp);
$signature->timestamp = "2012-07-08 11:14:15.638286";
$dt = new \DateTime($timestamp);
$dt2 = new \DateTime($signature->timestamp);
$result = $obj->compareWithSignature($signature);
$this->assertFalse($result['success']);
$this->assertEquals("Comparison of timestamp failed: value is not the same", $result['reason']);
}
}