AccountLifecycleTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. use PHPUnit\Framework\Attributes\Group;
  3. /**
  4. * Create an account, change its email and name, then delete it on a live install.
  5. */
  6. #[Group('integration')]
  7. class AccountLifecycleTest extends BxDolAccountTestCase
  8. {
  9. public function testCreateEditAndDeleteAccount(): void
  10. {
  11. $aCreated = $this->bxCreateLifecycleAccount();
  12. $sEmail = $aCreated['email'];
  13. $sEmailNew = 'lifecycle-' . bin2hex(random_bytes(4)) . '-new@example.com';
  14. $sNameNew = 'Lifecycle Renamed';
  15. $this->_aCreatedEmails[] = $sEmailNew;
  16. $this->assertTrue(isLogged());
  17. $this->assertSame($aCreated['id'], (int)getLoggedId());
  18. $this->assertSame($sEmail, $aCreated['account']->getEmail());
  19. $this->assertSame($aCreated['name'], $aCreated['account']->getDisplayName());
  20. $sEmailResult = $this->bxSubmitEmailForm($aCreated['id'], $sEmailNew, $aCreated['password']);
  21. $this->assertIsString($sEmailResult);
  22. $this->assertStringContainsString(_t('_sys_account_settings_email_successfully_submitted'), $sEmailResult);
  23. $oAccount = BxDolAccount::getInstance($aCreated['id'], true);
  24. $this->assertInstanceOf(BxDolAccount::class, $oAccount);
  25. $this->assertSame($sEmailNew, $oAccount->getEmail());
  26. $this->assertSame(0, $this->bxAccountIdByEmail($sEmail));
  27. $this->assertSame($aCreated['id'], $this->bxAccountIdByEmail($sEmailNew));
  28. $sNameResult = $this->bxSubmitInfoForm($aCreated['id'], $sNameNew);
  29. $this->assertIsString($sNameResult);
  30. $this->assertStringContainsString(_t('_sys_account_settings_info_successfully_submitted'), $sNameResult);
  31. $oAccount = BxDolAccount::getInstance($aCreated['id'], true);
  32. $this->assertInstanceOf(BxDolAccount::class, $oAccount);
  33. $this->assertSame($sNameNew, $oAccount->getDisplayName());
  34. $this->assertSame($sEmailNew, $oAccount->getEmail());
  35. $oDeleteForm = $this->bxSubmitDeleteForm($oAccount, $aCreated['password']);
  36. $this->assertTrue($oDeleteForm->isSubmittedAndValid(), $oDeleteForm->getFormErrors() ?: 'delete account form should accept the posted values');
  37. $this->assertTrue($oAccount->delete((int)$oDeleteForm->getCleanValue('delete_content') != 0, false));
  38. $this->_iCreatedAccountId = 0;
  39. $this->bxBecomeGuest();
  40. $this->assertFalse(BxDolAccount::getInstance($sEmailNew, true));
  41. $this->assertSame(0, $this->bxAccountIdByEmail($sEmail));
  42. $this->assertSame(0, $this->bxAccountIdByEmail($sEmailNew));
  43. $this->assertEmpty(BxDolAccountQuery::getInstance()->getInfoById($aCreated['id']));
  44. $this->assertEmpty(BxDolDb::getInstance()->getColumn("SELECT `id` FROM `sys_profiles` WHERE `account_id` = :id", [
  45. 'id' => $aCreated['id'],
  46. ]));
  47. }
  48. }