Nov 3, 2017
0
Level 1
BrowserKitTesting test if file was downloaded after form submit
I have a simple form in laravel to convert excel to csv. After i submit my button, a function called convertToCsv will be executed with the given requests. Finally the file will be downloaded and deleted after sending:
return response()
->download($destinationFilePath)
->deleteFileAfterSend(true);
This works good.
Now i want to test my form if the file was downloaded and is equal to a test csv file.
For this i wrote a PHPUnit test with BrowserKitTesting:
/**
* @param $init
* @param $expected
* @dataProvider convert_to_csv
*/
public function testconvert($init, $expected)
{
$inputFile = $init['inputFile'];
if($init['inputFile']) {
$inputFile = base_path($inputFile);
}
$user = $this->auth();
$this->actingAs($user)
->visit($init['url'])
->select($init['inputDelimiter'], 'inputDelimiter')
->select($init['outputDelimiter'], 'outputDelimiter')
->attach($inputFile, 'file');
$this->press($init['sendButton']);
}
public function convert_to_csv()
{
return [
'convert excel to csv' => [
'init' => [
'url' => '/converttocsv',
'inputDelimiter' => ';',
'outputDelimiter' => ';',
'headerAlternative' => false,
'inputFile' => 'path/to/input/file.xlsx',
'sendButton' => 'Convert'
],
'expected' => [
'expectedFile' => 'path/to/expected/file.csv'
]
]
];
}
I don't know how i continue after the press function to test with the downloaded file. I get this Error: Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "boolean".
Please or to participate in this conversation.