1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-16 07:02:31 +01:00
flox/backend/tests/Setting/UserTest.php

89 lines
2.0 KiB
PHP
Raw Normal View History

2016-12-16 14:06:50 +01:00
<?php
use Illuminate\Foundation\Testing\DatabaseMigrations;
2016-12-19 08:34:53 +01:00
use Illuminate\Support\Facades\Hash;
2016-12-16 14:06:50 +01:00
class UserTest extends TestCase {
use DatabaseMigrations;
protected $user;
public function setUp()
{
parent::setUp();
$this->user = factory(App\User::class)->create();
}
/** @test */
public function change_user_data_only_if_user_is_logged_in()
{
$this->json('PATCH', 'api/userdata', [
'username' => 'Ganta',
'password' => 'Igarashi',
]);
$this->seeStatusCode(401);
}
/** @test */
public function save_new_username()
{
$this->assertNotEquals('Ganta', $this->user->username);
$this->actingAs($this->user)->json('PATCH', 'api/userdata', [
'username' => 'Ganta',
'password' => 'Igarashi',
]);
$this->assertEquals('Ganta', $this->user->username);
}
/** @test */
public function save_new_password()
{
$this->actingAs($this->user)->json('PATCH', 'api/userdata', [
'username' => 'Ganta',
'password' => 'Igarashi'
]);
2016-12-19 08:34:53 +01:00
$this->assertTrue(Hash::check('Igarashi', $this->user->password));
2016-12-16 14:06:50 +01:00
}
/** @test */
public function change_password_only_if_new_password_is_given()
{
$oldPassword = $this->user->password;
$this->actingAs($this->user)->json('PATCH', 'api/userdata', [
'username' => 'Ganta',
'password' => ''
]);
$this->assertEquals($oldPassword, $this->user->password);
}
/** @test */
public function user_can_login_with_correct_credentials()
{
$this->json('POST', 'api/login', [
'username' => $this->user->username,
'password' => 'secret',
]);
$this->seeStatusCode(200);
}
/** @test */
public function user_can_not_login_with_wrong_credentials()
{
$this->json('POST', 'api/login', [
'username' => $this->user->username,
'password' => 'wrong_password',
]);
$this->seeStatusCode(401);
}
}