Yii Framework Forum: [Extension] wUnit - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Extension] wUnit Functional testing without Selenium Rate Topic: -----

#1 User is offline   Weavora Team 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 06-December 10

Posted 24 January 2012 - 09:19 AM

This is the topic for wUnit extension.

If you have questions or found a bug let me know.
0

#2 User is offline   Levka 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 31-January 12

Posted 31 January 2012 - 03:57 PM

Thank you for this extension!

I have made all under the instructions, but no result.
Output:

c:\...\tests>phpunit unit
PHPUnit 3.6.7 by Sebastian Bergmann.

Configuration read from C:\...\tests\phpunit.xml

..

Time: 3 seconds, Memory: 8.75Mb

OK (2 tests, 4 assertions)

c:\...\tests>phpunit functional

c:\...\tests>phpunit functional/AccessControllerTest.php

c:\...\tests>


Help please!
0

#3 User is offline   Levka 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 31-January 12

Posted 31 January 2012 - 04:09 PM

It occurs seems when request with a redirect.
0

#4 User is offline   Weavora Team 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 06-December 10

Posted 31 January 2012 - 04:24 PM

Could you show me your bootstrap.php for tests ? I guess you use Yii::createWebApplication() instead of WUnit::createWebApplication().

If you create application with Yii::createWebApplication() and try to call action with redirect you will get no output, because redirect() contains 'exit;', which terminate script execution at all, no matter test it or not. That's why we had to override some method with exit by WUnit::createWebApplication().
0

#5 User is offline   Levka 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 31-January 12

Posted 31 January 2012 - 04:45 PM

You're right. My mistake.

Nevertheless, requests are processed not as I expect.

For example logout:
public function testIndex()
{
        $client = static::createClient();

        $crawler = $client->request('GET', '/logout');

        $this->assertTrue($crawler->filter('html:contains("ERP-system")')->count() > 0);
}


Output:
AccessControllerTest::testIndex()
Failed asserting that false is true.


But login:
public function testIndex()
{
        $client = static::createClient();

        $crawler = $client->request('GET', '/login');

        $this->assertTrue($crawler->filter('html:contains("ERP-system")')->count() > 0);
}

All right.
0

#6 User is offline   Weavora Team 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 06-December 10

Posted 31 January 2012 - 04:49 PM

Hum... What about:

public function testIndex()
{
        $client = static::createClient();
        $crawler = $client->request('GET', '/logout');
        $crawler = $client->followRedirect();
        $this->assertTrue($crawler->filter('html:contains("ERP-system")')->count() > 0);
}

0

#7 User is offline   Weavora Team 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 06-December 10

Posted 01 February 2012 - 10:45 AM

New version released.

Changelog

0.2.1
  • Fixed issues in unix-like systems
  • Enabled followRedirects by default (as per documentation)

0.2
  • Added classes autoloader so XPathExpr error should not appear any more
  • Fixed exception with YiiExitApplication
  • Modified manual to specify printerFile into phpunit.xml

0

#8 User is offline   Weavora Team 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 06-December 10

Posted 01 February 2012 - 10:48 AM

Levka,

Please, update extension with latest version, and your wouldn't require followRedirect() calls.

Here is unit tests for wunit related to login/logout:

class LoginTest extends \PHPUnit_Framework_TestCase
{

	protected static $wunit;

	public static function setUpBeforeClass()
	{
		static::$wunit = new WUnit();
		static::$wunit->init();
	}

	public function testLoginPage()
	{
		$client = static::$wunit->createClient();
		$crawler = $client->request('GET', '/test/login');


		$this->assertTrue($crawler->filter('html:contains("Please fill out the following form with your login credentials")')->count() > 0);
	}

	public function testLoginForm()
	{
		$client = static::$wunit->createClient();

		$usermame = "demo";
		$password = "demo";
		
		$crawler = $client->request('GET', '/test/index');
		$this->assertTrue($crawler->filter('html:contains("You are not loged in")')->count() > 0);

		$this->assertTrue($this->login($client, $usermame, $password)->filter('html:contains("You are loged in as demo")')->count() > 0);

		$client->back();
		$crawler = $client->request('GET', '/test/index');
		$this->assertTrue($crawler->filter('html:contains("You are loged in as demo")')->count() > 0);

		$crawler = $client->request('GET', '/test/logout');

		$this->assertTrue($crawler->filter('html:contains("You are not loged in")')->count() > 0);
		$crawler = $client->request('GET', '/test/index');

		$this->assertTrue($this->login($client, 'demo', 'demo')->filter('html:contains("You are loged in as demo")')->count() > 0);
	}

	private function login($client, $username, $password){
		$crawler = $client->request('GET', '/test/login');

		$form = $crawler->selectButton('Login')->form();
		$form['LoginForm[username]'] = $username;
		$form['LoginForm[password]'] = $password;
		$form['LoginForm[rememberMe]']->tick();

		return $client->submit($form);
	}

}

0

#9 User is offline   Levka 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 31-January 12

Posted 03 February 2012 - 12:58 PM

That's great!
No problems now with autoredirect.

Does may this extension analyze messageboxes?
0

#10 User is offline   bungcip 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 16-November 10

Posted 13 March 2012 - 01:03 AM

Thanks for this great extension.

Can you add this comment in top of function createClient (WUnitTestCase.php) ?

    /**
     * Create HttpKernel Client
     * @return WUnit\HttpKernel\Client
     */

This will allow netbeans to give autocomplete hint when you typed something like this:

   $client = static::createClient();
   $crawler = $client->
//                     ^^^ autocomplete hints appear



Edit: add this issues in github
0

#11 User is offline   Mayank Singhai 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 29-May 12

Posted 07 September 2013 - 02:32 PM

Hello I have recently downloaded this but facing an issue. When I am running the following code

public function testIndex()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/users/default/login',array(), array(),array('PHP_SELF'=>'/bma/app/index.php'));

        $this->assertTrue($crawler->filter('html:contains("Congratulations!")')->count() > 0);
    }


I am getting the error

1) SiteControllerTest::testIndex
CHttpException: The system is unable to find the requested action "login".

G:\xampp\htdocs\bma\framework\web\CController.php:483
G:\xampp\htdocs\bma\framework\web\CController.php:270
G:\xampp\htdocs\bma\framework\web\CWebApplication.php:282
G:\xampp\htdocs\bma\framework\web\CWebApplication.php:141
G:\xampp\htdocs\bma\app\protected\extensions\wunit\Http\YiiKernel.php:28
G:\xampp\htdocs\bma\app\protected\extensions\wunit\HttpKernel\Client.php:60
G:\xampp\htdocs\bma\app\protected\extensions\wunit\BrowserKit\Client.php:265
G:\xampp\htdocs\bma\app\protected\extensions\wunit\BrowserKit\Client.php:418
G:\xampp\htdocs\bma\app\protected\extensions\wunit\BrowserKit\Client.php:275
G:\xampp\htdocs\bma\app\protected\tests\functional\SiteControllerTest.php:8

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.


Please let me know where i am wrong. My application is at path http://localhost/bma/app/index.php.
0

#12 User is offline   secretlm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-September 13

Posted 15 November 2013 - 01:18 AM

Thanks for your extension. It's working well. However, I would like to know how to request a real DELETE or PUT Http (not simulated by POST method)?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users