1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2011 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Cms \Test \Unit \Block \Adminhtml \Block \Widget ;
9
9
10
10
use Magento \Backend \Block \Template \Context ;
11
+ use Magento \Backend \Helper \Data ;
11
12
use Magento \Cms \Block \Adminhtml \Block \Widget \Chooser ;
12
13
use Magento \Cms \Model \Block ;
13
14
use Magento \Cms \Model \BlockFactory ;
15
+ use Magento \Cms \Model \ResourceModel \Block \CollectionFactory ;
14
16
use Magento \Framework \Data \Form \Element \AbstractElement ;
15
17
use Magento \Framework \Escaper ;
16
18
use Magento \Framework \Math \Random ;
@@ -77,6 +79,16 @@ class ChooserTest extends TestCase
77
79
*/
78
80
protected $ chooserMock ;
79
81
82
+ /**
83
+ * @var Data|MockObject
84
+ */
85
+ protected $ backendHelperMock ;
86
+
87
+ /**
88
+ * @var CollectionFactory|MockObject
89
+ */
90
+ protected $ collectionFactoryMock ;
91
+
80
92
protected function setUp (): void
81
93
{
82
94
$ this ->layoutMock = $ this ->getMockBuilder (LayoutInterface::class)
@@ -93,6 +105,7 @@ protected function setUp(): void
93
105
->onlyMethods (
94
106
[
95
107
'escapeHtml ' ,
108
+ 'escapeJs '
96
109
]
97
110
)
98
111
->getMock ();
@@ -138,6 +151,13 @@ protected function setUp(): void
138
151
)
139
152
->onlyMethods (['toHtml ' ])
140
153
->getMockForAbstractClass ();
154
+ $ this ->backendHelperMock = $ this ->getMockBuilder (Data::class)
155
+ ->disableOriginalConstructor ()
156
+ ->getMock ();
157
+
158
+ $ this ->collectionFactoryMock = $ this ->getMockBuilder (CollectionFactory::class)
159
+ ->disableOriginalConstructor ()
160
+ ->getMock ();
141
161
142
162
$ objectManager = new ObjectManager ($ this );
143
163
$ objectManager ->prepareObjectManager ();
@@ -286,4 +306,33 @@ public function testGetGridUrl()
286
306
287
307
$ this ->assertEquals ($ url , $ this ->this ->getGridUrl ());
288
308
}
309
+
310
+ /**
311
+ * @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::testGetRowClickCallback
312
+ */
313
+ public function testGetRowClickCallback (): void
314
+ {
315
+ $ chooserBlock = new Chooser (
316
+ $ this ->context ,
317
+ $ this ->backendHelperMock ,
318
+ $ this ->blockFactoryMock ,
319
+ $ this ->collectionFactoryMock
320
+ );
321
+ $ this ->escaper ->expects ($ this ->once ())
322
+ ->method ('escapeJs ' )
323
+ ->willReturnCallback (function ($ input ) {
324
+ return $ input ;
325
+ });
326
+ $ jsCallback = $ chooserBlock ->getRowClickCallback ();
327
+
328
+ $ this ->assertStringContainsString (
329
+ 'blockId = trElement.down("td").innerHTML.replace(/^\s+|\s+$/g,"") ' ,
330
+ $ jsCallback ,
331
+ 'JavaScript callback should use first TD cell for block ID '
332
+ );
333
+
334
+ $ this ->assertStringContainsString ('setElementValue(blockId) ' , $ jsCallback );
335
+ $ this ->assertStringContainsString ('setElementLabel(blockTitle) ' , $ jsCallback );
336
+ $ this ->assertStringContainsString ('close() ' , $ jsCallback );
337
+ }
289
338
}
0 commit comments