Ejemplo n.º 1
0
 /**
  * @test
  */
 public function canRegisterANewAccountWithSurvey()
 {
     $email = 'actest' . time() . '@testerson.com';
     $this->visit('/register')->type($email, 'email')->type($this->password, 'password')->type($this->password, 'password_confirmation')->press('Register')->seePageIs('/login')->see('Please follow the link in the confirmation email we just sent you.');
     // skip the email confirmation step
     User::where('email', $email)->update(['status' => User::STATUS_CONFIRMED]);
     $this->login($email, $this->password)->type('Johnson', 'first_name')->type('Johnson', 'last_name')->type('1234567890', 'phone')->type('123 Test Street', 'address_one')->type('Apt 1', 'address_two')->type('40241', 'zip_code');
     $answerId = 4;
     $otherText = uniqid();
     $this->check('answer[1][' . $answerId . ']')->check('answer[1][7]')->type($otherText, 'other[1]')->press('Save')->seePageIs('/dashboard');
     $user = User::where('email', $email)->first();
     $otherAnswer = RegistrationSurveyAnswer::where('question_id', 1)->where('answer', 'Other')->first();
     $userSurvey = $user->surveys->get(2);
     $this->assertEquals($answerId, $user->surveys->first()->answer_id);
     $this->assertEquals($otherAnswer->id, $userSurvey->answer_id);
     $this->assertEquals($otherText, $userSurvey->other);
 }
Ejemplo n.º 2
0
 /**
  * @return mixed
  */
 public function postSetup(Request $request, Scrubber $scrubber)
 {
     $request->merge(['name' => 'Home', 'phone' => $scrubber->integer($request->get('phone'))]);
     $userRules = array_only(User::validationRules(), ['gender', 'phone', 'first_name', 'last_name']);
     $this->validate($request, array_merge(Address::validationRules(), $userRules), Address::validationMessages());
     //update the info
     DB::transaction(function () use($request) {
         $user = Auth::user();
         $user->first_name = $request->get('first_name');
         $user->last_name = $request->get('last_name');
         $user->phone = $request->get('phone');
         $user->gender = $request->get('gender');
         $user->save();
         // set timezone
         $settings = $user->settings;
         $settings->setTimezone($request->input('timezone'));
         $user->update(['settings' => $settings]);
         // add user address
         $address = App::make(Address::class, [$request->except(['first_name', 'last_name', 'phone', 'gender', 'timezone', 'answer', 'other'])]);
         $user->addresses()->save($address);
         $user->update(['primary_address_id' => $address->id]);
         // record survey
         if ($request->has('answer') && count($request->get('answer')) > 0) {
             $surveys = [];
             foreach ($request->get('answer') as $questionId => $answers) {
                 foreach ($answers as $answerId => $true) {
                     $surveys[] = app(RegistrationSurvey::class, [['answer_id' => $answerId]]);
                 }
                 // update that question's "Other"
                 if ($request->has('other.' . $questionId) && strlen($request->get('other')[$questionId]) > 0) {
                     $otherAnswer = RegistrationSurveyAnswer::where('question_id', $questionId)->where('answer', 'Other')->first();
                     $surveys[] = app(RegistrationSurvey::class, [['answer_id' => $otherAnswer->id, 'other' => $request->get('other')[$questionId]]]);
                 }
             }
             $user->surveys()->saveMany($surveys);
         }
     });
     return redirect('/dashboard');
 }