public function test_execute()
 {
     $event = new \Magento\Framework\Event\Observer();
     /* load Magento order */
     $mageOrder = $this->repoSaleOrder->get(1);
     $event->setOrder($mageOrder);
     $resp = $this->obj->execute($event);
     $this->assertNotNull($resp);
 }
Exemplo n.º 2
0
 public function testAddObserver()
 {
     $testEvent = 'testEvent';
     $observer = new \Magento\Framework\Event\Observer();
     $observer->setData('event_name', $testEvent);
     $eventName = 'eventName';
     $eventMock = $this->getMock('\\Magento\\Framework\\Event', ['getName'], [], '', false, false);
     $eventMock->setData('name', $eventName);
     $this->collection->addObserver($observer);
     $this->assertNotEmpty($this->collection->getEventByName($testEvent)->getObservers());
 }
Exemplo n.º 3
0
 /**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  */
 public function testEmulateQuote()
 {
     $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->setMethods([])->getMock();
     $requestMock->expects($this->once())->method('getFullActionName')->will($this->returnValue('valid_action'));
     $event = new \Magento\Framework\Event(['request' => $requestMock]);
     $observer = new \Magento\Framework\Event\Observer();
     $observer->setEvent($event);
     $this->_customerSession->loginById(1);
     $customer = $this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->_checkoutSession->expects($this->once())->method('setCustomerData')->with($customer);
     $this->_customerSession->logout();
     $this->_observer->execute($observer);
 }
 public function dispatch($eventName, array $data = [])
 {
     \Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
     foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
         $event = new \Magento\Framework\Event($data);
         $event->setName($eventName);
         $wrapper = new \Magento\Framework\Event\Observer();
         $wrapper->setData(array_merge(['event' => $event], $data));
         \Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
         $this->_invoker->dispatch($observerConfig, $wrapper);
         $this->_devHelper->setObserverDetails($observerConfig, $eventName);
         \Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
     }
     \Magento\Framework\Profiler::stop('EVENT:' . $eventName);
 }
 public function testUpgradeCustomerPassword()
 {
     $customerId = '1';
     $password = '******';
     $passwordHash = 'hash:salt:999';
     $model = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->setMethods(['getPasswordHash', 'setPasswordHash'])->getMock();
     $model->expects($this->exactly(2))->method('getId')->willReturn($customerId);
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure);
     $customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($passwordHash);
     $this->encryptorMock->expects($this->once())->method('validateHashVersion')->with($passwordHash)->willReturn(false);
     $this->encryptorMock->expects($this->once())->method('getHash')->with($password, true)->willReturn($passwordHash);
     $customerSecure->expects($this->once())->method('setPasswordHash')->with($passwordHash);
     $this->customerRepository->expects($this->once())->method('save')->with($customer);
     $event = new \Magento\Framework\DataObject();
     $event->setData(['password' => 'password', 'model' => $model]);
     $observerMock = new \Magento\Framework\Event\Observer();
     $observerMock->setEvent($event);
     $this->model->execute($observerMock);
 }