function testCreatePair() { $staff_1 = new Staff(); $staff_1->set(array('first_name' => 'First', 'last_name' => 'User')); $staff_1->save(); $staff_2 = new Staff(); $staff_2->set(array('first_name' => 'Second', 'last_name' => 'User')); $staff_2->save(); $h = new Hour(); $h->set(array('hours' => 6, 'staff_id' => $staff_1->id, 'pair_id' => $staff_2->id)); $h->updateOrCreateWithPair(); $this->assertTrue($h->id, 'should have an id'); $this->assertTrue($h->get('pair_hour_id'), 'should have a pair hour id'); $h2 = $h->getPairHour(); $this->assertIsA($h2, 'Hour'); $this->assertTrue($h2->id, 'should have an hour id'); $this->assertEqual($h2->get('hours'), 6); $h->set(array('hours' => 7)); $h->updateOrCreateWithPair(); $h3 = $h->getPairHour(); $this->assertEqual($h2->id, $h3->id); $this->assertEqual($h3->get('hours'), 7); $this->assertEqual($h3->getPairName(), $staff_1->getName()); $this->assertEqual($h->getPairName(), $staff_2->getName()); }
function destroy($params) { if (!$params['id']) { bail('Required $params["id"] not present.'); } $h = new Hour($params['id']); $support_contract_id = $h->get('support_contract_id'); $h->destroy(); isset($params['redirect']) ? $redirect = $params['redirect'] : ($redirect = array('controller' => 'SupportContract', 'action' => 'show', 'id' => $support_contract_id)); $this->redirectTo($redirect); }
function testCreateFormForOneObject() { $hour = new Hour(); $hour->set(array('description' => 'SimpleTest Hour Description 2', 'support_contract_id' => 1, 'date' => '2010-02-20', 'hours' => '2.5', 'discount' => '1')); $hour->save(); $hour_id = $hour->get('id'); $form = new Form(array('controller' => 'Hour', 'action' => 'update', 'method' => 'post')); $f = $form->getFieldSetFor($hour); $html = $f->description; $html .= $f->hours; $html .= $f->discount; $form->content = $html; $form_html = $form->html; $correct_html = '<form method="post" action="index.php" class = "standard-form" > <input type="hidden" name="controller" value="Hour"/> <input type="hidden" name="action" value="update"/> <input type="text" value="SimpleTest Hour Description 2" id = "ActiveRecord[Hour][' . $hour_id . '][description]" class = "description-field Hour-field text-field" name = "ActiveRecord[Hour][' . $hour_id . '][description]" /><input type="text" value="2.5" id = "ActiveRecord[Hour][' . $hour_id . '][hours]" class = "hours-field Hour-field float-field" name = "ActiveRecord[Hour][' . $hour_id . '][hours]" /><input type="text" value="1" id = "ActiveRecord[Hour][' . $hour_id . '][discount]" class = "discount-field Hour-field float-field" name = "ActiveRecord[Hour][' . $hour_id . '][discount]" /><div class="submit-container"><input type="submit" class="submit_btn" value="submit"/></div> </form> '; $this->assertEqual($correct_html, $form_html); $hour->delete(); }