コード例 #1
0
 /**
  * Edit existed profile
  *
  * Handler GET, POST request
  * @link GET /profile/edit/:id display form profile populated
  * @link POST /profile/edit persit profile
  *
  */
 public function editAction()
 {
     $profileRepoFactory = new Application_Factory_ProfileRepository();
     $profileModelFactory = new Application_Factory_ProfileModel();
     $profileForm = new Application_Form_Profile(['id' => 'edit-profile']);
     $profileForm->submit->setLabel("Save");
     $profileRepo = $profileRepoFactory->createService();
     $this->view->profileForm = $profileForm;
     //GET request handler
     $visitEditProfilePage = !$this->getRequest()->isPost();
     if ($visitEditProfilePage) {
         $profileId = (int) $this->getParam('id', 0);
         $profileEntity = $profileRepo->findById($profileId);
         $profileForm->bindFromProfile($profileEntity);
         return;
         //render edit profile form
     }
     //POST request handler
     $postInvalidProfile = !$profileForm->isValid($this->getRequest()->getPost());
     if ($postInvalidProfile) {
         return;
         //represent profile form with error messages
     }
     //Persit filtered profile to persistent
     $profileRepo->save($profileModelFactory->createService($profileForm->getValues()));
     $this->_helper->redirector('index', 'profile', 'default');
 }
コード例 #2
0
 public function testDeleteProfileByProfileSuccess()
 {
     $profileFactory = new Application_Factory_ProfileModel();
     $this->profileTable->deleteProfile($profileFactory->createService(['id' => 1]));
     $currentDate = new DateTime('2015-07-16');
     $current = $currentDate->format('Y-m-d');
     $expected = $this->createArrayDataSet(['profile' => [['id' => 2, 'fullname' => 'Quang B', 'dob' => $current, 'email' => '*****@*****.**'], ['id' => 3, 'fullname' => 'Quang C', 'dob' => $current, 'email' => '*****@*****.**']]]);
     $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($this->getConnection());
     $ds->addTable('profile', "SELECT * FROM PROFILE");
     $this->assertDataSetsEqual($expected, $ds);
 }