Added DB Access + Error page
This commit is contained in:
36
demos/blog/protected/tests/functional/CommentTest.php
Normal file
36
demos/blog/protected/tests/functional/CommentTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class CommentTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* We use both 'Post' and 'Comment' fixtures.
|
||||
* @see CWebTestCase::fixtures
|
||||
*/
|
||||
public $fixtures=array(
|
||||
'posts'=>'Post',
|
||||
'comments'=>'Comment',
|
||||
);
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$this->open('post/1/xyz');
|
||||
|
||||
// verify the sample post title exists
|
||||
$this->assertTextPresent($this->posts['sample1']['title']);
|
||||
$this->assertElementPresent("name=Comment[author]");
|
||||
|
||||
// verify validation errors
|
||||
$this->clickAndWait("//input[@value='Submit']");
|
||||
$this->assertTextPresent('Name cannot be blank.');
|
||||
$this->assertTextPresent('Email cannot be blank.');
|
||||
$this->assertTextPresent('Comment cannot be blank.');
|
||||
|
||||
// verify commenting is successful
|
||||
$comment="comment 1";
|
||||
$this->type('name=Comment[author]','me');
|
||||
$this->type('name=Comment[email]','me@example.com');
|
||||
$this->type('name=Comment[content]',$comment);
|
||||
$this->clickAndWait("//input[@value='Submit']");
|
||||
$this->assertTextPresent('Thank you for your comment');
|
||||
}
|
||||
}
|
||||
30
demos/blog/protected/tests/functional/PostTest.php
Normal file
30
demos/blog/protected/tests/functional/PostTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class PostTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* We use the 'Post' only for this test.
|
||||
* @see CWebTestCase::fixtures
|
||||
*/
|
||||
public $fixtures=array(
|
||||
'posts'=>'Post',
|
||||
);
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$this->open('');
|
||||
// verify header title exists
|
||||
$this->assertTextPresent('Yii Blog Demo');
|
||||
// verify the sample post title exists
|
||||
$this->assertTextPresent($this->posts['sample1']['title']);
|
||||
}
|
||||
|
||||
public function testView()
|
||||
{
|
||||
$this->open('post/1/xyz');
|
||||
// verify the sample post title exists
|
||||
$this->assertTextPresent($this->posts['sample1']['title']);
|
||||
// verify comment form exists
|
||||
$this->assertTextPresent('Leave a Comment');
|
||||
}
|
||||
}
|
||||
41
demos/blog/protected/tests/functional/SiteTest.php
Normal file
41
demos/blog/protected/tests/functional/SiteTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class SiteTest extends WebTestCase
|
||||
{
|
||||
public function testContact()
|
||||
{
|
||||
$this->open('site/contact');
|
||||
$this->assertTextPresent('Contact Us');
|
||||
$this->assertElementPresent('name=ContactForm[name]');
|
||||
|
||||
$this->type('name=ContactForm[name]','tester');
|
||||
$this->type('name=ContactForm[email]','tester@example.com');
|
||||
$this->type('name=ContactForm[subject]','test subject');
|
||||
$this->clickAndWait("//input[@value='Submit']");
|
||||
$this->assertTextPresent('Body cannot be blank.');
|
||||
}
|
||||
|
||||
public function testLoginLogout()
|
||||
{
|
||||
$this->open('');
|
||||
// ensure the user is logged out
|
||||
if($this->isTextPresent('Logout'))
|
||||
$this->clickAndWait('link=Logout');
|
||||
|
||||
// test login process, including validation
|
||||
$this->clickAndWait('link=Login');
|
||||
$this->assertElementPresent('name=LoginForm[username]');
|
||||
$this->type('name=LoginForm[username]','demo');
|
||||
$this->clickAndWait("//input[@value='Login']");
|
||||
$this->assertTextPresent('Password cannot be blank.');
|
||||
$this->type('name=LoginForm[password]','demo');
|
||||
$this->clickAndWait("//input[@value='Login']");
|
||||
$this->assertTextNotPresent('Password cannot be blank.');
|
||||
$this->assertTextPresent('Logout');
|
||||
|
||||
// test logout process
|
||||
$this->assertTextNotPresent('Login');
|
||||
$this->clickAndWait('link=Logout');
|
||||
$this->assertTextPresent('Login');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user