Issue With Functional Testing Of A Restricted Area

Hi Guys,

I’m adapting to TDD and therefor I’m new to the concept. So I have been reading/ the testing section mentioned in the Yii documentation.

At the moment I want to do a functional test for a module called ‘geo’ which handles Countries, states/ provinces, and cities.

To begin my functional testing, I have thought to test Country section first. For this I have created CountryTest.php file in protected/tests/functiona/geo/ path. Now from the browser the countries can be listed by visiting "http://localhost/somesite/index-test.php/locations/country"

In this page, there is a link to create a country. If the user is logged in and has access to create a country, the create page will be displayed. So I’ve added the following test to CountryTest.php.

public function testCreateCountry() {






However since I’m doing functional testing with Selenium, once the $this->clickAndWait(‘link=Create’); statement is executed, the browser is redirected to site/login page. Therefore my last assert statement in the test fails.

So my question is, how to login an user (e.g. admin) so that I can pass this test?

Also if you think I’m doing something in the wrong way, please guide me. Thanks a lot.


Hi guys,

I have managed to find a solution. The solution was posted by someone in the functional testing page. I should have read the comments.

Anyway the approach is to log in the user and then open the page. A new function can be implemented in WebTestCase class to perform this.