Browse Source

adding some basic auth tests.

Taylor Otwell 12 years ago
parent
commit
f4e1eaf29e
2 changed files with 72 additions and 1 deletions
  1. 3 1
      phpunit.xml
  2. 69 0
      tests/cases/laravel/auth.test.php

+ 3 - 1
phpunit.xml

@@ -1,4 +1,6 @@
-<phpunit colors="true" bootstrap="phpunit.php">
+<phpunit colors="true"
+         bootstrap="phpunit.php"
+         backupGlobals="false">
 	<testsuites>
 		<testsuite name="Test Suite">
 			<directory suffix=".test.php">tests/cases</directory>

+ 69 - 0
tests/cases/laravel/auth.test.php

@@ -0,0 +1,69 @@
+<?php
+
+class AuthTest extends PHPUnit_Framework_TestCase {
+
+	/**
+	 * Test the Auth::user method.
+	 *
+	 * @group laravel
+	 */
+	public function testUserMethodReturnsCurrentUser()
+	{
+		Auth::$user = 'Taylor';
+
+		$this->assertEquals('Taylor', Auth::user());
+	}
+
+	/**
+	 * Test the Auth::check method.
+	 *
+	 * @group laravel
+	 */
+	public function testCheckMethodReturnsTrueWhenUserIsSet()
+	{
+		$this->assertTrue(AuthUserReturnsDummy::check());
+	}
+
+	/**
+	 * Test the Auth::check method.
+	 *
+	 * @group laravel
+	 */
+	public function testCheckMethodReturnsFalseWhenNoUserIsSet()
+	{
+		$this->assertFalse(AuthUserReturnsNull::check());
+	}
+
+	/**
+	 * Test the Auth::guest method.
+	 *
+	 * @group laravel
+	 */
+	public function testGuestReturnsTrueWhenNoUserIsSet()
+	{
+		$this->assertTrue(AuthUserReturnsNull::guest());
+	}
+
+	/**
+	 * Test the Auth::guest method.
+	 *
+	 * @group laravel
+	 */
+	public function testGuestReturnsFalseWhenUserIsSet()
+	{
+		$this->assertFalse(AuthUserReturnsDummy::guest());
+	}
+
+}
+
+class AuthUserReturnsNull extends Laravel\Auth {
+
+	public static function user() {}
+
+}
+
+class AuthUserReturnsDummy extends Laravel\Auth {
+
+	public static function user() { return 'Taylor'; }
+
+}