createSubject('lti_provider_list.json'); $this->assertEquals(2, $subject->count()); $providers = $subject->findAll(); $this->assertInstanceOf(LtiProvider::class, $providers[0]); $this->assertEquals('provider1_uri', $providers[0]->getId()); $this->assertEquals('provider1_label', $providers[0]->getLabel()); $this->assertEquals('provider1_key', $providers[0]->getKey()); $this->assertEquals('provider1_secret', $providers[0]->getSecret()); $this->assertEquals('provider1_callback_url', $providers[0]->getCallbackUrl()); $this->assertEquals('jwksUrl', $providers[0]->getToolJwksUrl()); $this->assertEquals(['Learner'], $providers[0]->getRoles()); $this->assertInstanceOf(LtiProvider::class, $providers[1]); $this->assertEquals('provider2_uri', $providers[1]->getId()); $this->assertEquals('provider2_label', $providers[1]->getLabel()); $this->assertEquals('provider2_key', $providers[1]->getKey()); $this->assertEquals('provider2_secret', $providers[1]->getSecret()); $this->assertEquals('provider2_callback_url', $providers[1]->getCallbackUrl()); $this->assertEquals([], $providers[1]->getRoles()); } public function testSearchByLabel(): void { $subject = $this->createSubject('lti_provider_list.json'); $providers = $subject->searchByLabel('provider1'); $this->assertEquals(1, count($providers)); $this->assertInstanceOf(LtiProvider::class, $providers[0]); $this->assertEquals('provider1_uri', $providers[0]->getId()); $this->assertEquals('provider1_label', $providers[0]->getLabel()); $this->assertEquals('provider1_key', $providers[0]->getKey()); $this->assertEquals('provider1_secret', $providers[0]->getSecret()); $this->assertEquals('provider1_callback_url', $providers[0]->getCallbackUrl()); } public function testSearchByOauthKey(): void { $subject = $this->createSubject('lti_provider_list.json'); $provider = $subject->searchByOauthKey('provider2_key'); $this->assertInstanceOf(LtiProvider::class, $provider); $this->assertEquals('provider2_uri', $provider->getId()); $this->assertEquals('provider2_label', $provider->getLabel()); $this->assertEquals('provider2_key', $provider->getKey()); $this->assertEquals('provider2_secret', $provider->getSecret()); $this->assertEquals('provider2_callback_url', $provider->getCallbackUrl()); $this->assertNull($subject->searchByOauthKey('not_existing')); } public function testConstructorWithNullProviderListThrowsException(): void { $subject = $this->createSubject(null); $this->expectException(InvalidArgumentException::class); $subject->count(); } public function testConstructorWithInvalidProviderListThrowsException(): void { $subject = $this->createSubject('incomplete_lti_provider_list.json'); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('"key": This field is required'); $subject->count(); } private function createSubject(string $providerListPath = null): ConfigurableLtiProviderRepository { $subject = new ConfigurableLtiProviderRepository( [ ConfigurableLtiProviderRepository::OPTION_LTI_PROVIDER_LIST => $providerListPath ? json_decode( file_get_contents( __DIR__ . DIRECTORY_SEPARATOR . '_resources' . DIRECTORY_SEPARATOR . $providerListPath ), true ) : null ] ); $validationService = new LtiProviderValidator(); $factory = new LtiProviderFactory(); $validationFactory = new ValidatorsFactory(); $validationFactory->setServiceLocator( $this->getServiceLocatorMock( [ ValidationRegistry::class => new ValidationRegistry(), ] ) ); $validationService->setServiceLocator( $this->getServiceLocatorMock( [ LtiProviderFieldsMapper::class => new LtiProviderFieldsMapper(), ValidationRegistry::class => new ValidationRegistry(), ValidatorsFactory::class => $validationFactory, ] ) ); $factory->setServiceLocator( $this->getServiceLocatorMock( [ LtiProviderValidator::class => $validationService, ] ) ); $subject->setServiceLocator( $this->getServiceLocatorMock( [ LtiProviderFactory::class => $factory ] ) ); return $subject; } }