Created
June 15, 2012 04:40
-
-
Save jamband/2934694 to your computer and use it in GitHub Desktop.
Yii Framework: Test case in Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Frontend WordController class file. | |
*/ | |
class WordController extends Controller | |
{ | |
/** | |
* @see CController::accessRules() | |
*/ | |
public function accessRules() | |
{ | |
return array( | |
array('allow', | |
'users' => array('@'), | |
), | |
array('deny', | |
'users' => array('*'), | |
), | |
); | |
} | |
/** | |
* Lists all words. | |
* @param mixed $sort null or sorting strings | |
*/ | |
public function actionIndex() | |
{ | |
list($pages, $words) = Word::model()->getAll($sort); | |
$this->render('index', compact('pages', 'words')); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WordTest extends WebTestCase | |
{ | |
public $fixtures = array( | |
'words' => 'Word', | |
'users' => 'User', | |
); | |
public function testIndex() | |
{ | |
$this->open('word/index'); | |
$this->login(); | |
$this->assertLocation('word/index'); | |
} | |
public function login() | |
{ | |
$this->assertElementPresent('name=LoginForm[password]'); | |
$this->type('name=LoginForm[username]', 'admin'); | |
$this->type('name=LoginForm[password]', 'admin'); | |
$this->clickAndWait("//input[@value='Login']"); // ここらへんでブラウザがずっと読み込み中になる(FirefoxがダメでIEはOK) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment