Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PagingTest.php
Go to the documentation of this file.
1 <?php
7 
12 
16 class PagingTest extends \PHPUnit\Framework\TestCase
17 {
21  protected $contextMock;
22 
26  protected $objectManager;
27 
31  protected function setUp()
32  {
33  $this->objectManager = new ObjectManager($this);
34 
35  $this->contextMock = $this->getMockForAbstractClass(
36  \Magento\Framework\View\Element\UiComponent\ContextInterface::class,
37  [],
38  '',
39  false,
40  true,
41  true,
42  []
43  );
44  }
45 
51  public function testGetComponentName()
52  {
53  $this->contextMock->expects($this->never())->method('getProcessor');
55  $paging = $this->objectManager->getObject(
56  \Magento\Ui\Component\Paging::class,
57  [
58  'context' => $this->contextMock,
59  'data' => []
60  ]
61  );
62 
63  $this->assertTrue($paging->getComponentName() === Paging::NAME);
64  }
65 
71  public function testPrepare()
72  {
73  $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
74  ->disableOriginalConstructor()
75  ->getMock();
76  $this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($processor);
77  $resultData = [
78  'js_config' => [
79  'extends' => 'test_config_extends',
80  'testData' => 'testValue'
81  ],
82  'config' => [
83  'options' => [
84  [
85  'value' => 20,
86  'label' => 20
87  ],
88  [
89  'value' => 30,
90  'label' => 30
91  ],
92  [
93  'value' => 50,
94  'label' => 50
95  ],
96  [
97  'value' => 100,
98  'label' => 100
99  ],
100  [
101  'value' => 200,
102  'label' => 200
103  ],
104  [
105  'value' => 20,
106  'label' => 'options1'
107  ],
108  [
109  'value' => 40,
110  'label' => 'options2'
111  ],
112  ],
113  'pageSize' => 20,
114  'current' => 2
115  ]
116  ];
117 
119  $paging = $this->objectManager->getObject(
120  \Magento\Ui\Component\Paging::class,
121  [
122  'context' => $this->contextMock,
123  'data' => [
124  'js_config' => [
125  'extends' => 'test_config_extends',
126  'testData' => 'testValue',
127  ],
128  'config' => [
129  'options' => [
130  'options1' => [
131  'label' => 'options1',
132  'value' => '20'
133  ],
134  'options2' => [
135  'label' => 'options2',
136  'value' => '40'
137  ]
138  ],
139  'current' => 2,
140  'pageSize' => 20
141  ]
142  ]
143  ]
144  );
146  $dataProviderMock = $this->getMockBuilder(DataProviderInterface::class)->getMockForAbstractClass();
147 
148  $this->contextMock->expects($this->once())
149  ->method('getRequestParam')
150  ->with('paging')
151  ->willReturn(['pageSize' => 5, 'current' => 3]);
152  $this->contextMock->expects($this->once())
153  ->method('getDataProvider')
154  ->willReturn($dataProviderMock);
155 
156  $dataProviderMock->expects($this->once())
157  ->method('setLimit')
158  ->with(3, 5);
159 
160  $this->contextMock->expects($this->once())
161  ->method('addComponentDefinition')
162  ->with($paging->getComponentName(), ['extends' => 'test_config_extends', 'testData' => 'testValue']);
163 
164  $paging->prepare();
165 
166  $this->assertEquals($paging->getData(), $resultData);
167  }
168 }
$processor
Definition: 404.php:10