当前位置: 首页>>代码示例>>PHP>>正文


PHP Session::loginById方法代码示例

本文整理汇总了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();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:ObserverTest.php

示例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();
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:15,代码来源:AdditionalTest.php

示例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);
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:12,代码来源:WishlistRssTest.php

示例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());
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:18,代码来源:EmulateCustomerTest.php

示例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());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:EmulateCustomerTest.php

示例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);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:21,代码来源:EmulateQuoteTest.php

示例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();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:AdditionalTest.php

示例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());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:SynchronizePersistentOnLogoutObserverTest.php

示例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));
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:7,代码来源:SessionTest.php

示例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());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:22,代码来源:WishlistTest.php

示例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;
 }
开发者ID:magefan,项目名称:module-login-as-customer,代码行数:17,代码来源:Login.php

示例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());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:DataTest.php

示例13: login

 /**
  * Authorization customer by id
  *
  * @param int $customerId
  */
 private function login($customerId)
 {
     $this->customerSession->loginById($customerId);
     $this->customerSession->regenerateId();
 }
开发者ID:Viktor-V,项目名称:Facebook-Login,代码行数:10,代码来源:Index.php

示例14: testLoginById

 public function testLoginById()
 {
     $this->assertTrue($this->_customerSession->loginById(1));
     // fixture
     $this->assertTrue($this->_customerSession->isLoggedIn());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:6,代码来源:SessionTest.php


注:本文中的Magento\Customer\Model\Session::loginById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。