-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write initial tests for export command
- Loading branch information
1 parent
7442266
commit aaa40d8
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
class ExportCommandTest extends TestCase | ||
{ | ||
public function testCreatesExcelFile() | ||
{ | ||
$this->createTempFiles([ | ||
'en' => ['user' => "<?php\n return['address' => 'Address', 'contact' => ['cellphone' => 'Mobile']];"], | ||
'es' => ['user' => "<?php\n return['address' => 'Dirección', 'contact' => ['cellphone' => 'Movil']];"], | ||
]); | ||
|
||
$this->artisan('langman:export'); | ||
|
||
$exportedFilePath = $this->app['config']['langman.exports_path'] . '/' . date('Y_m_d_His') . '_langman.xlsx'; | ||
|
||
$excelRows = $this->getExcelFileContents($exportedFilePath); | ||
|
||
$headerRow = $excelRows[1]; | ||
$contentRows = [$excelRows[2], $excelRows[3]]; | ||
|
||
$this->assertFileExists($exportedFilePath); | ||
$this->assertHeaderRow($headerRow); | ||
$this->assertContentRows($contentRows); | ||
} | ||
|
||
/** | ||
* @param $exportedFilePath | ||
* @return array | ||
*/ | ||
protected function getExcelFileContents($exportedFilePath) | ||
{ | ||
$excelObj = \PHPExcel_IOFactory::load($exportedFilePath); | ||
$rows = $excelObj->getActiveSheet()->toArray('', true, true, true); | ||
|
||
return $rows; | ||
} | ||
|
||
/** | ||
* @param $headerRow | ||
*/ | ||
protected function assertHeaderRow($headerRow) | ||
{ | ||
$this->assertEquals($headerRow['A'], 'Language File'); | ||
$this->assertEquals($headerRow['B'], 'Key'); | ||
$this->assertEquals($headerRow['C'], 'en'); | ||
$this->assertEquals($headerRow['D'], 'es'); | ||
} | ||
|
||
/** | ||
* @param $row1 | ||
* @param $row2 | ||
*/ | ||
protected function assertContentRows($contentRows) | ||
{ | ||
$row1 = $contentRows[0]; | ||
$this->assertEquals($row1['A'], 'user'); | ||
$this->assertEquals($row1['B'], 'address'); | ||
$this->assertEquals($row1['C'], 'Address'); | ||
$this->assertEquals($row1['D'], 'Dirección'); | ||
|
||
$row2 = $contentRows[1]; | ||
$this->assertEquals($row2['A'], 'user'); | ||
$this->assertEquals($row2['B'], 'contact.cellphone'); | ||
$this->assertEquals($row2['C'], 'Mobile'); | ||
$this->assertEquals($row2['D'], 'Movil'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters