/** * Impersonate an admin * */ public function beAdmin() { $admin = Sentry::findUserByLogin('*****@*****.**'); Sentry::setUser($admin); Session::put('userId', 1); Session::put('email', '*****@*****.**'); }
public function setUp() { Illuminate\Foundation\Testing\TestCase::setUp(); Artisan::call('migrate', array('--package' => 'cartalyst\\sentry')); // Artisan::call('migrate'); Artisan::call('migrate', array('--package' => 'rtconner\\laravel-addresses')); Artisan::call('db:seed', array('--class' => 'Conner\\Addresses\\DatabaseSeeder')); $user = new \Cartalyst\Sentry\Users\Eloquent\User(); $user->id = 1; \Sentry::setUser($user); }
/** * Test the two basic user types * */ public function testBasicUserTypes() { $this->assertTrue(Sentry::getUser() == NULL, 'User should not be logged in initially.'); $admin = Sentry::findUserByLogin($this->adminEmail); $this->assertTrue($admin != NULL, 'Admin account not found.'); $user = Sentry::findUserByLogin($this->userEmail); $this->assertTrue($user != NULL, 'User account not found.'); Sentry::setUser($user); $this->assertTrue(Sentry::check(), 'User not logged in.'); Sentry::setUser($admin); $this->assertTrue(Sentry::check(), 'Admin not logged in.'); Sentry::logout(); }
/** * Update a user without referencing the username */ public function testUpdatingUserWithAdditionalData() { // Explicitly set the 'additional user fields' app()['config']->set('sentinel.additional_user_fields', ['first_name' => 'alpha_spaces', 'last_name' => 'alpha_spaces']); // Find the user we are going to update $user = Sentry::findUserByLogin('*****@*****.**'); // Find the admin user we are going to impersonate $admin = Sentry::findUserByLogin('*****@*****.**'); Sentry::setUser($admin); // This is the code we are testing $result = $this->repo->update(['id' => $user->id, 'first_name' => 'Irina', 'last_name' => 'Prozorova', 'email' => '*****@*****.**']); // Assertions $this->assertInstanceOf('Sentinel\\Models\\User', $user); $this->assertInstanceOf('Sentinel\\Models\\User', $result->getPayload()['user']); $this->assertTrue($result->isSuccessful()); $testUser = DB::table('users')->where('id', $user->id)->where('first_name', 'Irina')->where('last_name', 'Prozorova')->where('email', '*****@*****.**')->first(); $this->assertEquals('*****@*****.**', $testUser->email); }
/** * Impersonate an admin * */ public function beAdmin() { $admin = Sentry::findUserByLogin($this->adminEmail); Sentry::setUser($admin); Session::put('userId', 1); Session::put('email', $this->adminEmail); }
/** * Impersonate an admin * */ public function beAdmin() { $admin = Sentry::findUserByLogin($this->adminEmail); Sentry::setUser($admin); }