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.

class PostTest extends WebTestCase<br />

{<br />

public $fixtures=array(<br />

'posts'=>'Post',<br />

);<br />

public function testShow()<br />

{<br />

$this->open('post/1');<br />

// verify the sample post title exists<br />

$this->assertTextPresent($this->posts['sample1']['title']);<br />

// verify comment form exists<br />

$this->assertTextPresent('Leave a Comment');<br />

}<br />

}<br />

......<br />

Like writing a unit test class, we declare the fixtures to be used by this test. Here we<br />

indicate that the Postfixture should be used. In the testShow test method, we first instruct<br />

Selenium RC to open the URL post/1. Note that this is a relative URL, and the complete<br />

URL is formed by appending it to the base URL we set in the base class (i.e. http://<br />

localhost/yii/demos/blog/index-test.php/post/1). We then verify that we can find the title of<br />

the sample1 post can be found in the current Web page. And we also verify that the page<br />

contains the text Leave a Comment.<br />

Tip: Before running functional tests, the Selenium-RC server must be started. This can<br />

be <strong>do</strong>ne by executing the command java -jar selenium-server.jar under your Selenium<br />

server installation directory.

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

Saved successfully!

Ooh no, something went wrong!