Completed
Push — master ( 1a684b...f7cbf1 )
by Christian
03:21 queued 14s
created

it_creates_statement_voiding_itself()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Xabbuh\XApi\Model;
13
14
use PhpSpec\ObjectBehavior;
15
use Xabbuh\XApi\Model\Activity;
16
use Xabbuh\XApi\Model\Agent;
17
use Xabbuh\XApi\Model\Group;
18
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
19
use Xabbuh\XApi\Model\Statement;
20
use Xabbuh\XApi\Model\Verb;
21
22
class StatementSpec extends ObjectBehavior
23
{
24
    function let()
25
    {
26
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
27
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
28
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
29
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object);
30
    }
31
32
    function it_creates_reference_to_itself()
33
    {
34
        $reference = $this->getStatementReference();
35
        $reference->shouldBeAnInstanceOf('Xabbuh\XApi\Model\StatementReference');
36
        $reference->getStatementId()->shouldReturn('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
37
    }
38
39
    function it_creates_statement_voiding_itself()
40
    {
41
        $voidingActor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
42
        $voidingStatement = $this->getVoidStatement($voidingActor);
43
        $voidingStatement->getActor()->shouldBe($voidingActor);
44
        $voidingStatement->getVerb()->getId()->shouldReturn('http://adlnet.gov/expapi/verbs/voided');
45
46
        $voidedStatement = $voidingStatement->getObject();
47
        $voidedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\StatementReference');
48
        $voidedStatement->getStatementId()->shouldReturn('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
49
    }
50
51
    function it_can_be_authorized()
52
    {
53
        $authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
54
        $authorizedStatement = $this->withAuthority($authority);
55
        $authorizedStatement->getAuthority()->shouldReturn($authority);
56
57
        $authorizedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Statement');
58
        $authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true);
59
        $authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true);
60
        $authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true);
61
    }
62
63
    function it_overrides_existing_authority_when_it_is_authorized()
64
    {
65
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
66
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
67
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
68
        $authority = new Group(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
69
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object, null, $authority);
70
71
        $authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
72
        $authorizedStatement = $this->withAuthority($authority);
73
        $authorizedStatement->getAuthority()->shouldReturn($authority);
74
75
        $authorizedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Statement');
76
        $authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true);
77
        $authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true);
78
        $authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true);
79
        $authorizedStatement->getAuthority()->equals($this->getAuthority())->shouldBe(false);
80
    }
81
82
    function its_object_can_be_an_agent()
83
    {
84
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
85
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
86
        $object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
87
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object);
88
89
        $this->getObject()->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Object');
90
        $this->getObject()->shouldBe($object);
91
    }
92
93
    function it_does_not_equal_another_statement_with_different_timestamp()
94
    {
95
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
96
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
97
        $object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
98
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
99
100
        $otherStatement = new Statement('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object, null, null, new \DateTime('2015-07-23T12:34:02-05:00'));
101
102
        $this->equals($otherStatement)->shouldBe(false);
103
    }
104
105
    function it_equals_another_statement_with_same_timestamp()
106
    {
107
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
108
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
109
        $object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
110
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
111
112
        $otherStatement = new Statement('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
113
114
        $this->equals($otherStatement)->shouldBe(true);
115
    }
116
}
117