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

3
vendor/php-xapi/model/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/composer.lock
/phpunit.xml
/vendor

29
vendor/php-xapi/model/.travis.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
sudo: false
language: php
cache:
directories:
- $HOME/.composer/cache/files
env:
global:
- deps=""
matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.2
env: deps="low"
before_install:
- phpenv config-rm xdebug.ini
- composer self-update
install:
- if [ "$deps" = "low" ]; then composer update --prefer-lowest --prefer-stable; fi
- if [ "$deps" = "" ]; then composer install; fi
script:
- vendor/bin/phpspec run

283
vendor/php-xapi/model/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,283 @@
CHANGELOG
=========
3.1.0
-----
* Introduce a new `Person` class.
* Constructing a `State` object with an instance of any child class of `Actor`
other than `Agent` as the second argument is deprecated. Starting with `4.0`,
only instances of `Agent` will be accepted.
* The `State::getActor()` method is deprecated and will be removed in `4.0`.
Use `State::getAgent()` instead.
* Added a `StateDocumentsFilter` class that allows to draft filters for
`StateDocument` objects.
3.0.0
-----
* The `Statement::getTimestamp()` method has been removed. Use
`Statement::getCreated()` instead.
* The `Statement::withTimestamp()` method has been removed. Use
`Statement::withCreated()` instead.
* The `SubStatement::getTimestamp()` method has been removed. Use
`SubStatement::getCreated()` instead.
* The `SubStatement::withTimestamp()` method has been removed. Use
`SubStatement::withCreated()` instead.
* Dropped support for PHP < 7.1 as well as HHVM.
* The `Object` class was renamed to `StatementObject` for compatibility with PHP
7.2.
2.2.0
-----
* Introduce a new `Person` class.
* Constructing a `State` object with an instance of any child class of `Actor`
other than `Agent` as the second argument is deprecated. Starting with `4.0`,
only instances of `Agent` will be accepted.
* The `State::getActor()` method is deprecated and will be removed in `4.0`.
Use `State::getAgent()` instead.
* Added a `StateDocumentsFilter` class that allows to draft filters for
`StateDocument` objects.
2.1.0
-----
* The `Statement::getTimestamp()` method is deprecated and will be removed in
3.0. Use `Statement::getCreated()` instead.
* The `Statement::withTimestamp()` method is deprecated and will be removed in
3.0. Use `Statement::withCreated()` instead.
* The `SubStatement::getTimestamp()` method is deprecated and will be removed in
3.0. Use `SubStatement::getCreated()` instead.
* The `SubStatement::withTimestamp()` method is deprecated and will be removed in
3.0. Use `SubStatement::withCreated()` instead.
2.0.1
-----
* Added missing `$version` attribute to the `Statement` class which defaults to
`null`.
2.0.0
-----
* Introducing a new `Uuid` class that supports both `ramsey/uuid` 2.x and 3.x.
Applications and packages using this library should not longer refer to the
`Uuid` class from the `ramsey/uuid` package, but should always use the `Uuid`
class from the this package instead.
* The type of the `StatemendId::$id` property has been changed from an instance
of `Rhumsaa\Uuid\Uuid` to an instance of the added `Uuid` class.
1.2.0
-----
* The `Statement::getTimestamp()` method is deprecated and will be removed in
3.0. Use `Statement::getCreated()` instead.
* The `Statement::withTimestamp()` method is deprecated and will be removed in
3.0. Use `Statement::withCreated()` instead.
* The `SubStatement::getTimestamp()` method is deprecated and will be removed in
3.0. Use `SubStatement::getCreated()` instead.
* The `SubStatement::withTimestamp()` method is deprecated and will be removed in
3.0. Use `SubStatement::withCreated()` instead.
* Introduce a new `Person` class.
* Constructing a `State` object with an instance of any child class of `Actor`
other than `Agent` as the second argument is deprecated. Starting with `4.0`,
only instances of `Agent` will be accepted.
* The `State::getActor()` method is deprecated and will be removed in `4.0`.
Use `State::getAgent()` instead.
* Added a `StateDocumentsFilter` class that allows to draft filters for
`StateDocument` objects.
1.1.1
-----
* Added missing `$version` attribute to the `Statement` class which defaults to
`null`.
1.1.0
-----
* The `StatementsFilter::format()`, `StatementsFilter::includeAttachments()`,
and `StatementsFilter::excludeAttachments()` methods are deprecated and will
be removed in 2.0.
* Added a `$content` attribute to the `Attachment` class to make it possible
to attach the raw content to an attachment.
1.0.1
-----
* Added missing `$timestamp` and `$attachments` properties to the `SubStatement`
class.
* Fixed comparing scores where some values are integers instead of floats.
1.0.0
-----
This is the first stable release of the 1.x series. All objects that are
part of the 1.0.1 Experience API spec have been implemented and the current
API is considered to be stable.
In terms of existing classes and methods, there is no difference to the
0.5 release series.
0.5.1
-----
* Fixed the handling of `IRI` instances (for `Verb::$id` and `Activity::$id`)
in `StatementsFilter` to only include the IRI's string value in the generated
filter.
0.5.0
-----
* The type of the following properties has been changed from `string` to
instances of the new `IRI` class:
* `Activity::$id`
* `Attachment::$usageType`
* `Definition::$type`
* `InverseFunctionalIdentifier::$mbox`
* `Verb::$id`
Type hints of respective methods have been updated accordingly.
* The type of the following properties has been changed from `string` to
instances of the new `IRL` class:
* `Account::$homePage`
* `Attachment::$fileUrl`
* `Definition::$moreInfo`
* `StatementResult::$moreUrlPath`
Type hints of respective methods have been updated accordingly.
* Fixed how context attributes of statements are dealt with in `Statement::equals()`
(previously, they were completely ignored).
* Fixed handling `null` values for statement ids inside `Statement::equals()`.
Previously, `StatementId::equals()` might have been called even if a statement's
identifier was not defined.
* Added an `Attachment` class to store statement attachments.
* Fixed some edge cases in `Context::equals()` where statement references,
teams, and extensions would not have been compared properly.
* Added missing extensions to activity definitions.
* Added `with*()` methods for the `$name`, `$description`, `$type`, and `$moreInfo`
properties of the `Definition` class and its subclasses to ease the creation
of new `Definition` objects based on existing instances.
* Added new classes to model user interaction activity definitions (all extending
an abstract `InteractionDefinition` class which in turn is a child class
of the already existing `Definition` class):
* `ChoiceInteractionDefinition`
* `FillInInteractionDefinition`
* `LikertInteractionDefinition`
* `LongFillInInteractionDefinition`
* `MatchingInteractionDefinition`
* `NumericInteractionDefinition`
* `OtherInteractionDefinition`
* `PerformanceInteractionDefinition`
* `SequencingInteractionDefinition`
* `TrueFalseInteractionDefinition`
Interaction components which are part of some of the new definition classes
will be handled by `InteractionComponent` instances.
* Added a `LanguageMap` value object class to model the `$display` property
of `Verb` instances as well as the `$name` and `$description` properties
of the `Definition` class (all these properties have been plain PHP arrays
before).
* Added a value object for statement ids.
* The constructor of the `SubStatement` class now throws an exception when
a `SubStatement` instance is passed as the `$object` argument to comply
with the Experience API spec which does not allow to nest sub statements.
* Removed the `$id` property from the `SubStatement` class as well as the
`getStatementReference()` and `getVoidStatement()` methods which relied
on the existence of an id as a sub statement must not have an id according
to the xAPI spec.
* added a `$context` attribute to `SubStatement` instances
* added `equals()` method to the `Result` model class
* added a `StatementFactory` to ease the creation of complex xAPI statements
* Added `with*()` methods to `Result`, `Score`, `Statement`, `SubStatement`
that allow the creation of new model objects based on existing instances.
* added `Context`, `ContextActivities`, and `Extensions` classes that represent
statement contexts, their context's activities, and statement extensions
respectively
0.4.1
-----
* also compare timestamps when performing statement equality checks
0.4.0
-----
* fixed some edge cases in the `equals()` methods of the `Definition`, `Result`,
and `Verb` classes
* Made `Object` a parent class of the `Actor` class to reflect the fact that
actors can also be objects in xAPI statements.
* The argument type of the `equals()` method in the `Actor` base class was
changed from `Actor` to `Object` to be compatible with the same method from
the parent `Object` class.
0.3.0
-----
* made sure that boolean statements filter parameters are passed as the strings
`'true'` and `'false'`
* added missing return statements to some methods of the `StatementsFilter`
class to ensure the fluent interface
* changed the default value of the `display` property of the `Verb` class to
`null` (was the empty array before) to make it possible to distinguish the
empty list from the case when the `display` property was omitted
* added the possibility to attach an IRL to an activity definition that acts as
a reference to a document that contains human-readable information about the
activity
* all values of an activity definition are optional, pass `null` to omit them
* all values of a result are optional, pass `null` to omit them
* throw an exception when not existing document data is accessed instead of
failing with a PHP notice
* all values of a score are optional, pass `null` to omit them
* values passed to the constructor of the `Score` class are no longer cast to
`float`
0.2.0
-----
* added a dedicated class to refer to inverse functional identifiers, refer to
the upgrade file for more detailed information
* marked the `Statement` class as final
0.1.0
-----
This is the first release containing immutable and final classes that reflect
all parts of Experience API statements.
This package replaces the `xabbuh/xapi-model` package which is now deprecated
and should no longer be used.

19
vendor/php-xapi/model/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2014-2018 Christian Flothmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

7
vendor/php-xapi/model/README.md vendored Normal file
View File

@@ -0,0 +1,7 @@
xAPI Model Classes
==================
[![Build Status](https://travis-ci.org/php-xapi/model.svg?branch=master)](https://travis-ci.org/php-xapi/model)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-xapi/model/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-xapi/model/?branch=master)
Package providing model classes for Experience API libraries.

181
vendor/php-xapi/model/UPGRADE.md vendored Normal file
View File

@@ -0,0 +1,181 @@
UPGRADE
=======
Upgrading from 2.x to 3.0
-------------------------
* The `Object` class has been renamed to `StatementObject`.
Upgrading from 1.x to 2.0
-------------------------
* The `StatementsFilter::format()`, `StatementsFilter::includeAttachments()`,
and `StatementsFilter::excludeAttachments()` methods have been removed.
Upgrading from 1.0 to 1.1
-------------------------
* The `StatementsFilter::format()`, `StatementsFilter::includeAttachments()`,
and `StatementsFilter::excludeAttachments()` methods are deprecated and will
be removed in 2.0.
* Constructing an `Attachment` instance with specifying neither a file URL
nor the raw attachment content throws an `\InvalidArgumentException`.
Upgrading from 0.4 to 0.5
-------------------------
* The type of the following properties has been changed from `string` to
instances of the new `IRI` class:
* `Activity::$id`
* `Attachment::$usageType`
* `Definition::$type`
* `InverseFunctionalIdentifier::$mbox`
* `Verb::$id`
Type hints of respective methods have been updated accordingly.
* The type of the following properties has been changed from `string` to
instances of the new `IRL` class:
* `Account::$homePage`
* `Attachment::$fileUrl`
* `Definition::$moreInfo`
* `StatementResult::$moreUrlPath`
Type hints of respective methods have been updated accordingly.
* The `$display` property of the `Verb` class as well as the `$name` and
`$description` properties of the `Definition` class are no longer plain
PHP arrays, but are now instances of `LanguageMap`.
* Statement ids are no longer plain strings, but are `StatementId` value objects:
Before:
```php
// passing an id to the Statement constructor
$statement = new Statement('16fd2706-8baf-433b-82eb-8c7fada847da', ...);
// building a new statement based on an existing one with a different id
$statement = $statement->withId('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
// reference another statement with its id
$statementRef = new StatementReference('16fd2706-8baf-433b-82eb-8c7fada847da');
```
After:
```php
// passing an id to the Statement constructor
$statement = new Statement(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'), ...);
// building a new statement based on an existing one with a different id
$statement = $statement->withId(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af'));
// reference another statement with its id
$statementRef = new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
```
* The constructor of the `SubStatement` class now throws an exception when
a `SubStatement` instance is passed as the `$object` argument to comply
with the Experience API spec which does not allow to nest sub statements.
* The `$id` attribute has been removed from the `SubStatement` class. Also,
the `$id` argument of the class constructor has been removed respectively.
The first constructor argument is now the sub statement's actor.
* The `getStatementReference()` and `getVoidStatement()` methods have been
removed from the `SubStatement` class as they are not usable without an id.
Upgrading from 0.3 to 0.4
-------------------------
* The argument type of the `equals()` method in the `Actor` base class was
changed from `Actor` to `Object` to be compatible with the same method from
the parent `Object` class.
Upgrading from 0.2 to 0.3
-------------------------
* The default value of the `display` property of the `Verb` class was changed
to `null` (was the empty array before).
Upgrading from 0.2.0 to 0.2.1
-----------------------------
* Data passed to the `Score` class during construction is no longer cast to
`float` values to ensure that integers are not needlessly cast. You need to
make sure to always pass the expected data types when build `Score` objects.
Upgrading from 0.1 to 0.2
-------------------------
* the getter methods to retrieve the inverse functional identifier properties
`mbox`, `mboxsha1sum`, `openid`, and `account` have been removed from the
`Actor` class
* the `getInverseFunctionalIdentifier()` method in the `Actor` class no longer
returns a string, but returns an `InverseFunctionalIdentifier` instance
instead
* A new class `InverseFunctionalIdentifier` was introduced to reflect the
inverse functional identifier of an actor. It reflects the fact that an IRI
must only contain exactly one property of `mbox`, `mboxsha1sum`, `openid`,
and `account` by providing four factory methods to obtain an IRI instance:
* `withMbox()`
* `withMboxSha1Sum()`
* `withOpenId()`
* `withAccount()`
You now need to pass an `InverseFunctionalIdentifier` when creating an actor
or group.
Before:
```php
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Group;
$agent = new Agent(
'mailto:christian@example.com',
null,
null,
null,
'Christian'
);
$group = new Group(
null,
null,
null,
new Account('GroupAccount', 'http://example.com/homePage'),
'Example Group'
);
```
After:
```php
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Group;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
$agent = new Agent(
InverseFunctionalIdentifier::withMbox('mailto:christian@example.com'),
'Christian'
);
$group = new Group(
InverseFunctionalIdentifier::withAccount(
new Account('GroupAccount', 'http://example.com/homePage')
),
'Example Group'
);
```
* The `Statement` class is now marked as final. This means that you can no
longer extend it.

42
vendor/php-xapi/model/composer.json vendored Normal file
View File

@@ -0,0 +1,42 @@
{
"name": "php-xapi/model",
"type": "library",
"description": "Experience API model classes",
"keywords": ["xAPI", "Experience API", "Tin Can API", "models"],
"homepage": "https://github.com/php-xapi/model",
"license": "MIT",
"authors": [
{
"name": "Christian Flothmann",
"homepage": "https://github.com/xabbuh"
}
],
"require": {
"php": "^7.1",
"php-xapi/exception": "~0.1",
"ramsey/uuid": "^2.9 || ^3.0"
},
"require-dev": {
"phpspec/phpspec": "~2.3"
},
"conflict": {
"xabbuh/xapi-model": "*"
},
"autoload": {
"psr-4": {
"Xabbuh\\XApi\\Model\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"spec\\Xabbuh\\XApi\\Model\\": "spec/"
}
},
"extra": {
"branch-alias": {
"1.x-dev": "1.2.x-dev",
"2.x-dev": "2.2.x-dev",
"dev-master": "3.0.x-dev"
}
}
}

View File

@@ -0,0 +1,4 @@
suites:
default:
namespace: Xabbuh\XApi\Model
psr4_prefix: Xabbuh\XApi\Model

17
vendor/php-xapi/model/phpunit.xml.dist vendored Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="xAPI model classes">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

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);
}
}

63
vendor/php-xapi/model/src/Account.php vendored Normal file
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 Xabbuh\XApi\Model;
/**
* A user account on an existing system.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Account
{
private $name;
private $homePage;
public function __construct(string $name, IRL $homePage)
{
$this->name = $name;
$this->homePage = $homePage;
}
/**
* Returns the unique id or name used to log in to this account.
*/
public function getName(): string
{
return $this->name;
}
/**
* Returns the home page for the system the account is on.
*/
public function getHomePage(): IRL
{
return $this->homePage;
}
/**
* Checks if another account is equal.
*
* Two accounts are equal if and only if all of their properties are equal.
*/
public function equals(Account $account): bool
{
if ($this->name !== $account->name) {
return false;
}
if (!$this->homePage->equals($account->homePage)) {
return false;
}
return true;
}
}

73
vendor/php-xapi/model/src/Activity.php vendored Normal file
View File

@@ -0,0 +1,73 @@
<?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 Xabbuh\XApi\Model;
/**
* An Activity in a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Activity extends StatementObject
{
private $id;
private $definition;
public function __construct(IRI $id, Definition $definition = null)
{
$this->id = $id;
$this->definition = $definition;
}
/**
* Returns the Activity's unique identifier.
*/
public function getId(): IRI
{
return $this->id;
}
/**
* Returns the Activity's {@link Definition}.
*/
public function getDefinition(): ?Definition
{
return $this->definition;
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $object): bool
{
if (!$object instanceof Activity) {
return false;
}
if (!$this->id->equals($object->id)) {
return false;
}
if (null === $this->definition && null !== $object->definition) {
return false;
}
if (null !== $this->definition && null === $object->definition) {
return false;
}
if (null !== $this->definition && !$this->definition->equals($object->definition)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,37 @@
<?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 Xabbuh\XApi\Model;
/**
* A {@link Profile} related to an {@link Activity}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ActivityProfile extends Profile
{
private $activity;
public function __construct(string $profileId, Activity $activity)
{
parent::__construct($profileId);
$this->activity = $activity;
}
/**
* Returns the {@link Activity}.
*/
public function getActivity(): Activity
{
return $this->activity;
}
}

View File

@@ -0,0 +1,34 @@
<?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 Xabbuh\XApi\Model;
/**
* A {@link Document} that is related to an {@link Activity}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ActivityProfileDocument extends Document
{
private $profile;
public function __construct(ActivityProfile $profile, DocumentData $data)
{
parent::__construct($data);
$this->profile = $profile;
}
public function getActivityProfile(): ActivityProfile
{
return $this->profile;
}
}

75
vendor/php-xapi/model/src/Actor.php vendored Normal file
View File

@@ -0,0 +1,75 @@
<?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 Xabbuh\XApi\Model;
/**
* The Actor of a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class Actor extends StatementObject
{
private $iri;
private $name;
public function __construct(InverseFunctionalIdentifier $iri = null, string $name = null)
{
$this->iri = $iri;
$this->name = $name;
}
/**
* Returns the Actor's {@link InverseFunctionalIdentifier inverse functional identifier}.
*/
public function getInverseFunctionalIdentifier(): ?InverseFunctionalIdentifier
{
return $this->iri;
}
/**
* Returns the name of the {@link Agent} or {@link Group}.
*/
public function getName(): ?string
{
return $this->name;
}
/**
* Checks if another actor is equal.
*
* Two actors are equal if and only if all of their properties are equal.
*/
public function equals(StatementObject $actor): bool
{
if (!parent::equals($actor)) {
return false;
}
if (!$actor instanceof Actor) {
return false;
}
if ($this->name !== $actor->name) {
return false;
}
if (null !== $this->iri xor null !== $actor->iri) {
return false;
}
if (null !== $this->iri && null !== $actor->iri && !$this->iri->equals($actor->iri)) {
return false;
}
return true;
}
}

37
vendor/php-xapi/model/src/Agent.php vendored Normal file
View File

@@ -0,0 +1,37 @@
<?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 Xabbuh\XApi\Model;
/**
* An individual Agent of an xAPI {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Agent extends Actor
{
public function __construct(InverseFunctionalIdentifier $iri, string $name = null)
{
parent::__construct($iri, $name);
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $actor): bool
{
if (!parent::equals($actor)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,34 @@
<?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 Xabbuh\XApi\Model;
/**
* A {@link Profile} related to an {@link Agent}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class AgentProfile extends Profile
{
private $agent;
public function __construct(string $profileId, Agent $agent)
{
parent::__construct($profileId);
$this->agent = $agent;
}
public function getAgent(): Agent
{
return $this->agent;
}
}

View File

@@ -0,0 +1,34 @@
<?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 Xabbuh\XApi\Model;
/**
* A {@link Document} that is related to an {@link Agent}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class AgentProfileDocument extends Document
{
private $profile;
public function __construct(AgentProfile $profile, DocumentData $data)
{
parent::__construct($data);
$this->profile = $profile;
}
public function getAgentProfile(): AgentProfile
{
return $this->profile;
}
}

137
vendor/php-xapi/model/src/Attachment.php vendored Normal file
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 Xabbuh\XApi\Model;
/**
* An Experience API statement {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#attachments attachment}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Attachment
{
private $usageType;
private $contentType;
private $length;
private $sha2;
private $display;
private $description;
private $fileUrl;
private $content;
/**
* @param IRI $usageType The type of usage of this attachment
* @param string $contentType The content type of the attachment
* @param int $length The length of the attachment data in octets
* @param string $sha2 The SHA-2 hash of the attachment data
* @param LanguageMap $display Localized display name (title)
* @param LanguageMap|null $description Localized description
* @param IRL|null $fileUrl An IRL at which the attachment data can be retrieved
* @param string|null $content The raw attachment content, please note that the content is not validated against
* the given SHA-2 hash
*/
public function __construct(IRI $usageType, string $contentType, int $length, string $sha2, LanguageMap $display, LanguageMap $description = null, IRL $fileUrl = null, string $content = null)
{
if (null === $fileUrl && null === $content) {
throw new \InvalidArgumentException('An attachment cannot be created without a file URL or raw content data.');
}
$this->usageType = $usageType;
$this->contentType = $contentType;
$this->length = $length;
$this->sha2 = $sha2;
$this->display = $display;
$this->description = $description;
$this->fileUrl = $fileUrl;
$this->content = $content;
}
public function getUsageType(): IRI
{
return $this->usageType;
}
public function getContentType(): string
{
return $this->contentType;
}
public function getLength(): int
{
return $this->length;
}
public function getSha2(): string
{
return $this->sha2;
}
public function getDisplay(): LanguageMap
{
return $this->display;
}
public function getDescription(): ?LanguageMap
{
return $this->description;
}
public function getFileUrl(): ?IRL
{
return $this->fileUrl;
}
public function getContent(): ?string
{
return $this->content;
}
public function equals(Attachment $attachment): bool
{
if (!$this->usageType->equals($attachment->usageType)) {
return false;
}
if ($this->contentType !== $attachment->contentType) {
return false;
}
if ($this->length !== $attachment->length) {
return false;
}
if ($this->sha2 !== $attachment->sha2) {
return false;
}
if (!$this->display->equals($attachment->display)) {
return false;
}
if (null !== $this->description xor null !== $attachment->description) {
return false;
}
if (null !== $this->description && null !== $attachment->description && !$this->description->equals($attachment->description)) {
return false;
}
if (null !== $this->fileUrl xor null !== $attachment->fileUrl) {
return false;
}
if (null !== $this->fileUrl && null !== $attachment->fileUrl && !$this->fileUrl->equals($attachment->fileUrl)) {
return false;
}
return true;
}
}

204
vendor/php-xapi/model/src/Context.php vendored Normal file
View File

@@ -0,0 +1,204 @@
<?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 Xabbuh\XApi\Model;
/**
* Contextual information for an xAPI statement.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Context
{
private $registration;
private $instructor;
private $team;
private $contextActivities;
private $revision;
private $platform;
private $language;
private $statement;
private $extensions;
public function withRegistration(string $registration): self
{
$context = clone $this;
$context->registration = $registration;
return $context;
}
public function withInstructor(Actor $instructor): self
{
$context = clone $this;
$context->instructor = $instructor;
return $context;
}
public function withTeam(Group $team): self
{
$context = clone $this;
$context->team = $team;
return $context;
}
public function withContextActivities(ContextActivities $contextActivities): self
{
$context = clone $this;
$context->contextActivities = $contextActivities;
return $context;
}
public function withRevision(string $revision): self
{
$context = clone $this;
$context->revision = $revision;
return $context;
}
public function withPlatform(string $platform): self
{
$context = clone $this;
$context->platform = $platform;
return $context;
}
public function withLanguage(string $language): self
{
$context = clone $this;
$context->language = $language;
return $context;
}
public function withStatement(StatementReference $statement): self
{
$context = clone $this;
$context->statement = $statement;
return $context;
}
public function withExtensions(Extensions $extensions): self
{
$context = clone $this;
$context->extensions = $extensions;
return $context;
}
public function getRegistration(): ?string
{
return $this->registration;
}
public function getInstructor(): ?Actor
{
return $this->instructor;
}
public function getTeam(): ?Group
{
return $this->team;
}
public function getContextActivities(): ?ContextActivities
{
return $this->contextActivities;
}
public function getRevision(): ?string
{
return $this->revision;
}
public function getPlatform(): ?string
{
return $this->platform;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function getStatement(): ?StatementReference
{
return $this->statement;
}
public function getExtensions(): ?Extensions
{
return $this->extensions;
}
public function equals(Context $context): bool
{
if ($this->registration !== $context->registration) {
return false;
}
if (null !== $this->instructor xor null !== $context->instructor) {
return false;
}
if (null !== $this->instructor && null !== $context->instructor && !$this->instructor->equals($context->instructor)) {
return false;
}
if (null !== $this->team xor null !== $context->team) {
return false;
}
if (null !== $this->team && null !== $context->team && !$this->team->equals($context->team)) {
return false;
}
if ($this->contextActivities != $context->contextActivities) {
return false;
}
if ($this->revision !== $context->revision) {
return false;
}
if ($this->platform !== $context->platform) {
return false;
}
if ($this->language !== $context->language) {
return false;
}
if (null !== $this->statement xor null !== $context->statement) {
return false;
}
if (null !== $this->statement && null !== $context->statement && !$this->statement->equals($context->statement)) {
return false;
}
if (null !== $this->extensions xor null !== $context->extensions) {
return false;
}
if (null !== $this->extensions && null !== $context->extensions && !$this->extensions->equals($context->extensions)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,155 @@
<?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 Xabbuh\XApi\Model;
/**
* xAPI context activities.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ContextActivities
{
private $parentActivities;
private $groupingActivities;
private $categoryActivities;
private $otherActivities;
/**
* @param Activity[]|null $parentActivities
* @param Activity[]|null $groupingActivities
* @param Activity[]|null $categoryActivities
* @param Activity[]|null $otherActivities
*/
public function __construct(array $parentActivities = null, array $groupingActivities = null, array $categoryActivities = null, array $otherActivities = null)
{
$this->parentActivities = $parentActivities;
$this->groupingActivities = $groupingActivities;
$this->categoryActivities = $categoryActivities;
$this->otherActivities = $otherActivities;
}
public function withAddedParentActivity(Activity $parentActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->parentActivities)) {
$contextActivities->parentActivities = array();
}
$contextActivities->parentActivities[] = $parentActivity;
return $contextActivities;
}
public function withoutParentActivities(): self
{
$contextActivities = clone $this;
$contextActivities->parentActivities = null;
return $contextActivities;
}
public function withAddedGroupingActivity(Activity $groupingActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->groupingActivities)) {
$contextActivities->groupingActivities = array();
}
$contextActivities->groupingActivities[] = $groupingActivity;
return $contextActivities;
}
public function withoutGroupingActivities(): self
{
$contextActivities = clone $this;
$contextActivities->groupingActivities = null;
return $contextActivities;
}
public function withAddedCategoryActivity(Activity $categoryActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->categoryActivities)) {
$contextActivities->categoryActivities = array();
}
$contextActivities->categoryActivities[] = $categoryActivity;
return $contextActivities;
}
public function withoutCategoryActivities(): self
{
$contextActivities = clone $this;
$contextActivities->categoryActivities = null;
return $contextActivities;
}
public function withAddedOtherActivity(Activity $otherActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->otherActivities)) {
$contextActivities->otherActivities = array();
}
$contextActivities->otherActivities[] = $otherActivity;
return $contextActivities;
}
public function withoutOtherActivities(): self
{
$contextActivities = clone $this;
$contextActivities->otherActivities = null;
return $contextActivities;
}
/**
* @return Activity[]|null
*/
public function getParentActivities(): ?array
{
return $this->parentActivities;
}
/**
* @return Activity[]|null
*/
public function getGroupingActivities(): ?array
{
return $this->groupingActivities;
}
/**
* @return Activity[]|null
*/
public function getCategoryActivities(): ?array
{
return $this->categoryActivities;
}
/**
* @return Activity[]|null
*/
public function getOtherActivities(): ?array
{
return $this->otherActivities;
}
}

206
vendor/php-xapi/model/src/Definition.php vendored Normal file
View File

@@ -0,0 +1,206 @@
<?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 Xabbuh\XApi\Model;
/**
* Definition of an {@link Activity}.
*
* A number of derived classes exists each of them covering a specialized
* type of user interaction:
*
* <ul>
* <li>ChoiceInteractionDefinition</li>
* <li>FillInteractionDefinition</li>
* <li>LikertInteractionDefinition</li>
* <li>LongFillInInteractionDefinition</li>
* <li>MatchingInteractionDefinition</li>
* <li>NumericInteractionDefinition</li>
* <li>PerformanceInteractionDefinition</li>
* <li>OtherInteractionDefinition</li>
* <li>SequencingInteractionDefinition</li>
* <li>TrueFalseInteractionDefinition</li>
* </ul>
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class Definition
{
private $name;
private $description;
private $type;
private $moreInfo;
private $extensions;
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null)
{
$this->name = $name;
$this->description = $description;
$this->type = $type;
$this->moreInfo = $moreInfo;
$this->extensions = $extensions;
}
public function withName(LanguageMap $name = null): self
{
$definition = clone $this;
$definition->name = $name;
return $definition;
}
public function withDescription(LanguageMap $description = null): self
{
$definition = clone $this;
$definition->description = $description;
return $definition;
}
public function withType(IRI $type = null): self
{
$definition = clone $this;
$definition->type = $type;
return $definition;
}
public function withMoreInfo(IRL $moreInfo = null): self
{
$definition = clone $this;
$definition->moreInfo = $moreInfo;
return $definition;
}
public function withExtensions(Extensions $extensions): self
{
$definition = clone $this;
$definition->extensions = $extensions;
return $definition;
}
/**
* Returns the human readable names.
*/
public function getName(): ?LanguageMap
{
return $this->name;
}
/**
* Returns the human readable descriptions.
*/
public function getDescription(): ?LanguageMap
{
return $this->description;
}
/**
* Returns the {@link Activity} type.
*/
public function getType(): ?IRI
{
return $this->type;
}
/**
* Returns an IRL where human-readable information about the activity can be found.
*/
public function getMoreInfo(): ?IRL
{
return $this->moreInfo;
}
public function getExtensions(): ?Extensions
{
return $this->extensions;
}
/**
* Checks if another definition is equal.
*
* Two definitions are equal if and only if all of their properties are equal.
*/
public function equals(Definition $definition): bool
{
if (get_class($this) !== get_class($definition)) {
return false;
}
if (null !== $this->type xor null !== $definition->type) {
return false;
}
if (null !== $this->type && null !== $definition->type && !$this->type->equals($definition->type)) {
return false;
}
if (null !== $this->moreInfo xor null !== $definition->moreInfo) {
return false;
}
if (null !== $this->moreInfo && null !== $definition->moreInfo && !$this->moreInfo->equals($definition->moreInfo)) {
return false;
}
if (null !== $this->extensions xor null !== $definition->extensions) {
return false;
}
if (null !== $this->name xor null !== $definition->name) {
return false;
}
if (null !== $this->description xor null !== $definition->description) {
return false;
}
if (null !== $this->name) {
if (count($this->name) !== count($definition->name)) {
return false;
}
foreach ($this->name as $language => $value) {
if (!isset($definition->name[$language])) {
return false;
}
if ($value !== $definition->name[$language]) {
return false;
}
}
}
if (null !== $this->description) {
if (count($this->description) !== count($definition->description)) {
return false;
}
foreach ($this->description as $language => $value) {
if (!isset($definition->description[$language])) {
return false;
}
if ($value !== $definition->description[$language]) {
return false;
}
}
}
if (null !== $this->extensions && null !== $definition->extensions && !$this->extensions->equals($definition->extensions)) {
return false;
}
return true;
}
}

71
vendor/php-xapi/model/src/Document.php vendored Normal file
View File

@@ -0,0 +1,71 @@
<?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 Xabbuh\XApi\Model;
/**
* An Experience API document.
*
* A document is immutable. This means that it can be accessed like an array.
* But you can only do this to read data. Thus an {@link UnsupportedOperationException}
* is thrown when you try to unset data or to manipulate them.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class Document implements \ArrayAccess
{
private $data;
public function __construct(DocumentData $data)
{
$this->data = $data;
}
/**
* {@inheritDoc}
*/
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}
/**
* {@inheritDoc}
*/
public function offsetGet($offset)
{
return $this->data[$offset];
}
/**
* {@inheritDoc}
*/
public function offsetSet($offset, $value): void
{
$this->data[$offset] = $value;
}
/**
* {@inheritDoc}
*/
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
/**
* Returns the document's data.
*/
public function getData(): DocumentData
{
return $this->data;
}
}

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 Xabbuh\XApi\Model;
use Xabbuh\XApi\Common\Exception\UnsupportedOperationException;
/**
* An xAPI document's data.
*
* Document data are immutable. This means that they can be accessed like an array.
* But you can only do this to read data. Thus an {@link UnsupportedOperationException}
* is thrown when you try to unset data or to manipulate them.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class DocumentData implements \ArrayAccess
{
private $data = array();
public function __construct(array $data = array())
{
$this->data = $data;
}
/**
* {@inheritDoc}
*/
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}
/**
* {@inheritDoc}
*/
public function offsetGet($offset)
{
if (!isset($this->data[$offset])) {
throw new \InvalidArgumentException(sprintf('No data for name "%s" registered.', $offset));
}
return $this->data[$offset];
}
/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException Documents are immutable
*/
public function offsetSet($offset, $value): void
{
throw new UnsupportedOperationException('A document is immutable.');
}
/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException Documents are immutable
*/
public function offsetUnset($offset): void
{
throw new UnsupportedOperationException('A document is immutable.');
}
/**
* Returns all data as an array.
*/
public function getData(): array
{
return $this->data;
}
}

View File

@@ -0,0 +1,24 @@
<?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 Xabbuh\XApi\Model\Exception;
use Xabbuh\XApi\Common\Exception\XApiException;
/**
* Exception indicating that an xAPI statement is in an invalid state (e.g.
* some necessary properties are missing).
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class InvalidStateException extends XApiException
{
}

117
vendor/php-xapi/model/src/Extensions.php vendored Normal file
View File

@@ -0,0 +1,117 @@
<?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 Xabbuh\XApi\Model;
use Xabbuh\XApi\Common\Exception\UnsupportedOperationException;
/**
* xAPI statement extensions.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Extensions implements \ArrayAccess
{
private $extensions;
public function __construct(\SplObjectStorage $extensions = null)
{
$this->extensions = array();
if (null !== $extensions) {
foreach ($extensions as $iri) {
if (!$iri instanceof IRI) {
throw new \InvalidArgumentException(sprintf('Expected an IRI instance as key (got %s).', is_object($iri) ? get_class($iri) : gettype($iri)));
}
$this->extensions[$iri->getValue()] = $extensions[$iri];
}
}
}
/**
* {@inheritdoc}
*/
public function offsetExists($offset): bool
{
if (!$offset instanceof IRI) {
throw new \InvalidArgumentException(sprintf('Expected an IRI instance as key (got %s).', is_object($offset) ? get_class($offset) : gettype($offset)));
}
return isset($this->extensions[$offset->getValue()]);
}
/**
* {@inheritdoc}
*/
public function offsetGet($offset)
{
if (!$offset instanceof IRI) {
throw new \InvalidArgumentException(sprintf('Expected an IRI instance as key (got %s).', is_object($offset) ? get_class($offset) : gettype($offset)));
}
if (!isset($this->extensions[$offset->getValue()])) {
throw new \InvalidArgumentException(sprintf('No extension for key "%s" registered.', $offset->getValue()));
}
return $this->extensions[$offset->getValue()];
}
/**
* {@inheritdoc}
*
* @throws UnsupportedOperationException Statement extensions are immutable
*/
public function offsetSet($offset, $value): void
{
throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
}
/**
* {@inheritdoc}
*
* @throws UnsupportedOperationException Statement extensions are immutable
*/
public function offsetUnset($offset): void
{
throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
}
public function getExtensions(): \SplObjectStorage
{
$extensions = new \SplObjectStorage();
foreach ($this->extensions as $iri => $value) {
$extensions->attach(IRI::fromString($iri), $value);
}
return $extensions;
}
public function equals(Extensions $otherExtensions): bool
{
if (count($this->extensions) !== count($otherExtensions->extensions)) {
return false;
}
foreach ($this->extensions as $iri => $value) {
if (!array_key_exists($iri, $otherExtensions->extensions)) {
return false;
}
if ($this->extensions[$iri] != $otherExtensions->extensions[$iri]) {
return false;
}
}
return true;
}
}

66
vendor/php-xapi/model/src/Group.php vendored Normal file
View File

@@ -0,0 +1,66 @@
<?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 Xabbuh\XApi\Model;
/**
* A group of {@link Agent Agents} of a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Group extends Actor
{
private $members = array();
/**
* @param Agent[] $members
*/
public function __construct(InverseFunctionalIdentifier $iri = null, string $name = null, array $members = array())
{
parent::__construct($iri, $name);
$this->members = $members;
}
/**
* Returns the members of this group.
*
* @return Agent[]
*/
public function getMembers(): array
{
return $this->members;
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $actor): bool
{
if (!parent::equals($actor)) {
return false;
}
/** @var Group $actor */
if (count($this->members) !== count($actor->members)) {
return false;
}
foreach ($this->members as $member) {
if (!in_array($member, $actor->members)) {
return false;
}
}
return true;
}
}

47
vendor/php-xapi/model/src/IRI.php vendored Normal file
View File

@@ -0,0 +1,47 @@
<?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 Xabbuh\XApi\Model;
/**
* An internationalized resource identifier according to RFC 3987.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class IRI
{
private $value;
private function __construct()
{
}
/**
* @throws \InvalidArgumentException if the given value is no valid IRI
*/
public static function fromString(string $value): self
{
$iri = new self();
$iri->value = $value;
return $iri;
}
public function getValue(): string
{
return $this->value;
}
public function equals(IRI $iri): bool
{
return $this->value === $iri->value;
}
}

47
vendor/php-xapi/model/src/IRL.php vendored Normal file
View File

@@ -0,0 +1,47 @@
<?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 Xabbuh\XApi\Model;
/**
* An internationalized resource locator.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class IRL
{
private $value;
private function __construct()
{
}
/**
* @throws \InvalidArgumentException if the given value is no valid IRL
*/
public static function fromString(string $value): self
{
$iri = new self();
$iri->value = $value;
return $iri;
}
public function getValue(): string
{
return $this->value;
}
public function equals(IRL $irl): bool
{
return $this->value === $irl->value;
}
}

View File

@@ -0,0 +1,92 @@
<?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 Xabbuh\XApi\Model\Interaction;
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;
/**
* An interaction with a number of possible choices from which the learner
* can select.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ChoiceInteractionDefinition extends InteractionDefinition
{
private $choices;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $choices
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $choices = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->choices = $choices;
}
/**
* @param InteractionComponent[]|null $choices
*/
public function withChoices(array $choices = null): self
{
$interaction = clone $this;
$interaction->choices = $choices;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getChoices(): ?array
{
return $this->choices;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof ChoiceInteractionDefinition) {
return false;
}
if (null !== $this->choices xor null !== $definition->choices) {
return false;
}
if (null !== $this->choices) {
if (count($this->choices) !== count($definition->choices)) {
return false;
}
foreach ($this->choices as $key => $choice) {
if (!isset($definition->choices[$key])) {
return false;
}
if (!$choice->equals($definition->choices[$key])) {
return false;
}
}
}
return true;
}
}

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 Xabbuh\XApi\Model\Interaction;
/**
* An interaction which requires the learner to supply a short response
* in the form of one or more strings of characters.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class FillInInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,58 @@
<?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 Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\LanguageMap;
/**
* An XAPI activity interaction component.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class InteractionComponent
{
private $id;
private $description;
public function __construct(string $id, LanguageMap $description = null)
{
$this->id = $id;
$this->description = $description;
}
public function getId(): string
{
return $this->id;
}
public function getDescription(): ?LanguageMap
{
return $this->description;
}
public function equals(InteractionComponent $interactionComponent): bool
{
if ($this->id !== $interactionComponent->id) {
return false;
}
if (null !== $this->description xor null !== $interactionComponent->description) {
return false;
}
if (null !== $this->description && null !== $interactionComponent->description && !$this->description->equals($interactionComponent->description)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,86 @@
<?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 Xabbuh\XApi\Model\Interaction;
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;
/**
* Base class for interaction definitions of an {@link Activity}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class InteractionDefinition extends Definition
{
private $correctResponsesPattern;
/**
* @param string[]|null $correctResponsesPattern
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions);
$this->correctResponsesPattern = $correctResponsesPattern;
}
/**
* @param string[]|null $correctResponsesPattern
*/
public function withCorrectResponsesPattern(array $correctResponsesPattern = null): self
{
$interaction = clone $this;
$interaction->correctResponsesPattern = $correctResponsesPattern;
return $interaction;
}
/**
* @return string[]|null
*/
public function getCorrectResponsesPattern(): ?array
{
return $this->correctResponsesPattern;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof InteractionDefinition) {
return false;
}
if (null !== $this->correctResponsesPattern xor null !== $definition->correctResponsesPattern) {
return false;
}
if (null !== $this->correctResponsesPattern) {
if (count($this->correctResponsesPattern) !== count($definition->correctResponsesPattern)) {
return false;
}
foreach ($this->correctResponsesPattern as $value) {
if (!in_array($value, $definition->correctResponsesPattern, true)) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,92 @@
<?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 Xabbuh\XApi\Model\Interaction;
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;
/**
* An interaction which asks the learner to select from a discrete set of
* choices on a scale.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class LikertInteractionDefinition extends InteractionDefinition
{
private $scale;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $scale
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $scale = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->scale = $scale;
}
/**
* @param InteractionComponent[]|null $scale
*/
public function withScale(array $scale = null): self
{
$interaction = clone $this;
$interaction->scale = $scale;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getScale(): ?array
{
return $this->scale;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof LikertInteractionDefinition) {
return false;
}
if (null !== $this->scale xor null !== $definition->scale) {
return false;
}
if (null !== $this->scale) {
if (count($this->scale) !== count($definition->scale)) {
return false;
}
foreach ($this->scale as $key => $scale) {
if (!isset($definition->scale[$key])) {
return false;
}
if (!$scale->equals($definition->scale[$key])) {
return false;
}
}
}
return true;
}
}

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 Xabbuh\XApi\Model\Interaction;
/**
* An interaction which requires the learner to supply a response in the
* form of a long string of characters.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class LongFillInInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,134 @@
<?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 Xabbuh\XApi\Model\Interaction;
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;
/**
* An interaction where the learner is asked to match items in one set
* (the source set) to items in another set (the target set).
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class MatchingInteractionDefinition extends InteractionDefinition
{
private $source;
private $target;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $source
* @param InteractionComponent[]|null $target
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $source = null, array $target = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->source = $source;
$this->target = $target;
}
/**
* @param InteractionComponent[]|null $source
*/
public function withSource(array $source = null): self
{
$interaction = clone $this;
$interaction->source = $source;
return $interaction;
}
/**
* @param InteractionComponent[]|null $target
*/
public function withTarget(array $target = null): self
{
$interaction = clone $this;
$interaction->target = $target;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getSource(): ?array
{
return $this->source;
}
/**
* @return InteractionComponent[]|null
*/
public function getTarget(): ?array
{
return $this->target;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof MatchingInteractionDefinition) {
return false;
}
if (null !== $this->source xor null !== $definition->source) {
return false;
}
if (null !== $this->target xor null !== $definition->target) {
return false;
}
if (null !== $this->source) {
if (count($this->source) !== count($definition->source)) {
return false;
}
foreach ($this->source as $key => $source) {
if (!isset($definition->source[$key])) {
return false;
}
if (!$source->equals($definition->source[$key])) {
return false;
}
}
}
if (null !== $this->target) {
if (count($this->target) !== count($definition->target)) {
return false;
}
foreach ($this->target as $key => $target) {
if (!isset($definition->target[$key])) {
return false;
}
if (!$target->equals($definition->target[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?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 Xabbuh\XApi\Model\Interaction;
/**
* Any interaction which requires a numeric response from the learner.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class NumericInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,21 @@
<?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 Xabbuh\XApi\Model\Interaction;
/**
* A type of interaction that does not fit into the other defined ones.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class OtherInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,92 @@
<?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 Xabbuh\XApi\Model\Interaction;
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;
/**
* An interaction that requires the learner to perform a task that requires
* multiple steps.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class PerformanceInteractionDefinition extends InteractionDefinition
{
private $steps;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $steps
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $steps = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->steps = $steps;
}
/**
* @param InteractionComponent[]|null $steps
*/
public function withSteps(array $steps = null): self
{
$interaction = clone $this;
$interaction->steps = $steps;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getSteps(): ?array
{
return $this->steps;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof PerformanceInteractionDefinition) {
return false;
}
if (null !== $this->steps xor null !== $definition->steps) {
return false;
}
if (null !== $this->steps) {
if (count($this->steps) !== count($definition->steps)) {
return false;
}
foreach ($this->steps as $key => $step) {
if (!isset($definition->steps[$key])) {
return false;
}
if (!$step->equals($definition->steps[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,91 @@
<?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 Xabbuh\XApi\Model\Interaction;
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;
/**
* An interaction where the learner is asked to order items in a set.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class SequencingInteractionDefinition extends InteractionDefinition
{
private $choices;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $choices
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $choices = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->choices = $choices;
}
/**
* @param InteractionComponent[]|null $choices
*/
public function withChoices(array $choices = null): self
{
$interaction = clone $this;
$interaction->choices = $choices;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getChoices(): ?array
{
return $this->choices;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof SequencingInteractionDefinition) {
return false;
}
if (null !== $this->choices xor null !== $definition->choices) {
return false;
}
if (null !== $this->choices) {
if (count($this->choices) !== count($definition->choices)) {
return false;
}
foreach ($this->choices as $key => $choice) {
if (!isset($definition->choices[$key])) {
return false;
}
if (!$choice->equals($definition->choices[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?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 Xabbuh\XApi\Model\Interaction;
/**
* An interaction with two possible responses: true or false.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class TrueFalseInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,149 @@
<?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 Xabbuh\XApi\Model;
/**
* The inverse functional identifier of an {@link Actor}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class InverseFunctionalIdentifier
{
private $mbox;
private $mboxSha1Sum;
private $openId;
private $account;
/**
* Use one of the with*() factory methods to obtain an InverseFunctionalIdentifier
* instance.
*/
private function __construct()
{
}
public static function withMbox(IRI $mbox): self
{
$iri = new InverseFunctionalIdentifier();
$iri->mbox = $mbox;
return $iri;
}
public static function withMboxSha1Sum(string $mboxSha1Sum): self
{
$iri = new InverseFunctionalIdentifier();
$iri->mboxSha1Sum = $mboxSha1Sum;
return $iri;
}
public static function withOpenId(string $openId): self
{
$iri = new InverseFunctionalIdentifier();
$iri->openId = $openId;
return $iri;
}
public static function withAccount(Account $account): self
{
$iri = new InverseFunctionalIdentifier();
$iri->account = $account;
return $iri;
}
/**
* Returns the mailto IRI.
*/
public function getMbox(): ?IRI
{
return $this->mbox;
}
/**
* Returns the SHA1 hash of a mailto IRI.
*/
public function getMboxSha1Sum(): ?string
{
return $this->mboxSha1Sum;
}
/**
* Returns the openID.
*/
public function getOpenId(): ?string
{
return $this->openId;
}
/**
* Returns the user account of an existing system.
*/
public function getAccount(): ?Account
{
return $this->account;
}
/**
* Checks if another IRI is equal.
*
* Two inverse functional identifiers are equal if and only if all of their
* properties are equal.
*/
public function equals(InverseFunctionalIdentifier $iri): bool
{
if (null !== $this->mbox && null !== $iri->mbox && !$this->mbox->equals($iri->mbox)) {
return false;
}
if ($this->mboxSha1Sum !== $iri->mboxSha1Sum) {
return false;
}
if ($this->openId !== $iri->openId) {
return false;
}
if (null === $this->account && null !== $iri->account) {
return false;
}
if (null !== $this->account && null === $iri->account) {
return false;
}
if (null !== $this->account && !$this->account->equals($iri->account)) {
return false;
}
return true;
}
public function __toString(): string
{
if (null !== $this->mbox) {
return $this->mbox->getValue();
}
if (null !== $this->mboxSha1Sum) {
return $this->mboxSha1Sum;
}
if (null !== $this->openId) {
return $this->openId;
}
return sprintf('%s (%s)', $this->account->getName(), $this->account->getHomePage()->getValue());
}
}

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 Xabbuh\XApi\Model;
/**
* Read-only dictionary mapping RFC 5646 language tags to translated strings.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class LanguageMap implements \ArrayAccess, \Countable
{
private $map;
/**
* Creates a language map from the given dictionary.
*
* Keys are RFC 5646 language tags and each value is a string in the
* language specified by the key.
*/
public static function create(array $map): self
{
$languageMap = new self();
$languageMap->map = $map;
return $languageMap;
}
/**
* Creates a new language map based on the current map including the given entry.
*
* An existing entry will be overridden if the given language tag is already
* present in this language map.
*/
public function withEntry(string $languageTag, string $value): self
{
$languageMap = clone $this;
$languageMap->map[$languageTag] = $value;
return $languageMap;
}
/**
* Returns an unordered list of all language tags being used as keys
* in this language map.
*
* @return string[]
*/
public function languageTags(): array
{
return array_keys($this->map);
}
/**
* {@inheritdoc}
*/
public function offsetExists($languageTag): bool
{
return isset($this->map[$languageTag]);
}
/**
* {@inheritdoc}
*/
public function offsetGet($languageTag): string
{
if (!isset($this->map[$languageTag])) {
throw new \InvalidArgumentException(sprintf('The requested language tag "%s" does not exist in this language map.', $languageTag));
}
return $this->map[$languageTag];
}
/**
* {@inheritdoc}
*/
public function offsetSet($languageTag, $value): void
{
throw new \LogicException('The values of a language map cannot be modified. Use withEntry() instead to retrieve a new language map with the added or modified value.');
}
/**
* {@inheritdoc}
*/
public function offsetUnset($languageTag): void
{
throw new \LogicException('Entries of a language map cannot be removed.');
}
public function count(): int
{
return count($this->map);
}
public function equals(LanguageMap $languageMap): bool
{
if (count($this->map) !== count($languageMap->map)) {
return false;
}
foreach ($this->map as $languageTag => $value) {
if (!isset($languageMap[$languageTag])) {
return false;
}
if ($value !== $languageMap[$languageTag]) {
return false;
}
}
return true;
}
}

123
vendor/php-xapi/model/src/Person.php vendored Normal file
View File

@@ -0,0 +1,123 @@
<?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 Xabbuh\XApi\Model;
/**
* Combined informations from multiple {@link Agent agents}.
*
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
final class Person
{
/**
* @var string[] List of names of Agents
*/
private $names = array();
/**
* @var IRI[] List of mailto IRIs of Agents
*/
private $mboxes = array();
/**
* @var string[] List of the SHA1 hashes of mailto IRIs of Agents
*/
private $mboxSha1Sums = array();
/**
* @var string[] List of openids that uniquely identify the Agents
*/
private $openIds = array();
/**
* @var Account[] List of accounts of Agents
*/
private $accounts = array();
private function __construct()
{
}
/**
* @param Agent[] $agents
*/
public static function createFromAgents(array $agents): self
{
$person = new self();
foreach ($agents as $agent) {
$iri = $agent->getInverseFunctionalIdentifier();
if (null !== $mbox = $iri->getMbox()) {
$person->mboxes[] = $mbox;
}
if (null !== $mboxSha1Sum = $iri->getMboxSha1Sum()) {
$person->mboxSha1Sums[] = $mboxSha1Sum;
}
if (null !== $openId = $iri->getOpenId()) {
$person->openIds[] = $openId;
}
if (null !== $account = $iri->getAccount()) {
$person->accounts[] = $account;
}
if (null !== $name = $agent->getName()) {
$person->names[] = $name;
}
}
return $person;
}
/**
* @return string[]
*/
public function getNames(): array
{
return $this->names;
}
/**
* @return IRI[]
*/
public function getMboxes(): array
{
return $this->mboxes;
}
/**
* @return string[]
*/
public function getMboxSha1Sums(): array
{
return $this->mboxSha1Sums;
}
/**
* @return string[]
*/
public function getOpenIds(): array
{
return $this->openIds;
}
/**
* @return Account[]
*/
public function getAccounts(): array
{
return $this->accounts;
}
}

32
vendor/php-xapi/model/src/Profile.php vendored Normal file
View File

@@ -0,0 +1,32 @@
<?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 Xabbuh\XApi\Model;
/**
* A profile.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class Profile
{
private $profileId;
public function __construct(string $profileId)
{
$this->profileId = $profileId;
}
public function getProfileId(): string
{
return $this->profileId;
}
}

176
vendor/php-xapi/model/src/Result.php vendored Normal file
View File

@@ -0,0 +1,176 @@
<?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 Xabbuh\XApi\Model;
/**
* An {@link Actor Actor's} outcome related to the {@link Statement} in which
* it is included.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Result
{
private $score;
private $success;
private $completion;
private $response;
private $duration;
private $extensions;
public function __construct(Score $score = null, bool $success = null, bool $completion = null, string $response = null, string $duration = null, Extensions $extensions = null)
{
$this->score = $score;
$this->success = $success;
$this->completion = $completion;
$this->response = $response;
$this->duration = $duration;
$this->extensions = $extensions;
}
public function withScore(Score $score = null): self
{
$result = clone $this;
$result->score = $score;
return $result;
}
public function withSuccess(bool $success = null): self
{
$result = clone $this;
$result->success = $success;
return $result;
}
public function withCompletion(bool $completion = null): self
{
$result = clone $this;
$result->completion = $completion;
return $result;
}
public function withResponse(string $response = null): self
{
$result = clone $this;
$result->response = $response;
return $result;
}
public function withDuration(string $duration = null): self
{
$result = clone $this;
$result->duration = $duration;
return $result;
}
public function withExtensions(Extensions $extensions = null): self
{
$result = clone $this;
$result->extensions = $extensions;
return $result;
}
/**
* Returns the user's score.
*/
public function getScore(): ?Score
{
return $this->score;
}
/**
* Returns whether or not the user finished a task successfully.
*/
public function getSuccess(): ?bool
{
return $this->success;
}
/**
* Returns the completion status.
*/
public function getCompletion(): ?bool
{
return $this->completion;
}
/**
* Returns the response.
*/
public function getResponse(): ?string
{
return $this->response;
}
/**
* Returns the period of time over which the Activity was performed.
*/
public function getDuration(): ?string
{
return $this->duration;
}
/**
* Returns the extensions associated with the result.
*/
public function getExtensions(): ?Extensions
{
return $this->extensions;
}
/**
* Checks if another result is equal.
*
* Two results are equal if and only if all of their properties are equal.
*/
public function equals(Result $result): bool
{
if (null !== $this->score xor null !== $result->score) {
return false;
}
if (null !== $this->score && !$this->score->equals($result->score)) {
return false;
}
if ($this->success !== $result->success) {
return false;
}
if ($this->completion !== $result->completion) {
return false;
}
if ($this->response !== $result->response) {
return false;
}
if ($this->duration !== $result->duration) {
return false;
}
if (null !== $this->extensions xor null !== $result->extensions) {
return false;
}
if (null !== $this->extensions && null !== $result->extensions && !$this->extensions->equals($result->extensions)) {
return false;
}
return true;
}
}

165
vendor/php-xapi/model/src/Score.php vendored Normal file
View File

@@ -0,0 +1,165 @@
<?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 Xabbuh\XApi\Model;
/**
* The outcome of an {@link Activity} achieved by an {@link Agent}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Score
{
private $scaled;
private $raw;
private $min;
private $max;
/**
* @param float|int|null $scaled
* @param float|int|null $raw
* @param float|int|null $min
* @param float|int|null $max
*/
public function __construct($scaled = null, $raw = null, $min = null, $max = null)
{
$this->scaled = $scaled;
$this->raw = $raw;
$this->min = $min;
$this->max = $max;
}
/**
* @param float|int|null $scaled
*/
public function withScaled($scaled): self
{
$score = clone $this;
$score->scaled = $scaled;
return $score;
}
/**
* @param float|int|null $raw
*/
public function withRaw($raw): self
{
$score = clone $this;
$score->raw = $raw;
return $score;
}
/**
* @param float|int|null $min
*/
public function withMin($min): self
{
$score = clone $this;
$score->min = $min;
return $score;
}
/**
* @param float|int|null $max
*/
public function withMax($max): self
{
$score = clone $this;
$score->max = $max;
return $score;
}
/**
* Returns the Agent's scaled score (a number between -1 and 1).
*
* @return float|int|null The scaled score
*/
public function getScaled()
{
return $this->scaled;
}
/**
* Returns the Agent's score (a number between min and max).
*
* @return float|int|null The score
*/
public function getRaw()
{
return $this->raw;
}
/**
* Returns the lowest possible score.
*
* @return float|int|null The lowest possible score
*/
public function getMin()
{
return $this->min;
}
/**
* Returns the highest possible score.
*
* @return float|int|null The highest possible score
*/
public function getMax()
{
return $this->max;
}
/**
* Checks if another score is equal.
*
* Two scores are equal if and only if all of their properties are equal.
*/
public function equals(Score $score): bool
{
if (null !== $this->scaled xor null !== $score->scaled) {
return false;
}
if ((float) $this->scaled !== (float) $score->scaled) {
return false;
}
if (null !== $this->raw xor null !== $score->raw) {
return false;
}
if ((float) $this->raw !== (float) $score->raw) {
return false;
}
if (null !== $this->min xor null !== $score->min) {
return false;
}
if ((float) $this->min !== (float) $score->min) {
return false;
}
if (null !== $this->max xor null !== $score->max) {
return false;
}
if ((float) $this->max !== (float) $score->max) {
return false;
}
return true;
}
}

81
vendor/php-xapi/model/src/State.php vendored Normal file
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 Xabbuh\XApi\Model;
/**
* An activity provider's state stored on a remote LRS.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class State
{
private $activity;
private $actor;
private $registrationId;
private $stateId;
public function __construct(Activity $activity, Actor $actor, string $stateId, string $registrationId = null)
{
if (!$actor instanceof Agent) {
@trigger_error(sprintf('Passing an instance of "%s" as the second argument is deprecated since 1.2. In 4.0, only instances of "Xabbuh\XApi\Model\Agent" will be accepted.', get_class($actor)), E_USER_DEPRECATED);
}
$this->activity = $activity;
$this->actor = $actor;
$this->stateId = $stateId;
$this->registrationId = $registrationId;
}
/**
* Returns the activity.
*/
public function getActivity(): Activity
{
return $this->activity;
}
/**
* Returns the actor.
*
* @deprecated since 1.2, to be removed in 4.0
*/
public function getActor(): Actor
{
@trigger_error(sprintf('The "%s()" method is deprecated since 1.2 and will be removed in 4.0, use "%s::getAgent()" instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED);
return $this->getAgent();
}
/**
* Returns the agent.
*/
public function getAgent(): Agent
{
return $this->actor;
}
/**
* Returns the registration id.
*/
public function getRegistrationId(): ?string
{
return $this->registrationId;
}
/**
* Returns the state's id.
*/
public function getStateId(): string
{
return $this->stateId;
}
}

View File

@@ -0,0 +1,37 @@
<?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 Xabbuh\XApi\Model;
/**
* A document associated to an activity provider state.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StateDocument extends Document
{
private $state;
public function __construct(State $state, DocumentData $data)
{
parent::__construct($data);
$this->state = $state;
}
/**
* Returns the document's {@link State}.
*/
public function getState(): State
{
return $this->state;
}
}

View File

@@ -0,0 +1,75 @@
<?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 Xabbuh\XApi\Model;
/**
* Filter to apply on GET requests to the states API.
*
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
class StateDocumentsFilter
{
/**
* @var array The generated filter
*/
private $filter = array();
/**
* Filter by an Activity.
*/
public function byActivity(Activity $activity): self
{
$this->filter['activity'] = $activity->getId()->getValue();
return $this;
}
/**
* Filters by an Agent.
*/
public function byAgent(Agent $agent): self
{
$this->filter['agent'] = $agent;
return $this;
}
/**
* Filters for State documents matching the given registration id.
*/
public function byRegistration(string $registration): self
{
$this->filter['registration'] = $registration;
return $this;
}
/**
* Filters for State documents stored since the specified timestamp (exclusive).
*/
public function since(\DateTime $timestamp): self
{
$this->filter['since'] = $timestamp->format('c');
return $this;
}
/**
* Returns the generated filter.
*
* @return array The filter
*/
public function getFilter(): array
{
return $this->filter;
}
}

343
vendor/php-xapi/model/src/Statement.php vendored Normal file
View File

@@ -0,0 +1,343 @@
<?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 Xabbuh\XApi\Model;
/**
* An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Statement
{
private $id;
private $verb;
private $actor;
private $object;
private $result;
private $authority;
private $created;
private $stored;
private $context;
private $attachments;
private $version;
/**
* @param Attachment[]|null $attachments
*/
public function __construct(StatementId $id = null, Actor $actor, Verb $verb, StatementObject $object, Result $result = null, Actor $authority = null, \DateTime $created = null, \DateTime $stored = null, Context $context = null, array $attachments = null, string $version = null)
{
$this->id = $id;
$this->actor = $actor;
$this->verb = $verb;
$this->object = $object;
$this->result = $result;
$this->authority = $authority;
$this->created = $created;
$this->stored = $stored;
$this->context = $context;
$this->attachments = null !== $attachments ? array_values($attachments) : null;
$this->version = $version;
}
public function withId(StatementId $id = null): self
{
$statement = clone $this;
$statement->id = $id;
return $statement;
}
public function withActor(Actor $actor): self
{
$statement = clone $this;
$statement->actor = $actor;
return $statement;
}
public function withVerb(Verb $verb): self
{
$statement = clone $this;
$statement->verb = $verb;
return $statement;
}
public function withObject(StatementObject $object): self
{
$statement = clone $this;
$statement->object = $object;
return $statement;
}
public function withResult(Result $result = null): self
{
$statement = clone $this;
$statement->result = $result;
return $statement;
}
/**
* Creates a new Statement based on the current one containing an Authority
* that asserts the Statement true.
*/
public function withAuthority(Actor $authority = null): self
{
$statement = clone $this;
$statement->authority = $authority;
return $statement;
}
public function withCreated(\DateTime $created = null): self
{
$statement = clone $this;
$statement->created = $created;
return $statement;
}
public function withStored(\DateTime $stored = null): self
{
$statement = clone $this;
$statement->stored = $stored;
return $statement;
}
public function withContext(Context $context = null): self
{
$statement = clone $this;
$statement->context = $context;
return $statement;
}
/**
* @param Attachment[]|null $attachments
*/
public function withAttachments(array $attachments = null): self
{
$statement = clone $this;
$statement->attachments = null !== $attachments ? array_values($attachments) : null;
return $statement;
}
public function withVersion(string $version = null): self
{
$statement = clone $this;
$statement->version = $version;
return $statement;
}
/**
* Returns the Statement's unique identifier.
*/
public function getId(): ?StatementId
{
return $this->id;
}
/**
* Returns the Statement's {@link Verb}.
*/
public function getVerb(): Verb
{
return $this->verb;
}
/**
* Returns the Statement's {@link Actor}.
*/
public function getActor(): Actor
{
return $this->actor;
}
/**
* Returns the Statement's {@link StatementObject}.
*/
public function getObject(): StatementObject
{
return $this->object;
}
/**
* Returns the {@link Activity} {@link Result}.
*/
public function getResult(): ?Result
{
return $this->result;
}
/**
* Returns the Authority that asserted the Statement true.
*/
public function getAuthority(): ?Actor
{
return $this->authority;
}
/**
* Returns the timestamp of when the events described in this statement
* occurred.
*/
public function getCreated(): ?\DateTime
{
return $this->created;
}
/**
* Returns the timestamp of when this statement was recorded by the LRS.
*/
public function getStored(): ?\DateTime
{
return $this->stored;
}
/**
* Returns the context that gives the statement more meaning.
*/
public function getContext(): ?Context
{
return $this->context;
}
/**
* @return Attachment[]|null
*/
public function getAttachments(): ?array
{
return $this->attachments;
}
public function getVersion(): ?string
{
return $this->version;
}
/**
* Tests whether or not this Statement is a void Statement (i.e. it voids
* another Statement).
*/
public function isVoidStatement(): bool
{
return $this->verb->isVoidVerb();
}
/**
* Returns a {@link StatementReference} for the Statement.
*/
public function getStatementReference(): StatementReference
{
return new StatementReference($this->id);
}
/**
* Returns a Statement that voids the current Statement.
*/
public function getVoidStatement(Actor $actor): self
{
return new Statement(
null,
$actor,
Verb::createVoidVerb(),
$this->getStatementReference()
);
}
/**
* Checks if another statement is equal.
*
* Two statements are equal if and only if all of their properties are equal.
*/
public function equals(Statement $statement): bool
{
if (null !== $this->id xor null !== $statement->id) {
return false;
}
if (null !== $this->id && null !== $statement->id && !$this->id->equals($statement->id)) {
return false;
}
if (!$this->actor->equals($statement->actor)) {
return false;
}
if (!$this->verb->equals($statement->verb)) {
return false;
}
if (!$this->object->equals($statement->object)) {
return false;
}
if (null === $this->result && null !== $statement->result) {
return false;
}
if (null !== $this->result && null === $statement->result) {
return false;
}
if (null !== $this->result && !$this->result->equals($statement->result)) {
return false;
}
if (null === $this->authority && null !== $statement->authority) {
return false;
}
if (null !== $this->authority && null === $statement->authority) {
return false;
}
if (null !== $this->authority && !$this->authority->equals($statement->authority)) {
return false;
}
if ($this->created != $statement->created) {
return false;
}
if (null !== $this->context xor null !== $statement->context) {
return false;
}
if (null !== $this->context && null !== $statement->context && !$this->context->equals($statement->context)) {
return false;
}
if (null !== $this->attachments xor null !== $statement->attachments) {
return false;
}
if (null !== $this->attachments && null !== $statement->attachments) {
if (count($this->attachments) !== count($statement->attachments)) {
return false;
}
foreach ($this->attachments as $key => $attachment) {
if (!$attachment->equals($statement->attachments[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,101 @@
<?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 Xabbuh\XApi\Model;
use Xabbuh\XApi\Model\Exception\InvalidStateException;
/*
* Statement factory eases the creation of complex xAPI statements.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementFactory
{
private $id;
private $actor;
private $verb;
private $object;
private $result;
private $context;
private $created;
private $stored;
private $authority;
public function withId(StatementId $id): void
{
$this->id = $id;
}
public function withActor(Actor $actor): void
{
$this->actor = $actor;
}
public function withVerb(Verb $verb): void
{
$this->verb = $verb;
}
public function withObject(StatementObject $object): void
{
$this->object = $object;
}
public function withResult(Result $result = null): void
{
$this->result = $result;
}
public function withContext(Context $context = null): void
{
$this->context = $context;
}
public function withCreated(\DateTime $created = null): void
{
$this->created = $created;
}
public function withStored(\DateTime $stored = null): void
{
$this->stored = $stored;
}
public function withAuthority(Actor $authority = null): void
{
$this->authority = $authority;
}
/**
* Returns a statement based on the current configuration.
*
* Multiple calls to this method will return different instances.
*
* @throws InvalidStateException
*/
public function createStatement(): Statement
{
if (null === $this->actor) {
throw new InvalidStateException('A statement actor is missing.');
}
if (null === $this->verb) {
throw new InvalidStateException('A statement verb is missing.');
}
if (null === $this->object) {
throw new InvalidStateException('A statement object is missing.');
}
return new Statement($this->id, $this->actor, $this->verb, $this->object, $this->result, $this->authority, $this->created, $this->stored, $this->context);
}
}

View File

@@ -0,0 +1,54 @@
<?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 Xabbuh\XApi\Model;
/**
* An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement} identifier.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementId
{
private $uuid;
private function __construct()
{
}
public static function fromUuid(Uuid $uuid): self
{
$id = new self();
$id->uuid = $uuid;
return $id;
}
/**
* Creates a statement id based on the given UUID string.
*
* @throws \InvalidArgumentException when the given id is not a well-formed UUID
*/
public static function fromString(string $id): self
{
return self::fromUuid(Uuid::fromString($id));
}
public function getValue(): string
{
return (string) $this->uuid;
}
public function equals(StatementId $id): bool
{
return $this->uuid->equals($id->uuid);
}
}

View File

@@ -0,0 +1,30 @@
<?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 Xabbuh\XApi\Model;
/**
* The object of a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class StatementObject
{
/**
* Checks if another object is equal.
*
* Two objects are equal if and only if all of their properties are equal.
*/
public function equals(StatementObject $object): bool
{
return get_class($this) === get_class($object);
}
}

View File

@@ -0,0 +1,47 @@
<?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 Xabbuh\XApi\Model;
/**
* A reference to an existing {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementReference extends StatementObject
{
private $statementId;
public function __construct(StatementId $statementId)
{
$this->statementId = $statementId;
}
/**
* Returns the id of the referenced Statement.
*/
public function getStatementId(): StatementId
{
return $this->statementId;
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $object): bool
{
if (!$object instanceof StatementReference) {
return false;
}
return $this->statementId->equals($object->statementId);
}
}

View File

@@ -0,0 +1,51 @@
<?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 Xabbuh\XApi\Model;
/**
* Result when querying a Learning Record Store (LRS) for a list of
* {@link Statement Statements}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementResult
{
private $statements;
private $moreUrlPath;
/**
* @param Statement[] $statements The collection of Statements
*/
public function __construct(array $statements, IRL $moreUrlPath = null)
{
$this->statements = $statements;
$this->moreUrlPath = $moreUrlPath;
}
/**
* Returns the Statements.
*
* @return Statement[]
*/
public function getStatements(): array
{
return $this->statements;
}
/**
* Relative IRL that can be used to retrieve the next results.
*/
public function getMoreUrlPath(): ?IRL
{
return $this->moreUrlPath;
}
}

View File

@@ -0,0 +1,168 @@
<?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 Xabbuh\XApi\Model;
/**
* Filter to apply on GET requests to the statements API.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class StatementsFilter
{
private $filter = array();
/**
* Filters by an Agent or an identified Group.
*/
public function byActor(Actor $actor): self
{
$this->filter['agent'] = $actor;
return $this;
}
/**
* Filters by a verb.
*/
public function byVerb(Verb $verb): self
{
$this->filter['verb'] = $verb->getId()->getValue();
return $this;
}
/**
* Filter by an Activity.
*/
public function byActivity(Activity $activity): self
{
$this->filter['activity'] = $activity->getId()->getValue();
return $this;
}
/**
* Filters for Statements matching the given registration id.
*/
public function byRegistration(string $registration): self
{
$this->filter['registration'] = $registration;
return $this;
}
/**
* Applies the Activity filter to Sub-Statements.
*/
public function enableRelatedActivityFilter(): self
{
$this->filter['related_activities'] = 'true';
return $this;
}
/**
* Don't apply the Activity filter to Sub-Statements.
*/
public function disableRelatedActivityFilter(): self
{
$this->filter['related_activities'] = 'false';
return $this;
}
/**
* Applies the Agent filter to Sub-Statements.
*/
public function enableRelatedAgentFilter(): self
{
$this->filter['related_agents'] = 'true';
return $this;
}
/**
* Don't apply the Agent filter to Sub-Statements.
*/
public function disableRelatedAgentFilter(): self
{
$this->filter['related_agents'] = 'false';
return $this;
}
/**
* Filters for Statements stored since the specified timestamp (exclusive).
*/
public function since(\DateTime $timestamp): self
{
$this->filter['since'] = $timestamp->format('c');
return $this;
}
/**
* Filters for Statements stored at or before the specified timestamp.
*/
public function until(\DateTime $timestamp): self
{
$this->filter['until'] = $timestamp->format('c');
return $this;
}
/**
* Sets the maximum number of Statements to return. The server side sets
* the maximum number of results when this value is not set or when it is 0.
*
* @throws \InvalidArgumentException if the limit is not a non-negative
* integer
*/
public function limit(int $limit): self
{
if ($limit < 0) {
throw new \InvalidArgumentException('Limit must be a non-negative integer');
}
$this->filter['limit'] = $limit;
return $this;
}
/**
* Return statements in ascending order of stored time.
*/
public function ascending(): self
{
$this->filter['ascending'] = 'true';
return $this;
}
/**
*Return statements in descending order of stored time (the default behavior).
*/
public function descending(): self
{
$this->filter['ascending'] = 'false';
return $this;
}
/**
* Returns the generated filter.
*/
public function getFilter(): array
{
return $this->filter;
}
}

View File

@@ -0,0 +1,235 @@
<?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 Xabbuh\XApi\Model;
/**
* A {@link Statement} included as part of a parent Statement.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class SubStatement extends StatementObject
{
private $verb;
private $actor;
private $object;
private $result;
private $created;
private $context;
private $attachments;
/**
* @param Attachment[]|null $attachments
*/
public function __construct(Actor $actor, Verb $verb, StatementObject $object, Result $result = null, Context $context = null, \DateTime $created = null, array $attachments = null)
{
if ($object instanceof SubStatement) {
throw new \InvalidArgumentException('Nesting sub statements is forbidden by the xAPI spec.');
}
$this->actor = $actor;
$this->verb = $verb;
$this->object = $object;
$this->result = $result;
$this->created = $created;
$this->context = $context;
$this->attachments = null !== $attachments ? array_values($attachments) : null;
}
public function withActor(Actor $actor): self
{
$subStatement = clone $this;
$subStatement->actor = $actor;
return $subStatement;
}
public function withVerb(Verb $verb): self
{
$subStatement = clone $this;
$subStatement->verb = $verb;
return $subStatement;
}
public function withObject(StatementObject $object): self
{
$subStatement = clone $this;
$subStatement->object = $object;
return $subStatement;
}
public function withResult(Result $result): self
{
$subStatement = clone $this;
$subStatement->result = $result;
return $subStatement;
}
public function withCreated(\DateTime $created = null): self
{
$statement = clone $this;
$statement->created = $created;
return $statement;
}
public function withContext(Context $context): self
{
$subStatement = clone $this;
$subStatement->context = $context;
return $subStatement;
}
/**
* @param Attachment[]|null $attachments
*/
public function withAttachments(array $attachments = null): self
{
$statement = clone $this;
$statement->attachments = null !== $attachments ? array_values($attachments) : null;
return $statement;
}
/**
* Returns the Statement's {@link Verb}.
*/
public function getVerb(): Verb
{
return $this->verb;
}
/**
* Returns the Statement's {@link Actor}.
*/
public function getActor(): Actor
{
return $this->actor;
}
/**
* Returns the Statement's {@link StatementObject}.
*/
public function getObject(): StatementObject
{
return $this->object;
}
/**
* Returns the {@link Activity} {@link Result}.
*/
public function getResult(): ?Result
{
return $this->result;
}
/**
* Returns the timestamp of when the events described in this statement
* occurred.
*/
public function getCreated(): ?\DateTime
{
return $this->created;
}
/**
* Returns the {@link Statement} {@link Context}.
*/
public function getContext(): ?Context
{
return $this->context;
}
/**
* @return Attachment[]|null
*/
public function getAttachments(): ?array
{
return $this->attachments;
}
/**
* Tests whether or not this Statement is a void Statement (i.e. it voids
* another Statement).
*/
public function isVoidStatement(): bool
{
return $this->verb->isVoidVerb();
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $statement): bool
{
if (!$statement instanceof SubStatement) {
return false;
}
if (!$this->actor->equals($statement->actor)) {
return false;
}
if (!$this->verb->equals($statement->verb)) {
return false;
}
if (!$this->object->equals($statement->object)) {
return false;
}
if (null === $this->result && null !== $statement->result) {
return false;
}
if (null !== $this->result && null === $statement->result) {
return false;
}
if (null !== $this->result && !$this->result->equals($statement->result)) {
return false;
}
if ($this->created != $statement->created) {
return false;
}
if (null !== $this->context xor null !== $statement->context) {
return false;
}
if (null !== $this->context && null !== $statement->context && !$this->context->equals($statement->context)) {
return false;
}
if (null !== $this->attachments xor null !== $statement->attachments) {
return false;
}
if (null !== $this->attachments && null !== $statement->attachments) {
if (count($this->attachments) !== count($statement->attachments)) {
return false;
}
foreach ($this->attachments as $key => $attachment) {
if (!$attachment->equals($statement->attachments[$key])) {
return false;
}
}
}
return true;
}
}

112
vendor/php-xapi/model/src/Uuid.php vendored Normal file
View File

@@ -0,0 +1,112 @@
<?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 Xabbuh\XApi\Model;
use Ramsey\Uuid\Uuid as RamseyUuid;
use Rhumsaa\Uuid\Uuid as RhumsaaUuid;
/**
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
final class Uuid
{
/**
* @var RamseyUuid|RhumsaaUuid;
*/
private $uuid;
private function __construct($uuid)
{
$this->uuid = $uuid;
}
public static function fromString(string $uuid): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::fromString($uuid));
}
return new self(RamseyUuid::fromString($uuid));
}
/**
* Generate a version 1 UUID from a host ID, sequence number, and the current time.
*
* @param int|string $node a 48-bit number representing the hardware address
* This number may be represented as an integer or a hexadecimal string
* @param int $clockSeq a 14-bit number used to help avoid duplicates that
* could arise when the clock is set backwards in time or if the node ID
* changes
*/
public static function uuid1($node = null, int $clockSeq = null): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid1($node, $clockSeq));
}
return new self(RamseyUuid::uuid1($node, $clockSeq));
}
/**
* Generate a version 3 UUID based on the MD5 hash of a namespace identifier
* (which is a UUID) and a name (which is a string).
*
* @param string $ns The UUID namespace in which to create the named UUID
* @param string $name The name to create a UUID for
*/
public static function uuid3(string $ns, string $name): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid3($ns, $name));
}
return new self(RamseyUuid::uuid3($ns, $name));
}
/**
* Generate a version 4 (random) UUID.
*/
public static function uuid4(): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid4());
}
return new self(RamseyUuid::uuid4());
}
/**
* Generate a version 5 UUID based on the SHA-1 hash of a namespace
* identifier (which is a UUID) and a name (which is a string).
*
* @param string $ns The UUID namespace in which to create the named UUID
* @param string $name The name to create a UUID for
*/
public static function uuid5(string $ns, string $name): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid5($ns, $name));
}
return new self(RamseyUuid::uuid5($ns, $name));
}
public function __toString(): string
{
return $this->uuid->toString();
}
public function equals(Uuid $uuid): bool
{
return $this->uuid->equals($uuid->uuid);
}
}

97
vendor/php-xapi/model/src/Verb.php vendored Normal file
View File

@@ -0,0 +1,97 @@
<?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 Xabbuh\XApi\Model;
/**
* The verb in a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Verb
{
private $id;
private $display;
public function __construct(IRI $id, LanguageMap $display = null)
{
$this->id = $id;
$this->display = $display;
}
/**
* Returns the verb definition reference.
*/
public function getId(): IRI
{
return $this->id;
}
/**
* Returns the human readable representation of the Verb in one or more languages.
*/
public function getDisplay(): ?LanguageMap
{
return $this->display;
}
/**
* Checks if another verb is equal.
*
* Two verbs are equal if and only if all of their properties are equal.
*/
public function equals(Verb $verb): bool
{
if (!$this->id->equals($verb->id)) {
return false;
}
if (null === $this->display && null === $verb->display) {
return true;
}
if (null !== $this->display xor null !== $verb->display) {
return false;
}
if (count($this->display) !== count($verb->getDisplay())) {
return false;
}
foreach ($this->display as $language => $value) {
if (!isset($verb->display[$language])) {
return false;
}
if ($value !== $verb->display[$language]) {
return false;
}
}
return true;
}
/**
* Tests if the Verb can be used to void a Statement.
*/
public function isVoidVerb(): bool
{
return $this->id->equals(IRI::fromString('http://adlnet.gov/expapi/verbs/voided'));
}
/**
* Creates a Verb that can be used to void a {@link Statement}.
*/
public static function createVoidVerb(): self
{
return new Verb(IRI::fromString('http://adlnet.gov/expapi/verbs/voided'));
}
}