Completed
Pull Request — master (#12)
by Christian
09:01
created

StatementSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 6
dl 0
loc 71
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_creates_reference_to_itself() 0 6 1
A it_creates_statement_voiding_itself() 0 11 1
A it_can_be_authorized() 0 11 1
A it_overrides_existing_authority_when_it_is_authorized() 0 18 1
A its_object_can_be_an_agent() 0 10 1
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\Verb;
20
21
class StatementSpec extends ObjectBehavior
22
{
23
    function let()
24
    {
25
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
26
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
27
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
28
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object);
29
    }
30
31
    function it_creates_reference_to_itself()
32
    {
33
        $reference = $this->getStatementReference();
34
        $reference->shouldBeAnInstanceOf('Xabbuh\XApi\Model\StatementReference');
35
        $reference->getStatementId()->shouldReturn('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
36
    }
37
38
    function it_creates_statement_voiding_itself()
39
    {
40
        $voidingActor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
41
        $voidingStatement = $this->getVoidStatement($voidingActor);
42
        $voidingStatement->getActor()->shouldBe($voidingActor);
43
        $voidingStatement->getVerb()->getId()->shouldReturn('http://adlnet.gov/expapi/verbs/voided');
44
45
        $voidedStatement = $voidingStatement->getObject();
46
        $voidedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\StatementReference');
47
        $voidedStatement->getStatementId()->shouldReturn('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
48
    }
49
50
    function it_can_be_authorized()
51
    {
52
        $authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
53
        $authorizedStatement = $this->withAuthority($authority);
54
        $authorizedStatement->getAuthority()->shouldReturn($authority);
55
56
        $authorizedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Statement');
57
        $authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true);
58
        $authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true);
59
        $authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true);
60
    }
61
62
    function it_overrides_existing_authority_when_it_is_authorized()
63
    {
64
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
65
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
66
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
67
        $authority = new Group(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
68
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object, null, $authority);
69
70
        $authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
71
        $authorizedStatement = $this->withAuthority($authority);
72
        $authorizedStatement->getAuthority()->shouldReturn($authority);
73
74
        $authorizedStatement->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Statement');
75
        $authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true);
76
        $authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true);
77
        $authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true);
78
        $authorizedStatement->getAuthority()->equals($this->getAuthority())->shouldBe(false);
79
    }
80
81
    function its_object_can_be_an_agent()
82
    {
83
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
84
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
85
        $object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
86
        $this->beConstructedWith('39e24cc4-69af-4b01-a824-1fdc6ea8a3af', $actor, $verb, $object);
87
88
        $this->getObject()->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Object');
89
        $this->getObject()->shouldBe($object);
90
    }
91
}
92