Advertisement
Guest User

Untitled

a guest
May 10th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.87 KB | None | 0 0
  1. <?php
  2.  
  3. use Illuminate\Foundation\Testing\WithoutMiddleware;
  4. //use Illuminate\Foundation\Testing\DatabaseMigrations;
  5. use Illuminate\Foundation\Testing\DatabaseTransactions;
  6.  
  7. class UserTest extends TestCase {
  8.  
  9.     use DatabaseTransactions;
  10.  
  11.     public function setUp() {
  12.         parent::setUp();
  13.         Session::start();
  14.  
  15.         $this->faker = factory(App\Models\User::class)->create();
  16.     }
  17.  
  18.     public function testEmptyLogin() {
  19.         $this->visit("/")
  20.             ->type("", "login")
  21.             ->type("", "password")
  22.             ->press("Zaloguj")
  23.             ->seePageIs("/login")
  24.             ->dontSee("Cześć")
  25.             ->see("Login jest wymagany.")
  26.             ->see("Proszę podać hasło.")
  27.             ->see("Logowanie");
  28.     }
  29.  
  30.     public function testSimpleFailLogin() {
  31.         $this->visit("/")
  32.             ->type("badLogin", "login")
  33.             ->type("badPass", "password")
  34.             ->press("Zaloguj")
  35.             ->seePageIs("/login")
  36.             ->dontSee("Cześć")
  37.             ->see("Wprowadzono błędny login lub hasło.")
  38.             ->see("Logowanie");
  39.     }
  40.  
  41.     public function testSimpleSuccessLoginLogout() {
  42.         $this->visit("/")
  43.             ->type("ttest", "login")
  44.             ->type("test", "password")
  45.             ->press("Zaloguj")
  46.             ->seePageIs("/")
  47.             ->dontSee("Logowanie")
  48.             ->see("Cześć, Test!");
  49.  
  50.         $response = $this->call("POST", "/logout", ["_token" => csrf_token()]);
  51.  
  52.         $this->assertEquals(302, $response->status());
  53.         $this->assertRedirectedToRoute("login");
  54.  
  55.         $this->visit("/login")
  56.             ->seePageIs("/login")
  57.             ->see("Poprawnie wylogowano.");
  58.     }
  59.  
  60.     public function testFactoryLoginLogout() {
  61.         // Potrzebny prepareValue?
  62.         $login = mb_strtolower(mb_substr($this->faker->first_name, 0, 1) . $this->faker->last_name);
  63.         //$password = $this->faker->first_name . $this->faker->last_name;
  64.         $password = "test";
  65.  
  66.         $response = $this->call("POST", "/login", ["_token" => csrf_token(), "login" => $login, "password" => $password]);
  67.  
  68.         $this->assertEquals(302, $response->status());
  69.         $this->assertRedirectedToRoute("home");
  70.  
  71.         $this->visit("/")
  72.             ->dontSee("Logowanie")
  73.             ->see("Cześć, " . $this->faker->first_name . "!");
  74.  
  75.         $response = $this->call("POST", "/logout", ["_token" => csrf_token()]);
  76.  
  77.         $this->assertEquals(302, $response->status());
  78.         $this->assertRedirectedToRoute("login");
  79.  
  80.         $this->visit("/login")
  81.             ->seePageIs("/login")
  82.             ->see("Poprawnie wylogowano.");
  83.     }
  84.  
  85.     public function testFactoryUserSoftDelete() {
  86.         $this->withoutMiddleware();
  87.  
  88.         $response = $this->call("DELETE", "/user/delete/" . $this->faker->id, ["_token" => csrf_token()]);
  89.         $this->assertEquals(302, $response->getStatusCode());
  90.  
  91.         $this->seeInDatabase("users", ["id" => $this->faker->id])
  92.             ->notSeeInDatabase("users", ["id" => $this->faker->id, "deleted_at" => null]);
  93.     }
  94.  
  95.     /*public function testFactoryUserForceDelete() {
  96.         $id = $this->faker->id;
  97.  
  98.         $this->faker->forceDelete();
  99.         $this->notSeeInDatabase("users", ["id" => $id])
  100.             ->notSeeInDatabase("assigned_roles", ["user_id" => $id]);
  101.     }*/
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement