[SOLVED] Codeception test fail for LoginCest


(Sasha Tesh) #1

I would like to use different model for LoginCest from frontend/tests/.

I have the following test within LoginCest:

[spoiler]




<?php


namespace frontend\tests\functional;


use frontend\tests\FunctionalTester;

use common\fixtures\Clients as ClientFixture;


class LoginCest

{

    function _before(FunctionalTester $I)

    {

        $I->haveFixtures([

            'clients' => [

                'class' => ClientFixture::className(),

                'dataFile' => codecept_data_dir() . 'login_data.php'

            ]

        ]);

        $I->amOnRoute('site/login');

    }


    protected function formParams($email, $password)

    {

        return [

            'ClientLoginForm[email]' => $email,

            'ClientLoginForm[password]' => $password,

        ];

    }


    public function checkEmpty(FunctionalTester $I)

    {

        $I->submitForm('#login-form', $this->formParams('', ''));

        $I->seeValidationError('Email cannot be blank.');

        $I->seeValidationError('Password cannot be blank.');

    }


    public function checkWrongPassword(FunctionalTester $I)

    {

        $I->submitForm('#login-form', $this->formParams('admin@admin.com', 'wrong'));

        $I->seeValidationError('Incorrect email or password.');

    }


    public function checkValidLogin(FunctionalTester $I)

    {

        $I->submitForm('#login-form', $this->formParams('test@test.com', '123456'));

        $I->see('Logout (test@test.com)', 'form button[type=submit]');

        $I->dontSeeValidationError('Incorrect email or password.');

        $I->dontSeeLink('Login');

        $I->dontSeeLink('Signup');

    }

}



[/spoiler]

However, when I run the test, I keep on seeing the following:




<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> LoginCest: Check valid login

 Test  tests/functional/LoginCest.php:checkValidLogin

 Step  Have fixtures {"user":{"class":"common\\fixtures\\User","dataFile":"\/var\/www\/test\/frontend\/tests\/_data\/user.php"}}

 Fail  Failed asserting that any element by 'form button[type=submit]' on page /enter/login 

+ <button class="btn btn-primary" name="login-button" type="submit">Login</button>

contains text 'Logout (test@test.com)'


Scenario Steps:


 4. $I->see("Logout (test@test.com)","form button[type=submit]") at tests/functional/LoginCest.php:46

 3. $I->submitForm("#login-form",{"ClientLoginForm[email]":"test@test.com","ClientLoginForm[password]":"123456"}) at tests/functional/LoginCest.php:45

 2. $I->amOnRoute("site/login") at tests/functional/LoginCest.php:18

 1. $I->haveFixtures({"clients":{"class":"common\\fixtures\\Clients","dataFile":"\/var\/www\/test\/frontend\/tests\/_data\/login_data.php"}}) at tests/functional/LoginCest.php:17



Which says that I using different fixture, which is why the last test is failing with correct login details, because it must look in the clients table, but instead it is looking in users.


{"class":"common\\fixtures\\User","dataFile":"\/var\/www\/test\/frontend\/tests\/_data\/user.php"}}

Any suggestions?


(Sasha Tesh) #2

Why is it using common\\fixtures\\User when I changed it do Clients? And how to change it to a different user class? Let’s say Clients or so.

What am I doing wrong in LoginCest model?

I use two different classes for frontend and backend and don’t know how to fix problem about frontend, it is just forcing to use User class.


(Sasha Tesh) #3

Alright, problem is fixed, it was regiarding the configuration of user login (username and password were incorrect).