/** * @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); }