/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $dCopy = $data; $data = ['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'bdate' => $data['bdate'], 'gender' => $data['gender'] - 1, 'daily_calories' => $data['daily_calories']]; $user = User::create($data); $restrictions = Restriction::all(); //cannot eat(0); can eat(1) foreach ($restrictions as $restr) { if ($dCopy['restriction' . $restr->id] - 1 == 1) { $user->addRestriction($restr); } } return $user; }
public function testRegister() { $birthday = new Carbon(); $birthday->addYear(-23); $this->visit('/auth/register')->type('user1', 'name')->type('*****@*****.**', 'email')->type('useruser', 'password')->type('useruser', 'password_confirmation')->type($birthday->toDateTimeString(), 'bdate')->select('1', 'gender')->type('2000', 'daily_calories'); $map = []; $restrictions = Restriction::all(); foreach ($restrictions as $restriction) { $val = round(mt_rand() / mt_getrandmax()); $map[$restriction->id] = $val; $this->type($val + 1, 'restriction' . ($restriction->id + 1)); } $this->press('Register')->seePageIs('/home'); $this->seeInDatabase('users', ['name' => 'user1', 'email' => '*****@*****.**', 'bdate' => $birthday->toDateString(), 'gender' => '0', 'daily_calories' => '2000']); $user = \App\User::whereEmail('*****@*****.**')->first(); foreach ($restrictions as $restriction) { if ($map[$restriction->id] == 1) { $this->seeInDatabase('restriction_user', ['user_id' => $user->id, 'restriction_id' => $restriction->id]); } } }