本文整理汇总了PHP中Magento\Customer\Model\Session::loginById方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::loginById方法的具体用法?PHP Session::loginById怎么用?PHP Session::loginById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Model\Session
的用法示例。
在下文中一共展示了Session::loginById方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEmulateWelcomeBlock
/**
* @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();
}
示例2: testToHtml
/**
* @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();
}
示例3: setUp
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);
}
示例4: testEmulateCustomer
/**
* @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());
}
示例5: testEmulateCustomer
/**
* @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());
}
示例6: testEmulateQuote
/**
* @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);
}
示例7: testToHtml
/**
* @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();
}
示例8: testSynchronizePersistentOnLogout
/**
* @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());
}
示例9: testLoginById
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));
}
示例10: testGetWishlistCustomer
/**
* @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());
}
示例11: authenticateCustomer
/**
* 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;
}
示例12: testWishlistCustomer
/**
* @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());
}
示例13: login
/**
* Authorization customer by id
*
* @param int $customerId
*/
private function login($customerId)
{
$this->customerSession->loginById($customerId);
$this->customerSession->regenerateId();
}
示例14: testLoginById
public function testLoginById()
{
$this->assertTrue($this->_customerSession->loginById(1));
// fixture
$this->assertTrue($this->_customerSession->isLoggedIn());
}