public function testActivate() { $code = '123456789abc'; $mock = m::mock(); $mock->shouldReceive('attemptActivation')->with($code)->once()->andReturn(true); Sentry::shouldReceive('findUserById')->with(1)->once()->andReturn($mock); $this->assertTrue($this->users->activate(1, $code)); $mock->shouldReceive('attemptActivation')->once()->andReturn(false); Sentry::shouldReceive('findUserById')->with(1)->once()->andReturn($mock); $this->assertFalse($this->users->activate(1, $code)); $this->assertNotNull($this->users->getError()); Sentry::shouldReceive('findUserById')->once()->andThrow('Cartalyst\\Sentry\\Users\\UserNotFoundException'); $this->assertFalse($this->users->activate(10, $code)); $this->assertNotNull($this->users->getError()); Sentry::shouldReceive('findUserById')->once()->andThrow('Cartalyst\\Sentry\\Users\\UserAlreadyActivatedException'); $this->assertFalse($this->users->activate(2, $code)); $this->assertNotNull($this->users->getError()); }
/** * Attempt to activate user with code. * * @param int $id * @param string $code * @return \Illuminate\Http\RedirectResponse */ public function activate($id, $code) { if ($this->auth->check()) { return Redirect::route('profile.index'); } if ($this->users->activate($id, $code)) { return Redirect::route('session.create')->with('success_activation', true); } return Redirect::route('session.create')->with('error_activation', $this->users->getError()); }
/** * Activate the specified user in storage. * * @param int $id * @return \Illuminate\Http\RedirectResponse */ public function activate($id) { $this->users->activate($id, $this->users->findById($id)->getActivationCode()); return Redirect::route('users.index'); }