Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
III-1686: Check hidden labels as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberwolf committed Dec 15, 2016
1 parent 5870ed3 commit 0237f26
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Specification/IsUiTPASOrganizerAccordingToJSONLD.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function isSatisfiedBy($organizerId)
);
}

$organizerLabels = isset($organizer->labels) ? $organizer->labels : [];
$organizerLabels = $this->extractAllLabels($organizer);

$uitpasLabelsPresentOnOrganizer = array_filter(
$organizerLabels,
Expand All @@ -102,4 +102,18 @@ function ($label) {
return true;
}
}

/**
* Extracts all labels from an organizer, both visible and hidden.
*
* @param object $organizer
* @return array
*/
private function extractAllLabels($organizer)
{
$visibleLabels = isset($organizer->labels) ? $organizer->labels : [];
$hiddenLabels = isset($organizer->hiddenLabels) ? $organizer->hiddenLabels : [];

return array_merge($visibleLabels, $hiddenLabels);
}
}
40 changes: 40 additions & 0 deletions tests/Specification/IsUiTPASOrganizerAccordingToJSONLDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class IsUiTPASOrganizerAccordingToJSONLDTest extends \PHPUnit_Framework_TestCase
*/
private $organizerWithExactUiTPASLabel;

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

/**
* @var string
*/
Expand Down Expand Up @@ -77,6 +82,7 @@ public function setUp()

$this->organizerWithExactUiTPASLabel = 'organizer-with-uitpas-label';
$this->organizerWithLowercaseUiTPASLabel = 'organizer-with-lowercase-uitpas-label';
$this->organizerWithHiddenUiTPASLabel = 'organizer-with-hidden-uitpas-label';
$this->organizerWithoutUiTPASLabel = 'organizer-without-uitpas-label';
$this->organizerWithoutLabels = 'organizer-without-labels';
$this->organizerWithSyntaxError = 'organizer-with-syntax-error';
Expand Down Expand Up @@ -176,6 +182,40 @@ public function it_returns_true_for_organizers_with_a_case_insensitive_uitpas_la
$this->assertLogMessage('debug', 1, 'uitpas labels present on organizer', $expectedLabelLogContext);
}

/**
* @test
*/
public function it_matches_organizers_with_a_hidden_uitpas_label()
{
$this->assertTrue(
$this->specification->isSatisfiedBy(
$this->organizerWithHiddenUiTPASLabel
)
);

$expectedLogContext = $this->createDefaultLogContext($this->organizerWithHiddenUiTPASLabel);

$expectedJsonLogContext = $expectedLogContext + [
'json' => file_get_contents($expectedLogContext['url']),
];

$expectedLabelLogContext = $expectedLogContext + [
'uitpas_labels' => $this->uitpasLabels->asArray(),
'extracted_organizer_labels' => [
'foo',
'bar',
'UiTPAS',
'qa',
],
'organizer_uitpas_labels' => [
'UiTPAS',
],
];

$this->assertLogMessage('debug', 0, 'successfully retrieved organizer JSON-LD', $expectedJsonLogContext);
$this->assertLogMessage('debug', 1, 'uitpas labels present on organizer', $expectedLabelLogContext);
}

/**
* @test
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/Specification/samples/organizer-with-hidden-uitpas-label
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"@id": "http://example.com/organizers/dba1c53d-582c-4081-a78c-b4848f9e3653",
"labels": [
"foo",
"bar"
],
"hiddenLabels": [
"UiTPAS",
"qa"
]
}

0 comments on commit 0237f26

Please sign in to comment.