30 private $dataObjectProcessorMock;
35 private $methodsMapProcessorMock;
40 private $fieldNamerMock;
45 private $typeCasterMock;
55 private $authorizationMock;
62 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
64 $this->dataObjectProcessorMock = $this->getMockBuilder(\
Magento\Framework\Reflection\DataObjectProcessor::class)
65 ->disableOriginalConstructor()
67 $this->methodsMapProcessorMock = $this->getMockBuilder(\
Magento\Framework\Reflection\MethodsMap::class)
68 ->disableOriginalConstructor()
70 $this->typeCasterMock = $this->getMockBuilder(\
Magento\Framework\Reflection\TypeCaster::class)
71 ->disableOriginalConstructor()
73 $this->fieldNamerMock = $this->getMockBuilder(\
Magento\Framework\Reflection\FieldNamer::class)
74 ->disableOriginalConstructor()
76 $this->configMock = $this->getMockBuilder(\
Magento\Framework\Api\ExtensionAttribute\Config::class)
77 ->disableOriginalConstructor()
79 $this->authorizationMock = $this->getMockBuilder(\
Magento\Framework\AuthorizationInterface::class)
80 ->disableOriginalConstructor()
84 \
Magento\Framework\Reflection\ExtensionAttributesProcessor::class,
86 'dataObjectProcessor' => $this->dataObjectProcessorMock,
87 'methodsMapProcessor' => $this->methodsMapProcessorMock,
88 'typeCaster' => $this->typeCasterMock,
89 'fieldNamer' => $this->fieldNamerMock,
90 'authorization' => $this->authorizationMock,
91 'config' => $this->configMock,
92 'isPermissionChecked' =>
true,
104 $dataObject = new \Magento\Framework\Reflection\Test\Unit\ExtensionAttributesObject();
105 $dataObjectType = \Magento\Framework\Reflection\Test\Unit\ExtensionAttributesObject::class;
106 $methodName =
'getAttrName';
107 $attributeName =
'attr_name';
108 $attributeValue =
'attrName';
110 $this->methodsMapProcessorMock->expects($this->once())
111 ->method(
'getMethodsMap')
112 ->with($dataObjectType)
113 ->will($this->returnValue([$methodName => []]));
114 $this->methodsMapProcessorMock->expects($this->once())
115 ->method(
'isMethodValidForDataField')
116 ->with($dataObjectType, $methodName)
117 ->will($this->returnValue(
true));
118 $this->fieldNamerMock->expects($this->once())
119 ->method(
'getFieldNameForMethodName')
121 ->will($this->returnValue($attributeName));
122 $permissionName =
'Magento_Permission';
123 $this->configMock->expects($this->once())
125 ->will($this->returnValue([
130 $this->authorizationMock->expects($this->once())
131 ->method(
'isAllowed')
132 ->with($permissionName)
133 ->will($this->returnValue($isPermissionAllowed));
135 if ($isPermissionAllowed) {
136 $this->methodsMapProcessorMock->expects($this->once())
137 ->method(
'getMethodReturnType')
138 ->with($dataObjectType, $methodName)
139 ->will($this->returnValue(
'string'));
140 $this->typeCasterMock->expects($this->once())
141 ->method(
'castValueToType')
142 ->with($attributeValue,
'string')
143 ->will($this->returnValue($attributeValue));
146 $value = $this->model->buildOutputDataArray(
163 'permission allowed' => [
166 'attr_name' =>
'attrName',
169 'permission not allowed' => [
const RESOURCE_PERMISSIONS
testBuildOutputDataArrayWithPermission($isPermissionAllowed, $expectedValue)
buildOutputDataArrayWithPermissionProvider()