PasswordResetRequestEventTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Security\Model\ResourceModel;
  7. /**
  8. * Class PasswordResetRequestEventTest
  9. * @package Magento\Security\Model
  10. */
  11. class PasswordResetRequestEventTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Framework\Model\AbstractModel
  15. */
  16. protected $model;
  17. /**
  18. * @var \Magento\Security\Model\ResourceModel\PasswordResetRequestEvent
  19. */
  20. protected $resourceModel;
  21. /**
  22. * @var \Magento\Framework\ObjectManagerInterface
  23. */
  24. protected $objectManager;
  25. protected function setUp()
  26. {
  27. parent::setUp();
  28. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  29. $this->model = $this->objectManager->create(\Magento\Security\Model\PasswordResetRequestEvent::class);
  30. $this->resourceModel = $this->model->getResource();
  31. }
  32. protected function tearDown()
  33. {
  34. $this->objectManager = null;
  35. $this->resourceModel = null;
  36. parent::tearDown();
  37. }
  38. /**
  39. * Test data
  40. * @return array
  41. */
  42. public function getTestData()
  43. {
  44. return [
  45. 'request_type' => \Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST,
  46. 'account_reference' => 'test27.dev@gmail.com',
  47. 'created_at' => '2016-01-20 13:00:13',
  48. 'ip' => '3232249856'
  49. ];
  50. }
  51. /**
  52. * Saving test data to database
  53. * @return mixed
  54. */
  55. protected function saveTestData()
  56. {
  57. foreach ($this->getTestData() as $key => $value) {
  58. $this->model->setData($key, $value);
  59. }
  60. $this->model->save();
  61. return $this->model->getId();
  62. }
  63. /**
  64. * Checking that test data is saving to database
  65. *
  66. * @magentoDbIsolation enabled
  67. */
  68. public function testIsModelSavingDataToDatabase()
  69. {
  70. $modelId = $this->saveTestData();
  71. $newModel = $this->model->load($modelId);
  72. $testData = $this->getTestData();
  73. $newModelData = [];
  74. foreach (array_keys($testData) as $key) {
  75. $newModelData[$key] = $newModel->getData($key);
  76. }
  77. $this->assertEquals($testData, $newModelData);
  78. }
  79. /**
  80. * @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
  81. */
  82. public function testDeleteRecordsOlderThen()
  83. {
  84. /** @var \Magento\Security\Model\PasswordResetRequestEvent $passwordResetRequestEvent */
  85. $countBefore = $this->model->getCollection()->count();
  86. $this->resourceModel->deleteRecordsOlderThen(strtotime('2016-01-20 12:00:00'));
  87. $countAfter = $this->model->getCollection()->count();
  88. $this->assertLessThan($countBefore, $countAfter);
  89. }
  90. }