20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• A test method usually contains a sequence of statements that would issue commands<br />

to Selenium RC to interact with the Web application being tested. It also contains<br />

assertion statements to verify that the Web application responds as expected.<br />

Before we describe how to write a functional test, let's take a look at the WebTestCase.php<br />

file generated by the yiic webapp command. This file defines WebTestCase that may serve<br />

as the base class for all functional test classes.<br />

define('TEST_BASE_URL','http://localhost/yii/demos/blog/index-test.php/');<br />

class WebTestCase extends CWebTestCase<br />

{<br />

/**<br />

* Sets up before each test method runs.<br />

* This mainly sets the base URL for the test application.<br />

*/<br />

protected function setUp()<br />

{<br />

parent::setUp();<br />

$this->setBrowserUrl(TEST_BASE_URL);<br />

}<br />

}<br />

......<br />

The class WebTestCase mainly sets the base URL of the pages to be tested. Later in test<br />

methods, we can use relative URLs to specify which pages to be tested.<br />

We should also pay attention that in the base test URL, we use index-test.php as the entry<br />

script instead ofindex.php. The only difference between index-test.php and index.php is<br />

that the former uses test.phpas the application configuration file while the latter main.php.<br />

We now describe how to test the feature about showing a post in the blog demo. We first<br />

write the test class as follows, noting that the test class extends from the base class we<br />

just described:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!