AjaxLoginTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Controller;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. class AjaxLoginTest extends \Magento\TestFramework\TestCase\AbstractController
  9. {
  10. /**
  11. * Login the user
  12. *
  13. * @param string $customerId Customer to mark as logged in for the session
  14. * @return void
  15. */
  16. protected function login($customerId)
  17. {
  18. /** @var \Magento\Customer\Model\Session $session */
  19. $session = Bootstrap::getObjectManager()
  20. ->get(\Magento\Customer\Model\Session::class);
  21. $session->loginById($customerId);
  22. }
  23. /**
  24. * @magentoDataFixture Magento/Customer/_files/customer.php
  25. */
  26. public function testLogoutAction()
  27. {
  28. $this->login(1);
  29. $this->dispatch('customer/ajax/logout');
  30. $body = $this->getResponse()->getBody();
  31. $logoutMessage = Bootstrap::getObjectManager()->get(
  32. \Magento\Framework\Json\Helper\Data::class
  33. )->jsonDecode($body);
  34. $this->assertContains('Logout Successful', $logoutMessage['message']);
  35. }
  36. }