Skip to content

Commit

Permalink
Fixes for calling name() & word() on null
Browse files Browse the repository at this point in the history
  • Loading branch information
kedarkhaire committed Jan 22, 2025
1 parent 215ebdc commit 4b996a6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace Drupal\Tests\apigee_edge_actions\Kernel\Plugin\RulesEvent;

use Drupal\Tests\apigee_edge_actions\Kernel\ApigeeEdgeActionsRulesKernelTestBase;
use Drupal\TestTools\Random;
use Drupal\rules\Context\ContextConfig;

/**
Expand Down Expand Up @@ -62,7 +63,7 @@ public function testEvent() {
/** @var \Drupal\apigee_edge\Entity\DeveloperAppInterface $entity */
$entity = $this->createDeveloperApp();
$original_name = $entity->getDisplayName();
$new_name = $this->randomGenerator->name();
$new_name = Random::getGenerator()->name();
$this->queueDeveloperAppResponse($entity);
$entity->setDisplayName($new_name);
$this->queueDeveloperAppResponse($entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Apigee\Edge\Structure\MonetizationConfig;
use Apigee\MockClient\Generator\ApigeeSdkEntitySource;
use Drupal\Tests\apigee_edge\Traits\ApigeeEdgeUtilTestTrait;
use Drupal\TestTools\Random;
use Drupal\apigee_edge\Entity\Developer;
use Drupal\apigee_edge\Entity\DeveloperApp;
use Drupal\apigee_edge\Entity\DeveloperAppInterface;
Expand Down Expand Up @@ -370,7 +371,7 @@ protected function createTeam(): TeamInterface {
/** @var \Drupal\apigee_edge_teams\Entity\TeamInterface $team */
$team = Team::create([
'name' => $this->randomMachineName(),
'displayName' => $this->randomGenerator->name(),
'displayName' => Random::getGenerator()->name(),
]);
$this->queueCompanyResponse($team->decorated());
$this->stack->queueMockResponse('no_content');
Expand All @@ -391,7 +392,7 @@ protected function createApigeexTeam(): TeamInterface {
/** @var \Drupal\apigee_edge_teams\Entity\TeamInterface $team */
$team = Team::create([
'name' => $this->randomMachineName(),
'displayName' => $this->randomGenerator->name(),
'displayName' => Random::getGenerator()->name(),
]);

$this->queueAppGroupResponse($team->decorated());
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Functional/DeveloperAppUITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Apigee\Edge\Api\Management\Controller\DeveloperController;
use Drupal\Core\Url;
use Drupal\Tests\apigee_edge\Traits\EntityUtilsTrait;
use Drupal\TestTools\Random;
use Drupal\apigee_edge\Entity\Developer;
use Drupal\apigee_edge\Entity\DeveloperApp;

Expand Down Expand Up @@ -580,7 +581,7 @@ public function testCallbackUrlValidationServerSide() {
public function testInvalidEdgeSideCallbackUrl() {
$this->drupalLogin($this->rootUser);
$this->products[] = $this->createProduct();
$callback_url = $this->randomGenerator->word(8);
$callback_url = Random::getGenerator()->word(8);
$callback_url_warning_msg = "The Callback URL value should be fixed. The URI '{$callback_url}' is invalid. You must use a valid URI scheme.";
$app = $this->createDeveloperApp(
[
Expand Down
11 changes: 6 additions & 5 deletions tests/src/Functional/DeveloperSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Apigee\Edge\Api\Management\Controller\DeveloperController;
use Drupal\Core\Url;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
use Drupal\TestTools\Random;
use Drupal\apigee_edge\Entity\Developer;
use Drupal\apigee_edge\Plugin\ApigeeFieldStorageFormat\CSV;
use Drupal\apigee_edge\Plugin\ApigeeFieldStorageFormat\JSON;
Expand Down Expand Up @@ -234,8 +235,8 @@ protected function setUp(): void {
}

// Change first name and last name.
$this->modifiedEdgeDevelopers[$user->getEmail()]->setFirstName($this->randomGenerator->word(8));
$this->modifiedEdgeDevelopers[$user->getEmail()]->setLastName($this->randomGenerator->word(8));
$this->modifiedEdgeDevelopers[$user->getEmail()]->setFirstName(Random::getGenerator()->word(8));
$this->modifiedEdgeDevelopers[$user->getEmail()]->setLastName(Random::getGenerator()->word(8));

// Set unlinked attribute on the developer.
$this->modifiedEdgeDevelopers[$user->getEmail()]->setAttribute('one_track_field', 'developer');
Expand Down Expand Up @@ -273,9 +274,9 @@ protected function setUp(): void {
}

// Change first name, last name and username.
$this->modifiedDrupalUsers[$user->getEmail()]->set('first_name', $this->randomGenerator->word(8));
$this->modifiedDrupalUsers[$user->getEmail()]->set('last_name', $this->randomGenerator->word(8));
$this->modifiedDrupalUsers[$user->getEmail()]->set('name', $this->randomGenerator->word(8));
$this->modifiedDrupalUsers[$user->getEmail()]->set('first_name', Random::getGenerator()->word(8));
$this->modifiedDrupalUsers[$user->getEmail()]->set('last_name', Random::getGenerator()->word(8));
$this->modifiedDrupalUsers[$user->getEmail()]->set('name', Random::getGenerator()->word(8));

// Set unlinked field in Drupal.
$this->modifiedDrupalUsers[$user->getEmail()]->set($this->fieldNamePrefix . 'one_track_field', 'user');
Expand Down
11 changes: 6 additions & 5 deletions tests/src/FunctionalJavascript/Form/AuthenticationFormJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Drupal\Core\Url;
use Drupal\Tests\apigee_edge\FunctionalJavascript\ApigeeEdgeFunctionalJavascriptTestBase;
use Drupal\TestTools\Random;
use Drupal\apigee_edge\Form\AuthenticationForm;
use Drupal\apigee_edge\OauthTokenFileStorage;
use Drupal\apigee_edge\Plugin\EdgeKeyTypeInterface;
Expand Down Expand Up @@ -375,15 +376,15 @@ protected function validateForm(callable $visitFormAsAdmin): void {
// @todo Re-add this assert later, if requires.
// Irrespective of incorrect organization, username or password it will say Forbidden.
// Test invalid organization.
// $random_org = $this->randomGenerator->word(16);
// $random_org = Random::getGenerator()->word(16);
// $page->fillField('Organization', $random_org);
// $this->assertSendRequestMessage('.messages--error', "Failed to connect to Apigee Edge. The given organization name ({$random_org}) is incorrect. Error message: ");
// $web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', 'HTTP/1.1 404 Not Found');
// $web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', "\"organization\": \"{$random_org}\"");
// $page->fillField('Organization', $this->organization);
// Test invalid endpoint.
$page->selectFieldOption('key_input_settings[instance_type]', EdgeKeyTypeInterface::INSTANCE_TYPE_PRIVATE);
$invalid_domain = "{$this->randomGenerator->word(16)}.example.com";
$invalid_domain = "{Random::getGenerator()->word(16)}.example.com";
$page->fillField('Apigee endpoint', "http://{$invalid_domain}/");
$this->assertSendRequestMessage('.messages--error', "Failed to connect to Apigee Edge. The given endpoint (http://{$invalid_domain}/) is incorrect or something is wrong with the connection. Error message: ");
$web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', "\"endpoint\": \"http:\/\/{$invalid_domain}\/\"");
Expand All @@ -409,7 +410,7 @@ protected function validateForm(callable $visitFormAsAdmin): void {

// Test invalid authorization server.
$this->cssSelect('select[data-drupal-selector="edit-key-input-settings-auth-type"]')[0]->setValue('oauth');
$invalid_domain = "{$this->randomGenerator->word(16)}.example.com";
$invalid_domain = "{Random::getGenerator()->word(16)}.example.com";
$page->selectFieldOption('key_input_settings[authorization_server_type]', 'custom');
$page->fillField('Custom authorization server', "http://{$invalid_domain}/");
$this->assertSendRequestMessage('.messages--error', "Failed to connect to the OAuth authorization server. The given authorization server (http://{$invalid_domain}/) is incorrect or something is wrong with the connection. Error message: ");
Expand All @@ -422,7 +423,7 @@ protected function validateForm(callable $visitFormAsAdmin): void {
$page->selectFieldOption('key_input_settings[authorization_server_type]', 'default');

// Test invalid client secret.
$random_secret = $this->randomGenerator->word(16);
$random_secret = Random::getGenerator()->word(16);
$page->fillField('Client secret', $random_secret);
$this->assertSendRequestMessage('.messages--error', "Failed to connect to the OAuth authorization server. The given username ({$this->username}) or password or client ID (edgecli) or client secret is incorrect. Error message: ");
$web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', '"authorization_server": "https:\/\/login.apigee.com\/oauth\/token"');
Expand All @@ -432,7 +433,7 @@ protected function validateForm(callable $visitFormAsAdmin): void {
$page->fillField('Client secret', '');

// Test invalid client id.
$client_id = $this->randomGenerator->word(8);
$client_id = Random::getGenerator()->word(8);
$page->fillField('Client ID', $client_id);
$this->assertSendRequestMessage('.messages--error', "Failed to connect to the OAuth authorization server. The given username ({$this->username}) or password or client ID ({$client_id}) or client secret is incorrect. Error message: ");
$web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', '"authorization_server": "https:\/\/login.apigee.com\/oauth\/token"');
Expand Down

0 comments on commit 4b996a6

Please sign in to comment.