CustomerTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Block\Account;
  7. class CustomerTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Customer\Block\Account\Customer */
  10. private $block;
  11. /** @var \PHPUnit_Framework_MockObject_MockObject */
  12. private $httpContext;
  13. protected function setUp()
  14. {
  15. $this->httpContext = $this->getMockBuilder(\Magento\Framework\App\Http\Context::class)
  16. ->disableOriginalConstructor()->getMock();
  17. $this->block = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
  18. ->getObject(\Magento\Customer\Block\Account\Customer::class, ['httpContext' => $this->httpContext]);
  19. }
  20. /**
  21. * @return array
  22. */
  23. public function customerLoggedInDataProvider()
  24. {
  25. return [
  26. [1, true],
  27. [0, false],
  28. ];
  29. }
  30. /**
  31. * @param $isLoggedIn
  32. * @param $result
  33. * @dataProvider customerLoggedInDataProvider
  34. */
  35. public function testCustomerLoggedIn($isLoggedIn, $result)
  36. {
  37. $this->httpContext->expects($this->once())->method('getValue')
  38. ->with(\Magento\Customer\Model\Context::CONTEXT_AUTH)
  39. ->willReturn($isLoggedIn);
  40. $this->assertSame($result, $this->block->customerLoggedIn($isLoggedIn));
  41. }
  42. }