public function testCustomFieldNames()
 {
     $this->setExpectedException('fValidationException');
     $_GET['bar'] = 'true';
     try {
         $v = new fValidation();
         $v->overrideFieldName(array('foo' => 'Far', 'bar' => 'BAR'));
         $v->addRequiredFields('foo');
         $v->addIntegerFields('bar');
         $v->validate();
     } catch (fValidationException $e) {
         $this->assertContains('Far: Please enter a value', $e->getMessage());
         $this->assertContains('BAR: Please enter a whole number', $e->getMessage());
         throw $e;
     }
 }
Beispiel #2
0
    include 'views/consumables/addedit.php';
}
/**
 * Edit a consumable
 */
if ($action == 'edit') {
    // Get ID
    $id = fRequest::get('id', 'integer');
    try {
        // Get consumable via ID
        $c = new Consumable($id);
        if (fRequest::isPost()) {
            // Try to validate options
            $validator = new fValidation();
            $validator->addOneOrMoreRule('col_c', 'col_y', 'col_m', 'col_k');
            $validator->overrideFieldName(array('col_c' => 'Colour (Cyan)', 'col_y' => 'Colour (Yellow)', 'col_m' => 'Colour (Magenta)', 'col_k' => 'Colour (Black)'));
            $validator->validate();
            // Update consumable object from POST data and save
            $c->populate();
            $c->linkModels();
            $c->linkTags();
            $c->store();
            // Messaging
            fMessaging::create('affected', fURL::get(), $c->getId());
            fMessaging::create('success', fURL::get(), 'The consumable ' . $c->getName() . ' was successfully updated.');
            fURL::redirect(fURL::get());
        }
    } catch (fNotFoundException $e) {
        fMessaging::create('error', fURL::get(), 'The consumable requested, ID ' . $id . ', could not be found.');
        fURL::redirect(fURL::get());
    } catch (fExpectedException $e) {