assetRepoMock = $this->getMockBuilder(Repository::class) ->disableOriginalConstructor() ->getMock(); $this->urlMock = $this->getMockBuilder(UrlInterface::class) ->disableOriginalConstructor() ->getMock(); $this->assetRepoMock->expects($this->any()) ->method('getUrl') ->willReturn($this->jsPluginSourceUrl); $this->urlMock->expects($this->any()) ->method('getUrl') ->willReturn($this->actionUrl); $this->storeVariablesMock = $this->getMockBuilder(Variables::class) ->disableOriginalConstructor() ->setMethods(['getData']) ->getMock(); $this->customVarsCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $this->customVarsCollectionMock = $this->getMockBuilder(Collection::class) ->disableOriginalConstructor() ->setMethods(['getData']) ->getMock(); $this->customVarsCollectionFactoryMock->expects($this->any()) ->method('create') ->willReturn($this->customVarsCollectionMock); // Set up SUT $args = [ 'assetRepo' => $this->assetRepoMock, 'url' => $this->urlMock, 'collectionFactory' => $this->customVarsCollectionFactoryMock, 'storesVariables' => $this->storeVariablesMock, ]; $this->model = (new ObjectManager($this))->getObject(Config::class, $args); } /** * Test method getWysiwygPluginSettings */ public function testGetWysiwygPluginSettings() { $this->storeVariablesMock->expects($this->any()) ->method('getData') ->willReturn([]); $this->customVarsCollectionMock->expects($this->any()) ->method('getData') ->willReturn([]); $customKey = 'key'; $customVal = 'val'; $configObject = new \Magento\Framework\DataObject(); $configObject->setPlugins([[$customKey => $customVal]]); $variablePluginConfig = $this->model->getWysiwygPluginSettings($configObject)['plugins']; $customPluginConfig = $variablePluginConfig[0]; $addedPluginConfig = $variablePluginConfig[1]; // Verify custom plugin config is present $this->assertSame($customVal, $customPluginConfig[$customKey]); // Verify added plugin config is present $this->assertContains($this->actionUrl, $addedPluginConfig['options']['onclick']['subject']); $this->assertContains($this->actionUrl, $addedPluginConfig['options']['url']); $this->assertContains($this->jsPluginSourceUrl, $addedPluginConfig['src']); } }