public function testValidationFailsWhenPetitionCreatedByNotAdherent() { $petition = new Petition(); $petition->title = 'Some petition'; $petition->content = 'Petition content'; $petition->mandate_id = 1; $petition->creator_id = $creator_id = 1; $this->assertFalse($petition->save()); $this->assertContains('Petition can be created by mandate\'s adherents only', $petition->getErrors('creator_id'), 'Actual errors: ' . print_r($petition->getErrors('creator_id'), true)); }
public function handleCreatePetition() { $petition = new Petition(); $petition->class_name = Input::get('class_name'); $petition->class_desc = Input::get('class_desc'); $petition->subject = Input::get('subject'); if (!$petition->validate(Input::all())) { return Redirect::back()->withInput()->withErrors(array_merge($petition->getErrors()->toArray())); } else { $petition->save(); return Redirect::to('petitions')->with(array('alert' => 'Successful! Don\'t forget to sign your own petition', 'alert-class' => 'alert-success')); } }
public function testValidationFailsWhenRateCreatedByNotAdherent() { $petition = new Petition(); $petition->title = 'Some petition'; $petition->content = 'Petition content'; $petition->mandate_id = 1; $petition->creator_id = 2; $this->assertTrue($petition->save()); $pRate = new PetitionRate(); $pRate->target_id = $petition->id; $pRate->user_id = 1; $pRate->score = PetitionRate::SCORE_POSITIVE; $this->assertFalse($pRate->save()); $this->assertContains('Petition can be rated by mandate\'s adherents only', $pRate->getErrors('user_id'), 'Actual errors: ' . print_r($petition->getErrors('user_id'), true)); }