SectionPoolTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\CustomerData;
  7. use Magento\Customer\CustomerData\SectionPool;
  8. class SectionPoolTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \PHPUnit_Framework_MockObject_MockObject
  12. */
  13. protected $objectManagerMock;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $identifierMock;
  18. /**
  19. * @var array|null
  20. */
  21. protected $sectionSourceMap;
  22. /**
  23. * @var SectionPool
  24. */
  25. protected $model;
  26. protected function setUp()
  27. {
  28. $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  29. $this->identifierMock = $this->createMock(\Magento\Customer\CustomerData\Section\Identifier::class);
  30. $this->sectionSourceMap = ['section1' => 'b'];
  31. $this->model = new SectionPool(
  32. $this->objectManagerMock,
  33. $this->identifierMock,
  34. $this->sectionSourceMap
  35. );
  36. }
  37. public function testGetSectionsDataAllSections()
  38. {
  39. $sectionNames = ['section1'];
  40. $sectionsData = ['data1', 'data2'];
  41. $allSectionsData = [
  42. 'section1' => [
  43. 'data1',
  44. 'data2'
  45. ]
  46. ];
  47. $identifierResult = [1, 2, 3];
  48. $sectionSourceMock = $this->createMock(\Magento\Customer\CustomerData\SectionSourceInterface::class);
  49. $this->objectManagerMock->expects($this->once())
  50. ->method('get')
  51. ->with('b')
  52. ->willReturn($sectionSourceMock);
  53. $sectionSourceMock->expects($this->once())->method('getSectionData')->willReturn($sectionsData);
  54. $this->identifierMock->expects($this->once())
  55. ->method('markSections')
  56. //check also default value for $forceTimestamp = false
  57. ->with($allSectionsData, $sectionNames, false)
  58. ->willReturn($identifierResult);
  59. $modelResult = $this->model->getSectionsData($sectionNames);
  60. $this->assertEquals($identifierResult, $modelResult);
  61. }
  62. /**
  63. * @expectedException \Magento\Framework\Exception\LocalizedException
  64. * @expectedExceptionMessage b doesn't extend \Magento\Customer\CustomerData\SectionSourceInterface
  65. */
  66. public function testGetSectionsDataAllSectionsException()
  67. {
  68. $sectionNames = [];
  69. $identifierResult = [1, 2, 3];
  70. $this->objectManagerMock->expects($this->once())
  71. ->method('get')
  72. ->with('b')
  73. ->willReturn($this->model);
  74. $modelResult = $this->model->getSectionsData($sectionNames);
  75. $this->assertEquals($identifierResult, $modelResult);
  76. }
  77. }