Search code examples
codeception

Codeception Content-disposition assert file


I want to assert a xls file. I get this back:

"attachment; filename="testify.xlsx""

How can I do assertions on the file?

I have the tmp Path from the $_SERVER['TMPDIR'] and a clean filename, but there is no file in directory.


Solution

  • There are no built-in methods for this purpose, you will have to write your own helper.

    If you are using PhpBrowser or one of framework modules, they have two useful hidden methods: _getResponseContent returns page(or file) content,
    _savePageSource saves it to file.

    So your helper method would look like this:

    function seeXlsFileIsValid()
    {
        $fileContent = $this->getModule('PhpBrowser)->_getResponseContent();
        $this->assertTrue(..., 'returned xls file is not valid');
    }
    

    If you want to assert response headers, copy seeHttpHeader method from REST module.