Skip to content

Commit

Permalink
Merge pull request #54 from oat-sa/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ekkinox authored Aug 20, 2020
2 parents 2c238c3 + e44a818 commit 06b2df4
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.4.0
-----

* Added Basic Outcome claim handling

2.3.0
-----

Expand Down
74 changes: 74 additions & 0 deletions src/Message/Claim/BasicOutcomeClaim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2020 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace OAT\Library\Lti1p3Core\Message\Claim;

use OAT\Library\Lti1p3Core\Message\LtiMessageInterface;

/**
* @see https://www.imsglobal.org/spec/lti-bo/v1p1/#integration-with-lti-1-3
*/
class BasicOutcomeClaim implements MessageClaimInterface
{
/** @var string */
private $lisResultSourcedId;

/** @var string */
private $lisOutcomeServiceUrl;

public function __construct(string $lisResultSourcedId, string $lisOutcomeServiceUrl)
{
$this->lisResultSourcedId = $lisResultSourcedId;
$this->lisOutcomeServiceUrl = $lisOutcomeServiceUrl;
}

public static function getClaimName(): string
{
return LtiMessageInterface::CLAIM_LTI_BASIC_OUTCOME;
}

public function getLisResultSourcedId(): string
{
return $this->lisResultSourcedId;
}

public function getLisOutcomeServiceUrl(): string
{
return $this->lisOutcomeServiceUrl;
}

public function normalize(): array
{
return array_filter([
'lis_result_sourcedid' => $this->lisResultSourcedId,
'lis_outcome_service_url' => $this->lisOutcomeServiceUrl,
]);
}

public static function denormalize(array $claimData): BasicOutcomeClaim
{
return new self(
$claimData['lis_result_sourcedid'],
$claimData['lis_outcome_service_url']
);
}
}
6 changes: 6 additions & 0 deletions src/Message/LtiMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use OAT\Library\Lti1p3Core\Exception\LtiException;
use OAT\Library\Lti1p3Core\Message\Claim\AgsClaim;
use OAT\Library\Lti1p3Core\Message\Claim\BasicOutcomeClaim;
use OAT\Library\Lti1p3Core\Message\Claim\ContextClaim;
use OAT\Library\Lti1p3Core\Message\Claim\LaunchPresentationClaim;
use OAT\Library\Lti1p3Core\Message\Claim\LisClaim;
Expand Down Expand Up @@ -143,4 +144,9 @@ public function getNrps(): ?NrpsClaim
{
return $this->getClaim(NrpsClaim::class);
}

public function getBasicOutcome(): ?BasicOutcomeClaim
{
return $this->getClaim(BasicOutcomeClaim::class);
}
}
6 changes: 6 additions & 0 deletions src/Message/LtiMessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OAT\Library\Lti1p3Core\Message;

use OAT\Library\Lti1p3Core\Message\Claim\AgsClaim;
use OAT\Library\Lti1p3Core\Message\Claim\BasicOutcomeClaim;
use OAT\Library\Lti1p3Core\Message\Claim\ContextClaim;
use OAT\Library\Lti1p3Core\Message\Claim\LaunchPresentationClaim;
use OAT\Library\Lti1p3Core\Message\Claim\LisClaim;
Expand Down Expand Up @@ -59,6 +60,9 @@ interface LtiMessageInterface extends MessageInterface
// LTI NRPS claim
public const CLAIM_LTI_NRPS = 'https://purl.imsglobal.org/spec/lti-nrps/claim/namesroleservice';

// LTI Basic Outcome claim
public const CLAIM_LTI_BASIC_OUTCOME = 'https://purl.imsglobal.org/spec/lti-bo/claim/basicoutcome';

public function getMessageType(): string;

public function getVersion(): string;
Expand Down Expand Up @@ -88,4 +92,6 @@ public function getUserIdentity(): ?UserIdentityInterface;
public function getAgs(): ?AgsClaim;

public function getNrps(): ?NrpsClaim;

public function getBasicOutcome(): ?BasicOutcomeClaim;
}
9 changes: 9 additions & 0 deletions tests/Integration/Message/LtiMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OAT\Library\Lti1p3Core\Tests\Integration\Message;

use OAT\Library\Lti1p3Core\Message\Claim\AgsClaim;
use OAT\Library\Lti1p3Core\Message\Claim\BasicOutcomeClaim;
use OAT\Library\Lti1p3Core\Message\Claim\NrpsClaim;
use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;
use OAT\Library\Lti1p3Core\Launch\Builder\LtiLaunchRequestBuilder;
Expand Down Expand Up @@ -84,6 +85,7 @@ protected function setUp(): void
new LisClaim('course_offering_sourcedid'),
new AgsClaim(['scope'], 'line_items_container_url'),
new NrpsClaim('context_membership_url', ['1.0', '2.0']),
new BasicOutcomeClaim('id', 'url'),
'aaa' => 'bbb'
]
)->getLtiMessage();
Expand Down Expand Up @@ -174,4 +176,11 @@ public function testGetNrps(): void
$this->assertEquals('context_membership_url', $this->subject->getNrps()->getContextMembershipsUrl());
$this->assertEquals(['1.0', '2.0'], $this->subject->getNrps()->getServiceVersions());
}

public function testGetBasicOutcome(): void
{
$this->assertInstanceOf(BasicOutcomeClaim::class, $this->subject->getBasicOutcome());
$this->assertEquals('id', $this->subject->getBasicOutcome()->getLisResultSourcedId());
$this->assertEquals('url', $this->subject->getBasicOutcome()->getLisOutcomeServiceUrl());
}
}
72 changes: 72 additions & 0 deletions tests/Unit/Message/Claim/BasicOutcomeClaimTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2020 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace OAT\Library\Lti1p3Core\Tests\Unit\Message\Claim;

use OAT\Library\Lti1p3Core\Message\Claim\BasicOutcomeClaim;
use OAT\Library\Lti1p3Core\Message\LtiMessageInterface;
use PHPUnit\Framework\TestCase;

class BasicOutcomeClaimTest extends TestCase
{
/** @var BasicOutcomeClaim */
private $subject;

public function setUp(): void
{
$this->subject = new BasicOutcomeClaim('id', 'url');
}

public function testGetClaimName(): void
{
$this->assertEquals(LtiMessageInterface::CLAIM_LTI_BASIC_OUTCOME, $this->subject::getClaimName());
}

public function testGetters(): void
{
$this->assertEquals('id', $this->subject->getLisResultSourcedId());
$this->assertEquals('url', $this->subject->getLisOutcomeServiceUrl());
}

public function testNormalisation(): void
{
$this->assertEquals(
[
'lis_result_sourcedid' => 'id',
'lis_outcome_service_url' => 'url',
],
$this->subject->normalize()
);
}

public function testDenormalisation(): void
{
$denormalisation = BasicOutcomeClaim::denormalize([
'lis_result_sourcedid' => 'id',
'lis_outcome_service_url' => 'url',
]);

$this->assertInstanceOf(BasicOutcomeClaim::class, $denormalisation);
$this->assertEquals('id', $denormalisation->getLisResultSourcedId());
$this->assertEquals('url', $denormalisation->getLisOutcomeServiceUrl());
}
}

0 comments on commit 06b2df4

Please sign in to comment.