/**
  * @test
  * @group Consent
  * @group Value
  */
 public function same_type_of_consent_types_are_equal()
 {
     $explicit = ConsentType::explicit();
     $implicit = ConsentType::implicit();
     $this->assertTrue($explicit->equals(ConsentType::explicit()));
     $this->assertTrue($implicit->equals(ConsentType::implicit()));
 }
 /**
  * @test
  * @group Consent
  */
 public function it_can_create_a_consent_list()
 {
     $firstEntityId = 'http://profile.vm.openconext.invalid/authentication/metadata';
     $secondEntityId = 'https://serviceregistry.vm.openconext.invalid/simplesaml/module.php/saml/sp/metadata.php/default-sp';
     $firstEula = 'https://domain.invalid';
     $secondSupportEmail = '*****@*****.**';
     $givenFirstConsentTypeValue = 'explicit';
     $expectedFirstConsentType = ConsentType::explicit();
     $givenSecondConsentTypeValue = 'implicit';
     $expectedSecondConsentType = ConsentType::implicit();
     $given = [['service_provider' => ['entity_id' => $firstEntityId, 'display_name' => ['en' => '', 'nl' => ''], 'eula_url' => $firstEula, 'support_email' => null], 'consent_given_on' => '2015-11-05T08:43:01+01:00', 'last_used_on' => '2015-11-05T08:43:01+01:00', 'consent_type' => $givenFirstConsentTypeValue], ['service_provider' => ['entity_id' => $secondEntityId, 'display_name' => ['en' => 'OpenConext ServiceRegistry', 'nl' => 'OpenConext ServiceRegistry'], 'eula_url' => null, 'support_email' => $secondSupportEmail], 'consent_given_on' => '2015-11-05T08:17:04+01:00', 'last_used_on' => '2015-11-05T08:17:04+01:00', 'consent_type' => $givenSecondConsentTypeValue]];
     $expectedConsentList = new ConsentList([new Consent(new ServiceProvider(new Entity(new EntityId($firstEntityId), EntityType::SP()), new DisplayName(['nl' => '', 'en' => '']), new Url($firstEula), null), new DateTimeImmutable('2015-11-05T08:43:01+01:00'), new DateTimeImmutable('2015-11-05T08:43:01+01:00'), $expectedFirstConsentType), new Consent(new ServiceProvider(new Entity(new EntityId($secondEntityId), EntityType::SP()), new DisplayName(['nl' => 'OpenConext ServiceRegistry', 'en' => 'OpenConext ServiceRegistry']), null, new ContactEmailAddress($secondSupportEmail)), new DateTimeImmutable('2015-11-05T08:17:04+01:00'), new DateTimeImmutable('2015-11-05T08:17:04+01:00'), $expectedSecondConsentType)]);
     $this->assertEquals($expectedConsentList, ConsentListFactory::createListFromMetadata($given));
 }
 /**
  * @param mixed $data
  * @return Consent
  *
  * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
  */
 private static function createConsent($data)
 {
     Assert::keyExists($data, 'service_provider', 'Consent JSON structure must contain key "service_provider"');
     Assert::keyExists($data, 'consent_given_on', 'Consent JSON structure must contain key "consent_given_on"');
     Assert::keyExists($data, 'last_used_on', 'Consent JSON structure must contain key "last_used_on"');
     Assert::keyExists($data, 'consent_type', 'Consent JSON structure must contain key "consent_type"');
     Assert::choice($data['consent_type'], [ConsentType::TYPE_EXPLICIT, ConsentType::TYPE_IMPLICIT], '"%s" is not one of the valid ConsentTypes: %s');
     $consentGivenOn = DateTimeImmutable::createFromFormat(DateTime::ATOM, $data['consent_given_on']);
     $lastUsedOn = DateTimeImmutable::createFromFormat(DateTime::ATOM, $data['last_used_on']);
     Assert::isInstanceOf($consentGivenOn, '\\DateTimeImmutable', sprintf('Consent given on date must be formatted according to the ISO8601 standard, got "%s"', $data['consent_given_on']));
     Assert::isInstanceOf($lastUsedOn, '\\DateTimeImmutable', sprintf('Last used on date must be formatted according to the ISO8601 standard, got "%s"', $data['last_used_on']));
     if ($data['consent_type'] === ConsentType::TYPE_EXPLICIT) {
         $consentType = ConsentType::explicit();
     } else {
         $consentType = ConsentType::implicit();
     }
     return new Consent(self::createServiceProvider($data['service_provider']), $consentGivenOn, $lastUsedOn, $consentType);
 }
 /**
  * @test
  * @group AttributeReleasePolicy
  */
 public function consent_list_and_attributes_are_correctly_converted_to_a_request_and_the_response_is_mapped_correctly_to_a_result()
 {
     $someAttributeDefinition = new AttributeDefinition('someAttribute', 'urn:mace:some-attribute', 'urn:oid:0.0.0.0.0.1');
     $anotherAttributeDefinition = new AttributeDefinition('anotherAttribute', null, 'urn:oid:0.0.0.0.0.2');
     $attributeDictionary = new AttributeDictionary();
     $attributeDictionary->addAttributeDefinition($someAttributeDefinition);
     $attributeDictionary->addAttributeDefinition($anotherAttributeDefinition);
     $client = Mockery::mock(JsonApiClient::class);
     $arpService = new AttributeReleasePolicyService($client, $attributeDictionary);
     $client->shouldReceive('post')->withArgs([['entityIds' => ['some-entity-id', 'another-entity-id'], 'attributes' => ['urn:mace:some-attribute' => ['some-value'], 'urn:oid:0.0.0.0.0.1' => ['some-value'], 'urn:oid:0.0.0.0.0.2' => ['another-value']]], '/arp'])->andReturn(['some-entity-id' => ['urn:mace:some-attribute' => ['some-value'], 'urn:oid:0.0.0.0.0.1' => ['some-value'], 'urn:oid:0.0.0.0.0.2' => ['another-value']], 'another-entity-id' => ['urn:oid:0.0.0.0.0.2' => ['another-value']]]);
     $someConsent = new Consent(new ServiceProvider(new Entity(new EntityId('some-entity-id'), EntityType::SP()), new DisplayName(['en' => 'Some display name']), new Url('http://some-eula-url.example'), new ContactEmailAddress('*****@*****.**')), new DateTimeImmutable(), new DateTimeImmutable(), ConsentType::explicit());
     $anotherConsent = new Consent(new ServiceProvider(new Entity(new EntityId('another-entity-id'), EntityType::SP()), new DisplayName(['en' => 'Another display name']), new Url('http://another-eula-url.example'), new ContactEmailAddress('*****@*****.**')), new DateTimeImmutable(), new DateTimeImmutable(), ConsentType::explicit());
     $consentList = new ConsentList([$someConsent, $anotherConsent]);
     $someAttribute = new Attribute($someAttributeDefinition, ['some-value']);
     $anotherAttribute = new Attribute($anotherAttributeDefinition, ['another-value']);
     $attributeSet = AttributeSet::create([$someAttribute, $anotherAttribute]);
     $expectedResult = SpecifiedConsentList::createWith([SpecifiedConsent::specifies($someConsent, AttributeSetWithFallbacks::create([$someAttribute, $anotherAttribute])), SpecifiedConsent::specifies($anotherConsent, AttributeSetWithFallbacks::create([$anotherAttribute]))]);
     $result = $arpService->applyAttributeReleasePolicies($consentList, $attributeSet);
     $this->assertEquals($expectedResult, $result);
 }