Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EditActionTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class EditActionTest extends \PHPUnit\Framework\TestCase
13 {
15  protected $component;
16 
18  protected $context;
19 
22 
24  protected $urlBuilder;
25 
26  public function setup()
27  {
28  $this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
29  ->getMockForAbstractClass();
30  $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
31  ->disableOriginalConstructor()
32  ->getMock();
33  $this->context->expects($this->never())->method('getProcessor')->willReturn($processor);
34  $this->uiComponentFactory = $this->createMock(\Magento\Framework\View\Element\UiComponentFactory::class);
35  $this->urlBuilder = $this->getMockForAbstractClass(
36  \Magento\Framework\UrlInterface::class,
37  [],
38  '',
39  false
40  );
41  $this->component = new EditAction(
42  $this->context,
43  $this->uiComponentFactory,
44  $this->urlBuilder,
45  [],
46  [
47  'name' => 'name',
48  'config' => ['editUrlPath' => 'theme/design_config/edit']
49  ]
50  );
51  }
52 
60  public function testPrepareDataSource($dataSourceItem, $scope, $scopeId)
61  {
62  $expectedDataSourceItem = [
63  'name' => [
64  'edit' => [
65  'href' => 'http://magento.com/theme/design_config/edit',
66  'label' => new \Magento\Framework\Phrase('Edit'),
67  ]
68  ],
69  ];
70 
71  $expectedDataSource = ['data' => ['items' => [array_merge($expectedDataSourceItem, $dataSourceItem)]]];
72  $this->urlBuilder->expects($this->any())
73  ->method('getUrl')
74  ->with(
75  'theme/design_config/edit',
76  ['scope' => $scope, 'scope_id' => $scopeId]
77  )
78  ->willReturn('http://magento.com/theme/design_config/edit');
79  $dataSource = ['data' => ['items' => [$dataSourceItem]]];
80  $dataSource = $this->component->prepareDataSource($dataSource);
81 
82  $this->assertEquals($expectedDataSource, $dataSource);
83  }
84 
89  {
90  return [
91  [['entity_id' => 1], ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
92  [['entity_id' => 1, 'store_id' => 2, 'store_website_id' => 1], ScopeInterface::SCOPE_STORES, 2],
93  [['entity_id' => 1, 'store_website_id' => 1], ScopeInterface::SCOPE_WEBSITES, 1],
94  ];
95  }
96 }
$processor
Definition: 404.php:10