diff --git a/google_vision.install b/google_vision.install new file mode 100755 index 0000000..a7140c6 --- /dev/null +++ b/google_vision.install @@ -0,0 +1,28 @@ +get('api_key'); + if(!$key) { + $requirements['google_vision'] = array( + 'title' => t('Google Vision API'), + 'severity' => REQUIREMENT_ERROR, + 'description' => t('Google Vision API key is not set and it is required for some functionalities to work. Please set it up at the Google Vision module settings page.', array( + ':settings' => Url::fromRoute('google_vision.settings')->toString(), + )), + ); + } + } + return $requirements; +} diff --git a/src/Tests/ApiKeyConfigurationTest.php b/src/Tests/ApiKeyConfigurationTest.php new file mode 100755 index 0000000..608f11c --- /dev/null +++ b/src/Tests/ApiKeyConfigurationTest.php @@ -0,0 +1,82 @@ +adminUser = $this->drupalCreateUser(array('administer google vision','administer site configuration') + ); + $this->drupalLogin($this->adminUser); + } + + /** + * Test to implement a runtime requirement checking if API key is not set. + */ + function testKeyConfiguration() { + $this->drupalGet(Url::fromRoute('google_vision.settings')); + $this->assertResponse(200); + $this->assertFieldByName('api_key', '', 'The API key is not set'); + $this->drupalGet(Url::fromRoute('system.status')); + $this->assertResponse(200); + $this->assertText('Google Vision API key is not set and it is required for some functionalities to work.', 'The content exists on the report page'); + $this->assertLink('Google Vision module settings page', 0, 'Link to the api key configuration page found'); + $this->assertLinkByHref(Url::fromRoute('google_vision.settings')->toString()); + + } + + /** + * Test to verify that it is stored successfully. + */ + function testKeyStorage() { + $this->drupalGet(Url::fromRoute('google_vision.settings')); + $this->assertResponse(200); + $this->assertFieldByName('api_key', '', 'The key is not set currently'); + $apiKey = $this->randomString(40); + $data = array( + 'api_key' => $apiKey, + ); + $this->drupalPostForm(Url::fromRoute('google_vision.settings'), $data, t('Save configuration')); + $this->drupalGet(Url::fromRoute('google_vision.settings')); + $this->assertResponse(200); + $this->assertFieldByName('api_key', $apiKey, 'The key has been saved'); + } +}