Added DB Access + Error page
This commit is contained in:
57
demos/blog/protected/tests/unit/CommentTest.php
Normal file
57
demos/blog/protected/tests/unit/CommentTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
class CommentTest extends CDbTestCase
|
||||
{
|
||||
/**
|
||||
* We use both 'Post' and 'Comment' fixtures.
|
||||
* @see CWebTestCase::fixtures
|
||||
*/
|
||||
public $fixtures=array(
|
||||
'posts'=>'Post',
|
||||
'comments'=>'Comment',
|
||||
);
|
||||
|
||||
public function testFindRecentComments()
|
||||
{
|
||||
$this->assertEquals(array(), Comment::model()->findRecentComments());
|
||||
|
||||
$comment=new Comment;
|
||||
$comment->setAttributes(array(
|
||||
'content'=>'comment 1',
|
||||
'status'=>Comment::STATUS_APPROVED,
|
||||
'create_time'=>time(),
|
||||
'author'=>'me',
|
||||
'email'=>'me@example.com',
|
||||
'post_id'=>$this->posts['sample1']['id'],
|
||||
),false);
|
||||
$this->assertTrue($comment->save(false));
|
||||
$this->assertEquals(1,$comment->id);
|
||||
|
||||
$comments=Comment::model()->findRecentComments();
|
||||
$this->assertEquals(1,count($comments));
|
||||
$this->assertEquals($comment->attributes, $comments[0]->attributes);
|
||||
}
|
||||
|
||||
public function testApprove()
|
||||
{
|
||||
$comment=new Comment;
|
||||
$comment->setAttributes(array(
|
||||
'content'=>'comment 1',
|
||||
'status'=>Comment::STATUS_PENDING,
|
||||
'create_time'=>time(),
|
||||
'author'=>'me',
|
||||
'email'=>'me@example.com',
|
||||
'post_id'=>$this->posts['sample1']['id'],
|
||||
),false);
|
||||
$this->assertTrue($comment->save(false));
|
||||
|
||||
$comment=Comment::model()->findByPk($comment->id);
|
||||
$this->assertTrue($comment instanceof Comment);
|
||||
$this->assertEquals(Comment::STATUS_PENDING,$comment->status);
|
||||
|
||||
$comment->approve();
|
||||
$this->assertEquals(Comment::STATUS_APPROVED,$comment->status);
|
||||
$comment=Comment::model()->findByPk($comment->id);
|
||||
$this->assertEquals(Comment::STATUS_APPROVED,$comment->status);
|
||||
}
|
||||
}
|
||||
13
demos/blog/protected/tests/unit/LookupTest.php
Normal file
13
demos/blog/protected/tests/unit/LookupTest.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class LookupTest extends CDbTestCase
|
||||
{
|
||||
public $fixtures=array(
|
||||
'lookups'=>'Lookup',
|
||||
);
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
18
demos/blog/protected/tests/unit/PostTest.php
Normal file
18
demos/blog/protected/tests/unit/PostTest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class PostTest extends CDbTestCase
|
||||
{
|
||||
/**
|
||||
* We use both 'Post' and 'Comment' fixtures.
|
||||
* @see CWebTestCase::fixtures
|
||||
*/
|
||||
public $fixtures=array(
|
||||
'posts'=>'Post',
|
||||
'comments'=>'Comment',
|
||||
);
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
// write code here to test post saving method
|
||||
}
|
||||
}
|
||||
13
demos/blog/protected/tests/unit/TagTest.php
Normal file
13
demos/blog/protected/tests/unit/TagTest.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class TagTest extends CDbTestCase
|
||||
{
|
||||
public $fixtures=array(
|
||||
'tags'=>'Tag',
|
||||
);
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
24
demos/blog/protected/tests/unit/UserTest.php
Normal file
24
demos/blog/protected/tests/unit/UserTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class UserTest extends CDbTestCase
|
||||
{
|
||||
public $fixtures=array(
|
||||
'users'=>'User',
|
||||
);
|
||||
|
||||
public function testValidatePassword()
|
||||
{
|
||||
$this->assertTrue($this->users(0)->validatePassword('demo'));
|
||||
$this->assertFalse($this->users(0)->validatePassword('wrong'));
|
||||
|
||||
}
|
||||
|
||||
public function testChangePassword()
|
||||
{
|
||||
$user=$this->users(0);
|
||||
$user->password=$user->hashPassword('newpwd');
|
||||
$this->assertFalse($user->validatePassword('demo'));
|
||||
$this->assertTrue($user->validatePassword('newpwd'));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user