Created
June 20, 2015 23:35
-
-
Save iolson/1c81d58313a16aeca047 to your computer and use it in GitHub Desktop.
Laravel 5.1 Package Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @package Dashboard | |
| * @version 1.0.0 | |
| * @author Ian Olson <[email protected]> | |
| * @license MIT | |
| * @copyright 2015, Odot Media LLC | |
| * @link https://odotmedia.com | |
| */ | |
| use Cartalyst\Sentinel\Laravel\Facades\Sentinel; | |
| use Illuminate\Foundation\Testing\DatabaseMigrations; | |
| class AuthTest extends TestCase | |
| { | |
| use DatabaseMigrations; | |
| /** | |
| * Test: View Login | |
| * | |
| * Description: | |
| * This will test that the user will be able to view the login page. | |
| * | |
| * @return void | |
| */ | |
| public function testViewLogin() | |
| { | |
| $this->visit('/auth/login') | |
| ->see('Login'); | |
| } | |
| /** | |
| * Test: Email Validation | |
| * | |
| * Description: | |
| * This will test that the user has entered a valid email into the email field. | |
| * | |
| * @return void | |
| */ | |
| public function testEmailValidation() | |
| { | |
| $this->visit('/auth/login') | |
| ->submitForm('Login', ['email' => 'notemail', 'password' => 'test']) | |
| ->see('The email must be a valid email address.'); | |
| } | |
| /** | |
| * Test: Required Fields | |
| * | |
| * Description: | |
| * This will test that the required fields of the login form have been filled out. | |
| * | |
| * @return void | |
| */ | |
| public function testRequiredFields() | |
| { | |
| $this->visit('/auth/login') | |
| ->submitForm('Login') | |
| ->see('The email field is required.') | |
| ->see('The password field is required.'); | |
| } | |
| /** | |
| * Test: Successful Auth | |
| * | |
| * Description: | |
| * This will test that a user who is registered and activated in the database has successfully logged in | |
| * and is taken to the Dashboard page. | |
| * | |
| * @return void | |
| */ | |
| public function testSuccessAuth() | |
| { | |
| Sentinel::registerAndActivate([ | |
| 'email' => '[email protected]', | |
| 'password' => 'test', | |
| ]); | |
| $this->visit('/auth/login') | |
| ->submitForm('Login', ['email' => '[email protected]', 'password' => 'test']) | |
| ->see('Dashboard'); | |
| } | |
| /** | |
| * Test: Failed Auth | |
| * | |
| * Description: | |
| * This will test that a user who is registered and activated in the database has failed to log in | |
| * and is taken back to the login page and sees that error message. | |
| * | |
| * @return void | |
| */ | |
| public function testFailAuth() | |
| { | |
| Sentinel::registerAndActivate([ | |
| 'email' => '[email protected]', | |
| 'password' => 'test', | |
| ]); | |
| $this->visit('/auth/login') | |
| ->submitForm('Login', ['email' => '[email protected]', 'password' => 'test1']) | |
| ->see('Email \ Password combination incorrect.'); | |
| } | |
| /** | |
| * Test: Logout | |
| * | |
| * Description: | |
| * This will test that a user who is registered and activated in the database has successfully logged in | |
| * and has now chosen to logout. This will log the user out and redirect them to the login page. | |
| * | |
| * @return void | |
| */ | |
| public function testLogout() | |
| { | |
| $user = Sentinel::registerAndActivate([ | |
| 'email' => '[email protected]', | |
| 'password' => 'test', | |
| ]); | |
| Sentinel::login($user); | |
| $this->visit('/auth/logout') | |
| ->see('Login'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "odotmedia/dashboard", | |
| "description": "Laravel 5.1 (LTS) Dashboard Base", | |
| "keywords": [ | |
| "laravel", | |
| "dashboard", | |
| "admin", | |
| "odotmedia" | |
| ], | |
| "homepage": "https://github.com/odotmedia/dashboard", | |
| "license": "MIT", | |
| "authors": [ | |
| { | |
| "name": "Odot Media LLC", | |
| "email": "[email protected]" | |
| }, | |
| { | |
| "name": "Ian Olson", | |
| "email": "[email protected]", | |
| "role": "Developer" | |
| } | |
| ], | |
| "require": { | |
| "php": ">=5.6.0", | |
| "illuminate/support": "~5.1", | |
| "adamwathan/bootforms": "^0.6.3", | |
| "cartalyst/sentinel": "2.0.*", | |
| "laracasts/flash": "~1.3", | |
| "laravelista/ekko": "~1.0.3" | |
| }, | |
| "require-dev": { | |
| "laravel/laravel": "~5.1", | |
| "phpunit/phpunit": "~4.0", | |
| "phpspec/phpspec": "~2.1", | |
| "scrutinizer/ocular": "~1.1", | |
| "fzaninotto/faker": "^1.5" | |
| }, | |
| "repositories": [ | |
| { | |
| "type": "composer", | |
| "url": "https://packages.cartalyst.com" | |
| } | |
| ], | |
| "autoload": { | |
| "classmap": [ | |
| "src/Installer", | |
| "src/Controllers", | |
| "src/Middleware", | |
| "tests" | |
| ], | |
| "psr-4": { | |
| "Odotmedia\\Dashboard\\": "src" | |
| }, | |
| "autoload-dev": { | |
| "psr-4": { | |
| "Odotmedia\\Dashboard\\Test\\": "tests" | |
| } | |
| }, | |
| "scripts": { | |
| "test": "phpunit" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <phpunit backupGlobals="false" | |
| backupStaticAttributes="false" | |
| bootstrap="vendor/autoload.php" | |
| colors="true" | |
| convertErrorsToExceptions="true" | |
| convertNoticesToExceptions="true" | |
| convertWarningsToExceptions="true" | |
| processIsolation="false" | |
| stopOnFailure="false" | |
| syntaxCheck="false"> | |
| <testsuites> | |
| <testsuite name="Dashboard Package Test Suite"> | |
| <directory suffix=".php">./tests/</directory> | |
| </testsuite> | |
| </testsuites> | |
| <filter> | |
| <whitelist> | |
| <directory suffix=".php">./src/</directory> | |
| </whitelist> | |
| </filter> | |
| <php> | |
| <env name="APP_ENV" value="testing"/> | |
| <env name="APP_KEY" value="E96PKYNWtheyyje8gHw9dx8rv29fL9He"/> | |
| <env name="DB_CONNECTION" value="sqlite"/> | |
| <env name="DB_HOST" value="localhost"/> | |
| <env name="DB_DATABASE" value=":memory:"/> | |
| <env name="CACHE_DRIVER" value="array"/> | |
| <env name="SESSION_DRIVER" value="array"/> | |
| <env name="QUEUE_DRIVER" value="sync"/> | |
| </php> | |
| </phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @package Dashboard | |
| * @version 1.0.0 | |
| * @author Ian Olson <[email protected]> | |
| * @license MIT | |
| * @copyright 2015, Odot Media LLC | |
| * @link https://odotmedia.com | |
| */ | |
| class TestCase extends \Illuminate\Foundation\Testing\TestCase | |
| { | |
| /** | |
| * The base URL to use while testing the application. | |
| * | |
| * @var string | |
| */ | |
| protected $baseUrl = 'http://localhost'; | |
| /** | |
| * Creates the application. | |
| * | |
| * @return \Illuminate\Foundation\Application | |
| */ | |
| public function createApplication() | |
| { | |
| $app = require __DIR__ . '/../vendor/laravel/laravel/bootstrap/app.php'; | |
| $app->register(\Odotmedia\Dashboard\Providers\DashboardServiceProvider::class); | |
| $app->make(\Illuminate\Contracts\Console\Kernel::class) | |
| ->bootstrap(); | |
| return $app; | |
| } | |
| /** | |
| * Run migrations to the database. | |
| * | |
| * @return void | |
| */ | |
| public function migrate() | |
| { | |
| $fileSystem = new \Illuminate\Filesystem\Filesystem(); | |
| $classFinder = new \Illuminate\Filesystem\ClassFinder(); | |
| foreach ($fileSystem->files(__DIR__ . "/../vendor/cartalyst/sentinel/src/migrations") as $file) { | |
| $fileSystem->requireOnce($file); | |
| $migrationClass = $classFinder->findClass($file); | |
| (new $migrationClass)->up(); | |
| } | |
| } | |
| /** | |
| * Testing Laravel application. | |
| */ | |
| public function testLaravel() | |
| { | |
| $this->visit('/') | |
| ->see('Laravel 5'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment