فهرست منبع

Added logout test

Sergio Brighenti 4 سال پیش
والد
کامیت
00ae95e965
1فایلهای تغییر یافته به همراه28 افزوده شده و 1 حذف شده
  1. 28 1
      tests/Feature/Auth/LoginControllerTest.php

+ 28 - 1
tests/Feature/LoginControllerTest.php → tests/Feature/Auth/LoginControllerTest.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 
 
 
 
-namespace Tests\Feature;
+namespace Tests\Feature\Auth;
 
 
 use Tests\TestCase;
 use Tests\TestCase;
 
 
@@ -102,4 +102,31 @@ class LoginControllerTest extends TestCase
         $redirect = $this->submitForm($form)->getHeaderLine('Location');
         $redirect = $this->submitForm($form)->getHeaderLine('Location');
         $this->assertSame(route('profile'), $redirect);
         $this->assertSame(route('profile'), $redirect);
     }
     }
+
+    /** @test */
+    public function it_logout_the_user()
+    {
+        $this->createAdminUser();
+
+        $response = $this->get(route('login.show'));
+        $form = $this->getCrawler($response)
+            ->selectButton('Login')
+            ->form([
+                'username' => 'admin@example.com',
+                'password' => 'admin',
+                'remember' => 'on',
+            ], 'POST');
+
+        $this->submitForm($form);
+        $this->assertSame(200, $response->getStatusCode());
+
+        $response = $this->post(route('logout'));
+        $this->assertSame(302, $response->getStatusCode());
+
+        $response = $this->get(route('home'));
+        $this->assertSame(302, $response->getStatusCode());
+        $this->assertSame(route('login.show'), $response->getHeaderLine('Location'));
+
+        $this->assertFalse($this->app->getContainer()->get('session')->get('logged'));
+    }
 }
 }