D
D
Dmitry Dobryshin2020-09-21 16:19:47
Yii
Dmitry Dobryshin, 2020-09-21 16:19:47

How, when testing codeception, to check the creation of a pdf file?

I am writing a website in Yii2. One of the actions is the formation of a .pdf file that opens in the browser for viewing. Everything opens in the browser, but for automatic testing, you need to make sure that it was created.

Code generating pdf:
public function actionPrint()
    {
        // Список предметов/оборудования, если есть
        $id = Yii::$app->request->get('id');

        $models = Items::find();
        if (isset($id))
            if (is_array($id))
            {
                $models = $models->where([ 'in', 'id', $id ]); // Несколько предметов/оборудования
            } else
            {
                $models = $models->where([ 'id' => $id ]); // Один предмет/оборудование
            }
        $models = $models->all(); // Формирование списка

        $pdf = Yii::$app->pdf; // Pабота с PDF

        $pdf->methods[ 'SetHeader' ] = ''; // Yii::t('items', 'Items');
        $pdf->methods[ 'SetFooter' ] = ''; // ['{PAGENO}'];
        // Границы листа
        $pdf->marginLeft   = 5;
        $pdf->marginRight  = 5;
        $pdf->marginTop    = 9;
        $pdf->marginBottom = 15;
        $pdf->filename     = Yii::t('app', Yii::$app->name) . ' (' . Yii::t('items', 'Items') . ').pdf';

        $pdf->content = $this->renderPartial('print', [ 'models' => $models ]);

        // Выгрузка PDF
        return $pdf->render();
    }

Code I'm checking:
public function MoveToPrintItemsCheck(\FunctionalTester $I)
    {
        $I->click(Locator::contains('div a', Yii::t('items', 'Print Items')));
        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
    }

But when executing it, an error appears:
Test  tests/functional/ItemsCest.php:MoveToPrintItemsCheck
  [yii\base\UnknownPropertyException] Getting unknown property: yii\web\Application::pdf

How can I check that the file was successfully generated?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question