1 | <?php |
||
27 | class CKEditorScriptHandlerTest extends AbstractTestCase |
||
28 | { |
||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $path; |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | protected function setUp() |
||
38 | { |
||
39 | $this->path = __DIR__.'/../../src/Resources/public'; |
||
40 | |||
41 | $this->tearDown(); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | protected function tearDown() |
||
48 | { |
||
49 | if (file_exists($this->path)) { |
||
50 | exec('rm -rf '.$this->path); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | public function testInstall() |
||
55 | { |
||
56 | CKEditorScriptHandler::install($this->createEventMock()); |
||
57 | $this->assertInstall(); |
||
58 | } |
||
59 | |||
60 | public function testReinstall() |
||
61 | { |
||
62 | CKEditorScriptHandler::install($this->createEventMock()); |
||
63 | $this->assertInstall(); |
||
64 | |||
65 | CKEditorScriptHandler::install($this->createEventMock()); |
||
66 | $this->assertInstall(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return \PHPUnit_Framework_MockObject_MockObject|Event |
||
71 | */ |
||
72 | private function createEventMock() |
||
73 | { |
||
74 | $config = $this->createMock(Config::class); |
||
75 | $config |
||
76 | ->expects($this->any()) |
||
77 | ->method('get') |
||
78 | ->will($this->returnValueMap([ |
||
79 | ['process-timeout', 300], |
||
80 | ['vendor-dir', __DIR__.'/../../vendor'], |
||
81 | ])); |
||
82 | |||
83 | $package = $this->getMockBuilder(Package::class) |
||
84 | ->disableOriginalConstructor() |
||
85 | ->getMock(); |
||
86 | |||
87 | $package |
||
88 | ->expects($this->any()) |
||
89 | ->method('getExtra') |
||
90 | ->will($this->returnValue([ |
||
91 | 'ckeditor-clear' => CKEditorInstaller::CLEAR_DROP, |
||
92 | 'symfony-bin-dir' => __DIR__.'/../Fixtures', |
||
93 | 'symfony-var-dir' => __DIR__.'/../Fixtures', |
||
94 | ])); |
||
95 | |||
96 | $composer = $this->createMock(Composer::class); |
||
97 | $composer |
||
98 | ->expects($this->any()) |
||
99 | ->method('getConfig') |
||
100 | ->will($this->returnValue($config)); |
||
101 | |||
102 | $composer |
||
103 | ->expects($this->any()) |
||
104 | ->method('getPackage') |
||
105 | ->will($this->returnValue($package)); |
||
106 | |||
107 | $io = $this->createMock(IOInterface::class); |
||
108 | |||
109 | $event = $this->getMockBuilder(class_exists(CommandEvent::class) ? CommandEvent::class : Event::class) |
||
110 | ->disableOriginalConstructor() |
||
111 | ->getMock(); |
||
112 | |||
113 | $event |
||
114 | ->expects($this->any()) |
||
115 | ->method('getComposer') |
||
116 | ->will($this->returnValue($composer)); |
||
117 | |||
118 | $event |
||
119 | ->expects($this->any()) |
||
120 | ->method('getIO') |
||
121 | ->will($this->returnValue($io)); |
||
122 | |||
123 | return $event; |
||
124 | } |
||
125 | |||
126 | private function assertInstall() |
||
127 | { |
||
128 | $this->assertFileExists($this->path.'/ckeditor.js'); |
||
129 | } |
||
130 | } |
||
131 |