/**
  * @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
  * @magentoAppIsolation enabled
  */
 public function testEmulateWelcomeBlock()
 {
     $this->_customerSession->loginById(1);
     $httpContext = new \Magento\Framework\App\Http\Context();
     $httpContext->setValue(Context::CONTEXT_AUTH, 1, 1);
     $block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]);
     $this->_observer->emulateWelcomeBlock($block);
     $customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())));
     $translation = __('Welcome, %1!', $customerName);
     $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
     $this->_customerSession->logout();
 }
 /**
  * @magentoConfigFixture current_store persistent/options/customer 1
  * @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
  * @magentoAppIsolation enabled
  */
 public function testToHtml()
 {
     $this->_customerSession->loginById(1);
     $translation = __('Not you?');
     $this->assertStringMatchesFormat('%A<span>%A<a%Ahref="' . $this->_block->getHref() . '"%A>' . $translation . '</a>%A</span>%A', $this->_block->toHtml());
     $this->_customerSession->logout();
 }
 protected function setUp()
 {
     $this->_fixtureCustomerId = 1;
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_customerSession = $this->_objectManager->create('Magento\\Customer\\Model\\Session');
     $this->_coreData = $this->_objectManager->create('Magento\\Core\\Helper\\Data');
     $this->_contextHelper = $this->_objectManager->create('Magento\\Framework\\App\\Helper\\Context');
     $request = $this->_contextHelper->getRequest();
     $request->setParam('data', $this->_coreData->urlEncode($this->_fixtureCustomerId));
     $this->_wishlistHelper = $this->_objectManager->create('Magento\\Rss\\Helper\\WishlistRss', ['context' => $this->_contextHelper, 'customerSession' => $this->_customerSession]);
     $this->_customerSession->loginById($this->_fixtureCustomerId);
 }
 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
 /**
  * @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);
 }
Example #7
0
 /**
  * @magentoConfigFixture current_store persistent/options/customer 1
  * @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
  * @magentoAppIsolation enabled
  */
 public function testToHtml()
 {
     $this->_customerSession->loginById(1);
     /** @var \Magento\Customer\Helper\View $customerViewHelper */
     $customerViewHelper = $this->_objectManager->create('Magento\\Customer\\Helper\\View');
     $customerAccountService = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     /** @var \Magento\Framework\Escaper $escaper */
     $escaper = $this->_objectManager->create('Magento\\Framework\\Escaper');
     $persistentName = $escaper->escapeHtml($customerViewHelper->getCustomerName($customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId())));
     $translation = __('(Not %1?)', $persistentName);
     $this->assertStringMatchesFormat('%A<span>%A<a%Ahref="' . $this->_block->getHref() . '"%A>' . $translation . '</a>%A</span>%A', $this->_block->toHtml());
     $this->_customerSession->logout();
 }
 /**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 1
  * @magentoAppArea frontend
  * @magentoAppIsolation enabled
  */
 public function testSynchronizePersistentOnLogout()
 {
     $this->_customerSession->loginById(1);
     // check that persistent session has been stored for Customer
     /** @var \Magento\Persistent\Model\Session $sessionModel */
     $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
     $sessionModel->loadByCookieKey();
     $this->assertEquals(1, $sessionModel->getCustomerId());
     $this->_customerSession->logout();
     /** @var \Magento\Persistent\Model\Session $sessionModel */
     $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
     $sessionModel->loadByCookieKey();
     $this->assertNull($sessionModel->getCustomerId());
 }
Example #9
0
 public function testLoginById()
 {
     $customerId = 1;
     $customerDataMock = $this->prepareLoginDataMock($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($this->equalTo($customerId))->will($this->returnValue($customerDataMock));
     $this->assertTrue($this->_model->loginById($customerId));
 }
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
  */
 public function testGetWishlistCustomer()
 {
     $this->_customerSession->loginById(1);
     $expectedCustomer = $this->_customerSession->getCustomerDataObject();
     $actualCustomer = $this->_block->getWishlistCustomer();
     $this->assertInstanceOf('Magento\\Customer\\Api\\Data\\CustomerInterface', $actualCustomer);
     $this->assertEquals((int) $expectedCustomer->getId(), (int) $actualCustomer->getId());
     $this->assertEquals((int) $expectedCustomer->getWebsiteId(), (int) $actualCustomer->getWebsiteId());
     $this->assertEquals((int) $expectedCustomer->getStoreId(), (int) $actualCustomer->getStoreId());
     $this->assertEquals((int) $expectedCustomer->getGroupId(), (int) $actualCustomer->getGroupId());
     $this->assertEquals($expectedCustomer->getCustomAttributes(), $actualCustomer->getCustomAttributes());
     $this->assertEquals($expectedCustomer->getFirstname(), $actualCustomer->getFirstname());
     $this->assertEquals($expectedCustomer->getLastname(), $actualCustomer->getLastname());
     $this->assertEquals($expectedCustomer->getEmail(), $actualCustomer->getEmail());
     $this->assertEquals($expectedCustomer->getEmail(), $actualCustomer->getEmail());
     $this->assertEquals((int) $expectedCustomer->getDefaultBilling(), (int) $actualCustomer->getDefaultBilling());
     $this->assertEquals((int) $expectedCustomer->getDefaultShipping(), (int) $actualCustomer->getDefaultShipping());
 }
 /**
  * Login Customer
  * @return false || \Magento\Customer\Model\Customer
  */
 public function authenticateCustomer()
 {
     $customer = $this->getCustomer();
     if (!$customer->getId()) {
         throw new \Exception(__("Customer are no longer exist."), 1);
     }
     if ($this->_customerSession->loginById($customer->getId())) {
         $this->_customerSession->regenerateId();
         $this->_customerSession->setLoggedAsCustomerAdmindId($this->getAdminId());
     }
     $this->setUsed(1)->save();
     return $customer;
 }
Example #12
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_increments.php
  * @magentoAppArea frontend
  */
 public function testCustomerTitle()
 {
     $fixtureCustomerId = 1;
     $this->_customerSession->loginById($fixtureCustomerId);
     /** @var \Magento\Wishlist\Model\Wishlist $wishlist */
     $wishlist = $this->_objectManager->create('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId($fixtureCustomerId);
     /** @var \Magento\Framework\App\Helper\Context $contextHelper */
     $contextHelper = $this->_objectManager->create('Magento\\Framework\\App\\Helper\\Context');
     $wishlistHelper = $this->_objectManager->create('Magento\\Wishlist\\Helper\\Rss', ['context' => $contextHelper, 'customerSession' => $this->_customerSession]);
     /** @var \Magento\Catalog\Block\Product\Context $context */
     $contextBlock = $this->_objectManager->create('Magento\\Wishlist\\Block\\Context', ['request' => $contextHelper->getRequest(), 'wishlistHelper' => $wishlistHelper]);
     /** @var \Magento\Framework\App\Request\Http $request */
     $request = $contextHelper->getRequest();
     $request->setParam('wishlist_id', $wishlist->getId());
     $request->setParam('data', $this->_coreData->urlEncode($fixtureCustomerId));
     /** @var \Magento\Wishlist\Block\Rss $block */
     $block = $this->_objectManager->create('Magento\\Wishlist\\Block\\Rss', ['context' => $contextBlock]);
     /** @var \Magento\Framework\Escaper $escaper */
     $escaper = $this->_objectManager->create('Magento\\Framework\\Escaper');
     $expectedSting = '%A' . __("<title><![CDATA[%1 %2's Wishlist]]></title>", $escaper->escapeHtml($this->_customerSession->getCustomerDataObject()->getFirstname()), $escaper->escapeHtml($this->_customerSession->getCustomerDataObject()->getLastname())) . '%A';
     $this->assertStringMatchesFormat($expectedSting, $block->toHtml());
 }
Example #13
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testWishlistCustomer()
 {
     /** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerAccountService */
     $customerAccountService = $this->objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     $customer = $customerAccountService->getCustomer(1);
     $this->_wishlistHelper->setCustomer($customer);
     $this->assertSame($customer, $this->_wishlistHelper->getCustomer());
     $this->_wishlistHelper = null;
     /** @var \Magento\Wishlist\Helper\Data wishlistHelper */
     $this->_wishlistHelper = $this->objectManager->get('Magento\\Wishlist\\Helper\\Data');
     $this->_customerSession->loginById(1);
     $this->assertEquals($customer, $this->_wishlistHelper->getCustomer());
     /** @var \Magento\Customer\Helper\View $customerViewHelper */
     $customerViewHelper = $this->objectManager->create('Magento\\Customer\\Helper\\View');
     $this->assertEquals($customerViewHelper->getCustomerName($customer), $this->_wishlistHelper->getCustomerName());
 }
Example #14
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testWishlistCustomer()
 {
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = $this->objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customer = $customerRepository->getById(1);
     $this->_wishlistHelper->setCustomer($customer);
     $this->assertSame($customer, $this->_wishlistHelper->getCustomer());
     $this->_wishlistHelper = null;
     /** @var \Magento\Wishlist\Helper\Data wishlistHelper */
     $this->_wishlistHelper = $this->objectManager->get('Magento\\Wishlist\\Helper\\Data');
     $this->_customerSession->loginById(1);
     $this->assertEquals($customer, $this->_wishlistHelper->getCustomer());
     /** @var \Magento\Customer\Helper\View $customerViewHelper */
     $customerViewHelper = $this->objectManager->create('Magento\\Customer\\Helper\\View');
     $this->assertEquals($customerViewHelper->getCustomerName($customer), $this->_wishlistHelper->getCustomerName());
 }
Example #15
0
 /**
  * Authorization customer by id
  *
  * @param int $customerId
  */
 private function login($customerId)
 {
     $this->customerSession->loginById($customerId);
     $this->customerSession->regenerateId();
 }
Example #16
0
 public function testLoginById()
 {
     $this->assertTrue($this->_customerSession->loginById(1));
     // fixture
     $this->assertTrue($this->_customerSession->isLoggedIn());
 }
Example #17
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
  */
 public function testGetWishlistCustomer()
 {
     $this->_customerSession->loginById(1);
     $this->assertEquals($this->_customerSession->getCustomerDataObject(), $this->_block->getWishlistCustomer());
 }