5
5
*/
6
6
namespace Magento \Framework \View \Test \Unit \Asset \MergeStrategy ;
7
7
8
- use Magento \Framework \Filesystem \Directory \WriteInterface ;
9
- use \Magento \Framework \View \Asset \MergeStrategy \Direct ;
10
-
11
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
10
+ use Magento \Framework \View \Asset \MergeStrategy \Direct ;
12
11
12
+ /**
13
+ * Test for Magento\Framework\View\Asset\MergeStrategy\Direct.
14
+ */
13
15
class DirectTest extends \PHPUnit \Framework \TestCase
14
16
{
17
+ /**
18
+ * @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject
19
+ */
20
+ protected $ mathRandomMock ;
15
21
/**
16
22
* @var \Magento\Framework\View\Asset\MergeStrategy\Direct
17
23
*/
@@ -50,33 +56,47 @@ protected function setUp()
50
56
[DirectoryList::TMP , \Magento \Framework \Filesystem \DriverPool::FILE , $ this ->tmpDir ],
51
57
]);
52
58
$ this ->resultAsset = $ this ->createMock (\Magento \Framework \View \Asset \File::class);
53
- $ this ->object = new Direct ($ filesystem , $ this ->cssUrlResolver );
59
+ $ this ->mathRandomMock = $ this ->getMockBuilder (\Magento \Framework \Math \Random::class)
60
+ ->disableOriginalConstructor ()
61
+ ->getMock ();
62
+ $ this ->object = new Direct ($ filesystem , $ this ->cssUrlResolver , $ this ->mathRandomMock );
54
63
}
55
64
56
65
public function testMergeNoAssets ()
57
66
{
67
+ $ uniqId = '_b3bf82fa6e140594420fa90982a8e877 ' ;
58
68
$ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->will ($ this ->returnValue ('foo/result ' ));
59
69
$ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
60
- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , '' );
61
- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' , 'foo/result ' , $ this ->staticDir );
70
+ $ this ->mathRandomMock ->expects ($ this ->once ())
71
+ ->method ('getUniqueHash ' )
72
+ ->willReturn ($ uniqId );
73
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , '' );
74
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )
75
+ ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
62
76
$ this ->object ->merge ([], $ this ->resultAsset );
63
77
}
64
78
65
79
public function testMergeGeneric ()
66
80
{
81
+ $ uniqId = '_be50ccf992fd81818c1a2645d1a29e92 ' ;
67
82
$ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->will ($ this ->returnValue ('foo/result ' ));
68
83
$ assets = $ this ->prepareAssetsToMerge ([' one ' , 'two ' ]); // note leading space intentionally
69
84
$ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
70
- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , 'onetwo ' );
71
- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' , 'foo/result ' , $ this ->staticDir );
85
+ $ this ->mathRandomMock ->expects ($ this ->once ())
86
+ ->method ('getUniqueHash ' )
87
+ ->willReturn ($ uniqId );
88
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , 'onetwo ' );
89
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )
90
+ ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
72
91
$ this ->object ->merge ($ assets , $ this ->resultAsset );
73
92
}
74
93
75
94
public function testMergeCss ()
76
95
{
96
+ $ uniqId = '_f929c374767e00712449660ea673f2f5 ' ;
77
97
$ this ->resultAsset ->expects ($ this ->exactly (3 ))
78
98
->method ('getPath ' )
79
- ->will ( $ this -> returnValue ( 'foo/result ' ) );
99
+ ->willReturn ( 'foo/result ' );
80
100
$ this ->resultAsset ->expects ($ this ->any ())->method ('getContentType ' )->will ($ this ->returnValue ('css ' ));
81
101
$ assets = $ this ->prepareAssetsToMerge (['one ' , 'two ' ]);
82
102
$ this ->cssUrlResolver ->expects ($ this ->exactly (2 ))
@@ -85,10 +105,14 @@ public function testMergeCss()
85
105
$ this ->cssUrlResolver ->expects ($ this ->once ())
86
106
->method ('aggregateImportDirectives ' )
87
107
->with ('12 ' )
88
- ->will ($ this ->returnValue ('1020 ' ));
108
+ ->willReturn ('1020 ' );
109
+ $ this ->mathRandomMock ->expects ($ this ->once ())
110
+ ->method ('getUniqueHash ' )
111
+ ->willReturn ($ uniqId );
89
112
$ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
90
- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , '1020 ' );
91
- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' , 'foo/result ' , $ this ->staticDir );
113
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , '1020 ' );
114
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )
115
+ ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
92
116
$ this ->object ->merge ($ assets , $ this ->resultAsset );
93
117
}
94
118
0 commit comments