Skip to content

Instantly share code, notes, and snippets.

@jamband
Created June 15, 2012 04:40
Show Gist options
  • Save jamband/2934694 to your computer and use it in GitHub Desktop.
Save jamband/2934694 to your computer and use it in GitHub Desktop.
Yii Framework: Test case in Controller
<?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'));
}
}
<?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