/** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testToHtml() { $this->customerSession->setCustomerId(1); $html = $this->block->toHtml(); $this->assertContains("<div class=\"block block-dashboard-welcome\">", $html); $this->assertContains("<strong>Hello, Firstname Lastname!</strong>", $html); }
/** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testGetSubscriptionObject() { $this->customerSession->setCustomerId(1); $subscriber = $this->block->getSubscriptionObject(); $this->assertInstanceOf('Magento\\Newsletter\\Model\\Subscriber', $subscriber); $this->assertFalse($subscriber->isSubscribed()); }
public function testAddProductWithSession() { $this->_session->setCustomerId(1); /** @var $product \Magento\Catalog\Model\Product */ $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product')->load(1); $this->_model->addProduct($product); $this->assertTrue($this->_model->hasItems(1, $this->_visitor->getId())); }
/** * Reset session data when customer re-authenticates * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute($observer) { $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); if ($this->_requestHttp->getParam('context') != 'checkout') { $this->quoteManager->expire(); return; } $this->quoteManager->setGuest(); }
/** * Verify that the specified customer has different default billing and shipping addresses. * * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Customer/_files/customer_primary_addresses.php */ public function testGetPrimaryAddressesBillingShippingDifferent() { $this->customerSession->setCustomerId(1); $addresses = $this->block->getPrimaryAddresses(); $this->assertCount(2, $addresses); $this->assertNotEquals($addresses[0], $addresses[1]); $this->assertTrue($addresses[0]->isDefaultBilling()); $this->assertTrue($addresses[1]->isDefaultShipping()); }
/** * Set persistent data to customer session * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute($observer) { if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) { return $this; } if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) { $customer = $this->_customerAccountService->getCustomer($this->_persistentSession->getSession()->getCustomerId()); $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId()); } return $this; }
/** * Set persistent data to customer session * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) { return $this; } if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) { $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId()); $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId()); } return $this; }
/** * Check and clear session data if persistent session expired * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!$this->_persistentData->canProcess($observer)) { return; } if ($this->_persistentData->isEnabled() && !$this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && $this->_checkoutSession->getQuoteId() && !$observer->getControllerAction() instanceof \Magento\Checkout\Controller\Onepage) { $this->_eventManager->dispatch('persistent_session_expired'); $this->quoteManager->expire(); $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); } }
/** * Unset persistent cookie and make customer's quote as a guest * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute($observer) { if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent()) { return; } $this->_persistentSession->getSession()->removePersistentCookie(); if (!$this->_customerSession->isLoggedIn()) { $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); } $this->quoteManager->setGuest(); }
protected function setUp() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_customerSession = $objectManager->get('\\Magento\\Customer\\Model\\Session'); $this->_customerSession->setCustomerId(1); $this->_context = $objectManager->get('Magento\\Backend\\Block\\Template\\Context'); $this->_requestId = $this->_context->getRequest()->getParam('id'); $this->_context->getRequest()->setParam('id', '1'); $objectManager->get('Magento\\Framework\\App\\State')->setAreaCode('frontend'); /** @var $layout \Magento\Framework\View\Layout */ $layout = $objectManager->get('Magento\\Framework\\View\\LayoutInterface'); $currentCustomer = $objectManager->create('Magento\\Customer\\Helper\\Session\\CurrentCustomer', array('customerSession' => $this->_customerSession)); $this->_block = $layout->createBlock('Magento\\Customer\\Block\\Address\\Edit', '', array('customerSession' => $this->_customerSession, 'currentCustomer' => $currentCustomer)); }
protected function tearDown() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_customerSession->setCustomerId(null); $this->_context->getRequest()->setParam('id', $this->_requestId); /** @var \Magento\Customer\Model\AddressRegistry $addressRegistry */ $addressRegistry = $objectManager->get('Magento\\Customer\\Model\\AddressRegistry'); //Cleanup address from registry $addressRegistry->remove(1); $addressRegistry->remove(2); /** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */ $customerRegistry = $objectManager->get('Magento\\Customer\\Model\\CustomerRegistry'); //Cleanup customer from registry $customerRegistry->remove(1); }
/** * Set persistent data to customer session * * @param \Magento\Framework\Event\Observer $observer * @SuppressWarnings(PHPMD.CyclomaticComplexity) * * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) { return $this; } if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) { /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId()); if ($defaultShipping = $customer->getDefaultShipping()) { /** @var \Magento\Customer\Model\Data\Address $address */ $address = $this->addressRepository->getById($defaultShipping); if ($address) { $this->_customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]); } } if ($defaultBilling = $customer->getDefaultBilling()) { $address = $this->addressRepository->getById($defaultBilling); if ($address) { $this->_customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]); } } $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId()); } return $this; }
/** * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php * @magentoDataFixture Magento/Customer/_files/customer_no_address.php * @dataProvider getPrimaryAddressEditUrlDataProvider */ public function testGetPrimaryBillingAddressEditUrl($customerId, $expected) { if (!empty($customerId)) { $this->_customerSession->setCustomerId($customerId); } $url = $this->_block->getPrimaryBillingAddressEditUrl(); $this->assertEquals($expected, $url); }
/** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testGetEmail() { $this->customerSession->setCustomerId(1); $this->assertEquals('*****@*****.**', $this->block->getEmail()); }
protected function tearDown() { $this->customerSession->setCustomerId(null); $this->coreSession->unsData('_form_key'); }