Example #1
0
 public function testCRUD()
 {
     //CREATE Test
     $newProject = new Project();
     $projectName = 'This is a Test';
     $newProject->setAttributes(array('name' => $projectName, 'description' => 'This project is for test purpose only', 'start_date' => '2010-11-15 15:00:00', 'end_date' => '2010-12-06 00:00:00', 'update_user_id' => 1, 'category' => 2, 'status' => 1, 'owner' => 1));
     $this->assertTrue($newProject->save(false));
     //READ Test
     $readProject = Project::model()->findByPk($newProject->id);
     $this->assertTrue($readProject instanceof Project);
     $this->assertEquals($projectName, $readProject->name);
     //UPDATE Test
     $updateProjectName = 'Updated Name2';
     $newProject->name = $updateProjectName;
     $this->AssertTrue($newProject->save(false));
     $updatedProject = Project::model()->findByPk($newProject->id);
     $this->assertTrue($updatedProject instanceof Project);
     $this->assertNotEquals($projectName, $updatedProject->name);
     //DELETE Test
     $deletedProjectId = $newProject->id;
     $newProject->delete();
     $deletedProject = Project::model()->findByPk($newProject->id);
     $this->assertEquals(Null, $deletedProject);
     //GetUserVote Test
     $project = Project::model()->findByPk(18);
     $this->assertTrue($project->getUserVote(7) == true);
     //Vote Test
     $this->assertTrue($project->vote(1, 1) == 1);
 }
Example #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Project();
     $model->attributes = $_POST;
     $result = $model->save();
     $this->sendAjaxResponse($model);
 }
Example #3
0
 public function action_create()
 {
     $project_input = Input::get('project');
     if ($project_input["project_type_id"] == "Other") {
         if (!Input::get('new_project_type_name')) {
             Session::flash('errors', array(__("r.flashes.new_project_no_project_type")));
             return Redirect::to_route('new_projects')->with_input();
         } elseif ($existing_project_type = ProjectType::where_name(Input::get('new_project_type_name'))->first()) {
             $project_input["project_type_id"] = $existing_project_type->id;
         } else {
             $project_type = new ProjectType(array('name' => Input::get('new_project_type_name')));
             $project_type->save();
             $project_input["project_type_id"] = $project_type->id;
         }
     }
     $project = new Project($project_input);
     $dt = new \DateTime($project_input["proposals_due_at"], new DateTimeZone('America/New_York'));
     // if user doesn't specify a date, set it to 1 month from now
     if (!$project_input["proposals_due_at"]) {
         $dt->modify('+1 month');
     }
     $dt->setTimeZone(new DateTimeZone('UTC'));
     $project->proposals_due_at = $dt;
     if ($project->validator()->passes()) {
         $project->save();
         $project->officers()->attach(Auth::officer()->id, array('owner' => true));
         return Redirect::to_route('project_template', array($project->id));
     } else {
         Session::flash('errors', $project->validator()->errors->all());
         return Redirect::to_route('new_projects')->with_input();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $userToken = Input::get('token');
     $validation = Validator::make(['projectname' => Input::get('projectname'), 'description' => Input::get('description'), 'start_date' => Input::get('start_date'), 'end_date' => Input::get('end_date')], ['projectname' => 'required|min:4|max:40', 'description' => 'min:10|max:60', 'start_date' => 'required|date_format:"m/d/Y"', 'end_date' => 'required|date_format:"m/d/Y"']);
     if ($validation->fails()) {
         return Redirect::route('dashboard', array($userToken))->withErrors($validation);
     } else {
         $projectName = Input::get('projectname');
         $projectDesc = Input::get('description');
         $projectStart = Input::get('start_date');
         $start_day = date("Y-m-d", strtotime($projectStart));
         $projectEnd = Input::get('end_date');
         $end_day = date("Y-m-d", strtotime($projectEnd));
         $team_id = Input::get('team_id');
         try {
             $project = new Project();
             $project->project_title = $projectName;
             $project->project_desc = $projectDesc;
             $project->team_id = $team_id;
             $project->strat_date = $start_day;
             $project->end_date = $end_day;
             $project->save();
             return Redirect::route('dashboard', array($userToken));
         } catch (Exception $e) {
             echo $e;
             return 'Something is wrong!';
         }
     }
 }
 /**
  * Update project
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->request->isApiCall() && !$this->request->isSubmitted()) {
         $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true);
     }
     // if
     if ($this->active_project->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_project->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $project_data = $this->request->post('project');
     if (!is_array($project_data)) {
         $project_data = array('name' => $this->active_project->getName(), 'overview' => $this->active_project->getOverview(), 'default_visibility' => $this->active_project->getDefaultVisibility(), 'leader_id' => $this->active_project->getLeaderId(), 'group_id' => $this->active_project->getGroupId(), 'company_id' => $this->active_project->getCompanyId(), 'default_visibility' => $this->active_project->getDefaultVisibility(), 'starts_on' => $this->active_project->getStartsOn());
     }
     // if
     $this->smarty->assign('project_data', $project_data);
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $old_name = $this->active_project->getName();
         $this->active_project->setAttributes($project_data);
         if ($this->active_project->isModified('leader_id') && $this->active_project->getLeaderId()) {
             $leader = Users::findById($this->active_project->getLeaderId());
             if (instance_of($leader, 'User')) {
                 $this->active_project->setLeader($leader);
             }
             // if
         }
         // if
         if ($this->active_project->isModified('company_id')) {
             cache_remove('project_icons');
         }
         // if
         $save = $this->active_project->save();
         if ($save && !is_error($save)) {
             db_commit();
             if ($this->request->isApiCall()) {
                 $this->serveData($this->active_project, 'project');
             } else {
                 flash_success('Project :name has been updated', array('name' => $old_name));
                 $this->redirectToUrl($this->active_project->getOverviewUrl());
             }
             // if
         } else {
             db_rollback();
             if ($this->request->isApiCall()) {
                 $this->serveData($save);
             } else {
                 $this->smarty->assign('errors', $save);
             }
             // if
         }
         // if
     }
     // if
 }
Example #6
0
File: home.php Project: kuitang/sdi
 function submit()
 {
     $data['title'] = 'Submit a Project';
     $project = new Project();
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // Get the scalars.
         $project->from_array($_POST);
         // Convert properly to boolean
         if ($project->show_contact == 'yes') {
             $project->show_contact = TRUE;
         } else {
             $project->show_contact = FALSE;
         }
         // Handle the relations (tags)
         if ($project->save($this->_current_user())) {
             // validations run
             $this->_save_tags($project);
             $this->_submit_on_success();
         } else {
             // invalid
             $data['error'] = $project->error->string;
         }
     }
     // Otherwise, render a form.
     $tags = new Tag();
     foreach (array('field', 'type', 'location') as $category) {
         $tags->where('category', $category)->get();
         $data[$category . '_tags'] = array();
         foreach ($tags as $tag) {
             array_push($data[$category . '_tags'], $tag->name);
         }
     }
     $data['form'] = $project->render_form(array('title', 'start_date', 'end_date', 'field', 'type', 'location', 'text', 'show_contact'));
     $this->load->view('form_project', $data);
 }
 public function createAssocAction()
 {
     $user = User::findFirst();
     $project = new Project();
     $project->user = $user;
     $project->title = "Moon walker";
     $result = $project->save();
 }
 public static function createProject($id = '')
 {
     $project = new Project();
     $project->name = "testProject";
     $project->team_id = 1;
     $project->team_set_id = 1;
     $project->save();
     self::pushObject($project);
     return $project;
 }
 /**
  * Store a newly created resource in storage.
  * POST /projects
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $project = new Project($input);
     if ($project->save()) {
         return Redirect::route('projects.index')->with('message', 'Project created.');
     } else {
         return Redirect::route('projects.create')->withInput()->withErrors($project->errors());
     }
 }
 public static function createProjectByNameForOwner($name, $owner)
 {
     $project = new Project();
     $project->name = $name;
     $project->owner = $owner;
     $project->description = 'Description';
     $saved = $project->save();
     assert('$saved');
     return $project;
 }
Example #11
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $model = new Project($this->action->id);
     if (isset($_POST['Project'])) {
         // collect user input data
         $model->attributes = $_POST['Project'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['Company2Project'])) {
                 // assigned companies
                 $model->allCompany2Project = array(0 => new Company2Project('create'));
                 $model->allCompany2Project[0]->projectId = $model->id;
                 foreach ($model->allCompany2Project as $company2Project) {
                     $company2Project->attributes = $_POST['Company2Project'];
                     $company2Project->save();
                 }
             }
             if (isset($_POST['User2Project'])) {
                 // assigned managers
                 $model->allManager2Project = array(0 => new User2Project('create'));
                 $model->allManager2Project[0]->projectId = $model->id;
                 foreach ($model->allManager2Project as $user2Project) {
                     $user2Project->attributes = $_POST['User2Project'];
                     $user2Project->save();
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The new "{title}" project record has been successfully created.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     } else {
         // pre-assigned attributes (default values for a new record)
         $model->priority = Project::PRIORITY_MEDIUM;
         if (isset($_GET['companyId'])) {
             // company is known
             $model->allCompany2Project = array(0 => new Company2Project('create'));
             $model->allCompany2Project[0]->companyId = $_GET['companyId'];
             $model->allCompany2Project[0]->projectId = $model->id;
         }
     }
     if (!isset($model->allCompany2Project[0])) {
         // new associated company
         $model->allCompany2Project = array(0 => new Company2Project('create'));
         $model->allCompany2Project[0]->projectId = $model->id;
     }
     if (!isset($model->allManager2Project[0])) {
         // new associated manager
         $model->allManager2Project = array(0 => new User2Project('create'));
         $model->allManager2Project[0]->projectId = $model->id;
         $model->allManager2Project[0]->role = User2Project::MANAGER;
     }
     $this->render($this->action->id, array('model' => $model));
 }
 public function editProject()
 {
     $id = Input::get('id');
     $project = null;
     if ($id) {
         $this->check_own($id);
         $project = Project::find($id);
     }
     $src_addr = trim(Input::get('src_addr'));
     $error = '';
     if (Request::isMethod('post')) {
         if (!trim(Input::get('title'))) {
             $error = '请填写标题';
         }
         if (!trim(Input::get('manager'))) {
             $error = '请填写项目管理员';
         }
         if (!trim(Input::get('src_addr'))) {
             $error = '请填写源码地址';
         }
         if (!$error) {
             $project_created = false;
             if ($project) {
                 if ($project->src_addr != $src_addr) {
                     //生成task 清理当前source目录
                     $clean_task = Task::create('delete', Auth::id(), array('project_id' => $project->id));
                     //生成task 重新checkout,注意前置任务
                     Task::create('checkout', Auth::id(), array('project_id' => $project->id), $clean_task);
                 }
             } else {
                 $project = new Project();
                 $project_created = true;
             }
             $project->title = trim(Input::get('title'));
             $project->manager = trim(Input::get('manager'));
             $project->vcs_type = trim(Input::get('vcs_type'));
             $project->src_addr = $src_addr;
             $project->ignore_files = trim(Input::get('ignore_files'));
             $project->comments = trim(Input::get('comments'));
             $project->username = trim(Input::get('username'));
             $project->password = trim(Input::get('password'));
             if (!isset(Project::$vcs_types[$project->vcs_type])) {
                 $project->vcs_type = last(array_keys(Project::$vcs_types));
             }
             $project->save();
             if ($project_created) {
                 //生成task checkout
                 Task::create('checkout', Auth::id(), array('project_id' => $project->id));
             }
             return Redirect::action('ProjectsController@allProjects');
         }
     }
     return View::make('projects/edit', array('project' => $project, 'error' => $error));
 }
Example #13
0
 public function testNoSave()
 {
     $p = new Project();
     $p->id = 'ABC';
     $p->name = 'abc';
     try {
         $p->save();
     } catch (EQMException $e) {
         $this->assertEquals($e->getMessage(), 'save() is not possible for entities without auto increment primary key');
     }
 }
Example #14
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Project();
     if (isset($_POST['Project'])) {
         $model->attributes = $_POST['Project'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Project ' . $model->name . ' has been created successfully.');
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Project();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Project'])) {
         $model->attributes = $_POST['Project'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #16
0
 public function add()
 {
     $project = new Project();
     // Assign new values
     $project->slug = md5(time());
     $project->created_by = Auth::user()->id;
     $project->save();
     // Assign new attributes
     $project->url = URL::to('/project', array('slug' => $project->slug));
     $project->date = date_format(date_create($project->created_at), "Y-m-d");
     // Convert to JSON
     return $project->toJson();
 }
Example #17
0
 public function executeCreate(sfWebRequest $request)
 {
     $name = $request->getParameter("name");
     if (strlen($name) > 1 && strlen($name) < 45) {
         $p = new Project();
         $p->setName($name);
         $p->save();
     } else {
         $this->forward404("The project name is to long!");
     }
     $this->executeList($request);
     $this->setLayout("list");
 }
Example #18
0
 public function store()
 {
     $daterange = explode('-', Input::get('range'));
     $start_date = trim($daterange[0]);
     $end_date = trim($daterange[1]);
     $project = new Project();
     $project->code = Input::get('code');
     $project->name = Input::get('name');
     $project->start_date = date('Y-m-d', strtotime($start_date));
     $project->end_date = date('Y-m-d', strtotime($end_date));
     $project->save();
     Session::flash('message', 'Sukses membuat Project Baru');
 }
 public function createForUser($user, $attributes)
 {
     $project = new Project($attributes);
     if ($project->save()) {
         $user->projects()->associate($project);
         Mail::queue('projects.creation', compact('project'), function ($message) use($project) {
             $emails = $project->collaborators->lists('email');
             $message->to($emails)->subject("New Project {$project->name} Added");
         });
         return $this->listener->projectCreationSucceeded($project);
     } else {
         return $this->listener->projectCreationFailed($project);
     }
 }
 public function createForUser($user, $attributes)
 {
     $project = new Project($attributes);
     if ($project->save()) {
         $user->projects()->associate($project);
         Mail::queue('projects.creation', compact('project'), function ($message) use($project) {
             $emails = $project->collaborators->lists('email');
             $message->to($emails)->subject("New Project {$project->name} Added");
         });
     } else {
         $this->errors[] = 'Something has gone wrong';
     }
     return $project;
 }
Example #21
0
 public function executeUpdate()
 {
     $jira = new sfJiraPlugin($this->getUser()->getProfile()->getJiraLogin(), $this->getUser()->getProfile()->getJiraPassword());
     $aProjects = $jira->getProjects();
     foreach ($aProjects as $project) {
         #var_dump( $project );
         $c = new Criteria();
         $c->add(ProjectPeer::USER_ID, $this->getUser()->getProfile()->getId());
         $c->add(ProjectPeer::KEY, $project->key);
         $p = ProjectPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(UserPeer::JIRA_LOGIN, $project->lead);
         $u = UserPeer::doSelectOne($c);
         if (empty($p)) {
             $p = new Project();
             $p->setKey($project->key);
             $p->setLeadId(!empty($u) ? $u->getId() : null);
             $p->setUserId($this->getUser()->getProfile()->getId());
             $p->setName($project->name);
             $p->setUpdated(date('r'));
             $p->save();
         }
         $issues = $jira->getIssuesForProject($p->getKey());
         foreach ($issues as $issue) {
             #die($p->getKey());
             if ($issue->assignee == $this->getUser()->getProfile()->getJiraLogin()) {
                 $c = new Criteria();
                 $c->add(TaskPeer::KEY, $issue->key);
                 $t = TaskPeer::doSelectOne($c);
                 if (empty($t)) {
                     $c = new Criteria();
                     $c->add(UserPeer::JIRA_LOGIN, $issue->reporter);
                     $u = UserPeer::doSelectOne($c);
                     $t = new Task();
                     $t->setProjectId($p->getId());
                     $t->setTitle($issue->summary);
                     $t->setDescription($issue->description);
                     $t->setKey($issue->key);
                     $t->setUpdated(date('r'));
                     $t->setStatusId($issue->status);
                     $t->setPriorityId($issue->priority);
                     $t->setLeadId(!empty($u) ? $u->getId() : null);
                     $t->save();
                 }
             }
         }
     }
     $this->redirect('@homepage');
     return sfView::NONE;
 }
 public function testCopy()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = Yii::app()->user->userModel;
     $project = new Project();
     $project->name = 'Project 1';
     $project->owner = $user;
     $project->description = 'Description';
     $user = UserTestHelper::createBasicUser('Steven');
     $account = new Account();
     $account->owner = $user;
     $account->name = DataUtil::purifyHtml("Tom & Jerry's Account");
     $this->assertTrue($account->save());
     $id = $account->id;
     unset($account);
     $account = Account::getById($id);
     $this->assertEquals("Tom & Jerry's Account", $account->name);
     $contact = ContactTestHelper::createContactByNameForOwner('Jerry', $user);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Jerry Opp', $user);
     $this->assertTrue($project->save());
     $this->assertEquals(1, count($project->auditEvents));
     $id = $project->id;
     $project->forget();
     unset($project);
     $project = Project::getById($id);
     ProjectZurmoControllerUtil::resolveProjectManyManyAccountsFromPost($project, array('accountIds' => $account->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyContactsFromPost($project, array('contactIds' => $contact->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyOpportunitiesFromPost($project, array('opportunityIds' => $opportunity->id));
     $this->assertEquals('Project 1', $project->name);
     $this->assertEquals('Description', $project->description);
     $this->assertEquals(1, $project->accounts->count());
     $this->assertEquals(1, $project->contacts->count());
     $this->assertEquals(1, $project->opportunities->count());
     $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem1 = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
     $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
     $copyToProject = new Project();
     ProjectZurmoCopyModelUtil::copy($project, $copyToProject);
     ProjectZurmoCopyModelUtil::processAfterCopy($project, $copyToProject);
     $this->assertTrue($copyToProject->save());
     $this->assertEquals($copyToProject->name, $project->name);
     $this->assertEquals($copyToProject->description, $project->description);
     $this->assertEquals($copyToProject->status, $project->status);
     $project = Project::getByName('Project 1');
     $this->assertEquals(2, count($project));
     $tasks = Task::getAll();
     $this->assertEquals(2, count($tasks));
 }
Example #23
0
 public static function save()
 {
     $input = array("name" => $_POST["name"], "id" => $_POST["id"], "members" => $_POST["members"], "description" => $_POST["description"]);
     if ($_POST["action"] == "Save") {
         $project = new Project($input);
         $project->save();
     } else {
         if ($_POST["action"] == "Delete") {
             $project = Project::getById($input["id"]);
             $project->delete();
         }
     }
     //redirect so that we don't repost on refresh
     redirect_to("project");
 }
Example #24
0
 function createAction()
 {
     $project = new Project();
     $project->name = $_REQUEST['project_name'];
     $project->description = $_REQUEST['project_desc'];
     $project->dt_created = mysql_time();
     $project->created_by = Pfw_Session::get('login_id');
     try {
         $project->save();
     } catch (Exception $e) {
         error_log("Caught exception with [" . $e->getMessage() . "]");
     }
     $this->redirect("/home");
     return;
 }
Example #25
0
 public function testCreate()
 {
     // CREATE new project
     $newProject = new Project();
     $newProjectName = 'Test Project Creation';
     $newProject->setAttributes(array('name' => $newProjectName, 'description' => 'This is a test for new project creation'));
     Yii::app()->user->setId($this->users('user1')->id);
     // Save the new project, triggering attribute validation
     $this->assertTrue($newProject->save());
     // READ back the newly created project to ensure the creation worked
     $retrievedProject = Project::model()->findByPk($newProject->id);
     $this->assertTrue($retrievedProject instanceof Project);
     $this->assertEquals($newProjectName, $retrievedProject->name);
     $this->assertEquals(Yii::app()->user->id, $retrievedProject->create_user_id);
 }
Example #26
0
 public function testCreateNewProject()
 {
     // Create new record
     $model = new Project();
     $model->name = 'SomeProject';
     $model->description = 'A very good project';
     $model->crash_report_files_disc_quota = 500 * 1024 * 1024;
     $model->crash_reports_per_group_quota = 100;
     $model->debug_info_files_disc_quota = 2 * 1024 * 1024 * 1024;
     // Apply changes
     $this->assertTrue($model->save());
     // Find newly created record
     $model = Project::model()->findAll('name="SomeProject"');
     $this->assertTrue($model != null);
 }
Example #27
0
 function generate_project()
 {
     $project = new Project();
     //if we don't manually set this variable, the parameters from the $_POST array will be imported. We don't want
     //those parameters because then we would also be importing the Template id, which would effectively set this
     //new project model = this template model. We will manually set the parameters from the template that we want to
     //copy
     $project->params_imported = true;
     $project->set('client_id', Request::param('client_id'));
     $project->set('name', Request::param('name'));
     $project->set('start_date', Request::param('start_date'));
     $project->set('due_date', Request::param('due_date'));
     $project->save();
     $this->project = $project;
 }
Example #28
0
 public function testRelationshipSave()
 {
     $timedate = TimeDate::getInstance();
     $unid = uniqid();
     $project = new Project();
     $project->id = 'p_' . $unid;
     $project->name = 'test project ' . $unid;
     $project->estimated_start_date = $timedate->nowDate();
     $project->estimated_end_date = $timedate->asUserDate($timedate->getNow(true)->modify("+7 days"));
     $project->new_with_id = true;
     $project->disable_custom_fields = true;
     $newProjectId = $project->save();
     $this->project = $project;
     $savedProjectId = $GLOBALS['db']->getOne("\n                                SELECT project_id FROM projects_accounts\n                                WHERE project_id= '{$newProjectId}'\n                                AND account_id='{$this->account->id}'");
     $this->assertEquals($newProjectId, $savedProjectId);
 }
Example #29
0
 public function testCreate()
 {
     //Create new project
     $newProject = new Project();
     $newProjectName = 'Test Project 1';
     $newProject->setAttributes(array('name' => $newProjectName, 'description' => 'Unit test for project creation'));
     //Set user
     Yii::app()->user->setID($this->users('user1')->id);
     $this->assertTrue($newProject->save());
     //Read newly created project
     $retrievedProject = Project::model()->findByPk($newProject->id);
     $this->assertTrue($retrievedProject instanceof Project);
     $this->assertEquals($newProjectName, $retrievedProject->name);
     //Check user
     $this->assertEquals(Yii::app()->user->id, $retrievedProject->create_user_id);
 }
 /**
  * Create the new project
  *
  * @return Response
  */
 public function create()
 {
     // Rules
     $rules = array('name' => 'required');
     // Create validation
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $project = new Project();
     $project->name = Input::get('name');
     $project->client_id = Input::get('client_id');
     $project->user_id = Auth::id();
     $project->save();
     return Redirect::back()->with('success', Input::get('name') . " has been created.");
 }