示例#1
0
 public function testBeforeCreate()
 {
     $test = new UnitTest(array('integer_value' => '123', 'string_value' => 'before create test', 'email_value' => '*****@*****.**'));
     $this->assertFalse($test->save());
     $this->assertTrue($test->errors->isInvalid('string_value'));
 }
 function actionUnitMethod($method)
 {
     $meth = Method::model()->findByPk($method);
     if ($meth == null) {
         throw new CHttpException(404, 'Method not found :-(');
     }
     $t = UnitTest::model()->findByAttributes(array('id_method' => $method));
     if ($t != null) {
         $this->redirect(array('view', 'id' => $t->id_test));
     } else {
         $model = new Test();
         $special = new UnitTest();
         $special->id_method = $id_method;
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['Test'])) {
             $model->attributes = $_POST['Test'];
             $special->id_test = 0;
             if ($model->save()) {
                 $special->id_test = $model->id_test;
                 $special->save(false);
                 $this->redirect(array('view', 'id' => $model->id_test));
             }
         }
         $this->render('create', array('model' => $model, 'special' => $special));
     }
 }