From 03905a583dec21673e5b7d96b550c572f2c73e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Thu, 2 May 2024 16:09:30 +0300 Subject: [PATCH] UHF-9832: Added a separate test for the user sanitize drush command. --- .../Functional/UserSanitizeCommandsTest.php | 102 ++++++++++++++++++ tests/src/Functional/UserSanitizeFormTest.php | 37 ------- 2 files changed, 102 insertions(+), 37 deletions(-) create mode 100644 tests/src/Functional/UserSanitizeCommandsTest.php diff --git a/tests/src/Functional/UserSanitizeCommandsTest.php b/tests/src/Functional/UserSanitizeCommandsTest.php new file mode 100644 index 0000000..b757120 --- /dev/null +++ b/tests/src/Functional/UserSanitizeCommandsTest.php @@ -0,0 +1,102 @@ + 'Test', + 'password' => 'test', + 'email' => 'lTqgB@drupal.hel.ninja', + ]; + + /** + * {@inheritdoc} + */ + public function setUp(): void { + parent::setUp(); + // Create a test user with default values. + $this->testUser = $this->createUser( + ['access content'], + $this->defaultValues['username'], + FALSE, + [ + 'pass' => $this->defaultValues['password'], + 'mail' => $this->defaultValues['email'], + ], + ); + $this->testUser->block()->save(); + } + + /** + * Tests helfi:yser-sanitize command with field options. + */ + public function testUserSanitizeCommandWithFields() { + $this->drush('helfi:user-sanitize', [$this->testUser->id()], ['fields' => 'username']); + + $storage = \Drupal::entityTypeManager()->getStorage('user'); + $storage->resetCache([$this->testUser->id()]); + $entity = $storage->load($this->testUser->id()); + + $this->assertEquals($entity->getAccountName() === $this->defaultValues['username'], FALSE); + $this->assertEquals($entity->getEmail() === $this->defaultValues['email'], TRUE); + $password_service = $this->container->get('password'); + $this->assertEquals($password_service->check($this->defaultValues['password'], $entity->getPassword()), TRUE); + } + + /** + * Tests helfi:yser-sanitize command without field options. + */ + public function testUserSanitizeCommandWithOutFields() { + $this->drush('helfi:user-sanitize', [$this->testUser->id()]); + + $storage = \Drupal::entityTypeManager()->getStorage('user'); + $storage->resetCache([$this->testUser->id()]); + $entity = $storage->load($this->testUser->id()); + + $this->assertEquals($entity->getAccountName() === $this->defaultValues['username'], FALSE); + $this->assertEquals($entity->getEmail() === $this->defaultValues['email'], FALSE); + $password_service = $this->container->get('password'); + $this->assertEquals($password_service->check($this->defaultValues['password'], $entity->getPassword()), FALSE); + } + +} diff --git a/tests/src/Functional/UserSanitizeFormTest.php b/tests/src/Functional/UserSanitizeFormTest.php index 937044b..8ab62e7 100644 --- a/tests/src/Functional/UserSanitizeFormTest.php +++ b/tests/src/Functional/UserSanitizeFormTest.php @@ -13,12 +13,9 @@ * * @group helfi_api_base * @covers \Drupal\helfi_api_base\Entity\Form\UserEntitySanitizeForm - * @covers \Drupal\helfi_api_base\Commands\UserSanitizeCommands */ class UserSanitizeFormTest extends BrowserTestBase { - use DrushTestTrait; - /** * {@inheritdoc} */ @@ -140,38 +137,4 @@ public function testUserSanitizeForm(): void { $this->assertSession()->pageTextContains("User account id {$this->testUser->id()} was sanitized."); } - /** - * Tests helfi:yser-sanitize command with field options. - */ - public function testUserSanitizeCommandWithFields() { - $this->testUser->block()->save(); - $this->drush('helfi:user-sanitize', [$this->testUser->id()], ['fields' => 'username']); - - $storage = \Drupal::entityTypeManager()->getStorage('user'); - $storage->resetCache([$this->testUser->id()]); - $entity = $storage->load($this->testUser->id()); - - $this->assertEquals($entity->getAccountName() === $this->defaultValues['username'], FALSE); - $this->assertEquals($entity->getEmail() === $this->defaultValues['email'], TRUE); - $password_service = $this->container->get('password'); - $this->assertEquals($password_service->check($this->defaultValues['password'], $entity->getPassword()), TRUE); - } - - /** - * Tests helfi:yser-sanitize command without field options. - */ - public function testUserSanitizeCommandWithOutFields() { - $this->testUser->block()->save(); - $this->drush('helfi:user-sanitize', [$this->testUser->id()]); - - $storage = \Drupal::entityTypeManager()->getStorage('user'); - $storage->resetCache([$this->testUser->id()]); - $entity = $storage->load($this->testUser->id()); - - $this->assertEquals($entity->getAccountName() === $this->defaultValues['username'], FALSE); - $this->assertEquals($entity->getEmail() === $this->defaultValues['email'], FALSE); - $password_service = $this->container->get('password'); - $this->assertEquals($password_service->check($this->defaultValues['password'], $entity->getPassword()), FALSE); - } - }