19 private $objectManagerHelper;
29 private $serializerMock;
34 private $useConfigSettings;
39 private $jsonValidatorMock;
43 $this->objectManagerHelper =
new ObjectManagerHelper($this);
44 $this->contextMock = $this->createMock(\
Magento\Framework\View\Element\UiComponent\ContextInterface::class);
45 $this->serializerMock = $this->createMock(Json::class);
46 $this->jsonValidatorMock = $this->getMockBuilder(\
Magento\Framework\Serialize\JsonValidator::class)
47 ->disableOriginalConstructor()
49 $this->useConfigSettings = $this->objectManagerHelper->getObject(
50 UseConfigSettings::class,
52 'context' => $this->contextMock,
53 'serializer' => $this->serializerMock,
54 'jsonValidator' => $this->jsonValidatorMock
61 $processorMock = $this->createMock(\
Magento\Framework\View\Element\UiComponent\Processor::class);
62 $processorMock->expects($this->atLeastOnce())->method(
'register');
63 $this->contextMock->expects($this->atLeastOnce())->method(
'getProcessor')->willReturn($processorMock);
64 $config = [
'valueFromConfig' => 123];
65 $this->useConfigSettings->setData(
'config',
$config);
66 $this->useConfigSettings->prepare();
67 $this->assertEquals(
$config, $this->useConfigSettings->getData(
'config'));
77 public function testPrepareSource(
78 array $expectedResult,
80 $serializedCalledNum = 0,
83 $processorMock = $this->createMock(\
Magento\Framework\View\Element\UiComponent\Processor::class);
84 $processorMock->expects($this->atLeastOnce())->method(
'register');
85 $this->contextMock->expects($this->atLeastOnce())->method(
'getProcessor')->willReturn($processorMock);
87 $source = $this->createMock(ValueSourceInterface::class);
90 ->with($expectedResult[
'keyInConfiguration'])
91 ->willReturn($sourceValue);
93 $this->serializerMock->expects($this->exactly($serializedCalledNum))
94 ->method(
'unserialize')
96 ->willReturn($expectedResult[
'valueFromConfig']);
98 $this->jsonValidatorMock->expects($this->exactly($isValidCalledNum))
102 $config = array_replace($expectedResult, [
'valueFromConfig' =>
$source]);
103 $this->useConfigSettings->setData(
'config',
$config);
104 $this->useConfigSettings->prepare();
106 $this->assertEquals($expectedResult, $this->useConfigSettings->getData(
'config'));
116 'expectedResult' => [
117 'valueFromConfig' => 2,
118 'keyInConfiguration' =>
'validKey' 123 'expectedResult' => [
124 'valueFromConfig' => [
'32000' => 3],
125 'keyInConfiguration' =>
'serializedKey',
126 'unserialized' => true
128 'sourceValue' =>
'{"32000":3}',
129 'serialziedCalledNum' => 1,
130 'isValidCalledNum' => 1