DeveloperAppUITest.php in Apigee Edge 8
File
tests/src/FunctionalJavascript/DeveloperAppUITest.php
View source
<?php
namespace Drupal\Tests\apigee_edge\FunctionalJavascript;
use Drupal\Tests\apigee_edge\Functional\DeveloperAppUITestTrait;
class DeveloperAppUITest extends ApigeeEdgeFunctionalJavascriptTestBase {
use DeveloperAppUITestTrait;
protected function setUp() {
parent::setUp();
$this->products[] = $this
->createProduct();
$this->account = $this
->createAccount(static::$permissions);
$this
->drupalLogin($this->account);
}
protected function tearDown() {
try {
if ($this->account !== NULL) {
$this->account
->delete();
}
} catch (\Exception $exception) {
$this
->logException($exception);
}
foreach ($this->products as $product) {
try {
if ($product !== NULL) {
$product
->delete();
}
} catch (\Exception $exception) {
$this
->logException($exception);
}
}
parent::tearDown();
}
public function testCallbackUrlValidationClientSide() {
$isValidInput = function () : bool {
return $this
->getSession()
->evaluateScript('document.getElementById("edit-callbackurl-0-value").checkValidity()');
};
$checkValidationMessage = function (string $expected) : void {
$this
->assertEquals($expected, $this
->getSession()
->evaluateScript('document.getElementById("edit-callbackurl-0-value").validationMessage'));
};
$pattern_error_message = 'It must be https://example.com';
$this
->config('apigee_edge.common_app_settings')
->set('callback_url_pattern', '^https:\\/\\/example.com')
->set('callback_url_pattern_error_message', $pattern_error_message)
->save();
$app = $this
->createDeveloperApp([
'name' => $this
->randomMachineName(),
'displayName' => $this
->randomString(),
'callbackUrl' => $this
->randomMachineName(),
], $this->account, [
$this->products[0]
->id(),
]);
$app_edit_url = $app
->toUrl('edit-form-for-developer');
$this
->drupalGet($app_edit_url);
$this
->drupalPostForm($app_edit_url, [], 'Save');
$this
->createScreenshot('DeveloperAppUITest-' . __FUNCTION__);
$this
->assertFalse($isValidInput());
$checkValidationMessage('Please enter a URL.');
$this
->drupalPostForm($app_edit_url, [
'callbackUrl[0][value]' => 'http://example.com',
], 'Save');
$this
->createScreenshot('DeveloperAppUITest-' . __FUNCTION__);
$this
->assertFalse($isValidInput());
$checkValidationMessage('Please match the requested format.');
$this
->assertEquals($pattern_error_message, $this
->getSession()
->evaluateScript('document.getElementById("edit-callbackurl-0-value").title'));
$this
->drupalPostForm($app_edit_url, [
'callbackUrl[0][value]' => 'https://example.com',
], 'Save');
$this
->assertSession()
->pageTextContains('App has been successfully updated.');
$this
->assertSession()
->pageTextContains('https://example.com');
}
}