Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Account;
use Xabbuh\XApi\Model\IRL;
class AccountSpec extends ObjectBehavior
{
function its_properties_can_be_read()
{
$this->beConstructedWith('test', IRL::fromString('https://tincanapi.com'));
$this->getName()->shouldReturn('test');
$this->getHomePage()->equals(IRL::fromString('https://tincanapi.com'))->shouldReturn(true);
}
function it_is_not_equal_to_other_account_if_name_are_not_equal()
{
$this->beConstructedWith('foo', IRL::fromString('https://tincanapi.com'));
$this->equals(new Account('bar', IRL::fromString('https://tincanapi.com')))->shouldReturn(false);
}
function it_is_not_equal_to_other_account_if_home_pages_are_not_equal()
{
$this->beConstructedWith('test', IRL::fromString('https://tincanapi.com'));
$this->equals(new Account('test', IRL::fromString('https://tincanapi.com/OAuth/Token')))->shouldReturn(false);
}
function it_is_equal_to_other_account_if_all_properties_are_equal()
{
$this->beConstructedWith('test', IRL::fromString('https://tincanapi.com'));
$this->equals(new Account('test', IRL::fromString('https://tincanapi.com')))->shouldReturn(true);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\ActivityProfile;
use Xabbuh\XApi\Model\Document;
use Xabbuh\XApi\Model\DocumentData;
use Xabbuh\XApi\Model\IRI;
class ActivityProfileDocumentSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(new ActivityProfile('id', new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'))), new DocumentData(array(
'x' => 'foo',
'y' => 'bar',
)));
}
function it_is_a_document()
{
$this->shouldHaveType(Document::class);
}
function its_data_can_be_read()
{
$this->offsetExists('x')->shouldReturn(true);
$this->offsetGet('x')->shouldReturn('foo');
$this->offsetExists('y')->shouldReturn(true);
$this->offsetGet('y')->shouldReturn('bar');
$this->offsetExists('z')->shouldReturn(false);
}
function it_throws_exception_when_not_existing_data_is_being_read()
{
$this->shouldThrow('\InvalidArgumentException')->duringOffsetGet('z');
}
function its_data_cannot_be_manipulated()
{
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetSet('z', 'baz');
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetUnset('x');
}
}

View File

@@ -0,0 +1,33 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\StatementObject;
class ActivitySpec extends ObjectBehavior
{
function it_is_an_xapi_object()
{
$this->beConstructedWith(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->shouldHaveType(StatementObject::class);
}
function it_is_equal_with_other_activity_if_ids_are_equal_and_definitions_are_missing()
{
$this->beConstructedWith(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->equals(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')))->shouldReturn(true);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\AgentProfile;
use Xabbuh\XApi\Model\Document;
use Xabbuh\XApi\Model\DocumentData;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
class AgentProfileDocumentSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(new AgentProfile('id', new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')))), new DocumentData(array(
'x' => 'foo',
'y' => 'bar',
)));
}
function it_is_a_document()
{
$this->shouldHaveType(Document::class);
}
function its_data_can_be_read()
{
$this->offsetExists('x')->shouldReturn(true);
$this->offsetGet('x')->shouldReturn('foo');
$this->offsetExists('y')->shouldReturn(true);
$this->offsetGet('y')->shouldReturn('bar');
$this->offsetExists('z')->shouldReturn(false);
}
function it_throws_exception_when_not_existing_data_is_being_read()
{
$this->shouldThrow('\InvalidArgumentException')->duringOffsetGet('z');
}
function its_data_cannot_be_manipulated()
{
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetSet('z', 'baz');
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetUnset('x');
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Actor;
use Xabbuh\XApi\Model\Group;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
class AgentSpec extends ObjectBehavior
{
function it_is_an_actor()
{
$iri = InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'));
$this->beConstructedWith($iri);
$this->shouldHaveType(Actor::class);
}
function its_properties_can_be_read()
{
$iri = InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'));
$this->beConstructedWith($iri, 'test');
$this->getInverseFunctionalIdentifier()->shouldReturn($iri);
$this->getName()->shouldReturn('test');
}
function it_is_not_equal_to_a_group()
{
$this->beConstructedWith(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$this->equals(new Group(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))))->shouldReturn(false);
}
function it_is_not_equal_to_an_activity()
{
$this->beConstructedWith(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$this->equals(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')))->shouldReturn(false);
}
}

View File

@@ -0,0 +1,353 @@
<?php
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Attachment;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
class AttachmentSpec extends ObjectBehavior
{
function its_properties_can_be_read()
{
$display = LanguageMap::create(array('en-US' => 'Text attachment'));
$description = LanguageMap::create(array('en-US' => 'Text attachment description'));
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
$display,
$description,
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly'),
'some text content'
);
$this->getUsageType()->equals(IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'))->shouldReturn(true);
$this->getContentType()->shouldReturn('text/plain');
$this->getLength()->shouldReturn(18);
$this->getSha2()->shouldReturn('bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545');
$this->getDisplay()->shouldReturn($display);
$this->getDescription()->shouldReturn($description);
$this->getFileUrl()->equals(IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly'))->shouldReturn(true);
$this->getContent()->shouldReturn('some text content');
}
function it_throws_an_exception_when_an_attachment_does_not_contain_a_file_url_or_raw_content()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment'))
);
$this->shouldThrow('\InvalidArgumentException')->duringInstantiation();
}
function it_is_not_equal_to_other_attachment_if_usage_types_differ()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://adlnet.gov/expapi/attachments/signature'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_content_types_differ()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'application/json',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_lengths_differ()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
65556,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_sha2_hashes_differ()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'd14f1580a2cebb6f8d4a8a2fc0d13c67f970e84f8d15677a93ae95c9080df899',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_displays_differ()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'JSON attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_only_this_attachment_has_a_description()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
null,
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_only_the_other_attachment_has_a_description()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
null,
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_descriptions_are_not_equal()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-GB' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_only_this_attachment_has_a_file_url()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
null,
'some text content'
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_only_the_other_attachment_has_a_file_url()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
null,
'some text content'
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_not_equal_to_other_attachment_if_file_urls_are_not_equal()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/signature')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/certificate')
);
$this->equals($attachment)->shouldReturn(false);
}
function it_is_equal_to_other_attachment_if_all_properties_are_equal()
{
$this->beConstructedWith(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$this->equals($attachment)->shouldReturn(true);
}
}

View File

@@ -0,0 +1,154 @@
<?php
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\IRI;
class ContextActivitiesSpec extends ObjectBehavior
{
public function its_properties_are_empty_by_default()
{
$this->getParentActivities()->shouldBeNull();
$this->getGroupingActivities()->shouldBeNull();
$this->getCategoryActivities()->shouldBeNull();
$this->getOtherActivities()->shouldBeNull();
}
public function it_returns_a_new_instance_with_parent_activities()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$contextActivities = $this->withAddedParentActivity($activity);
$this->getParentActivities()->shouldBeNull();
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$parentActivities = $contextActivities->getParentActivities();
$parentActivities->shouldBeArray();
$parentActivities->shouldHaveCount(1);
$parentActivities->shouldHaveKeyWithValue(0, $activity);
}
public function it_returns_a_new_instance_with_parent_activities_removed()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith(array($activity));
$contextActivities = $this->withoutParentActivities();
$parentActivities = $this->getParentActivities();
$parentActivities->shouldBeArray();
$parentActivities->shouldHaveCount(1);
$parentActivities->shouldHaveKeyWithValue(0, $activity);
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$contextActivities->getParentActivities()->shouldBeNull();
}
public function it_returns_a_new_instance_with_grouping_activities()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$contextActivities = $this->withAddedGroupingActivity($activity);
$this->getGroupingActivities()->shouldBeNull();
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$groupingActivities = $contextActivities->getGroupingActivities();
$groupingActivities->shouldBeArray();
$groupingActivities->shouldHaveCount(1);
$groupingActivities->shouldHaveKeyWithValue(0, $activity);
}
public function it_returns_a_new_instance_with_grouping_activities_removed()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith(null, array($activity));
$contextActivities = $this->withoutGroupingActivities();
$groupingActivities = $this->getGroupingActivities();
$groupingActivities->shouldBeArray();
$groupingActivities->shouldHaveCount(1);
$groupingActivities->shouldHaveKeyWithValue(0, $activity);
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$contextActivities->getGroupingActivities()->shouldBeNull();
}
public function it_returns_a_new_instance_with_category_activities()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$contextActivities = $this->withAddedCategoryActivity($activity);
$this->getCategoryActivities()->shouldBeNull();
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$CategoryActivities = $contextActivities->getCategoryActivities();
$CategoryActivities->shouldBeArray();
$CategoryActivities->shouldHaveCount(1);
$CategoryActivities->shouldHaveKeyWithValue(0, $activity);
}
public function it_returns_a_new_instance_with_category_activities_removed()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith(null, null, array($activity));
$contextActivities = $this->withoutCategoryActivities();
$categoryActivities = $this->getCategoryActivities();
$categoryActivities->shouldBeArray();
$categoryActivities->shouldHaveCount(1);
$categoryActivities->shouldHaveKeyWithValue(0, $activity);
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$contextActivities->getCategoryActivities()->shouldBeNull();
}
public function it_returns_a_new_instance_with_other_activities()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$contextActivities = $this->withAddedOtherActivity($activity);
$this->getOtherActivities()->shouldBeNull();
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$otherActivities = $contextActivities->getOtherActivities();
$otherActivities->shouldBeArray();
$otherActivities->shouldHaveCount(1);
$otherActivities->shouldHaveKeyWithValue(0, $activity);
}
public function it_returns_a_new_instance_with_other_activities_removed()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith(null, null, null, array($activity));
$contextActivities = $this->withoutOtherActivities();
$otherActivities = $this->getOtherActivities();
$otherActivities->shouldBeArray();
$otherActivities->shouldHaveCount(1);
$otherActivities->shouldHaveKeyWithValue(0, $activity);
$contextActivities->shouldNotBe($this);
$contextActivities->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\ContextActivities');
$contextActivities->getOtherActivities()->shouldBeNull();
}
}

View File

@@ -0,0 +1,212 @@
<?php
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Context;
use Xabbuh\XApi\Model\ContextActivities;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\Group;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Model\StatementReference;
class ContextSpec extends ObjectBehavior
{
public function its_properties_are_empty_by_default()
{
$this->getRegistration()->shouldBeNull();
$this->getInstructor()->shouldBeNull();
$this->getTeam()->shouldBeNull();
$this->getContextActivities()->shouldBeNull();
$this->getRevision()->shouldBeNull();
$this->getPlatform()->shouldBeNull();
$this->getLanguage()->shouldBeNull();
$this->getStatement()->shouldBeNull();
$this->getExtensions()->shouldBeNull();
}
public function it_returns_a_new_instance_with_registration()
{
$context = $this->withRegistration('12345678-1234-5678-8234-567812345678');
$this->getRegistration()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getRegistration()->shouldReturn('12345678-1234-5678-8234-567812345678');
}
public function it_returns_a_new_instance_with_instructor()
{
$instructor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$context = $this->withInstructor($instructor);
$this->getInstructor()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getInstructor()->shouldReturn($instructor);
}
public function it_returns_a_new_instance_with_team()
{
$team = new Group(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')), 'team');
$context = $this->withTeam($team);
$this->getTeam()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getTeam()->shouldReturn($team);
}
public function it_returns_a_new_instance_with_context_activities()
{
$contextActivities = new ContextActivities();
$context = $this->withContextActivities($contextActivities);
$this->getContextActivities()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getContextActivities()->shouldReturn($contextActivities);
}
public function it_returns_a_new_instance_with_revision()
{
$context = $this->withRevision('test');
$this->getRevision()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getRevision()->shouldReturn('test');
}
public function it_returns_a_new_instance_with_platform()
{
$context = $this->withPlatform('test');
$this->getPlatform()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getPlatform()->shouldReturn('test');
}
public function it_returns_a_new_instance_with_language()
{
$context = $this->withLanguage('en-US');
$this->getLanguage()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getLanguage()->shouldReturn('en-US');
}
public function it_returns_a_new_instance_with_statement_reference()
{
$statementReference = new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
$context = $this->withStatement($statementReference);
$this->getStatement()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getStatement()->shouldReturn($statementReference);
}
public function it_returns_a_new_instance_with_extensions()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$extensions = new Extensions($extensions);
$context = $this->withExtensions($extensions);
$this->getExtensions()->shouldBeNull();
$context->shouldNotBe($this);
$context->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Context');
$context->getExtensions()->shouldReturn($extensions);
}
function it_is_not_equal_to_other_context_if_only_this_context_has_a_team()
{
$context = $this->withTeam(new Group());
$context->equals(new Context())->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_only_the_other_context_has_a_team()
{
$otherContext = $this->withTeam(new Group());
$this->equals($otherContext)->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_teams_are_not_equal()
{
$context = $this->withTeam(new Group());
$otherContext = new Context();
$otherContext = $otherContext->withTeam(new Group(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest-group@tincanapi.com'))));
$context->equals($otherContext)->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_only_this_context_has_a_statement_reference()
{
$context = $this->withStatement(new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da')));
$context->equals(new Context())->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_only_the_other_context_has_a_statement_reference()
{
$otherContext = $this->withStatement(new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da')));
$this->equals($otherContext)->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_statement_references_are_not_equal()
{
$context = $this->withStatement(new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da')));
$otherContext = new Context();
$otherContext = $otherContext->withStatement(new StatementReference(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af')));
$context->equals($otherContext)->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_only_this_context_has_extensions()
{
$context = $this->withExtensions(new Extensions());
$context->equals(new Context())->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_only_the_other_context_has_extensions()
{
$otherContext = $this->withExtensions(new Extensions());
$this->equals($otherContext)->shouldReturn(false);
}
function it_is_not_equal_to_other_context_if_extensions_are_not_equal()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/subject'), 'Conformance Testing');
$context = $this->withExtensions(new Extensions($extensions));
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$otherContext = new Context();
$otherContext = $otherContext->withExtensions(new Extensions($extensions));
$context->equals($otherContext)->shouldReturn(false);
}
}

View File

@@ -0,0 +1,237 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
class DefinitionSpec extends ObjectBehavior
{
function its_properties_can_be_read()
{
$name = LanguageMap::create(array('en-US' => 'test'));
$description = LanguageMap::create(array('en-US' => 'test'));
$this->beConstructedWith(
$name,
$description,
IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'),
IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test')
);
$this->getName()->shouldReturn($name);
$this->getDescription()->shouldReturn($description);
$this->getType()->equals(IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'))->shouldReturn(true);
$this->getMoreInfo()->equals(IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'))->shouldReturn(true);
}
function it_can_be_empty()
{
$this->getName()->shouldReturn(null);
$this->getDescription()->shouldReturn(null);
$this->getType()->shouldReturn(null);
$this->getMoreInfo()->shouldReturn(null);
$this->equals($this->createEmptyDefinition())->shouldReturn(true);
}
public function it_returns_a_new_instance_with_name()
{
$name = new LanguageMap();
$definition = $this->withName($name);
$this->getName()->shouldBeNull();
$definition->shouldNotBe($this);
$definition->shouldBeAnInstanceOf(get_class($this->getWrappedObject()));
$definition->getName()->shouldReturn($name);
}
public function it_returns_a_new_instance_with_description()
{
$description = new LanguageMap();
$definition = $this->withDescription($description);
$this->getDescription()->shouldBeNull();
$definition->shouldNotBe($this);
$definition->shouldBeAnInstanceOf(get_class($this->getWrappedObject()));
$definition->getDescription()->shouldReturn($description);
}
public function it_returns_a_new_instance_with_type()
{
$definition = $this->withType(IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'));
$this->getType()->shouldBeNull();
$definition->shouldNotBe($this);
$definition->shouldBeAnInstanceOf(get_class($this->getWrappedObject()));
$definition->getType()->equals(IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'))->shouldReturn(true);
}
public function it_returns_a_new_instance_with_more_info()
{
$definition = $this->withMoreInfo(IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'));
$this->getMoreInfo()->shouldBeNull();
$definition->shouldNotBe($this);
$definition->shouldBeAnInstanceOf(get_class($this->getWrappedObject()));
$definition->getMoreInfo()->equals(IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'))->shouldReturn(true);
}
public function it_returns_a_new_instance_with_extensions()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$extensions = new Extensions($extensions);
$definition = $this->withExtensions($extensions);
$this->getExtensions()->shouldBeNull();
$definition->shouldNotBe($this);
$definition->shouldBeAnInstanceOf(get_class($this->getWrappedObject()));
$definition->getExtensions()->shouldReturn($extensions);
}
function it_is_different_when_names_are_omitted_and_other_definition_contains_an_empty_list_of_names()
{
$this->equals(new Definition(new LanguageMap()))->shouldReturn(false);
}
function it_is_different_when_descriptions_are_omitted_and_other_definition_contains_an_empty_list_of_descriptions()
{
$this->equals(new Definition(null, new LanguageMap()))->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_only_this_definition_has_a_type()
{
$this->beConstructedWith(null, null, IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_only_the_other_definition_has_a_type()
{
$this->beConstructedWith();
$definition = $this->createEmptyDefinition();
$definition = $definition->withType(IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'));
$this->equals($definition)->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_types_are_not_equal()
{
$this->beConstructedWith(null, null, IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'));
$definition = $this->createEmptyDefinition();
$definition = $definition->withType(IRI::fromString('http://id.tincanapi.com/activity-type/unit-test'));
$this->equals($definition)->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_only_this_definition_has_more_info()
{
$this->beConstructedWith(null, null, null, IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_only_the_other_definition_has_more_info()
{
$this->beConstructedWith();
$definition = $this->createEmptyDefinition();
$definition = $definition->withMoreInfo(IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'));
$this->equals($definition)->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_more_infos_are_not_equal()
{
$this->beConstructedWith(null, null, null, IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'));
$definition = $this->createEmptyDefinition();
$definition = $definition->withMoreInfo(IRL::fromString('https://github.com/adlnet/xAPI-Spec'));
$this->equals($definition)->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_only_this_definition_has_extensions()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$this->beConstructedWith(null, null, null, null, new Extensions($extensions));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_only_the_other_definition_has_extensions()
{
$this->beConstructedWith();
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$definition = $this->createEmptyDefinition();
$definition = $definition->withExtensions(new Extensions($extensions));
$this->equals($definition)->shouldReturn(false);
}
function it_is_not_equal_to_other_definition_if_extensions_are_not_equal()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/subject'), 'Conformance Testing');
$this->beConstructedWith(null, null, null, null, new Extensions($extensions));
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$definition = $this->createEmptyDefinition();
$definition = $definition->withExtensions(new Extensions($extensions));
$this->equals($definition)->shouldReturn(false);
}
function it_is_equal_to_other_definition_if_properties_are_equal()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$this->beConstructedWith(
LanguageMap::create(array('en-US' => 'test')),
LanguageMap::create(array('en-US' => 'test')),
IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'),
IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'),
new Extensions($extensions)
);
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$definition = $this->createEmptyDefinition();
$definition = $definition->withName(LanguageMap::create(array('en-US' => 'test')));
$definition = $definition->withDescription(LanguageMap::create(array('en-US' => 'test')));
$definition = $definition->withType(IRI::fromString('http://id.tincanapi.com/activitytype/unit-test'));
$definition = $definition->withMoreInfo(IRL::fromString('https://github.com/adlnet/xAPI_LRS_Test'));
$definition = $definition->withExtensions(new Extensions($extensions));
$this->equals($definition)->shouldReturn(true);
}
protected function createEmptyDefinition()
{
return new Definition();
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
class ExtensionsSpec extends ObjectBehavior
{
function let()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$this->beConstructedWith($extensions);
}
function its_extensions_can_be_read()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/color'), array(
'model' => 'RGB',
'value' => '#FFFFFF',
));
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/starting-position'), 1);
$this->beConstructedWith($extensions);
$this->offsetExists(IRI::fromString('http://id.tincanapi.com/extension/topic'))->shouldReturn(true);
$this->offsetGet(IRI::fromString('http://id.tincanapi.com/extension/topic'))->shouldReturn('Conformance Testing');
$this->offsetExists(IRI::fromString('http://id.tincanapi.com/extension/color'))->shouldReturn(true);
$this->offsetGet(IRI::fromString('http://id.tincanapi.com/extension/color'))->shouldReturn(array(
'model' => 'RGB',
'value' => '#FFFFFF',
));
$this->offsetExists(IRI::fromString('http://id.tincanapi.com/extension/starting-position'))->shouldReturn(true);
$this->offsetGet(IRI::fromString('http://id.tincanapi.com/extension/starting-position'))->shouldReturn(1);
$returnedExtensions = $this->getExtensions();
$returnedExtensions->shouldBeAnInstanceOf('\SplObjectStorage');
$returnedExtensions->count()->shouldReturn(3);
}
function it_throws_exception_when_keys_are_passed_that_are_not_iri_instances_during_instantiation()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRL::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$this->beConstructedWith($extensions);
$this->shouldThrow('\InvalidArgumentException')->duringInstantiation();
}
function it_throws_exception_when_keys_are_passed_that_are_not_iri_instances()
{
$this->shouldThrow('\InvalidArgumentException')->during('offsetExists', array('http://id.tincanapi.com/extension/topic'));
$this->shouldThrow('\InvalidArgumentException')->during('offsetGet', array('http://id.tincanapi.com/extension/topic'));
}
function it_throws_exception_when_not_existing_extension_is_being_read()
{
$this->shouldThrow('\InvalidArgumentException')->duringOffsetGet(IRI::fromString('z'));
}
function its_extensions_cannot_be_manipulated()
{
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetSet(IRI::fromString('z'), 'baz');
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetUnset(IRI::fromString('x'));
}
function its_not_equal_to_other_extensions_with_a_different_number_of_entries()
{
$this->equals(new Extensions())->shouldReturn(false);
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/starting-position'), 1);
$this->equals(new Extensions($extensions))->shouldReturn(false);
}
function its_not_equal_to_other_extensions_if_extension_keys_differ()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/subject'), 'Conformance Testing');
$this->equals(new Extensions($extensions))->shouldReturn(false);
}
function its_not_equal_to_other_extensions_if_extension_values_differ()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Tests');
$this->equals(new Extensions($extensions))->shouldReturn(false);
}
function its_equal_to_other_extensions_even_if_extension_names_are_in_different_order()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/color'), array(
'model' => 'RGB',
'value' => '#FFFFFF',
));
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/starting-position'), 1);
$this->beConstructedWith($extensions);
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/starting-position'), 1);
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/color'), array(
'model' => 'RGB',
'value' => '#FFFFFF',
));
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$this->equals(new Extensions($extensions))->shouldReturn(true);
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Actor;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Group;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
class GroupSpec extends ObjectBehavior
{
function it_can_be_initialized_without_an_inverse_functional_identifier()
{
$this->beConstructedWith(null, 'anonymous group');
$this->shouldBeAnInstanceOf(Group::class);
}
function it_is_an_actor()
{
$this->beConstructedWith(null, 'test');
$this->shouldHaveType(Actor::class);
}
function its_properties_can_be_read()
{
$iri = InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'));
$members = array(new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))));
$this->beConstructedWith($iri, 'test', $members);
$this->getInverseFunctionalIdentifier()->shouldReturn($iri);
$this->getName()->shouldReturn('test');
$this->getMembers()->shouldReturn($members);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\ChoiceInteractionDefinition;
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
class ChoiceInteractionDefinitionSpec extends InteractionDefinitionSpec
{
public function it_returns_a_new_instance_with_choices()
{
$choices = array(new InteractionComponent('test'));
$interaction = $this->withChoices($choices);
$this->getChoices()->shouldBeNull();
$interaction->shouldNotBe($this);
$interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\ChoiceInteractionDefinition');
$interaction->getChoices()->shouldReturn($choices);
}
function it_is_not_equal_if_only_other_interaction_has_choices()
{
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_only_this_interaction_has_choices()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_if_number_of_choices_differs()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('test'), new InteractionComponent('foo')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_choices_differ()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('foo')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('bar')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_equal_if_choices_are_equal()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(true);
}
protected function createEmptyDefinition()
{
return new ChoiceInteractionDefinition();
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\FillInInteractionDefinition;
class FillInInteractionDefinitionSpec extends InteractionDefinitionSpec
{
protected function createEmptyDefinition()
{
return new FillInInteractionDefinition();
}
}

View File

@@ -0,0 +1,81 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
use Xabbuh\XApi\Model\LanguageMap;
class InteractionComponentSpec extends ObjectBehavior
{
function its_properties_can_be_read()
{
$description = LanguageMap::create(array('en-US' => 'test'));
$this->beConstructedWith('test', $description);
$this->getId()->shouldReturn('test');
$this->getDescription()->shouldReturn($description);
}
function it_is_not_equal_with_other_interaction_component_if_ids_differ()
{
$description = LanguageMap::create(array('en-US' => 'test'));
$this->beConstructedWith('test', $description);
$interactionComponent = new InteractionComponent('Test', $description);
$this->equals($interactionComponent)->shouldReturn(false);
}
function it_is_not_equal_with_other_interaction_component_if_descriptions_differ()
{
$this->beConstructedWith('test', LanguageMap::create(array('en-US' => 'test')));
$interactionComponent = new InteractionComponent('test', LanguageMap::create(array('en-GB' => 'test')));
$this->equals($interactionComponent)->shouldReturn(false);
}
function it_is_not_equal_with_other_interaction_component_if_other_interaction_component_does_not_have_a_description()
{
$this->beConstructedWith('test', LanguageMap::create(array('en-US' => 'test')));
$interactionComponent = new InteractionComponent('test');
$this->equals($interactionComponent)->shouldReturn(false);
}
function it_is_not_equal_with_other_interaction_component_if_only_the_other_interaction_component_does_have_a_description()
{
$this->beConstructedWith('test');
$interactionComponent = new InteractionComponent('test', LanguageMap::create(array('en-US' => 'test')));
$this->equals($interactionComponent)->shouldReturn(false);
}
function it_is_equal_with_other_interaction_component_if_ids_and_descriptions_are_equal()
{
$this->beConstructedWith('test', LanguageMap::create(array('en-US' => 'test')));
$interactionComponent = new InteractionComponent('test', LanguageMap::create(array('en-US' => 'test')));
$this->equals($interactionComponent)->shouldReturn(true);
}
function it_is_equal_with_other_interaction_component_if_ids_are_equal_and_descriptions_are_not_present()
{
$this->beConstructedWith('test');
$this->equals(new InteractionComponent('test'))->shouldReturn(true);
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use spec\Xabbuh\XApi\Model\DefinitionSpec;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Interaction\InteractionDefinition;
abstract class InteractionDefinitionSpec extends DefinitionSpec
{
function it_is_a_definition()
{
$this->shouldHaveType(Definition::class);
}
function it_is_an_interaction()
{
$this->shouldHaveType(InteractionDefinition::class);
}
function it_is_not_equal_to_generic_definition()
{
$this->equals(new Definition())->shouldReturn(false);
}
function it_is_not_equal_if_only_other_interaction_has_correct_responses_pattern()
{
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withCorrectResponsesPattern(array('test'));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_only_this_interaction_has_correct_responses_pattern()
{
$this->beConstructedWith(null, null, null, null, null, array('test'));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_if_number_of_correct_responses_pattern_differs()
{
$this->beConstructedWith(null, null, null, null, null, array('test'));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withCorrectResponsesPattern(array('test', 'foo'));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_correct_responses_pattern_values_differ()
{
$this->beConstructedWith(null, null, null, null, null, array('foo'));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withCorrectResponsesPattern(array('bar'));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_equal_if_correct_responses_pattern_values_are_equal()
{
$this->beConstructedWith(null, null, null, null, null, array('test'));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withCorrectResponsesPattern(array('test'));
$this->equals($interaction)->shouldReturn(true);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
use Xabbuh\XApi\Model\Interaction\LikertInteractionDefinition;
class LikertInteractionDefinitionSpec extends InteractionDefinitionSpec
{
public function it_returns_a_new_instance_with_scale()
{
$scale = array(new InteractionComponent('test'));
$interaction = $this->withScale($scale);
$this->getScale()->shouldBeNull();
$interaction->shouldNotBe($this);
$interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\LikertInteractionDefinition');
$interaction->getScale()->shouldReturn($scale);
}
function it_is_not_equal_if_only_other_interaction_has_scale()
{
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withScale(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_only_this_interaction_has_scale()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_if_number_of_scale_differs()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withScale(array(new InteractionComponent('test'), new InteractionComponent('foo')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_scale_differ()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('foo')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withScale(array(new InteractionComponent('bar')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_equal_if_scales_are_equal()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withScale(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(true);
}
protected function createEmptyDefinition()
{
return new LikertInteractionDefinition();
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\LongFillInInteractionDefinition;
class LongFillInInteractionDefinitionSpec extends InteractionDefinitionSpec
{
protected function createEmptyDefinition()
{
return new LongFillInInteractionDefinition();
}
}

View File

@@ -0,0 +1,137 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
use Xabbuh\XApi\Model\Interaction\MatchingInteractionDefinition;
class MatchingInteractionDefinitionSpec extends InteractionDefinitionSpec
{
public function it_returns_a_new_instance_with_source()
{
$source = array(new InteractionComponent('test'));
$interaction = $this->withSource($source);
$this->getSource()->shouldBeNull();
$interaction->shouldNotBe($this);
$interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\MatchingInteractionDefinition');
$interaction->getSource()->shouldReturn($source);
}
public function it_returns_a_new_instance_with_target()
{
$target = array(new InteractionComponent('test'));
$interaction = $this->withTarget($target);
$this->getTarget()->shouldBeNull();
$interaction->shouldNotBe($this);
$interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\MatchingInteractionDefinition');
$interaction->getTarget()->shouldReturn($target);
}
function it_is_not_equal_if_only_other_interaction_has_source()
{
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSource(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_only_this_interaction_has_source()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_if_number_of_source_differs()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSource(array(new InteractionComponent('test'), new InteractionComponent('foo')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_source_differ()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('foo')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSource(array(new InteractionComponent('bar')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_equal_if_sources_are_equal()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSource(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(true);
}
function it_is_not_equal_if_only_other_interaction_has_target()
{
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withTarget(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_only_this_interaction_has_target()
{
$this->beConstructedWith(null, null, null, null, null, null, null, array(new InteractionComponent('test')));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_if_number_of_target_differs()
{
$this->beConstructedWith(null, null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withTarget(array(new InteractionComponent('test'), new InteractionComponent('foo')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_target_differ()
{
$this->beConstructedWith(null, null, null, null, null, null, null, array(new InteractionComponent('foo')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withTarget(array(new InteractionComponent('bar')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_equal_if_targets_are_equal()
{
$this->beConstructedWith(null, null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withTarget(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(true);
}
protected function createEmptyDefinition()
{
return new MatchingInteractionDefinition();
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\NumericInteractionDefinition;
class NumericInteractionDefinitionSpec extends InteractionDefinitionSpec
{
protected function createEmptyDefinition()
{
return new NumericInteractionDefinition();
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\OtherInteractionDefinition;
class OtherInteractionDefinitionSpec extends InteractionDefinitionSpec
{
protected function createEmptyDefinition()
{
return new OtherInteractionDefinition();
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
use Xabbuh\XApi\Model\Interaction\PerformanceInteractionDefinition;
class PerformanceInteractionDefinitionSpec extends InteractionDefinitionSpec
{
public function it_returns_a_new_instance_with_steps()
{
$steps = array(new InteractionComponent('test'));
$interaction = $this->withSteps($steps);
$this->getSteps()->shouldBeNull();
$interaction->shouldNotBe($this);
$interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\PerformanceInteractionDefinition');
$interaction->getSteps()->shouldReturn($steps);
}
function it_is_not_equal_if_only_other_interaction_has_steps()
{
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSteps(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_only_this_interaction_has_steps()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_if_number_of_steps_differs()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSteps(array(new InteractionComponent('test'), new InteractionComponent('foo')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_steps_differ()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('foo')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSteps(array(new InteractionComponent('bar')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_equal_if_steps_are_equal()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withSteps(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(true);
}
protected function createEmptyDefinition()
{
return new PerformanceInteractionDefinition();
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
use Xabbuh\XApi\Model\Interaction\SequencingInteractionDefinition;
class SequencingInteractionDefinitionSpec extends InteractionDefinitionSpec
{
public function it_returns_a_new_instance_with_choices()
{
$choices = array(new InteractionComponent('test'));
$interaction = $this->withChoices($choices);
$this->getChoices()->shouldBeNull();
$interaction->shouldNotBe($this);
$interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\SequencingInteractionDefinition');
$interaction->getChoices()->shouldReturn($choices);
}
function it_is_not_equal_if_only_other_interaction_has_choices()
{
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_only_this_interaction_has_choices()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$this->equals($this->createEmptyDefinition())->shouldReturn(false);
}
function it_is_not_equal_if_number_of_choices_differs()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('test'), new InteractionComponent('foo')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_not_equal_if_choices_differ()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('foo')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('bar')));
$this->equals($interaction)->shouldReturn(false);
}
function it_is_equal_if_choices_are_equal()
{
$this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
$interaction = $this->createEmptyDefinition();
$interaction = $interaction->withChoices(array(new InteractionComponent('test')));
$this->equals($interaction)->shouldReturn(true);
}
protected function createEmptyDefinition()
{
return new SequencingInteractionDefinition();
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Interaction\TrueFalseInteractionDefinition;
class TrueFalseInteractionDefinitionSpec extends InteractionDefinitionSpec
{
protected function createEmptyDefinition()
{
return new TrueFalseInteractionDefinition();
}
}

View File

@@ -0,0 +1,131 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Account;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
class InverseFunctionalIdentifierSpec extends ObjectBehavior
{
function it_can_be_built_with_an_mbox()
{
$iri = IRI::fromString('mailto:conformancetest@tincanapi.com');
$this->beConstructedThrough(
array(InverseFunctionalIdentifier::class, 'withMbox'),
array($iri)
);
$this->getMbox()->shouldReturn($iri);
$this->getMboxSha1Sum()->shouldReturn(null);
$this->getOpenId()->shouldReturn(null);
$this->getAccount()->shouldReturn(null);
}
function it_can_be_built_with_an_mbox_sha1_sum()
{
$this->beConstructedThrough(
array(InverseFunctionalIdentifier::class, 'withMboxSha1Sum'),
array('db77b9104b531ecbb0b967f6942549d0ba80fda1')
);
$this->getMbox()->shouldReturn(null);
$this->getMboxSha1Sum()->shouldReturn('db77b9104b531ecbb0b967f6942549d0ba80fda1');
$this->getOpenId()->shouldReturn(null);
$this->getAccount()->shouldReturn(null);
}
function it_can_be_built_with_an_openid()
{
$this->beConstructedThrough(
array(InverseFunctionalIdentifier::class, 'withOpenId'),
array('http://openid.tincanapi.com')
);
$this->getMbox()->shouldReturn(null);
$this->getMboxSha1Sum()->shouldReturn(null);
$this->getOpenId()->shouldReturn('http://openid.tincanapi.com');
$this->getAccount()->shouldReturn(null);
}
function it_can_be_built_with_an_account()
{
$account = new Account('test', IRL::fromString('https://tincanapi.com'));
$this->beConstructedThrough(
array(InverseFunctionalIdentifier::class, 'withAccount'),
array($account)
);
$this->getMbox()->shouldReturn(null);
$this->getMboxSha1Sum()->shouldReturn(null);
$this->getOpenId()->shouldReturn(null);
$this->getAccount()->shouldReturn($account);
}
function it_is_equal_when_mboxes_are_equal()
{
$this->beConstructedThrough('withMbox', array(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$this->equals(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')))->shouldReturn(true);
}
function it_is_equal_when_mbox_sha1_sums_are_equal()
{
$this->beConstructedThrough('withMboxSha1Sum', array('db77b9104b531ecbb0b967f6942549d0ba80fda1'));
$this->equals(InverseFunctionalIdentifier::withMboxSha1Sum('db77b9104b531ecbb0b967f6942549d0ba80fda1'))->shouldReturn(true);
}
function it_is_equal_when_open_ids_are_equal()
{
$this->beConstructedThrough('withOpenId', array('http://openid.tincanapi.com'));
$this->equals(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'))->shouldReturn(true);
}
function it_is_equal_when_accounts_are_equal()
{
$this->beConstructedThrough('withAccount', array(new Account('test', IRL::fromString('https://tincanapi.com'))));
$this->equals(InverseFunctionalIdentifier::withAccount(new Account('test', IRL::fromString('https://tincanapi.com'))))->shouldReturn(true);
}
function its_mbox_value_can_be_retrieved_as_a_string()
{
$this->beConstructedWithMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'));
$this->__toString()->shouldReturn('mailto:conformancetest@tincanapi.com');
}
function its_mbox_sha1_sum_value_can_be_retrieved_as_a_string()
{
$this->beConstructedWithMboxSha1Sum('db77b9104b531ecbb0b967f6942549d0ba80fda1');
$this->__toString()->shouldReturn('db77b9104b531ecbb0b967f6942549d0ba80fda1');
}
function its_open_id_value_can_be_retrieved_as_a_string()
{
$this->beConstructedWithOpenId('http://openid.tincanapi.com');
$this->__toString()->shouldReturn('http://openid.tincanapi.com');
}
function its_account_value_can_be_retrieved_as_a_string()
{
$this->beConstructedWithAccount(new Account('test', IRL::fromString('https://tincanapi.com')));
$this->__toString()->shouldReturn('test (https://tincanapi.com)');
}
}

View File

@@ -0,0 +1,127 @@
<?php
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\LanguageMap;
class LanguageMapSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedThrough('create', array(array(
'de-DE' => 'teilgenommen',
'en-GB' => 'attended',
)));
}
function it_is_initializable()
{
$this->shouldHaveType(LanguageMap::class);
}
function it_can_be_created_with_an_existing_array_map()
{
$this->beConstructedThrough('create', array(array(
'de-DE' => 'teilgenommen',
'en-GB' => 'attended',
'en-US' => 'attended',
)));
$this->offsetGet('de-DE')->shouldReturn('teilgenommen');
$this->offsetGet('en-GB')->shouldReturn('attended');
$this->offsetGet('en-US')->shouldReturn('attended');
}
function it_returns_a_new_instance_with_an_added_entry()
{
$languageTag = $this->withEntry('en-US', 'attended');
$languageTag->offsetExists('en-US')->shouldReturn(true);
$languageTag->shouldNotBe($this);
$this->offsetExists('en-US')->shouldReturn(false);
}
function it_returns_a_new_instance_with_a_modified_entry()
{
$languageTag = $this->withEntry('en-GB', 'test');
$languageTag->offsetGet('en-GB')->shouldReturn('test');
$languageTag->shouldNotBe($this);
$this->offsetGet('en-GB')->shouldReturn('attended');
}
function its_language_tags_can_be_retrieved()
{
$languageTags = $this->languageTags();
$languageTags->shouldBeArray();
$languageTags->shouldHaveCount(2);
$languageTags->shouldContain('de-DE');
$languageTags->shouldContain('en-GB');
}
function it_throws_an_exception_when_a_non_existent_language_tag_is_requested()
{
$this->shouldThrow('\InvalidArgumentException')->during('offsetGet', array('en-US'));
}
function it_can_be_asked_if_a_language_tag_is_known()
{
$this->offsetExists('en-GB')->shouldReturn(true);
$this->offsetExists('en-US')->shouldReturn(false);
}
function its_values_cannot_be_modified()
{
$this->shouldThrow('\LogicException')->during('offsetSet', array('en-US', 'attended'));
}
function its_values_cannot_be_removed()
{
$this->shouldThrow('\LogicException')->during('offsetUnset', array('en-US'));
}
function it_is_not_equal_with_another_language_map_if_number_of_entries_differ()
{
$languageMap = LanguageMap::create(array(
'de-DE' => 'teilgenommen',
'en-GB' => 'attended',
'en-US' => 'attended',
));
$this->equals($languageMap)->shouldReturn(false);
}
function it_is_not_equal_with_another_language_map_if_keys_differ()
{
$languageMap = LanguageMap::create(array(
'de-DE' => 'teilgenommen',
'en-US' => 'attended',
));
$this->equals($languageMap)->shouldReturn(false);
}
function it_is_not_equal_with_another_language_map_if_values_differ()
{
$languageMap = LanguageMap::create(array(
'de-DE' => 'teilgenommen',
'en-GB' => 'participated',
));
$this->equals($languageMap)->shouldReturn(false);
}
function it_is_equal_with_itself()
{
$this->equals($this)->shouldReturn(true);
}
function it_is_equal_with_another_language_map_if_key_value_pairs_are_equal()
{
$languageMap = LanguageMap::create(array(
'en-GB' => 'attended',
'de-DE' => 'teilgenommen',
));
$this->equals($languageMap)->shouldReturn(true);
}
}

View File

@@ -0,0 +1,119 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Account;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
class PersonSpec extends ObjectBehavior
{
function it_can_be_built_from_an_array_of_agents()
{
$agents = array(
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))),
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))),
);
$this->beConstructedThrough('createFromAgents', array($agents));
$this->shouldHaveType('Xabbuh\XApi\Model\Person');
}
function it_has_mboxes_from_agents()
{
$mbox = IRI::fromString('mailto:conformancetest@tincanapi.com');
$mbox2 = IRI::fromString('mailto:conformancetest2@tincanapi.com');
$agents = array(
new Agent(InverseFunctionalIdentifier::withMbox($mbox)),
new Agent(InverseFunctionalIdentifier::withMbox($mbox2)),
);
$this->beConstructedThrough('createFromAgents', array($agents));
$this->getMboxes()->shouldReturn(array(
$mbox,
$mbox2,
));
}
function it_has_mbox_sha_1_sums_from_agents()
{
$sha1Sum = 'sha1Sum';
$sha1Sum2 = 'sha1Sum2';
$agents = array(
new Agent(InverseFunctionalIdentifier::withMboxSha1Sum($sha1Sum)),
new Agent(InverseFunctionalIdentifier::withMboxSha1Sum($sha1Sum2)),
);
$this->beConstructedThrough('createFromAgents', array($agents));
$this->getMboxSha1Sums()->shouldReturn(array(
$sha1Sum,
$sha1Sum2,
));
}
function it_has_open_ids_from_agents()
{
$openId = 'openId';
$openId2 = 'openId2';
$agents = array(
new Agent(InverseFunctionalIdentifier::withOpenId($openId)),
new Agent(InverseFunctionalIdentifier::withOpenId($openId2)),
);
$this->beConstructedThrough('createFromAgents', array($agents));
$this->getOpenIds()->shouldReturn(array(
$openId,
$openId2,
));
}
function it_has_accounts_from_agents()
{
$account = new Account('test', IRL::fromString('http://example.com'));
$account2 = new Account('test2', IRL::fromString('http://example.com'));
$agents = array(
new Agent(InverseFunctionalIdentifier::withAccount($account)),
new Agent(InverseFunctionalIdentifier::withAccount($account2)),
);
$this->beConstructedThrough('createFromAgents', array($agents));
$this->getAccounts()->shouldReturn(array(
$account,
$account2,
));
}
function it_has_names_from_agents()
{
$name = 'name';
$name2 = 'name2';
$agents = array(
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')), $name),
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')), $name2),
);
$this->beConstructedThrough('createFromAgents', array($agents));
$this->getNames()->shouldReturn(array(
$name,
$name2,
));
}
}

View File

@@ -0,0 +1,143 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\Result;
use Xabbuh\XApi\Model\Score;
class ResultSpec extends ObjectBehavior
{
function its_properties_can_be_read()
{
$score = new Score(1);
$this->beConstructedWith($score, true, true, 'test', 'PT2H');
$this->getScore()->shouldReturn($score);
$this->getSuccess()->shouldReturn(true);
$this->getCompletion()->shouldReturn(true);
$this->getResponse()->shouldReturn('test');
$this->getDuration()->shouldReturn('PT2H');
}
function it_can_be_empty()
{
$this->getScore()->shouldReturn(null);
$this->getSuccess()->shouldReturn(null);
$this->getCompletion()->shouldReturn(null);
$this->getResponse()->shouldReturn(null);
$this->getDuration()->shouldReturn(null);
$this->equals(new Result())->shouldReturn(true);
}
function it_is_empty_and_is_not_equal_to_a_result_with_a_score()
{
$this->equals(new Result(new Score(1)))->shouldReturn(false);
}
function it_is_not_equal_to_other_result_if_not_both_results_have_extensions()
{
$this->beConstructedWith(new Score(1), true, true, 'test', 'PT2H');
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$this
->equals(new Result(new Score(1), true, true, 'test', 'PT2H', new Extensions($extensions)))
->shouldReturn(false);
}
function it_is_not_equal_to_other_result_if_extensions_are_not_equal()
{
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/topic'), 'Conformance Testing');
$this->beConstructedWith(new Score(1), true, true, 'test', 'PT2H', new Extensions($extensions));
$extensions = new \SplObjectStorage();
$extensions->attach(IRI::fromString('http://id.tincanapi.com/extension/subject'), 'Conformance Testing');
$this
->equals(new Result(new Score(1), true, true, 'test', 'PT2H', new Extensions($extensions)))
->shouldReturn(false);
}
public function it_returns_a_new_instance_with_score()
{
$score = new Score(1);
$result = $this->withScore($score);
$this->getScore()->shouldBeNull();
$result->shouldNotBe($this);
$result->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Result');
$result->getScore()->shouldReturn($score);
}
public function it_returns_a_new_instance_with_success()
{
$this->beConstructedWith(null, false);
$result = $this->withSuccess(true);
$this->getSuccess()->shouldReturn(false);
$result->shouldNotBe($this);
$result->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Result');
$result->getSuccess()->shouldReturn(true);
}
public function it_returns_a_new_instance_with_completion()
{
$this->beConstructedWith(null, null, false);
$result = $this->withCompletion(true);
$this->getCompletion()->shouldReturn(false);
$result->shouldNotBe($this);
$result->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Result');
$result->getCompletion()->shouldReturn(true);
}
public function it_returns_a_new_instance_with_response()
{
$result = $this->withResponse('test');
$this->getResponse()->shouldReturn(null);
$result->shouldNotBe($this);
$result->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Result');
$result->getResponse()->shouldReturn('test');
}
public function it_returns_a_new_instance_with_duration()
{
$result = $this->withDuration('PT2H');
$this->getDuration()->shouldReturn(null);
$result->shouldNotBe($this);
$result->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Result');
$result->getDuration()->shouldReturn('PT2H');
}
public function it_returns_a_new_instance_with_extensions()
{
$extensions = new Extensions();
$result = $this->withExtensions($extensions);
$this->getScore()->shouldBeNull();
$result->shouldNotBe($this);
$result->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Result');
$result->getExtensions()->shouldReturn($extensions);
}
}

121
vendor/php-xapi/model/spec/ScoreSpec.php vendored Normal file
View File

@@ -0,0 +1,121 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Score;
class ScoreSpec extends ObjectBehavior
{
function its_properties_can_be_read()
{
$this->beConstructedWith(1, 100, 0, 100);
$this->getScaled()->shouldReturn(1);
$this->getRaw()->shouldReturn(100);
$this->getMin()->shouldReturn(0);
$this->getMax()->shouldReturn(100);
}
function it_can_be_constructed_with_a_scaled_value_only()
{
$this->beConstructedWith(1);
$this->getScaled()->shouldReturn(1);
$this->getRaw()->shouldReturn(null);
$this->getMin()->shouldReturn(null);
$this->getMax()->shouldReturn(null);
}
function it_can_be_constructed_with_a_raw_value_only()
{
$this->beConstructedWith(null, 100);
$this->getScaled()->shouldReturn(null);
$this->getRaw()->shouldReturn(100);
$this->getMin()->shouldReturn(null);
$this->getMax()->shouldReturn(null);
}
function it_can_be_constructed_with_a_min_value_only()
{
$this->beConstructedWith(null, null, 0);
$this->getScaled()->shouldReturn(null);
$this->getRaw()->shouldReturn(null);
$this->getMin()->shouldReturn(0);
$this->getMax()->shouldReturn(null);
}
function it_can_be_constructed_with_a_max_value_only()
{
$this->beConstructedWith(null, null, null, 100);
$this->getScaled()->shouldReturn(null);
$this->getRaw()->shouldReturn(null);
$this->getMin()->shouldReturn(null);
$this->getMax()->shouldReturn(100);
}
public function it_returns_a_new_instance_with_scaled()
{
$score = $this->withScaled(1);
$this->getScaled()->shouldBeNull();
$score->shouldNotBe($this);
$score->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Score');
$score->getScaled()->shouldReturn(1);
}
public function it_returns_a_new_instance_with_raw()
{
$score = $this->withRaw(100);
$this->getRaw()->shouldBeNull();
$score->shouldNotBe($this);
$score->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Score');
$score->getRaw()->shouldReturn(100);
}
public function it_returns_a_new_instance_with_min()
{
$score = $this->withMin(0);
$this->getMin()->shouldBeNull();
$score->shouldNotBe($this);
$score->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Score');
$score->getMin()->shouldReturn(0);
}
public function it_returns_a_new_instance_with_max()
{
$score = $this->withMax(100);
$this->getMax()->shouldBeNull();
$score->shouldNotBe($this);
$score->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Score');
$score->getMax()->shouldReturn(100);
}
function it_treats_integers_as_floats_when_comparing()
{
$this->beConstructedWith(1, 100, 0, 100);
$score = new Score(1.0, 100.0, 0.0, 100.0);
$this->equals($score)->shouldReturn(true);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Document;
use Xabbuh\XApi\Model\DocumentData;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\State;
class StateDocumentSpec extends ObjectBehavior
{
function let()
{
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$agent = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$this->beConstructedWith(new State($activity, $agent, 'state-id'), new DocumentData(array(
'x' => 'foo',
'y' => 'bar',
)));
}
function it_is_a_document()
{
$this->shouldHaveType(Document::class);
}
function its_data_can_be_read()
{
$this->offsetExists('x')->shouldReturn(true);
$this->offsetGet('x')->shouldReturn('foo');
$this->offsetExists('y')->shouldReturn(true);
$this->offsetGet('y')->shouldReturn('bar');
$this->offsetExists('z')->shouldReturn(false);
}
function it_throws_exception_when_not_existing_data_is_being_read()
{
$this->shouldThrow('\InvalidArgumentException')->duringOffsetGet('z');
}
function its_data_cannot_be_manipulated()
{
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetSet('z', 'baz');
$this->shouldThrow('\Xabbuh\XApi\Common\Exception\UnsupportedOperationException')->duringOffsetUnset('x');
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\LanguageMap;
use Xabbuh\XApi\Model\Verb;
class StateDocumentsFilterSpec extends ObjectBehavior
{
function it_does_not_filter_anything_by_default()
{
$filter = $this->getFilter();
$filter->shouldHaveCount(0);
}
function it_can_filter_by_activity()
{
$this->byActivity(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')))->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('activity', 'http://tincanapi.com/conformancetest/activityid');
}
function it_can_filter_by_agent()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$this->byAgent($actor)->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('agent', $actor);
}
function it_can_filter_by_registration()
{
$this->byRegistration('foo')->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('registration', 'foo');
}
function it_can_filter_by_timestamp()
{
$this->since(\DateTime::createFromFormat(\DateTime::ISO8601, '2013-05-18T05:32:34Z'))->shouldReturn($this);
$this->getFilter()->shouldHaveKeyWithValue('since', '2013-05-18T05:32:34+00:00');
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Context;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\Result;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Model\Verb;
class StatementFactorySpec extends ObjectBehavior
{
function it_creates_a_statement()
{
$this->withActor(new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))));
$this->withVerb(new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid')));
$this->withObject(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')));
$this->createStatement()->shouldBeAnInstanceOf('\Xabbuh\Xapi\Model\Statement');
}
function it_configures_all_statement_properties()
{
$id = StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$result = new Result();
$context = new Context();
$created = new \DateTime('2014-07-23T12:34:02-05:00');
$stored = new \DateTime('2014-07-24T12:34:02-05:00');
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->withId($id);
$this->withActor($actor);
$this->withVerb($verb);
$this->withObject($object);
$this->withResult($result);
$this->withContext($context);
$this->withCreated($created);
$this->withStored($stored);
$this->withAuthority($authority);
$statement = $this->createStatement();
$statement->getId()->shouldBe($id);
$statement->getActor()->shouldBe($actor);
$statement->getVerb()->shouldBe($verb);
$statement->getObject()->shouldBe($object);
$statement->getResult()->shouldBe($result);
$statement->getContext()->shouldBe($context);
$statement->getCreated()->shouldBe($created);
$statement->getStored()->shouldBe($stored);
$statement->getAuthority()->shouldBe($authority);
}
function it_throws_an_exception_when_a_statement_is_created_without_an_actor()
{
$this->withVerb(new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid')));
$this->withObject(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')));
$this->shouldThrow('\Xabbuh\XApi\Model\Exception\InvalidStateException')->during('createStatement');
}
function it_throws_an_exception_when_a_statement_is_created_without_a_verb()
{
$this->withActor(new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))));
$this->withObject(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')));
$this->shouldThrow('\Xabbuh\XApi\Model\Exception\InvalidStateException')->during('createStatement');
}
function it_throws_an_exception_when_a_statement_is_created_without_an_object()
{
$this->withActor(new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))));
$this->withVerb(new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid')));
$this->shouldThrow('\Xabbuh\XApi\Model\Exception\InvalidStateException')->during('createStatement');
}
function it_can_reset_the_result()
{
$this->configureAllProperties();
$this->withResult(null);
$statement = $this->createStatement();
$statement->getResult()->shouldReturn(null);
}
function it_can_reset_the_context()
{
$this->configureAllProperties();
$this->withContext(null);
$statement = $this->createStatement();
$statement->getContext()->shouldReturn(null);
}
function it_can_reset_the_created()
{
$this->configureAllProperties();
$this->withCreated(null);
$statement = $this->createStatement();
$statement->getCreated()->shouldReturn(null);
}
function it_can_reset_the_stored()
{
$this->configureAllProperties();
$this->withStored(null);
$statement = $this->createStatement();
$statement->getStored()->shouldReturn(null);
}
function it_can_reset_the_authority()
{
$this->configureAllProperties();
$this->withAuthority(null);
$statement = $this->createStatement();
$statement->getAuthority()->shouldReturn(null);
}
private function configureAllProperties()
{
$id = StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$result = new Result();
$context = new Context();
$created = new \DateTime('2014-07-23T12:34:02-05:00');
$stored = new \DateTime('2014-07-24T12:34:02-05:00');
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->withId($id);
$this->withActor($actor);
$this->withVerb($verb);
$this->withObject($object);
$this->withResult($result);
$this->withContext($context);
$this->withCreated($created);
$this->withStored($stored);
$this->withAuthority($authority);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Model\Uuid;
class StatementIdSpec extends ObjectBehavior
{
function it_can_be_created_from_a_uuid()
{
$this->beConstructedThrough('fromUuid', array(Uuid::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af')));
$this->shouldBeAnInstanceOf(StatementId::class);
}
function it_can_be_created_from_a_string()
{
$this->beConstructedThrough('fromString', array('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'));
$this->shouldBeAnInstanceOf(StatementId::class);
}
function it_should_reject_malformed_uuids()
{
$this->beConstructedThrough('fromString', array('bad-uuid'));
$this->shouldThrow('\InvalidArgumentException')->duringInstantiation();
}
function its_value_is_a_uuid_string()
{
$this->beConstructedThrough('fromUuid', array(Uuid::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af')));
$this->getValue()->shouldReturn('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
}
function it_is_equal_to_statement_ids_with_equal_value()
{
$value = '39e24cc4-69af-4b01-a824-1fdc6ea8a3af';
$uuid = Uuid::fromString($value);
$this->beConstructedThrough('fromUuid', array($uuid));
$this->equals(StatementId::fromString($value))->shouldReturn(true);
$this->equals(StatementId::fromUuid(Uuid::fromString($value)))->shouldReturn(true);
$this->equals(StatementId::fromUuid($uuid))->shouldReturn(true);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Model\StatementObject;
use Xabbuh\XApi\Model\StatementReference;
class StatementReferenceSpec extends ObjectBehavior
{
function it_is_an_xapi_object()
{
$this->beConstructedWith(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
$this->shouldHaveType(StatementObject::class);
}
function it_is_equal_to_another_reference_with_the_same_statement_id()
{
$this->beConstructedWith(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
$statementReference = new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
$this->equals($statementReference)->shouldReturn(true);
}
}

View File

@@ -0,0 +1,399 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Attachment;
use Xabbuh\XApi\Model\Context;
use Xabbuh\XApi\Model\Group;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
use Xabbuh\XApi\Model\Result;
use Xabbuh\XApi\Model\Statement;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Model\StatementObject;
use Xabbuh\XApi\Model\StatementReference;
use Xabbuh\XApi\Model\Verb;
class StatementSpec extends ObjectBehavior
{
function let()
{
$id = StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith($id, $actor, $verb, $object);
}
function its_default_version_is_null()
{
$this->getVersion()->shouldReturn(null);
}
function it_creates_reference_to_itself()
{
$reference = $this->getStatementReference();
$reference->shouldBeAnInstanceOf(StatementReference::class);
$reference->getStatementId()->equals(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'))->shouldReturn(true);
}
function it_creates_statement_voiding_itself()
{
$voidingActor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$voidingStatement = $this->getVoidStatement($voidingActor);
$voidingStatement->getActor()->shouldBe($voidingActor);
$voidingStatement->getVerb()->isVoidVerb()->shouldReturn(true);
$voidedStatement = $voidingStatement->getObject();
$voidedStatement->shouldBeAnInstanceOf(StatementReference::class);
$voidedStatement->getStatementId()->equals(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'))->shouldReturn(true);
}
function it_can_be_authorized()
{
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$authorizedStatement = $this->withAuthority($authority);
$authorizedStatement->getAuthority()->shouldReturn($authority);
$authorizedStatement->shouldBeAnInstanceOf(Statement::class);
$authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true);
$authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true);
$authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true);
}
function it_overrides_existing_authority_when_it_is_authorized()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$authority = new Group(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, $authority);
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$authorizedStatement = $this->withAuthority($authority);
$authorizedStatement->getAuthority()->shouldReturn($authority);
$authorizedStatement->shouldBeAnInstanceOf(Statement::class);
$authorizedStatement->getActor()->equals($this->getActor())->shouldBe(true);
$authorizedStatement->getVerb()->equals($this->getVerb())->shouldBe(true);
$authorizedStatement->getObject()->equals($this->getObject())->shouldBe(true);
$authorizedStatement->getAuthority()->equals($this->getAuthority())->shouldBe(false);
}
function its_object_can_be_an_agent()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object);
$this->getObject()->shouldBeAnInstanceOf(StatementObject::class);
$this->getObject()->shouldBe($object);
}
function it_does_not_equal_another_statement_with_different_timestamp()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
$otherStatement = new Statement(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2015-07-23T12:34:02-05:00'));
$this->equals($otherStatement)->shouldBe(false);
}
function it_equals_another_statement_with_same_timestamp()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->beConstructedWith(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
$otherStatement = new Statement(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'), $actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
$this->equals($otherStatement)->shouldBe(true);
}
public function it_returns_a_new_instance_with_id()
{
$id = StatementId::fromString('12345678-1234-5678-8234-567812345678');
$statement = $this->withId($id);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getId()->shouldReturn($id);
}
public function it_returns_a_new_instance_with_actor()
{
$actor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$statement = $this->withActor($actor);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getActor()->shouldReturn($actor);
}
public function it_returns_a_new_instance_with_verb()
{
$verb = new Verb(IRI::fromString('http://adlnet.gov/expapi/verbs/voided'));
$statement = $this->withVerb($verb);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getVerb()->shouldReturn($verb);
}
public function it_returns_a_new_instance_with_object()
{
$statementReference = new StatementReference(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
$statement = $this->withObject($statementReference);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getObject()->shouldReturn($statementReference);
}
public function it_returns_a_new_instance_with_result()
{
$result = new Result();
$statement = $this->withResult($result);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getResult()->shouldReturn($result);
}
public function it_returns_a_new_instance_with_authority()
{
$authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$statement = $this->withAuthority($authority);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getAuthority()->shouldReturn($authority);
}
public function it_returns_a_new_instance_with_stored()
{
$stored = new \DateTime('2014-07-23T12:34:02-05:00');
$statement = $this->withStored($stored);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getStored()->shouldReturn($stored);
}
public function it_returns_a_new_instance_with_context()
{
$context = new Context();
$statement = $this->withContext($context);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getContext()->shouldReturn($context);
}
public function it_returns_a_new_instance_with_attachments()
{
$attachments = array(new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
));
$statement = $this->withAttachments($attachments);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getAttachments()->shouldReturn($attachments);
}
function it_returns_a_new_instance_with_version()
{
$statement = $this->withVersion('1.0.1');
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getVersion()->shouldReturn('1.0.1');
}
function it_ignores_array_keys_in_attachment_lists()
{
$textAttachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachments = array(1 => $textAttachment);
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith(null, $actor, $verb, $object, null, null, null, null, null, $attachments);
$this->getAttachments()->shouldBeArray();
$this->getAttachments()->shouldHaveKeyWithValue(0, $textAttachment);
$statement = $this->withAttachments($attachments);
$statement->getAttachments()->shouldBeArray();
$statement->getAttachments()->shouldHaveKeyWithValue(0, $textAttachment);
}
function it_is_not_equal_with_other_statement_if_only_this_statement_has_an_id()
{
$this->equals($this->withId(null))->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_only_the_other_statement_has_an_id()
{
$statement = $this->withId(null);
$otherStatement = $statement->withId(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'));
$statement->equals($otherStatement)->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_ids_differ()
{
$statement = $this->withId(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
$this->equals($statement)->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_only_this_statement_has_context()
{
$statement = $this->withContext(new Context());
$statement->equals($statement->withContext(null))->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_only_the_other_statement_has_context()
{
$statement = $this->withContext(new Context());
$this->equals($statement)->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_contexts_differ()
{
$context = new Context();
$revisionContext = $context->withRevision('test');
$platformContext = $context->withPlatform('test');
$statement = $this->withContext($revisionContext);
$this->withContext($platformContext)->equals($statement)->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_only_this_statement_has_attachments()
{
$attachments = array(new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
));
$statement = $this->withAttachments($attachments);
$statement->equals($this->withAttachments(null))->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_only_the_other_statement_has_attachments()
{
$attachments = array(new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
));
$statement = $this->withAttachments($attachments);
$this->equals($statement)->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_number_of_attachments_differs()
{
$textAttachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$jsonAttachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'application/json',
60,
'f4135c31e2710764604195dfe4e225884d8108467cc21670803e384b80df88ee',
LanguageMap::create(array('en-US' => 'JSON attachment')),
null,
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$statement = $this->withAttachments(array($textAttachment, $jsonAttachment));
$statement->equals($statement->withAttachments(array($textAttachment)))->shouldReturn(false);
}
function it_is_not_equal_with_other_statement_if_attachments_differ()
{
$textAttachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$jsonAttachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'application/json',
60,
'f4135c31e2710764604195dfe4e225884d8108467cc21670803e384b80df88ee',
LanguageMap::create(array('en-US' => 'JSON attachment')),
null,
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$statement = $this->withAttachments(array($textAttachment));
$statement->equals($statement->withAttachments(array($jsonAttachment)))->shouldReturn(false);
}
function it_is_equal_with_other_statement_even_if_versions_differ()
{
$statement = $this->withVersion('1.0.0');
$otherStatement = $this->withVersion('1.0.1');
$statement->equals($otherStatement)->shouldReturn(true);
}
}

View File

@@ -0,0 +1,144 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\LanguageMap;
use Xabbuh\XApi\Model\Verb;
class StatementsFilterSpec extends ObjectBehavior
{
function it_does_not_filter_anything_by_default()
{
$filter = $this->getFilter();
$filter->shouldHaveCount(0);
}
function it_can_filter_by_actor()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$this->byActor($actor)->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('agent', $actor);
}
function it_can_filter_by_verb()
{
$this->byVerb(new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test'))))->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('verb', 'http://tincanapi.com/conformancetest/verbid');
}
function it_can_filter_by_activity()
{
$iri = IRI::fromString('http://tincanapi.com/conformancetest/activityid');
$this->byActivity(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')))->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('activity', 'http://tincanapi.com/conformancetest/activityid');
}
function it_can_filter_by_registration()
{
$this->byRegistration('foo')->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('registration', 'foo');
}
function it_can_enable_to_filter_related_activities()
{
$this->enableRelatedActivityFilter()->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('related_activities', 'true');
}
function it_can_disable_to_filter_related_activities()
{
$this->disableRelatedActivityFilter()->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('related_activities', 'false');
}
function it_can_enable_to_filter_related_agents()
{
$this->enableRelatedAgentFilter()->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('related_agents', 'true');
}
function it_can_disable_to_filter_related_agents()
{
$this->disableRelatedAgentFilter()->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('related_agents', 'false');
}
function it_can_filter_by_timestamp()
{
$this->since(\DateTime::createFromFormat(\DateTime::ISO8601, '2013-05-18T05:32:34Z'))->shouldReturn($this);
$this->getFilter()->shouldHaveKeyWithValue('since', '2013-05-18T05:32:34+00:00');
$this->until(\DateTime::createFromFormat(\DateTime::ISO8601, '2014-05-18T05:32:34Z'))->shouldReturn($this);
$this->getFilter()->shouldHaveKeyWithValue('until', '2014-05-18T05:32:34+00:00');
}
function it_can_sort_the_result_in_ascending_order()
{
$this->ascending()->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('ascending', 'true');
}
function it_can_sort_the_result_in_descending_order()
{
$this->descending()->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('ascending', 'false');
}
function it_can_limit_the_number_of_results()
{
$this->limit(10)->shouldReturn($this);
$filter = $this->getFilter();
$filter->shouldHaveCount(1);
$filter->shouldHaveKeyWithValue('limit', 10);
}
function it_rejects_choosing_a_negative_number_of_results()
{
$this->shouldThrow('\InvalidArgumentException')->duringLimit(-1);
}
}

View File

@@ -0,0 +1,223 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Attachment;
use Xabbuh\XApi\Model\Context;
use Xabbuh\XApi\Model\ContextActivities;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\Group;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
use Xabbuh\XApi\Model\Result;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Model\StatementObject;
use Xabbuh\XApi\Model\StatementReference;
use Xabbuh\XApi\Model\SubStatement;
use Xabbuh\XApi\Model\Verb;
class SubStatementSpec extends ObjectBehavior
{
function let()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith($actor, $verb, $object);
}
function it_is_an_xapi_object()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith($actor, $verb, $object);
$this->shouldHaveType(StatementObject::class);
}
function its_object_can_be_an_agent()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->beConstructedWith($actor, $verb, $object);
$this->getObject()->shouldBeAnInstanceOf(StatementObject::class);
$this->getObject()->shouldBe($object);
}
function it_does_not_equal_another_statement_with_different_timestamp()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->beConstructedWith($actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
$otherStatement = new SubStatement($actor, $verb, $object, null, null, new \DateTime('2015-07-23T12:34:02-05:00'));
$this->equals($otherStatement)->shouldBe(false);
}
function it_equals_another_statement_with_same_timestamp()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$this->beConstructedWith($actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
$otherStatement = new SubStatement($actor, $verb, $object, null, null, new \DateTime('2014-07-23T12:34:02-05:00'));
$this->equals($otherStatement)->shouldBe(true);
}
function it_is_different_from_another_sub_statement_if_contexts_differ()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith($actor, $verb, $object, null, new Context());
$subStatement = new SubStatement($actor, $verb, $object);
$this->equals($subStatement)->shouldReturn(false);
$context = new Context();
$context = $context->withRegistration('16fd2706-8baf-433b-82eb-8c7fada847da')
->withInstructor(new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com'))))
->withTeam(new Group(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest-group@tincanapi.com'))))
->withContextActivities(new ContextActivities(
array(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'))),
array(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'))),
array(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'))),
array(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')))
))
->withRevision('test')
->withPlatform('test')
->withLanguage('en-US')
->withStatement(new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da')))
->withExtensions(new Extensions())
;
$subStatement = new SubStatement($actor, $verb, $object, null, $context);
$this->equals($subStatement)->shouldReturn(false);
}
function it_rejects_to_hold_another_sub_statement_as_object()
{
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$subStatement = new SubStatement($actor, $verb, $object);
$this->shouldThrow('\InvalidArgumentException')->during('__construct', array($actor, $verb, $subStatement));
}
public function it_returns_a_new_instance_with_actor()
{
$actor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
$subStatement = $this->withActor($actor);
$subStatement->shouldNotBe($this);
$subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
$subStatement->getActor()->shouldReturn($actor);
}
public function it_returns_a_new_instance_with_verb()
{
$verb = new Verb(IRI::fromString('http://adlnet.gov/expapi/verbs/voided'));
$subStatement = $this->withVerb($verb);
$subStatement->shouldNotBe($this);
$subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
$subStatement->getVerb()->shouldReturn($verb);
}
public function it_returns_a_new_instance_with_object()
{
$statementReference = new StatementReference(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
$subStatement = $this->withObject($statementReference);
$subStatement->shouldNotBe($this);
$subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
$subStatement->getObject()->shouldReturn($statementReference);
}
public function it_returns_a_new_instance_with_result()
{
$result = new Result();
$subStatement = $this->withResult($result);
$subStatement->shouldNotBe($this);
$subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
$subStatement->getResult()->shouldReturn($result);
}
public function it_returns_a_new_instance_with_context()
{
$context = new Context();
$subStatement = $this->withContext($context);
$subStatement->shouldNotBe($this);
$subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
$subStatement->getContext()->shouldReturn($context);
}
public function it_returns_a_new_instance_with_attachments()
{
$attachments = array(new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
));
$statement = $this->withAttachments($attachments);
$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
$statement->getAttachments()->shouldReturn($attachments);
}
function it_ignores_array_keys_in_attachment_lists()
{
$textAttachment = new Attachment(
IRI::fromString('http://id.tincanapi.com/attachment/supporting_media'),
'text/plain',
18,
'bd1a58265d96a3d1981710dab8b1e1ed04a8d7557ea53ab0cf7b44c04fd01545',
LanguageMap::create(array('en-US' => 'Text attachment')),
LanguageMap::create(array('en-US' => 'Text attachment description')),
IRL::fromString('http://tincanapi.com/conformancetest/attachment/fileUrlOnly')
);
$attachments = array(1 => $textAttachment);
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
$verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), LanguageMap::create(array('en-US' => 'test')));
$object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
$this->beConstructedWith($actor, $verb, $object, null, null, null, $attachments);
$this->getAttachments()->shouldBeArray();
$this->getAttachments()->shouldHaveKeyWithValue(0, $textAttachment);
$statement = $this->withAttachments($attachments);
$statement->getAttachments()->shouldBeArray();
$statement->getAttachments()->shouldHaveKeyWithValue(0, $textAttachment);
}
}

67
vendor/php-xapi/model/spec/VerbSpec.php vendored Normal file
View File

@@ -0,0 +1,67 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Xabbuh\XApi\Model;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\LanguageMap;
use Xabbuh\XApi\Model\Verb;
class VerbSpec extends ObjectBehavior
{
function it_detects_voiding_verbs()
{
$this->beConstructedWith(IRI::fromString('http://adlnet.gov/expapi/verbs/voided'));
$this->isVoidVerb()->shouldReturn(true);
}
function its_properties_can_be_read()
{
$iri = IRI::fromString('http://tincanapi.com/conformancetest/verbid');
$languageMap = LanguageMap::create(array('en-US' => 'test'));
$this->beConstructedWith($iri, $languageMap);
$this->getId()->shouldReturn($iri);
$this->getDisplay()->shouldReturn($languageMap);
}
function its_display_property_is_null_if_omitted()
{
$iri = IRI::fromString('http://tincanapi.com/conformancetest/verbid');
$this->beConstructedWith($iri);
$this->getId()->shouldReturn($iri);
$this->getDisplay()->shouldReturn(null);
}
function it_creates_voiding_verb_through_factory_method()
{
$this->beConstructedThrough(array(Verb::class, 'createVoidVerb'));
$this->shouldHaveType(Verb::class);
$this->isVoidVerb()->shouldReturn(true);
}
function it_is_different_when_displays_are_omitted_and_other_verb_contains_an_empty_list_of_displays()
{
$this->beConstructedWith(IRI::fromString('http://tincanapi.com/conformancetest/verbid'));
$this->equals(new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'), new LanguageMap()))->shouldReturn(false);
}
function it_is_equal_when_verb_id_is_equal_and_display_values_are_omitted()
{
$this->beConstructedWith(IRI::fromString('http://tincanapi.com/conformancetest/verbid'));
$this->equals(new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid')))->shouldReturn(true);
}
}