Chinaunix首页 | 论坛 | 博客
  • 博客访问: 711247
  • 博文数量: 160
  • 博客积分: 8847
  • 博客等级: 中将
  • 技术积分: 1656
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-25 16:46
个人简介

。。。。。。。。。。。。。。。。。。。。。。

文章分类

全部博文(160)

文章存档

2015年(1)

2013年(1)

2012年(4)

2011年(26)

2010年(14)

2009年(36)

2008年(38)

2007年(39)

2006年(1)

分类: 系统运维

2011-03-19 23:52:46

  1. class ProjectTest extends CDbTestCase {
  2.     //test fixtures
  3.     public $fixtures = array(
  4.         'projects' => 'Project', //可以直接在这里$this->projects引用里面的数据
  5.     );

  6.     public function testCreate(){
  7.         //由于设置了fixturs数据,所以在测试开始的时候,fixture就会填充到表中
  8.         $newProject = new Project;
  9.         $newProjectName = 'test project creation';
  10.         $newProject->setAttributes(array(
  11.             'name' => $newProjectName,
  12.             'description' => 'test project creation description',
  13.         ));

  14.         $this->assertTrue($newProject->save(false));

  15.         //读取刚刚建立的project
  16.         $retrivedLastProject = Project::model()->findByPk($newProject->id);
  17.         //var_dump($retrivedLastProject->id); //4
  18.         $this->assertTrue($retrivedLastProject instanceof Project);
  19.         $this->assertEquals($retrivedLastProject->name, $newProjectName);
  20.     }

  21.     public function testRead(){
  22.         /**从表trackstar_test.tbl_project以AR对象的方式返回一行数据,project1表示的是fixtures设置的key,它对应的值:
  23.         'project1' => array(
  24.             'name' => 'fixture data for project1 name',
  25.             'description' => 'fixture data for project1 description.',
  26.             'create_time' => '2010-03-19 22:25:21',
  27.             'create_user_id' => '1',
  28.             'update_time' => '2010-03-19 22:25:22',
  29.             'update_user_id' => '2',
  30.         ),
  31.          */
  32.         $retrivedProject = $this->projects('project1');
  33.         $this->assertTrue($retrivedProject instanceof Project);
  34.         $this->assertEquals($retrivedProject->name, 'fixture data for project1 name');
  35.     }

  36.     public function testDelete(){
  37.         $project = $this->projects('project3');

  38.         $savedProjectId = $project->id;
  39.         $this->assertTrue($project->delete());
  40.         $criteria = new CDbCriteria(array(
  41.             'condition' => 'id=:id',
  42.             'params' => array(
  43.                 ':id' => $savedProjectId,
  44.             ),
  45.         ));
  46.         $this->assertEquals(NULL, Project::model()->find($criteria));
  47.     }

  48.     public function testUpdate(){
  49.         $project = $this->projects('project2');
  50.         $updateTheSecondProjectName = 'Update the second project name';
  51.         $project->name = $updateTheSecondProjectName;
  52.         $this->assertTrue($project->save(FALSE));
  53.         //读取刚刚更新的数据
  54.         $updateProject = Project::model()->findByPk($project->id);
  55.         $this->assertTrue($updateProject instanceof Project);
  56.         $this->assertEquals($updateProject->name, $updateTheSecondProjectName);
  57.     }
  58. }
阅读(1099) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~