Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Illuminate\Foundation\Testing\WithoutMiddleware;
- //use Illuminate\Foundation\Testing\DatabaseMigrations;
- use Illuminate\Foundation\Testing\DatabaseTransactions;
- class UserTest extends TestCase {
- use DatabaseTransactions;
- public function setUp() {
- parent::setUp();
- Session::start();
- $this->faker = factory(App\Models\User::class)->create();
- }
- public function testEmptyLogin() {
- $this->visit("/")
- ->type("", "login")
- ->type("", "password")
- ->press("Zaloguj")
- ->seePageIs("/login")
- ->dontSee("Cześć")
- ->see("Login jest wymagany.")
- ->see("Proszę podać hasło.")
- ->see("Logowanie");
- }
- public function testSimpleFailLogin() {
- $this->visit("/")
- ->type("badLogin", "login")
- ->type("badPass", "password")
- ->press("Zaloguj")
- ->seePageIs("/login")
- ->dontSee("Cześć")
- ->see("Wprowadzono błędny login lub hasło.")
- ->see("Logowanie");
- }
- public function testSimpleSuccessLoginLogout() {
- $this->visit("/")
- ->type("ttest", "login")
- ->type("test", "password")
- ->press("Zaloguj")
- ->seePageIs("/")
- ->dontSee("Logowanie")
- ->see("Cześć, Test!");
- $response = $this->call("POST", "/logout", ["_token" => csrf_token()]);
- $this->assertEquals(302, $response->status());
- $this->assertRedirectedToRoute("login");
- $this->visit("/login")
- ->seePageIs("/login")
- ->see("Poprawnie wylogowano.");
- }
- public function testFactoryLoginLogout() {
- // Potrzebny prepareValue?
- $login = mb_strtolower(mb_substr($this->faker->first_name, 0, 1) . $this->faker->last_name);
- //$password = $this->faker->first_name . $this->faker->last_name;
- $password = "test";
- $response = $this->call("POST", "/login", ["_token" => csrf_token(), "login" => $login, "password" => $password]);
- $this->assertEquals(302, $response->status());
- $this->assertRedirectedToRoute("home");
- $this->visit("/")
- ->dontSee("Logowanie")
- ->see("Cześć, " . $this->faker->first_name . "!");
- $response = $this->call("POST", "/logout", ["_token" => csrf_token()]);
- $this->assertEquals(302, $response->status());
- $this->assertRedirectedToRoute("login");
- $this->visit("/login")
- ->seePageIs("/login")
- ->see("Poprawnie wylogowano.");
- }
- public function testFactoryUserSoftDelete() {
- $this->withoutMiddleware();
- $response = $this->call("DELETE", "/user/delete/" . $this->faker->id, ["_token" => csrf_token()]);
- $this->assertEquals(302, $response->getStatusCode());
- $this->seeInDatabase("users", ["id" => $this->faker->id])
- ->notSeeInDatabase("users", ["id" => $this->faker->id, "deleted_at" => null]);
- }
- /*public function testFactoryUserForceDelete() {
- $id = $this->faker->id;
- $this->faker->forceDelete();
- $this->notSeeInDatabase("users", ["id" => $id])
- ->notSeeInDatabase("assigned_roles", ["user_id" => $id]);
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement