Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynchronizePersistentOnLoginObserverTest.php
Go to the documentation of this file.
1 <?php
7 
11 class SynchronizePersistentOnLoginObserverTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_model;
17 
21  protected $_objectManager;
22 
27 
31  protected $_customerSession;
32 
33  public function setUp()
34  {
36  $this->_persistentSession = $this->_objectManager->get(\Magento\Persistent\Helper\Session::class);
37  $this->_customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
38  $this->_model = $this->_objectManager->create(
39  \Magento\Persistent\Observer\SynchronizePersistentOnLoginObserver::class,
40  [
41  'persistentSession' => $this->_persistentSession,
42  'customerSession' => $this->_customerSession
43  ]
44  );
45  }
46 
50  public function testSynchronizePersistentOnLogin()
51  {
52  $event = new \Magento\Framework\Event();
53  $observer = new \Magento\Framework\Event\Observer(['event' => $event]);
54 
56  $customerRepository = $this->_objectManager->create(
57  \Magento\Customer\Api\CustomerRepositoryInterface::class
58  );
59 
61  $customer = $customerRepository->getById(1);
62  $event->setData('customer', $customer);
63  $this->_persistentSession->setRememberMeChecked(true);
64  $this->_model->execute($observer);
65 
66  // check that persistent session has been stored for Customer
69  \Magento\Persistent\Model\Session::class
70  );
71  $sessionModel->loadByCustomerId(1);
72  $this->assertEquals(1, $sessionModel->getCustomerId());
73  }
74 }
$customer
Definition: customers.php:11
$customerRepository