OSDN Git Service

Внесены исправления в тесты для корректной работы с контролем доступа по ролям
[invent/invent.git] / tests / functional / ItemsIndexCest.php
1 <?php
2
3 use Codeception\Util\Locator;
4
5 class ItemsIndexCest
6 {
7     // Страница Items
8     public function _before(\FunctionalTester $I)
9     {
10         $I->amLoggedInAs(\app\models\User::findByUsername('admin'));
11         $I->amOnPage(['items/index']);
12     }
13
14     // наполнение страницы
15     public function openItemsPage(\FunctionalTester $I)
16     {
17         $I->see(Yii::t('items', 'Items'), 'h1');
18         $I->see(Yii::t('items', 'Inventory number'), '#ItemsTable tr th a');
19         $I->see(Yii::t('items', 'Serial number'), '#ItemsTable tr th a');
20         $I->see(Yii::t('items', 'Model'), '#ItemsTable tr th a');
21         $I->see(Yii::t('regions', 'Region'), '#ItemsTable tr th a');
22         $I->see(Yii::t('status', 'Status'), '#ItemsTable tr th a');
23     }
24
25     // Переход к странице добавления
26     public function pushCreateItem(\FunctionalTester $I)
27     {
28         $I->click(Locator::contains('div a', Yii::t('items', 'Create Items')));
29         $I->see(Yii::t('items', 'Create Items'), 'h1');
30     }
31
32     // Переход к странице импорта
33     public function pushImportItems(\FunctionalTester $I)
34     {
35         $I->click(Locator::contains('div a', Yii::t('items', 'Import')));
36         $I->see(Yii::t('items', 'Import Items'), 'h1');
37     }
38
39     // Формирование печатной формы PDF
40     public function pushPrintItems(\FunctionalTester $I)
41     {
42         $I->click(Locator::contains('div a', Yii::t('items', 'Print Items')));
43         $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
44
45         // Этот участок кода пока не понятно как включить, но функционал обязательно добавлю.
46         // Точно .pdf
47         //$I->canSeeHttpHeader('Content-type', 'application/pdf');
48         //$I->canSeeHttpHeader('Content-disposition', 'attachment; filename="' . Yii::t('app', Yii::$app->name) . ' (' . Yii::t('items', 'Items') . ').pdf"');
49         $I->see('%PDF');
50
51         // Не пустой документ
52         //$I->canSeeHttpHeader('Content-length', '1024');
53         // или
54         //$actualLength= $I->grabHttpHeader('Content-length');
55         //$I->assertGreaterThan(1024, $actualLength);
56     }
57
58     // Начало инвентаризации
59     public function pushStartInventory(\FunctionalTester $I)
60     {
61         $I->click(Locator::contains('div a', Yii::t('items', 'Start checking')));
62         $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
63         $I->see('', 'tr.danger');
64     }
65
66     // Нажатие на кнопку "Удалить"
67     public function clickDeleteItem(\FunctionalTester $I)
68     {
69         $I->click(Locator::find('a', [ 'title' => Yii::t('yii', 'Delete') ]));
70         $I->seeResponseCodeIs(405);
71         //$I->see(Yii::t('yii', 'Are you sure you want to delete this item?'));
72     }
73
74     // Печать отдельной наклейки
75     public function clickPrintItem(\FunctionalTester $I)
76     {
77         $I->click(Locator::find('a', [ 'title' => Yii::t('items', 'Print selected labels') ]));
78         $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
79         $I->see('%PDF');
80     }
81
82     // переход к редактированию элемента
83     public function clickItem(\FunctionalTester $I)
84     {
85         $I->click(Locator::contains('tr td a', ''));
86         $I->see(Yii::t('items', 'Update Items: {name}', [ 'name' => '', ]), 'h1');
87     }
88 }