Skip to content

Commit 207edd1

Browse files
authored
Fixes for calling name() & word() on null (#1127)
1 parent 94395a5 commit 207edd1

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

modules/apigee_edge_actions/tests/src/Kernel/Plugin/RulesEvent/EdgeEntityUpdateEventTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace Drupal\Tests\apigee_edge_actions\Kernel\Plugin\RulesEvent;
2222

2323
use Drupal\Tests\apigee_edge_actions\Kernel\ApigeeEdgeActionsRulesKernelTestBase;
24+
use Drupal\TestTools\Random;
2425
use Drupal\rules\Context\ContextConfig;
2526

2627
/**
@@ -62,7 +63,7 @@ public function testEvent() {
6263
/** @var \Drupal\apigee_edge\Entity\DeveloperAppInterface $entity */
6364
$entity = $this->createDeveloperApp();
6465
$original_name = $entity->getDisplayName();
65-
$new_name = $this->randomGenerator->name();
66+
$new_name = Random::getGenerator()->name();
6667
$this->queueDeveloperAppResponse($entity);
6768
$entity->setDisplayName($new_name);
6869
$this->queueDeveloperAppResponse($entity);

tests/modules/apigee_mock_api_client/tests/src/Traits/ApigeeMockApiClientHelperTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Apigee\Edge\Structure\MonetizationConfig;
2828
use Apigee\MockClient\Generator\ApigeeSdkEntitySource;
2929
use Drupal\Tests\apigee_edge\Traits\ApigeeEdgeUtilTestTrait;
30+
use Drupal\TestTools\Random;
3031
use Drupal\apigee_edge\Entity\Developer;
3132
use Drupal\apigee_edge\Entity\DeveloperApp;
3233
use Drupal\apigee_edge\Entity\DeveloperAppInterface;
@@ -370,7 +371,7 @@ protected function createTeam(): TeamInterface {
370371
/** @var \Drupal\apigee_edge_teams\Entity\TeamInterface $team */
371372
$team = Team::create([
372373
'name' => $this->randomMachineName(),
373-
'displayName' => $this->randomGenerator->name(),
374+
'displayName' => Random::getGenerator()->name(),
374375
]);
375376
$this->queueCompanyResponse($team->decorated());
376377
$this->stack->queueMockResponse('no_content');
@@ -391,7 +392,7 @@ protected function createApigeexTeam(): TeamInterface {
391392
/** @var \Drupal\apigee_edge_teams\Entity\TeamInterface $team */
392393
$team = Team::create([
393394
'name' => $this->randomMachineName(),
394-
'displayName' => $this->randomGenerator->name(),
395+
'displayName' => Random::getGenerator()->name(),
395396
]);
396397

397398
$this->queueAppGroupResponse($team->decorated());

tests/src/Functional/DeveloperAppUITest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Apigee\Edge\Api\Management\Controller\DeveloperController;
2323
use Drupal\Core\Url;
2424
use Drupal\Tests\apigee_edge\Traits\EntityUtilsTrait;
25+
use Drupal\TestTools\Random;
2526
use Drupal\apigee_edge\Entity\Developer;
2627
use Drupal\apigee_edge\Entity\DeveloperApp;
2728

@@ -580,7 +581,7 @@ public function testCallbackUrlValidationServerSide() {
580581
public function testInvalidEdgeSideCallbackUrl() {
581582
$this->drupalLogin($this->rootUser);
582583
$this->products[] = $this->createProduct();
583-
$callback_url = $this->randomGenerator->word(8);
584+
$callback_url = Random::getGenerator()->word(8);
584585
$callback_url_warning_msg = "The Callback URL value should be fixed. The URI '{$callback_url}' is invalid. You must use a valid URI scheme.";
585586
$app = $this->createDeveloperApp(
586587
[

tests/src/Functional/DeveloperSyncTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Apigee\Edge\Api\Management\Controller\DeveloperController;
2323
use Drupal\Core\Url;
2424
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
25+
use Drupal\TestTools\Random;
2526
use Drupal\apigee_edge\Entity\Developer;
2627
use Drupal\apigee_edge\Plugin\ApigeeFieldStorageFormat\CSV;
2728
use Drupal\apigee_edge\Plugin\ApigeeFieldStorageFormat\JSON;
@@ -234,8 +235,8 @@ protected function setUp(): void {
234235
}
235236

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

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

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

280281
// Set unlinked field in Drupal.
281282
$this->modifiedDrupalUsers[$user->getEmail()]->set($this->fieldNamePrefix . 'one_track_field', 'user');

tests/src/FunctionalJavascript/Form/AuthenticationFormJsTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
use Drupal\Core\Url;
2323
use Drupal\Tests\apigee_edge\FunctionalJavascript\ApigeeEdgeFunctionalJavascriptTestBase;
24+
use Drupal\TestTools\Random;
2425
use Drupal\apigee_edge\Form\AuthenticationForm;
2526
use Drupal\apigee_edge\OauthTokenFileStorage;
2627
use Drupal\apigee_edge\Plugin\EdgeKeyTypeInterface;
@@ -375,15 +376,15 @@ protected function validateForm(callable $visitFormAsAdmin): void {
375376
// @todo Re-add this assert later, if requires.
376377
// Irrespective of incorrect organization, username or password it will say Forbidden.
377378
// Test invalid organization.
378-
// $random_org = $this->randomGenerator->word(16);
379+
// $random_org = Random::getGenerator()->word(16);
379380
// $page->fillField('Organization', $random_org);
380381
// $this->assertSendRequestMessage('.messages--error', "Failed to connect to Apigee Edge. The given organization name ({$random_org}) is incorrect. Error message: ");
381382
// $web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', 'HTTP/1.1 404 Not Found');
382383
// $web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', "\"organization\": \"{$random_org}\"");
383384
// $page->fillField('Organization', $this->organization);
384385
// Test invalid endpoint.
385386
$page->selectFieldOption('key_input_settings[instance_type]', EdgeKeyTypeInterface::INSTANCE_TYPE_PRIVATE);
386-
$invalid_domain = "{$this->randomGenerator->word(16)}.example.com";
387+
$invalid_domain = "{Random::getGenerator()->word(16)}.example.com";
387388
$page->fillField('Apigee endpoint', "http://{$invalid_domain}/");
388389
$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: ");
389390
$web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', "\"endpoint\": \"http:\/\/{$invalid_domain}\/\"");
@@ -409,7 +410,7 @@ protected function validateForm(callable $visitFormAsAdmin): void {
409410

410411
// Test invalid authorization server.
411412
$this->cssSelect('select[data-drupal-selector="edit-key-input-settings-auth-type"]')[0]->setValue('oauth');
412-
$invalid_domain = "{$this->randomGenerator->word(16)}.example.com";
413+
$invalid_domain = "{Random::getGenerator()->word(16)}.example.com";
413414
$page->selectFieldOption('key_input_settings[authorization_server_type]', 'custom');
414415
$page->fillField('Custom authorization server', "http://{$invalid_domain}/");
415416
$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: ");
@@ -422,7 +423,7 @@ protected function validateForm(callable $visitFormAsAdmin): void {
422423
$page->selectFieldOption('key_input_settings[authorization_server_type]', 'default');
423424

424425
// Test invalid client secret.
425-
$random_secret = $this->randomGenerator->word(16);
426+
$random_secret = Random::getGenerator()->word(16);
426427
$page->fillField('Client secret', $random_secret);
427428
$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: ");
428429
$web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', '"authorization_server": "https:\/\/login.apigee.com\/oauth\/token"');
@@ -432,7 +433,7 @@ protected function validateForm(callable $visitFormAsAdmin): void {
432433
$page->fillField('Client secret', '');
433434

434435
// Test invalid client id.
435-
$client_id = $this->randomGenerator->word(8);
436+
$client_id = Random::getGenerator()->word(8);
436437
$page->fillField('Client ID', $client_id);
437438
$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: ");
438439
$web_assert->elementContains('css', 'textarea[data-drupal-selector="edit-debug-text"]', '"authorization_server": "https:\/\/login.apigee.com\/oauth\/token"');

0 commit comments

Comments
 (0)