コード例 #1
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);
     $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();
 }
コード例 #2
0
ファイル: AdditionalTest.php プロジェクト: aiesh/magento2
 /**
  * @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();
 }
コード例 #3
0
 /**
  * Run test toHtml method
  *
  * @param bool $customerId
  * @return void
  *
  * @dataProvider dataProviderToHtml
  */
 public function testToHtml($customerId)
 {
     $cacheData = false;
     $idQueryParam = 'id-query-param';
     $sessionId = 'session-id';
     $this->additional->setData('cache_lifetime', 789);
     $this->additional->setData('cache_key', 'cache-key');
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]);
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false);
     // get cache
     $this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true);
     // save cache
     $this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false);
     $this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData);
     $this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam);
     $this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId);
     // call protected _toHtml method
     $sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false);
     $this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock);
     $sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId);
     if ($customerId) {
         $this->assertEquals('<span><a  >Not you?</a></span>', $this->additional->toHtml());
     } else {
         $this->assertEquals('', $this->additional->toHtml());
     }
 }