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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public function testApprove()<br />

{<br />

// insert a comment in pending status<br />

$comment=new Comment;<br />

$comment->setAttributes(array(<br />

'content'=>'comment 1',<br />

'status'=>Comment::STATUS_PENDING,<br />

'createTime'=>time(),<br />

'author'=>'me',<br />

'email'=>'me@example.com',<br />

'postId'=>$this->posts['sample1']['id'],<br />

),false);<br />

$this->assertTrue($comment->save(false));<br />

// verify the comment is in pending status<br />

$comment=Comment::model()->findByPk($comment->id);<br />

$this->assertTrue($comment instanceof Comment);<br />

$this->assertEquals(Comment::STATUS_PENDING,$comment->status);<br />

}<br />

// call approve() and verify the comment is in approved status<br />

$comment->approve();<br />

$this->assertEquals(Comment::STATUS_APPROVED,$comment->status);<br />

$comment=Comment::model()->findByPk($comment->id);<br />

$this->assertEquals(Comment::STATUS_APPROVED,$comment->status);<br />

Testes Funcionais<br />

Before reading this section, it is recommended that you read the Selenium <strong>do</strong>cumentation<br />

and the PHPUnit <strong>do</strong>cumentation first. We summarize in the following the basic principles<br />

of writing a functional test in <strong>Yii</strong>:<br />

• Like unit test, a functional test is written in terms of a class XyzTest which extends<br />

from CWebTestCase, where Xyz stands for the class being tested. Because<br />

PHPUnit_Extensions_SeleniumTestCase is the ancestor class for CWebTestCase,<br />

we can use all methods inherited from this class.<br />

• The functional test class is saved in a PHP file named as XyzTest.php. By<br />

convention, the functional test file may be stored under the directory protected/tests/<br />

functional.<br />

• The test class mainly contains a set of test methods named as testAbc, where Abc is<br />

often the name of a feature to be tested. For example, to test the user login feature,<br />

we can have a test method named astestLogin.

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

Saved successfully!

Ooh no, something went wrong!