public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2'); $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson'); $account = Account::getById($superAccountId); $account2 = Account::getById($superAccountId2); $contact = Contact::getById($superContactId); //confirm no existing activities exist $activities = Activity::getAll(); $this->assertEquals(0, count($activities)); //Test just going to the create from relation view. $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCreateFromRelation'); //add related task for account using createFromRelation action $activityItemPostData = array('Account' => array('id' => $superAccountId)); $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTask'))); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalSaveFromRelation'); //now test that the new task exists, and is related to the account. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); $this->assertEquals('myTask', $tasks[0]->name); $this->assertEquals(1, $tasks[0]->activityItems->count()); $activityItem1 = $tasks[0]->activityItems->offsetGet(0); $this->assertEquals($account, $activityItem1); //test viewing the existing task in a details view $this->setGetArray(array('id' => $tasks[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails'); //test submitting the task on change $this->setGetArray(array('id' => $tasks[0]->id)); $this->setPostArray(array('Task' => array('name' => 'myTask', 'status' => Task::STATUS_IN_PROGRESS))); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails'); //Test just going to the copy from relation $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'id' => $tasks[0]->id)); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCopyFromRelation'); $tasks = Task::getAll(); $this->assertEquals(2, count($tasks)); $this->assertEquals('myTask', $tasks[1]->name); $this->assertEquals(1, $tasks[1]->activityItems->count()); //test removing a task. $this->setGetArray(array('id' => $tasks[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/delete', true); //Confirm no more tasks exist. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2'); $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson'); $account = Account::getById($superAccountId); $account2 = Account::getById($superAccountId2); $contact = Contact::getById($superContactId); //confirm no existing activities exist $activities = Activity::getAll(); $this->assertEquals(0, count($activities)); //Test just going to the create from relation view. $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/createFromRelation'); //add related task for account using createFromRelation action $activityItemPostData = array('Account' => array('id' => $superAccountId)); $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTask'))); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/createFromRelation'); //now test that the new task exists, and is related to the account. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); $this->assertEquals('myTask', $tasks[0]->name); $this->assertEquals(1, $tasks[0]->activityItems->count()); $activityItem1 = $tasks[0]->activityItems->offsetGet(0); $this->assertEquals($account, $activityItem1); //test viewing the existing task in a details view $this->setGetArray(array('id' => $tasks[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/details'); //test editing an existing task and saving. Add a second relation, to a contact. //First just go to the edit view and confirm it loads ok. $this->setGetArray(array('id' => $tasks[0]->id, 'redirectUrl' => 'someRedirect')); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('tasks/default/edit'); //Save changes via edit action. $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId)); $this->setGetArray(array('id' => $tasks[0]->id, 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTaskX'))); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/edit'); //Confirm changes applied correctly. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); $this->assertEquals('myTaskX', $tasks[0]->name); $this->assertEquals(2, $tasks[0]->activityItems->count()); $activityItem1 = $tasks[0]->activityItems->offsetGet(0); $activityItem2 = $tasks[0]->activityItems->offsetGet(1); $this->assertEquals($account, $activityItem1); $this->assertEquals($contact, $activityItem2); //Remove contact relation. Switch account relation to a different account. $activityItemPostData = array('Account' => array('id' => $superAccountId2)); $this->setGetArray(array('id' => $tasks[0]->id)); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTaskX'))); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/edit'); //Confirm changes applied correctly. $tasks = Task::getAll(); $this->assertEquals(1, count($tasks)); $this->assertEquals('myTaskX', $tasks[0]->name); $this->assertEquals(1, $tasks[0]->activityItems->count()); $activityItem1 = $tasks[0]->activityItems->offsetGet(0); $this->assertEquals($account2, $activityItem1); //test removing a task. $this->setGetArray(array('id' => $tasks[0]->id)); $this->resetPostArray(); $this->runControllerWithRedirectExceptionAndGetContent('tasks/default/delete'); //Confirm no more tasks exist. $tasks = Task::getAll(); $this->assertEquals(0, count($tasks)); }
}); //path to specific users account info and activity info $app->get("/updateuser/{id}", function () use($app) { return $app['twig']->render('updateuser.html.twig', array('user' => $user)); }); //Update user info $app->post("/userhome", function () use($app) { $user_name = $_POST['user_name']; $user_phone = $_POST['user_phone']; $user_email = $_POST['user_email']; $user = new User($user_name, $user_buy_quantity = null, $user_phone, $user_email, $activity_id = null, $id = null); $user->save(); return $app['twig']->render('userhome.html.twig', array('users' => User::getAll())); }); //Path to update and activity $app->get("/updateactivity/{id}", function () use($app) { return $app['twig']->render('updateactivity.html.twig', array('activity' => $activity)); }); //Update activity info $app->post("/updateactivity/{id}", function () use($app) { $activity_name = $_POST['activity_name']; $activity_date = $_POST['activity_date']; $activity_location = $_POST['activity_location']; $activity_description = $_POST['activity_description']; $activity_price = $_POST['activity_price']; $activity_quantity = $_POST['activity_quantity']; $activity = new Activity($activity_name, $activity_date, $activity_location, $activity_description, $activity_price, $activity_quantity, $business_id = null, $activity_category_id = null, $id = null); $activity->save(); return $app['twig']->render('updateactivity.html.twig', array('activities' => Activity::getAll())); }); return $app;
static function find($search_id) { $found_activity = NULL; $activities = Activity::getAll(); foreach ($activities as $activity) { $activity_id = $activity->getId(); if ($activity_id == $search_id) { $found_activity = $activity; } } return $found_activity; }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2'); $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson'); $superContactId2 = self::getModelIdByModelNameAndName('Contact', 'superContact2 superContact2son'); $superContactId3 = self::getModelIdByModelNameAndName('Contact', 'superContact3 superContact3son'); $account = Account::getById($superAccountId); $account2 = Account::getById($superAccountId2); $contact = Contact::getById($superContactId); $contact2 = Contact::getById($superContactId2); $contact3 = Contact::getById($superContactId3); //confirm no existing activities exist $activities = Activity::getAll(); $this->assertEquals(0, count($activities)); //Test just going to the create from relation view. $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->runControllerWithNoExceptionsAndGetContent('meetings/default/createFromRelation'); //add related meeting for account using createFromRelation action $activityItemPostData = array('Account' => array('id' => $superAccountId)); $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeeting', 'startDateTime' => '11/1/2011 7:45 PM'))); $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/createFromRelation'); //now test that the new meeting exists, and is related to the account. $meetings = Meeting::getAll(); $this->assertEquals(1, count($meetings)); $this->assertEquals('myMeeting', $meetings[0]->name); $this->assertEquals(1, $meetings[0]->activityItems->count()); $activityItem1 = $meetings[0]->activityItems->offsetGet(0); $this->assertEquals($account, $activityItem1); //test viewing the existing meeting in a details view $this->setGetArray(array('id' => $meetings[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details'); //test editing an existing meeting and saving. Add a second relation, to a contact. //First just go to the edit view and confirm it loads ok. $this->setGetArray(array('id' => $meetings[0]->id, 'redirectUrl' => 'someRedirect')); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('meetings/default/edit'); //Save changes via edit action. $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId)); $this->setGetArray(array('id' => $meetings[0]->id, 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeetingX'))); $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/edit'); //Confirm changes applied correctly. $meetings = Meeting::getAll(); $this->assertEquals(1, count($meetings)); $this->assertEquals('myMeetingX', $meetings[0]->name); $this->assertEquals(2, $meetings[0]->activityItems->count()); $activityItem1 = $meetings[0]->activityItems->offsetGet(0); $activityItem2 = $meetings[0]->activityItems->offsetGet(1); $this->assertEquals($account, $activityItem1); $this->assertEquals($contact, $activityItem2); //Remove contact relation. Switch account relation to a different account. $activityItemPostData = array('Account' => array('id' => $superAccountId2)); $this->setGetArray(array('id' => $meetings[0]->id)); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeetingX'))); $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/edit'); //Confirm changes applied correctly. $meetings = Meeting::getAll(); $this->assertEquals(1, count($meetings)); $this->assertEquals('myMeetingX', $meetings[0]->name); $this->assertEquals(1, $meetings[0]->activityItems->count()); $activityItem1 = $meetings[0]->activityItems->offsetGet(0); $this->assertEquals($account2, $activityItem1); //test removing a meeting. $this->setGetArray(array('id' => $meetings[0]->id)); $this->resetPostArray(); $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/delete'); //Confirm no more meetings exist. $meetings = Meeting::getAll(); $this->assertEquals(0, count($meetings)); //Test adding a meeting with multiple contacts $contactItemPrefix = Meeting::CONTACT_ATTENDEE_PREFIX; $meetingAttendeesData = $contactItemPrefix . $superContactId . ',' . $contactItemPrefix . $superContactId2 . ',' . $contactItemPrefix . $superContactId3; $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('ids' => $meetingAttendeesData)); // Not Coding Standard $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeeting2', 'startDateTime' => '11/1/2011 7:45 PM'))); $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/createFromRelation'); //now test that the new meeting exists, and is related to the account. $meetings = Meeting::getAll(); $this->assertEquals(1, count($meetings)); $this->assertEquals('myMeeting2', $meetings[0]->name); $this->assertEquals(4, $meetings[0]->activityItems->count()); $activityItem1 = $meetings[0]->activityItems->offsetGet(0); $this->assertEquals($account, $activityItem1); }
public function doWebRedActivity() { global $_W, $_GPC; if (!$_W['ispost']) { $this->doWebAuth(); checklogin(); } $modulePublic = '../addons/wwx_fxxt/style/static/'; $foo = $_GPC['foo']; $foos = array('list', 'create', 'modify', 'delete', 'records'); $foo = in_array($foo, $foos) ? $foo : 'list'; require_once WWX_FXXT_ROOT . '/class/Activity.class.php'; if ($foo == 'create') { if ($_W['ispost']) { $input = $_GPC; $input['rules'] = htmlspecialchars_decode($input['rules']); $input['start'] = strtotime($input['time']['start'] . ':00'); $input['end'] = strtotime($input['time']['end'] . ':59'); $input['share'] = serialize($input['share']); $input['limit'] = serialize($input['limit']); if ($input['type'] == 'game') { $input['tag'] = serialize($input['game']); } elseif ($input['type'] == 'shared') { $input['tag'] = serialize($input['shared']); } else { $input['tag'] = serialize($input['tag']); } $gifts = array(); foreach ($input['gifts']['id'] as $k => $v) { $gifts[] = array('gift' => $v, 'quantity' => $input['gifts']['quantity'][$k], 'rate' => $input['gifts']['rate'][$k]); } $a = new Activity(); $ret = $a->create($input, $gifts); /**Activity:1.保存活动**/ if (is_error($ret)) { message($ret['message']); } else { message("成功创建活动", $this->createWebUrl('redactivity')); } } $activity = array(); $time = array(); $time['start'] = date('Y-m-d 00:00'); $time['end'] = date('Y-m-d 15:00'); $activity['gifts'] = array(); $activity['type'] = 'shared'; load()->func('tpl'); include $this->template('redactivity_form'); } if ($foo == 'modify') { $id = $_GPC['id']; $id = intval($id); $a = new Activity(); $activity = $a->getOne($id); /**Activity:2.根据活动ID查询活动内容及设置等**/ if (empty($activity)) { $this->error('访问错误'); } if ($_W['ispost']) { $input = $_GPC; $input['rules'] = htmlspecialchars_decode($input['rules']); $input['start'] = strtotime($input['time']['start'] . ':00'); $input['end'] = strtotime($input['time']['end'] . ':59'); $input['share'] = serialize($input['share']); $input['limit'] = serialize($input['limit']); if ($input['type'] == 'game') { $input['tag'] = serialize($input['game']); } elseif ($input['type'] == 'shared') { $input['tag'] = serialize($input['shared']); } else { $input['tag'] = serialize($input['tag']); } $gifts = array(); foreach ($input['gifts']['id'] as $k => $v) { $gifts[] = array('gift' => $v, 'quantity' => $input['gifts']['quantity'][$k], 'rate' => $input['gifts']['rate'][$k]); } $a = new Activity(); $ret = $a->modify($id, $input, $gifts); /**Activity:3.根据活动ID编辑活动内容及设置等**/ if (is_error($ret)) { message($ret['message']); } else { message("成功编辑活动", $this->createWebUrl('redactivity')); } } $time = array(); $time['start'] = date('Y-m-d H:i', $activity['start']); $time['end'] = date('Y-m-d H:i', $activity['end']); if ($activity['type'] == 'game') { $game = $activity['tag']; } elseif ($activity['type'] == 'shared') { $shared = $activity['tag']; } load()->func('tpl'); include $this->template('redactivity_form'); } if ($foo == 'records') { $id = $_GPC['id']; $id = intval($id); $a = new Activity(); $activity = $a->getOne($id); /**Activity:2.根据活动ID查询活动内容及设置等**/ if (empty($activity)) { $this->error('访问错误'); } $filters = array(); $filters['activity'] = $id; $filters['nickname'] = $_GPC['nickname']; $pindex = intval($_GPC['page']); $pindex = max($pindex, 1); $psize = 20; $total = 0; $ds = $a->getRecords($filters, $pindex, $psize, $total); /**Activity:4.分页活动列表**/ $pager = pagination($total, $pindex, $psize); include $this->template('redactivity_records'); } if ($foo == 'delete') { $id = $_GPC['id']; $id = intval($id); $a = new Activity(); $ret = $a->remove($id); /**Activity:5.删除活动**/ if (is_error($ret)) { message($ret['message']); } else { message('操作成功', $this->createWebUrl('redactivity')); } } if ($foo == 'list') { $a = new Activity(); $ds = $a->getAll(array()); /**Activity:6.查询所有活动**/ if (is_array($ds)) { foreach ($ds as &$row) { $url = $this->createMobileUrl('redactivity', array('actid' => $row['actid'])); $row['surl'] = $url; $url = substr($url, 2); $url = $_W['siteroot'] . 'app/' . $url; $row['url'] = $url; $row['count'] = $a->calcCount($row['actid']); /**Activity:7.查询活动礼品信息:总数量、已发放、还剩余。**/ } unset($row); } include $this->template('redactivity_list'); } }
$app->post("/businesshome", function () use($app) { $business_name = $_POST['business_name']; $business_phone = $_POST['business_phone']; $business_contact = $_POST['business_contact']; $business_website = $_POST['business_website']; $business_address = $_POST['business_address']; $business_contact_email = $_POST['business_contact_email']; $business = new Business($business_name, $business_phone, $business_contact, $business_website, $business_address, $business_contact_email, $business_category_id = null, $id = null); $business->save(); return $app['twig']->render('businesshome.html.twig', array('businesses' => Business::getAll())); }); //specific business viewing page to be viewed by the user. //(NEED TO FINALIZE ARRAY!!!) $app->get("/business/{id}", function ($id) use($app) { $business = Business::find($id); return $app['twig']->render('business.html.twig', array('business' => $business, 'all_activities' => Activity::getAll())); }); //Path to update business info --- NOT FINISHED AND NEEDS PROPER THINGS! $app->get("/updatebusiness", function () use($app) { return $app['twig']->render('updatebusiness.html.twig', array('businesses' => Business::getAll)); }); //path to userhome for viewing current users and adding new $app->get("/userhome", function () use($app) { return $app['twig']->render('userhome.html.twig', array('users' => User::getAll())); }); //path to specific users account info and activity info $app->get("/updateuser/{id}", function () use($app) { return $app['twig']->render('updateuser.html.twig', array('users' => User::getAll())); }); //Update info $app->post("/userhome", function () use($app) {
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2'); $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson'); $account = Account::getById($superAccountId); $account2 = Account::getById($superAccountId2); $contact = Contact::getById($superContactId); //confirm no existing activities exist $activities = Activity::getAll(); $this->assertEquals(0, count($activities)); //Test just going to the create from relation view. $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->runControllerWithNoExceptionsAndGetContent('notes/default/createFromRelation'); //add related note for account using createFromRelation action $activityItemPostData = array('account' => array('id' => $superAccountId)); $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNote'))); $this->runControllerWithRedirectExceptionAndGetContent('notes/default/createFromRelation'); //now test that the new note exists, and is related to the account. $notes = Note::getAll(); $this->assertEquals(1, count($notes)); $this->assertEquals('myNote', $notes[0]->description); $this->assertEquals(1, $notes[0]->activityItems->count()); $activityItem1 = $notes[0]->activityItems->offsetGet(0); $this->assertEquals($account, $activityItem1); //test viewing the existing note in a details view $this->setGetArray(array('id' => $notes[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('notes/default/details'); //test editing an existing note and saving. //First just go to the edit view and confirm it loads ok. $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect')); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('notes/default/edit'); //Save changes via edit action. $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId)); $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNoteX'))); $this->runControllerWithRedirectExceptionAndGetContent('notes/default/edit'); //Confirm changes applied correctly. $notes = Note::getAll(); $this->assertEquals(1, count($notes)); $this->assertEquals('myNoteX', $notes[0]->description); $this->assertEquals(2, $notes[0]->activityItems->count()); $activityItem1 = $notes[0]->activityItems->offsetGet(0); $activityItem2 = $notes[0]->activityItems->offsetGet(1); $this->assertEquals($account, $activityItem1); $this->assertEquals($contact, $activityItem2); //Remove contact relation. Switch account relation to a different account. $activityItemPostData = array('Account' => array('id' => $superAccountId2)); $this->setGetArray(array('id' => $notes[0]->id)); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNoteX'))); $this->runControllerWithRedirectExceptionAndGetContent('notes/default/edit'); //Confirm changes applied correctly. $notes = Note::getAll(); $this->assertEquals(1, count($notes)); $this->assertEquals('myNoteX', $notes[0]->description); $this->assertEquals(1, $notes[0]->activityItems->count()); $activityItem1 = $notes[0]->activityItems->offsetGet(0); $this->assertEquals($account2, $activityItem1); //Test validating an existing note via the inline edit validation (failed Validation) $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId)); $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'ajax' => 'inline-edit-form', 'Note' => array('description' => ''))); $content = $this->runControllerWithExitExceptionAndGetContent('notes/default/inlineCreateSave'); $this->assertTrue(strlen($content) > 20); //approximate, but should definetely be larger than 20. //Test validating an existing note via the inline edit validation (Success) $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'ajax' => 'inline-edit-form', 'Note' => array('description' => 'a Valid Name of a Note'))); $content = $this->runControllerWithExitExceptionAndGetContent('notes/default/inlineCreateSave'); $this->assertEquals('[]', $content); //Test saving an existing note via the inline edit validation $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'a Valid Name of a Note'))); $content = $this->runControllerWithRedirectExceptionAndGetContent('notes/default/inlineCreateSave'); //Confirm changes applied correctly. $notes = Note::getAll(); $this->assertEquals(2, count($notes)); $this->assertEquals('a Valid Name of a Note', $notes[1]->description); //test removing a note. $this->setGetArray(array('id' => $notes[1]->id)); $this->resetPostArray(); $this->runControllerWithRedirectExceptionAndGetContent('notes/default/delete'); //Confirm no more notes exist. $notes = Note::getAll(); $this->assertEquals(1, count($notes)); }
function testDelete() { //Arrange $activity_name = "Activity One"; $activity_date = '2016-01-01'; $activity_location = "Location"; $activity_description = "Description of Activity One"; $activity_price = "Price of Activity One"; $activity_quantity = 10; $business_id = 11; $activity_category_id = 12; $id = 1; $test_activity = new Activity($activity_name, $activity_date, $activity_location, $activity_description, $activity_price, $activity_quantity, $business_id, $activity_category_id, $id = null); $test_activity->save(); $activity_name2 = "Activity Two"; $activity_date2 = '2016-02-02'; $activity_location2 = "Location Two"; $activity_description2 = "Description of Activity Two"; $activity_price2 = "Price of Activity Two"; $activity_quantity2 = 20; $business_id2 = 21; $activity_category_id2 = 22; $id2 = 2; $test_activity2 = new Activity($activity_name, $activity_date, $activity_location, $activity_description, $activity_price, $activity_quantity, $business_id, $activity_category_id, $id = null); $test_activity2->save(); //Act $test_activity2->delete(); $result = Activity::getAll(); //Assert $this->assertEquals([$test_activity], $result); }
$url = $_W['siteroot'] . 'app/' . $url; $activity['url'] = $url; include $this->template('activity-devices'); } if ($foo == 'delete') { $id = $_GPC['id']; $id = intval($id); $a = new Activity(); $activity = $a->getOne($id); if (!empty($activity)) { $api = new Api(); $api->deletePage($activity['page']); } $ret = $a->remove($id); if (is_error($ret)) { message($ret['message']); } else { message('操作成功', $this->createWebUrl('activity')); } } if ($foo == 'list') { $a = new Activity(); $ds = $a->getAll(array()); if (is_array($ds)) { foreach ($ds as &$row) { $row['count'] = $a->calcCount($row['actid']); } unset($row); } include $this->template('activity-list'); }