OSDN Git Service

Добавлены тесты функционала на страницы site/index, site/contact, site/login, site...
authorDmitry Dobryshin <dimkainc@mail.ru>
Tue, 22 Sep 2020 12:13:30 +0000 (15:13 +0300)
committerDmitry Dobryshin <dimkainc@mail.ru>
Tue, 22 Sep 2020 12:13:30 +0000 (15:13 +0300)
ned

tests/functional/ItemsCreateCest.php [new file with mode: 0644]
tests/functional/ItemsIndexCest.php [new file with mode: 0644]
tests/functional/ItemsUpdateCest.php [new file with mode: 0644]

diff --git a/tests/functional/ItemsCreateCest.php b/tests/functional/ItemsCreateCest.php
new file mode 100644 (file)
index 0000000..42d9ab0
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+use Codeception\Util\Locator;
+
+class ItemsCreateCest
+{
+    public function _before(\FunctionalTester $I)
+    {
+        $I->amOnRoute('items/create');
+    }
+
+    // tests
+    // Открыта страница добавления
+    public function openCreatePage(\FunctionalTester $I)
+    {
+        $I->amOnPage([ 'items/create' ]);
+        $I->see(Yii::t('items', 'Create Items'), 'h1');
+    }
+
+    // Заполнение формы
+    public function enterData(\FunctionalTester $I)
+    {
+        $I->submitForm('#ItemForm', [
+            'Items[type_id]'      => '1',
+            'Items[name]'         => 'TEST-WS-0001',
+            'Items[model]'        => 'Тестовый компьютер',
+            'Items[os]'           => 'Тестовая ОС',
+            'Items[mac]'          => '00:00-MAC-:00:00',
+            'Items[serial]'       => '*TEST SERIAL NUMBER*',
+            'Items[product]'      => 'TEST PRODUCT',
+            'Items[modelnumber]'  => 'TEST MODEL NUMBER',
+            'Items[invent]'       => '*TEST INVENTORY NUMBER*',
+            'Items[comment]'      => 'Тестирование. Это тестовая запись.',
+            'Moving[date]'        => '01.01.2020',
+            'Moving[state_id]'    => '1',
+            'Moving[location_id]' => '1',
+        ]);
+        $I->see(Yii::t('items', 'Items'), 'h1');
+        $I->dontSee(Yii::t('items', 'Create Items'), 'h1');
+        $I->haveInDatabase('items', ['name' => 'TEST-WS-0001', 'model' => 'Тестовый компьютер', 'serial' => '*TEST SERIAL NUMBER*', 'invent' => '*TEST INVENTORY NUMBER*']);
+    }
+    
+    // Нажатие на кнопку "Типы"
+    public function pushTypes(\FunctionalTester $I)
+    {
+        $I->click(Locator::contains('div a', Yii::t('types', 'Types')));
+        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
+        $I->see(Yii::t('types', 'Types'), 'h1');
+    }
+
+    // Нажатие на кнопку "Места размещения"
+    public function pushLocations(\FunctionalTester $I)
+    {
+        $I->click(Locator::contains('div a', Yii::t('locations', 'Locations')));
+        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
+        $I->see(Yii::t('locations', 'Locations'), 'h1');
+    }
+
+}
diff --git a/tests/functional/ItemsIndexCest.php b/tests/functional/ItemsIndexCest.php
new file mode 100644 (file)
index 0000000..f08badc
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+
+use Codeception\Util\Locator;
+
+class ItemsIndexCest
+{
+    // Страница Items
+    public function _before(\FunctionalTester $I)
+    {
+        $I->amOnPage(['items/index']);
+    }
+
+    // Есть заголовок
+    public function openItemsPage(\FunctionalTester $I)
+    {
+        $I->see(Yii::t('items', 'Items'), 'h1');
+    }
+
+    // Переход к странице добавления
+    public function pushCreateItem(\FunctionalTester $I)
+    {
+        $I->click(Locator::contains('div a', Yii::t('items', 'Create Items')));
+        $I->see(Yii::t('items', 'Create Items'), 'h1');
+    }
+
+    // Переход к странице импорта
+    public function pushImportItems(\FunctionalTester $I)
+    {
+        $I->click(Locator::contains('div a', Yii::t('items', 'Import')));
+        $I->see(Yii::t('items', 'Import Items'), 'h1');
+    }
+
+    // Формирование печатной формы PDF
+    public function moveToPrintItemsCheck(\FunctionalTester $I)
+    {
+        $I->click(Locator::contains('div a', Yii::t('items', 'Print Items')));
+        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
+
+        // Этот участок кода пока не понятно как включить, но функционал обязательно добавлю.
+        // Точно .pdf
+        //$I->canSeeHttpHeader('Content-type', 'application/pdf');
+        //$I->canSeeHttpHeader('Content-disposition', 'attachment; filename="' . Yii::t('app', Yii::$app->name) . ' (' . Yii::t('items', 'Items') . ').pdf"');
+        $I->see('%PDF');
+
+        // Не пустой документ
+        //$I->canSeeHttpHeader('Content-length', '1024');
+        // или
+        //$actualLength= $I->grabHttpHeader('Content-length');
+        //$I->assertGreaterThan(1024, $actualLength);
+    }
+
+    // Начало инвентаризации
+    public function startInventoryCheck(\FunctionalTester $I)
+    {
+        $I->click(Locator::contains('div a', Yii::t('items', 'Start checking')));
+        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
+        $I->see('', 'tr.danger');
+    }
+
+    //* // Нажатие на кнопку "Удалить"
+    public function deleteItemCheck(\FunctionalTester $I)
+    {
+        $I->click(Locator::find('a', [ 'title' => Yii::t('yii', 'Delete') ]));
+        $I->seeResponseCodeIs(405);
+        //$I->see(Yii::t('yii', 'Are you sure you want to delete this item?'));
+    } // */
+
+    // Печать отдельной наклейки
+    public function printItemCheck(\FunctionalTester $I)
+    {
+        $I->click(Locator::find('a', [ 'title' => Yii::t('items', 'Print selected labels') ]));
+        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
+        $I->see('%PDF');
+    }
+
+    // переход к редактированию элемента
+    public function clickItemCheck(\FunctionalTester $I)
+    {
+        $I->click(Locator::contains('tr td a', ''));
+        $I->see(Yii::t('items', 'Update Items: {name}', [ 'name' => '', ]), 'h1');
+    }
+}
diff --git a/tests/functional/ItemsUpdateCest.php b/tests/functional/ItemsUpdateCest.php
new file mode 100644 (file)
index 0000000..cd5bc84
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+use Codeception\Util\Locator;
+
+class ItemsUpdateCest
+{
+    public function _before(\FunctionalTester $I)
+    {
+        $I->amOnRoute('items/Update');
+    }
+
+    // tests
+    // Открыта страница добавления
+    public function openCreatePage(\FunctionalTester $I)
+    {
+        $I->amOnRoute('items/update', [ 'id' => '1' ]);
+        $I->see(Yii::t('items', 'Update Items: {name}', ['name' => '',]), 'h1');
+    }
+
+    // Заполнение формы
+    public function enterData(\FunctionalTester $I)
+    {
+        $I->amOnRoute('items/update', ['id' => '1']);
+        $I->submitForm('#ItemForm', []);
+        $I->see(Yii::t('items', 'Items'), 'h1');
+        $I->dontSee(Yii::t('items', 'Update Items: {name}', ['name' => '',]), 'h1');
+    }
+    
+    // Нажатие на кнопку "Типы"
+    public function pushTypes(\FunctionalTester $I)
+    {
+        $I->amOnRoute('items/update', ['id' => '1']);
+        $I->click(Locator::contains('div a', Yii::t('types', 'Types')));
+        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
+        $I->see(Yii::t('types', 'Types'), 'h1');
+    }
+
+}