Explorar el Código

Acceptance tests refactoring (#1)

Maxim Shcherbakov hace 9 años
padre
commit
aaee0841e1

+ 26 - 0
tests/codeception/_support/AcceptanceTester.php

@@ -0,0 +1,26 @@
+<?php
+
+
+/**
+ * Inherited Methods
+ * @method void wantToTest($text)
+ * @method void wantTo($text)
+ * @method void execute($callable)
+ * @method void expectTo($prediction)
+ * @method void expect($prediction)
+ * @method void amGoingTo($argumentation)
+ * @method void am($role)
+ * @method void lookForwardTo($achieveValue)
+ * @method void comment($description)
+ * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
+ *
+ * @SuppressWarnings(PHPMD)
+*/
+class AcceptanceTester extends \Codeception\Actor
+{
+    use _generated\AcceptanceTesterActions;
+
+   /**
+    * Define custom actions here
+    */
+}

+ 26 - 0
tests/codeception/_support/FunctionalTester.php

@@ -0,0 +1,26 @@
+<?php
+
+
+/**
+ * Inherited Methods
+ * @method void wantToTest($text)
+ * @method void wantTo($text)
+ * @method void execute($callable)
+ * @method void expectTo($prediction)
+ * @method void expect($prediction)
+ * @method void amGoingTo($argumentation)
+ * @method void am($role)
+ * @method void lookForwardTo($achieveValue)
+ * @method void comment($description)
+ * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
+ *
+ * @SuppressWarnings(PHPMD)
+*/
+class FunctionalTester extends \Codeception\Actor
+{
+    use _generated\FunctionalTesterActions;
+
+   /**
+    * Define custom actions here
+    */
+}

+ 26 - 0
tests/codeception/_support/UnitTester.php

@@ -0,0 +1,26 @@
+<?php
+
+
+/**
+ * Inherited Methods
+ * @method void wantToTest($text)
+ * @method void wantTo($text)
+ * @method void execute($callable)
+ * @method void expectTo($prediction)
+ * @method void expect($prediction)
+ * @method void amGoingTo($argumentation)
+ * @method void am($role)
+ * @method void lookForwardTo($achieveValue)
+ * @method void comment($description)
+ * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
+ *
+ * @SuppressWarnings(PHPMD)
+*/
+class UnitTester extends \Codeception\Actor
+{
+    use _generated\UnitTesterActions;
+
+   /**
+    * Define custom actions here
+    */
+}

+ 2 - 0
tests/codeception/_support/_generated/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 2 - 0
tests/codeception/acceptance.suite.yml

@@ -12,6 +12,8 @@ class_name: AcceptanceTester
 modules:
     enabled:
         - PhpBrowser
+#        - Yii2:
+#           configFile: '/codeception/config/acceptance.php'
 # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
 # This will require you to install selenium. See http://codeception.com/docs/03-AcceptanceTests#selenium-webdriver
 # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,

+ 0 - 10
tests/codeception/acceptance/AboutCept.php

@@ -1,10 +0,0 @@
-<?php
-
-use tests\codeception\_pages\AboutPage;
-
-/* @var $scenario Codeception\Scenario */
-
-$I = new AcceptanceTester($scenario);
-$I->wantTo('ensure that about works');
-AboutPage::openBy($I);
-$I->see('About', 'h1');

+ 11 - 0
tests/codeception/acceptance/AboutCest.php

@@ -0,0 +1,11 @@
+<?php
+
+class AboutCest
+{
+    public function ensureThatAboutWorks(AcceptanceTester $I)
+    {
+        //$I->amOnPage(['site/about']);
+        $I->amOnPage('index.php?r=site%2Fabout');
+        $I->see('About', 'h1');
+    }
+}

+ 0 - 11
tests/codeception/acceptance/HomeCept.php

@@ -1,11 +0,0 @@
-<?php
-
-/* @var $scenario Codeception\Scenario */
-
-$I = new AcceptanceTester($scenario);
-$I->wantTo('ensure that home page works');
-$I->amOnPage(Yii::$app->homeUrl);
-$I->see('My Company');
-$I->seeLink('About');
-$I->click('About');
-$I->see('This is the About page.');

+ 16 - 0
tests/codeception/acceptance/HomeCest.php

@@ -0,0 +1,16 @@
+<?php
+
+class HomeCest
+{
+    public function ensureThatHomePageWorks(AcceptanceTester $I)
+    {
+        //$I->amOnPage(Yii::$app->homeUrl);
+        $I->amOnPage('index.php?r=site%2Findex');        
+        $I->see('My Company');
+        
+        $I->seeLink('About');
+        $I->click('About');
+        
+        $I->see('This is the About page.');
+    }
+}

+ 0 - 37
tests/codeception/acceptance/LoginCept.php

@@ -1,37 +0,0 @@
-<?php
-
-use tests\codeception\_pages\LoginPage;
-
-/* @var $scenario Codeception\Scenario */
-
-$I = new AcceptanceTester($scenario);
-$I->wantTo('ensure that login works');
-
-$loginPage = LoginPage::openBy($I);
-
-$I->see('Login', 'h1');
-
-$I->amGoingTo('try to login with empty credentials');
-$loginPage->login('', '');
-if (method_exists($I, 'wait')) {
-    $I->wait(3); // only for selenium
-}
-$I->expectTo('see validations errors');
-$I->see('Username cannot be blank.');
-$I->see('Password cannot be blank.');
-
-$I->amGoingTo('try to login with wrong credentials');
-$loginPage->login('admin', 'wrong');
-if (method_exists($I, 'wait')) {
-    $I->wait(3); // only for selenium
-}
-$I->expectTo('see validations errors');
-$I->see('Incorrect username or password.');
-
-$I->amGoingTo('try to login with correct credentials');
-$loginPage->login('admin', 'admin');
-if (method_exists($I, 'wait')) {
-    $I->wait(3); // only for selenium
-}
-$I->expectTo('see user info');
-$I->see('Logout (admin)');

+ 19 - 0
tests/codeception/acceptance/LoginCest.php

@@ -0,0 +1,19 @@
+<?php
+
+class LoginCest
+{
+    public function ensureThatLoginWorks(AcceptanceTester $I)
+    {
+        //$I->amOnPage(['site/login']);
+        $I->amOnPage('index.php?r=site%2Flogin');
+        $I->see('Login', 'h1');
+
+        $I->amGoingTo('try to login with correct credentials');
+        $I->fillField('input[name="LoginForm[username]"]', 'admin');
+        $I->fillField('input[name="LoginForm[password]"]', 'admin');
+        $I->click('login-button');
+
+        $I->expectTo('see user info');
+        $I->see('Logout (admin)');
+    }
+}