Answer the question
In order to leave comments, you need to log in
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.
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();
}
public function MoveToPrintItemsCheck(\FunctionalTester $I)
{
$I->click(Locator::contains('div a', Yii::t('items', 'Print Items')));
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
}
Test tests/functional/ItemsCest.php:MoveToPrintItemsCheck
[yii\base\UnknownPropertyException] Getting unknown property: yii\web\Application::pdf
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question