Created regular tests

This commit is contained in:
Gregorio Chiko Putra
2018-07-21 10:00:34 +07:00
parent 2871865e82
commit 70fe3a814c
32 changed files with 891 additions and 4 deletions

0
tests/_data/.gitkeep Normal file
View File

View File

@@ -0,0 +1,47 @@
-- Adminer 4.3.0 MySQL dump
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
SET NAMES utf8mb4;
DROP TABLE IF EXISTS `migrations`;
CREATE TABLE `migrations` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`batch` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
(59, '2014_10_12_000000_create_users_table', 1),
(60, '2014_10_12_100000_create_password_resets_table', 1);
DROP TABLE IF EXISTS `password_resets`;
CREATE TABLE `password_resets` (
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
KEY `password_resets_email_index` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO `users` (`id`, `name`, `email`, `password`, `remember_token`, `created_at`, `updated_at`) VALUES
(1, 'Dr. Ena Steuber III', 'admin@laraland.test', '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', 'x4Jo6Fc40Y', '2018-07-19 05:02:22', '2018-07-19 05:02:22');
-- 2018-07-19 05:02:32

2
tests/_output/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

View File

@@ -0,0 +1,151 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
private $mailcathcher,
$mail;
/**
* @Given Saya mempunyai hak akses di database
*/
public function sayaMempunyaiHakAksesDiDatabase()
{
$I = $this;
$I->seeInDatabase('users', ['email' => 'admin@laraland.test']);
}
/**
* @When Saya mengirim form berisi email saya
*/
public function sayaMengirimFormBerisiEmailSaya()
{
$I = $this;
$I->amOnPage('/password/reset');
$I->fillField('email', 'admin@laraland.test');
$I->click('button[type=submit]');
}
/**
* @Then Saya melihat bahwa sebuah email telah dikirim dari sistem
*/
public function sayaMelihatBahwaSebuahEmailTelahDikirimDariSistem()
{
$I = $this;
$I->see('We have e-mailed your password reset link!');
}
/**
* @Given Saya membuka link pada email dari sistem
*/
public function sayaMembukaLinkPadaEmailDariSistem()
{
$I = $this;
$I->requestEmailResetPasswordLink($I);
$this->mailcatcher = new GuzzleHttp\Client([
'base_uri' => 'http://localhost:8025/api/v1/'
]);
$this->mail = $this->getLastMessage($this->mailcatcher);
$pattern = '/\/password\/reset\/[\w=\s]+[^\W]+/';
foreach($this->mail as $key => $val) {
if ($key == 'Content') {
foreach($val as $head => $body) {
if ($head == 'Body') {
preg_match($pattern, $body, $matches);
}
}
}
}
$url = preg_replace('/=\s+/', '', $matches[0]);
$url = preg_replace('/\s+[\w\W]+/', '', $url);
$I->amOnPage($url);
}
/**
* @When Saya mengirim form berisi password baru
*/
public function sayaMengirimFormBerisiPasswordBaru()
{
$I = $this;
$I->fillField('email', 'admin@laraland.test');
$I->fillField('password', 'newsecret');
$I->fillField('password_confirmation', 'newsecret');
$I->click('button[type=submit]');
}
/**
* @Then Saya berhasil signin dengan password baru
*/
public function sayaBerhasilSigninDenganPasswordBaru()
{
$I = $this;
$I->seeCurrentUrlEquals('/home');
$I->see('Your password has been reset!');
}
/**
* @Given Saya berada di halaman registrasi
*/
public function sayaBeradaDiHalamanRegistrasi()
{
$I = $this;
$I->amOnPage('/register');
}
/**
* @When Saya mengirim form registrasi
*/
public function sayaMengirimFormRegistrasi()
{
$I = $this;
$I->fillField('name', \Faker\Factory::create()->name);
$I->fillField('email', 'admin2@laraland.test');
$I->fillField('password', 'sosecret');
$I->fillField('password_confirmation', 'sosecret');
$I->click('button[type=submit]');
}
/**
* @Then Saya akan dialihkan ke halaman dashboard
*/
public function sayaAkanDialihkanKeHalamanDashboard()
{
$I = $this;
$I->seeCurrentUrlEquals('/home');
$I->see('Dashboard');
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
public function cleanMessages(\GuzzleHttp\Client $mailcatcher)
{
$mailcatcher->delete('messages');
}
public function getLastMessage(\GuzzleHttp\Client $mailcatcher)
{
$messages = $this->getMessages($mailcatcher);
if (empty($messages)) $this->fail('No messages received');
return reset($messages);
}
public function getMessages(\GuzzleHttp\Client $mailcatcher)
{
$jsonResponse = $mailcatcher->get('messages');
return json_decode($jsonResponse->getBody());
}
public function requestEmailResetPasswordLink(\AcceptanceTester $I)
{
$I->amOnPage('/password/reset');
$I->fillField('email', 'admin@laraland.test');
$I->click('button[type=submit]');
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}

2
tests/_support/_generated/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

View File

@@ -0,0 +1,22 @@
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
# - WebDriver:
# browser: chrome
url: http://laraland.test
- \Helper\Acceptance
- Db:
dsn: 'mysql:host=mariadb;port=3306;dbname=laraland'
user: 'root'
password: 'root'
cleanup: true
dump: 'tests/_data/db_laraland.sql'
populate: true
populator: 'mysql -u$user -p$password -h$host $dbname < $dump'

View File

@@ -0,0 +1,28 @@
<?php
class ResetPasswordCest
{
public function _before(AcceptanceTester $I)
{
// Artisan::call('migrate');
// factory(App\User::class)->create(['email' => 'admin@laraland.test']);
}
public function _after(AcceptanceTester $I)
{
// Artisan::call('migrate:rollback');
}
// tests
public function memintaLinkResetPassword(AcceptanceTester $I)
{
$I->wantTo('get emailed by system with reset password link inside it');
$I->amOnPage('/password/reset');
$I->fillField('email', 'admin@laraland.test');
$I->click('button[type=submit]');
$I->see('We have e-mailed your password reset link!');
}
}

View File

@@ -0,0 +1,44 @@
<?php
class SigninCest
{
public function _before(AcceptanceTester $I)
{
// Artisan::call('migrate');
// factory(App\User::class)->create(['email' => 'admin@laraland.test']);
}
public function _after(AcceptanceTester $I)
{
// Artisan::call('migrate:rollback');
}
// tests
public function signinSuccessful(AcceptanceTester $I)
{
$I->wantTo('signin with correct credential and should go to dashboard page');
$I->amOnPage('/login');
$I->fillField('email', 'admin@laraland.test');
$I->fillField('password', 'secret');
$I->click('button[type=submit]');
$I->see('Dashboard');
$I->seeCurrentUrlEquals('/home');
}
public function signinUnsuccessful(AcceptanceTester $I)
{
$I->wantTo('signin with incorrect credential and should go back to login page');
$I->amOnPage('/login');
$I->fillField('email', 'admin@laraland.test');
$I->fillField('password', 'notsecret');
$I->click('button[type=submit]');
$I->see('Login');
$I->seeCurrentUrlEquals('/login');
}
}

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1,12 @@
#language: id
Fitur: registrasi user baru
Sistem dapat mendaftarkan user(admin) baru
dengan mengisi form registrasi yang ada di halaman depan aplikasi
Skenario: registrasi dan masuk ke halaman dashboard
Dengan Saya berada di halaman registrasi
Ketika Saya mengirim form registrasi
Maka Saya akan dialihkan ke halaman dashboard

View File

@@ -0,0 +1,21 @@
#language: id
Fitur: reset password
Pengguna dapat mengganti password
dengan memasukkan email pada halaman reset password
lalu link reset password akan dikirimkan ke email tersebut
dan pengguna dapat membuat password baru melalui link tersebut
Skenario: meminta link reset password
Dengan Saya mempunyai hak akses di database
Ketika Saya mengirim form berisi email saya
Maka Saya melihat bahwa sebuah email telah dikirim dari sistem
Skenario: mengganti password
Dengan Saya membuka link pada email dari sistem
Ketika Saya mengirim form berisi password baru
Maka Saya berhasil signin dengan password baru

View File

@@ -0,0 +1,12 @@
# Codeception Test Suite Configuration
#
# Suite for functional tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
# Remove this suite if you don't use frameworks
actor: FunctionalTester
modules:
enabled:
# add a framework module here
- \Helper\Functional

9
tests/unit.suite.yml Normal file
View File

@@ -0,0 +1,9 @@
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests.
actor: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit