1+ <?php
2+
3+ class ExportCommandTest extends TestCase
4+ {
5+ public function testCreatesExcelFile ()
6+ {
7+ $ this ->createTempFiles ([
8+ 'en ' => ['user ' => "<?php \n return['address' => 'Address', 'contact' => ['cellphone' => 'Mobile']]; " ],
9+ 'es ' => ['user ' => "<?php \n return['address' => 'Dirección', 'contact' => ['cellphone' => 'Movil']]; " ],
10+ ]);
11+
12+ $ this ->artisan ('langman:export ' );
13+
14+ $ exportedFilePath = $ this ->app ['config ' ]['langman.exports_path ' ] . '/ ' . date ('Y_m_d_His ' ) . '_langman.xlsx ' ;
15+
16+ $ excelRows = $ this ->getExcelFileContents ($ exportedFilePath );
17+
18+ $ headerRow = $ excelRows [1 ];
19+ $ contentRows = [$ excelRows [2 ], $ excelRows [3 ]];
20+
21+ $ this ->assertFileExists ($ exportedFilePath );
22+ $ this ->assertHeaderRow ($ headerRow );
23+ $ this ->assertContentRows ($ contentRows );
24+ }
25+
26+ /**
27+ * @param $exportedFilePath
28+ * @return array
29+ */
30+ protected function getExcelFileContents ($ exportedFilePath )
31+ {
32+ $ excelObj = \PHPExcel_IOFactory::load ($ exportedFilePath );
33+ $ rows = $ excelObj ->getActiveSheet ()->toArray ('' , true , true , true );
34+
35+ return $ rows ;
36+ }
37+
38+ /**
39+ * @param $headerRow
40+ */
41+ protected function assertHeaderRow ($ headerRow )
42+ {
43+ $ this ->assertEquals ($ headerRow ['A ' ], 'Language File ' );
44+ $ this ->assertEquals ($ headerRow ['B ' ], 'Key ' );
45+ $ this ->assertEquals ($ headerRow ['C ' ], 'en ' );
46+ $ this ->assertEquals ($ headerRow ['D ' ], 'es ' );
47+ }
48+
49+ /**
50+ * @param $row1
51+ * @param $row2
52+ */
53+ protected function assertContentRows ($ contentRows )
54+ {
55+ $ row1 = $ contentRows [0 ];
56+ $ this ->assertEquals ($ row1 ['A ' ], 'user ' );
57+ $ this ->assertEquals ($ row1 ['B ' ], 'address ' );
58+ $ this ->assertEquals ($ row1 ['C ' ], 'Address ' );
59+ $ this ->assertEquals ($ row1 ['D ' ], 'Dirección ' );
60+
61+ $ row2 = $ contentRows [1 ];
62+ $ this ->assertEquals ($ row2 ['A ' ], 'user ' );
63+ $ this ->assertEquals ($ row2 ['B ' ], 'contact.cellphone ' );
64+ $ this ->assertEquals ($ row2 ['C ' ], 'Mobile ' );
65+ $ this ->assertEquals ($ row2 ['D ' ], 'Movil ' );
66+ }
67+ }
0 commit comments