Exemplo n.º 1
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());
     }
 }