Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gradesReleased to LtiLineItem #106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/LtiLineitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LtiLineitem
private $tag;
private $start_date_time;
private $end_date_time;
private ?bool $grades_released;

public function __construct(array $lineitem = null)
{
Expand All @@ -23,6 +24,7 @@ public function __construct(array $lineitem = null)
$this->tag = $lineitem['tag'] ?? null;
$this->start_date_time = $lineitem['startDateTime'] ?? null;
$this->end_date_time = $lineitem['endDateTime'] ?? null;
$this->grades_released = $lineitem['gradesReleased'] ?? null;
}

public function __toString()
Expand All @@ -37,6 +39,7 @@ public function __toString()
'tag' => $this->tag,
'startDateTime' => $this->start_date_time,
'endDateTime' => $this->end_date_time,
'gradesReleased' => $this->grades_released,
], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue'));
}

Expand Down Expand Up @@ -143,4 +146,16 @@ public function setEndDateTime($value)

return $this;
}

public function getGradesReleased(): ?bool
{
return $this->grades_released;
}

public function setGradesReleased(?bool $value): self
{
$this->grades_released = $value;

return $this;
}
}
38 changes: 38 additions & 0 deletions tests/LtiLineitemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class LtiLineitemTest extends TestCase
{
private LtiLineitem $lineItem;

public function setUp(): void
{
$this->lineItem = new LtiLineitem();
Expand Down Expand Up @@ -175,6 +177,41 @@ public function testItSetsEndDateTime()
$this->assertEquals($expected, $this->lineItem->getEndDateTime());
}

public function testItGetsGradesReleased(): void
{
$expected = true;
$grade = new LtiLineitem(['gradesReleased' => $expected]);

$result = $grade->getGradesReleased();

$this->assertEquals($expected, $result);
}

public function testItSetsGradesReleased(): void
{
$expected = false;

$this->lineItem->setGradesReleased($expected);

$this->assertEquals($expected, $this->lineItem->getGradesReleased());
}

public function testGradesReleasedConstructedNullable(): void
{
$grade = new LtiLineitem();

$result = $grade->getGradesReleased();

$this->assertNull($result);
}

public function testGradesReleasedSetNullable(): void
{
$this->lineItem->setGradesReleased(null);

$this->assertNull($this->lineItem->getGradesReleased());
}

public function testItCastsFullObjectToString()
{
$expected = [
Expand All @@ -186,6 +223,7 @@ public function testItCastsFullObjectToString()
'tag' => 'Tag',
'startDateTime' => 'StartDateTime',
'endDateTime' => 'EndDateTime',
'gradesReleased' => true,
];

$lineItem = new LtiLineitem($expected);
Expand Down