ConfigTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Eav\Model\Entity\Attribute\Config
  8. */
  9. namespace Magento\Eav\Test\Unit\Model\Entity\Attribute;
  10. class ConfigTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Eav\Model\Entity\Attribute\Config
  14. */
  15. protected $_model;
  16. /**
  17. * @var \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $_readerMock;
  20. /**
  21. * @var \PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $_cacheMock;
  24. /**
  25. * @var \PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $_cacheId;
  28. /**
  29. * @var \Magento\Eav\Model\Entity\Attribute|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $_attribute;
  32. /**
  33. * @var \PHPUnit_Framework_MockObject_MockObject
  34. */
  35. protected $_entityType;
  36. protected function setUp()
  37. {
  38. $this->_attribute = $this->createMock(\Magento\Eav\Model\Entity\Attribute::class);
  39. $this->_entityType = $this->createMock(\Magento\Eav\Model\Entity\Type::class);
  40. $this->_readerMock = $this->createMock(\Magento\Eav\Model\Entity\Attribute\Config\Reader::class);
  41. $this->_cacheMock = $this->createMock(\Magento\Framework\App\Cache\Type\Config::class);
  42. $this->_cacheId = 'eav_attributes';
  43. $this->_cacheMock->expects($this->once())
  44. ->method('load')
  45. ->with($this->_cacheId)
  46. ->willReturn('');
  47. $serializerMock = $this->createMock(\Magento\Framework\Serialize\SerializerInterface::class);
  48. $serializerMock->method('unserialize')
  49. ->willReturn([]);
  50. $this->_model = new \Magento\Eav\Model\Entity\Attribute\Config(
  51. $this->_readerMock,
  52. $this->_cacheMock,
  53. $this->_cacheId,
  54. $serializerMock
  55. );
  56. }
  57. public function testGetLockedFieldsEmpty()
  58. {
  59. $this->_entityType->expects($this->once())->method('getEntityTypeCode')->will($this->returnValue('test_code'));
  60. $this->_attribute->expects(
  61. $this->once()
  62. )->method(
  63. 'getEntityType'
  64. )->will(
  65. $this->returnValue($this->_entityType)
  66. );
  67. $this->_attribute->expects(
  68. $this->once()
  69. )->method(
  70. 'getAttributeCode'
  71. )->will(
  72. $this->returnValue('attribute_code')
  73. );
  74. $result = $this->_model->getLockedFields($this->_attribute);
  75. $this->assertEquals([], $result);
  76. }
  77. public function testGetLockedFields()
  78. {
  79. $this->_entityType->expects(
  80. $this->once()
  81. )->method(
  82. 'getEntityTypeCode'
  83. )->will(
  84. $this->returnValue('test_code1/test_code2')
  85. );
  86. $this->_attribute->expects(
  87. $this->once()
  88. )->method(
  89. 'getEntityType'
  90. )->will(
  91. $this->returnValue($this->_entityType)
  92. );
  93. $this->_attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue('test_code'));
  94. $data = [
  95. 'test_code1' => [
  96. 'test_code2' => ['attributes' => ['test_code' => ['test_code1' => 'test_code1']]],
  97. ],
  98. ];
  99. $this->_model->merge($data);
  100. $result = $this->_model->getLockedFields($this->_attribute);
  101. $this->assertEquals(['test_code1' => 'test_code1'], $result);
  102. }
  103. public function testGetEntityAttributesLockedFields()
  104. {
  105. $data = [
  106. 'entity_code' => [
  107. 'attributes' => [
  108. 'attribute_code' => [
  109. 'attribute_data' => ['locked' => 'locked_field', 'code' => 'code_test'],
  110. ],
  111. ],
  112. ],
  113. ];
  114. $this->_model->merge($data);
  115. $result = $this->_model->getEntityAttributesLockedFields('entity_code');
  116. $this->assertEquals(['attribute_code' => ['code_test']], $result);
  117. }
  118. }