Browse Source
Update 2016-07-08.22.41
Update 2016-07-08.22.41
Add Customer Subsciption with TDD Add with roles on getUsers method on UsersRepositorypull/1/head
21 changed files with 689 additions and 1 deletions
-
28app/Entities/Subscriptions/Subscription.php
-
13app/Entities/Subscriptions/SubscriptionPresenter.php
-
23app/Entities/Subscriptions/SubscriptionsRepository.php
-
1app/Entities/Users/UsersRepository.php
-
82app/Http/Controllers/SubscriptionsController.php
-
40app/Http/Requests/Subscriptions/CreateRequest.php
-
31app/Http/Requests/Subscriptions/DeleteRequest.php
-
40app/Http/Requests/Subscriptions/UpdateRequest.php
-
3app/Http/routes.php
-
9app/Http/routes/subscriptions.php
-
1app/Services/FormField.php
-
23database/factories/ModelFactory.php
-
31resources/lang/id/subscription.php
-
3resources/views/layouts/partials/sidebar.blade.php
-
55resources/views/subscriptions/create.blade.php
-
18resources/views/subscriptions/delete.blade.php
-
52resources/views/subscriptions/edit.blade.php
-
51resources/views/subscriptions/index.blade.php
-
28resources/views/subscriptions/partials/subscription-show.blade.php
-
12resources/views/subscriptions/show.blade.php
-
146tests/ManageSubscriptionsTest.php
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
namespace App\Entities\Subscriptions; |
|||
|
|||
use App\Entities\Projects\Project; |
|||
use App\Entities\Subscriptions\SubscriptionPresenter; |
|||
use App\Entities\Users\User; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Laracasts\Presenter\PresentableTrait; |
|||
|
|||
class Subscription extends Model { |
|||
|
|||
use PresentableTrait; |
|||
|
|||
protected $presenter = SubscriptionPresenter::class; |
|||
protected $guarded = ['id','created_at','updated_at']; |
|||
|
|||
public function project() |
|||
{ |
|||
return $this->belongsTo(Project::class); |
|||
} |
|||
|
|||
public function customer() |
|||
{ |
|||
return $this->belongsTo(User::class,'customer_id'); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
<?php |
|||
|
|||
namespace App\Entities\Subscriptions; |
|||
|
|||
use Laracasts\Presenter\Presenter; |
|||
|
|||
class SubscriptionPresenter extends Presenter |
|||
{ |
|||
public function customerNameAndEmail() |
|||
{ |
|||
return $this->customer_id ? $this->customer->name . ' (' . $this->customer->email . ')' : '-'; |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<?php |
|||
|
|||
namespace App\Entities\Subscriptions; |
|||
|
|||
use App\Entities\BaseRepository; |
|||
|
|||
/** |
|||
* Subscriptions Repository Class |
|||
*/ |
|||
class SubscriptionsRepository extends BaseRepository |
|||
{ |
|||
protected $model; |
|||
|
|||
public function __construct(Subscription $model) |
|||
{ |
|||
parent::__construct($model); |
|||
} |
|||
|
|||
public function getAll($q) |
|||
{ |
|||
return $this->model->orderBy('due_date')->where('domain_name','like','%' . $q . '%')->paginate($this->_paginate); |
|||
} |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers; |
|||
|
|||
use App\Http\Requests\Subscriptions\CreateRequest; |
|||
use App\Http\Requests\Subscriptions\UpdateRequest; |
|||
use App\Http\Requests\Subscriptions\DeleteRequest; |
|||
use App\Http\Controllers\Controller; |
|||
use App\Entities\Subscriptions\SubscriptionsRepository; |
|||
|
|||
use Illuminate\Http\Request; |
|||
|
|||
class SubscriptionsController extends Controller { |
|||
|
|||
private $repo; |
|||
|
|||
public function __construct(SubscriptionsRepository $repo) |
|||
{ |
|||
$this->repo = $repo; |
|||
} |
|||
|
|||
public function index(Request $req) |
|||
{ |
|||
$subscriptions = $this->repo->getAll($req->get('q')); |
|||
return view('subscriptions.index',compact('subscriptions')); |
|||
} |
|||
|
|||
public function create() |
|||
{ |
|||
$projects = $this->repo->getProjectsList(); |
|||
$customers = $this->repo->getCustomersList(); |
|||
return view('subscriptions.create', compact('projects','customers')); |
|||
} |
|||
|
|||
public function store(CreateRequest $req) |
|||
{ |
|||
$subscription = $this->repo->create($req->except('_token')); |
|||
flash()->success(trans('subscription.created')); |
|||
return redirect()->route('subscriptions.index'); |
|||
} |
|||
|
|||
public function show($subscriptionId) |
|||
{ |
|||
$subscription = $this->repo->requireById($subscriptionId); |
|||
return view('subscriptions.show', compact('subscription')); |
|||
} |
|||
|
|||
public function edit($subscriptionId) |
|||
{ |
|||
$subscription = $this->repo->requireById($subscriptionId); |
|||
$projects = $this->repo->getProjectsList(); |
|||
$customers = $this->repo->getCustomersList(); |
|||
return view('subscriptions.edit',compact('subscription','projects','customers')); |
|||
} |
|||
|
|||
public function update(UpdateRequest $req, $subscriptionId) |
|||
{ |
|||
$subscription = $this->repo->update($req->except(['_method','_token']), $subscriptionId); |
|||
flash()->success(trans('subscription.updated')); |
|||
return redirect()->route('subscriptions.edit', $subscriptionId); |
|||
} |
|||
|
|||
public function delete($subscriptionId) |
|||
{ |
|||
$subscription = $this->repo->requireById($subscriptionId); |
|||
return view('subscriptions.delete', compact('subscription')); |
|||
} |
|||
|
|||
public function destroy(DeleteRequest $req, $subscriptionId) |
|||
{ |
|||
if ($subscriptionId == $req->get('subscription_id')) |
|||
{ |
|||
$this->repo->delete($subscriptionId); |
|||
flash()->success(trans('subscription.deleted')); |
|||
} |
|||
else |
|||
flash()->error(trans('subscription.undeleted')); |
|||
|
|||
return redirect()->route('subscriptions.index'); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests\Subscriptions; |
|||
|
|||
use App\Http\Requests\Request; |
|||
|
|||
class CreateRequest extends Request { |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return auth()->user()->can('manage_subscriptions'); |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
'domain_name' => 'required|max:60|unique:subscriptions,domain_name', |
|||
'epp_code' => 'max:60', |
|||
'domain_price' => 'required|numeric', |
|||
'hosting_capacity' => 'max:60', |
|||
'hosting_price' => 'required_with:hosting_capacity|numeric', |
|||
'start_date' => 'required|date|date_format:Y-m-d', |
|||
'due_date' => 'required|date|date_format:Y-m-d', |
|||
'customer_id' => 'required|numeric', |
|||
'project_id' => 'required|numeric', |
|||
'remark' => 'max:255', |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests\Subscriptions; |
|||
|
|||
use App\Http\Requests\Request; |
|||
|
|||
class DeleteRequest extends Request { |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return auth()->user()->can('manage_subscriptions'); |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
'subscription_id' => 'required' |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests\Subscriptions; |
|||
|
|||
use App\Http\Requests\Request; |
|||
|
|||
class UpdateRequest extends Request { |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return auth()->user()->can('manage_subscriptions'); |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
'domain_name' => 'required|max:60|unique:subscriptions,domain_name,' . $this->segment(2), |
|||
'epp_code' => 'max:60', |
|||
'domain_price' => 'required|numeric', |
|||
'hosting_capacity' => 'max:60', |
|||
'hosting_price' => 'required_with:hosting_capacity|numeric', |
|||
'start_date' => 'required|date|date_format:Y-m-d', |
|||
'due_date' => 'required|date|date_format:Y-m-d', |
|||
'customer_id' => 'required|numeric', |
|||
'project_id' => 'required|numeric', |
|||
'remark' => 'max:255', |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
<?php |
|||
|
|||
Route::group(['middleware' => ['web','role:admin']], function() { |
|||
/** |
|||
* Subscriptions Routes |
|||
*/ |
|||
Route::get('subscriptions/{id}/delete', ['as'=>'subscriptions.delete', 'uses'=>'SubscriptionsController@delete']); |
|||
Route::resource('subscriptions','SubscriptionsController'); |
|||
}); |
|||
@ -0,0 +1,31 @@ |
|||
<?php |
|||
|
|||
return [ |
|||
'subscription' => 'Langganan', |
|||
'subscriptions' => 'Daftar Langganan', |
|||
'domain_name' => 'Domain', |
|||
'domain_price' => 'Harga Domain', |
|||
'epp_code' => 'Kode EPP', |
|||
'hosting_capacity' => 'Kapasitas Hosting', |
|||
'hosting_price' => 'Harga Hosting', |
|||
'start_date' => 'Mulai Sewa', |
|||
'due_date' => 'Perpanjangan', |
|||
'extension_price' => 'Biaya Perpanjangan', |
|||
'create' => 'Input Langganan Baru', |
|||
'created' => 'Input Langganan baru telah berhasil.', |
|||
'show' => 'Detail Langganan', |
|||
'edit' => 'Edit Langganan', |
|||
'update' => 'Update Langganan', |
|||
'updated' => 'Update data Langganan telah berhasil.', |
|||
'delete' => 'Hapus Langganan', |
|||
'deleted' => 'Hapus data Langganan telah berhasil.', |
|||
'undeleted' => 'Data Langganan gagal dihapus.', |
|||
'remark' => 'Catatan', |
|||
'search' => 'Cari Langganan', |
|||
'found' => 'Langganan ditemukan', |
|||
'not_found' => 'Langganan tidak ditemukan', |
|||
'empty' => 'Belum ada Langganan', |
|||
'back_to_index' => 'Kembali ke daftar Langganan', |
|||
'customer' => 'Customer', |
|||
'project' => 'Project', |
|||
]; |
|||
@ -0,0 +1,55 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.create')) |
|||
|
|||
@section('content') |
|||
<ul class="breadcrumb hidden-print"> |
|||
<li>{{ link_to_route('subscriptions.index',trans('subscription.subscriptions')) }}</li> |
|||
<li class="active">{{ trans('subscription.create') }}</li> |
|||
</ul> |
|||
|
|||
<div class="row"> |
|||
<div class="col-md-4"> |
|||
{!! Form::open(['route'=>'subscriptions.store']) !!} |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ trans('subscription.create') }}</h3></div> |
|||
<div class="panel-body"> |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('domain_name',['label'=> trans('subscription.domain_name')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::price('domain_price',['label'=> trans('subscription.domain_price')]) !!} |
|||
</div> |
|||
</div> |
|||
{!! FormField::text('epp_code',['label'=> trans('subscription.epp_code')]) !!} |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('hosting_capacity',['label'=> trans('subscription.hosting_capacity')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::price('hosting_price',['label'=> trans('subscription.hosting_price')]) !!} |
|||
</div> |
|||
</div> |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('start_date',['label'=> trans('subscription.start_date')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('due_date',['label'=> trans('subscription.due_date')]) !!} |
|||
</div> |
|||
</div> |
|||
{!! FormField::select('customer_id', $customers,['label'=> trans('subscription.customer')]) !!} |
|||
{!! FormField::select('project_id', $projects,['label'=> trans('subscription.project')]) !!} |
|||
{!! FormField::textarea('remark',['label'=> trans('subscription.remark')]) !!} |
|||
</div> |
|||
|
|||
<div class="panel-footer"> |
|||
{!! Form::submit(trans('subscription.create'), ['class'=>'btn btn-primary']) !!} |
|||
{!! link_to_route('subscriptions.index', trans('app.cancel'), [], ['class'=>'btn btn-default']) !!} |
|||
</div> |
|||
</div> |
|||
{!! Form::close() !!} |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -0,0 +1,18 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.delete')) |
|||
|
|||
@section('content') |
|||
<h1 class="page-header"> |
|||
<div class="pull-right"> |
|||
{!! delete_button(['route'=>['subscriptions.destroy',$subscription->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['subscription_id'=>$subscription->id]) !!} |
|||
</div> |
|||
{{ trans('app.delete_confirm') }} |
|||
{!! link_to_route('subscriptions.show', trans('app.cancel'), [$subscription->id], ['class' => 'btn btn-default']) !!} |
|||
</h1> |
|||
<div class="row"> |
|||
<div class="col-md-4"> |
|||
@include('subscriptions.partials.subscription-show') |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -0,0 +1,52 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.edit')) |
|||
|
|||
@section('content') |
|||
<div class="row"><br> |
|||
<div class="col-md-4"> |
|||
{!! Form::model($subscription, ['route'=>['subscriptions.update', $subscription->id], 'method' => 'patch']) !!} |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ $subscription->domain_name }} <small>{{ trans('subscription.edit') }}</small></h3></div> |
|||
<div class="panel-body"> |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('domain_name',['label'=> trans('subscription.domain_name')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::price('domain_price',['label'=> trans('subscription.domain_price')]) !!} |
|||
</div> |
|||
</div> |
|||
{!! FormField::text('epp_code',['label'=> trans('subscription.epp_code')]) !!} |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('hosting_capacity',['label'=> trans('subscription.hosting_capacity')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::price('hosting_price',['label'=> trans('subscription.hosting_price')]) !!} |
|||
</div> |
|||
</div> |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('start_date',['label'=> trans('subscription.start_date')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('due_date',['label'=> trans('subscription.due_date')]) !!} |
|||
</div> |
|||
</div> |
|||
{!! FormField::select('customer_id', $customers,['label'=> trans('subscription.customer')]) !!} |
|||
{!! FormField::select('project_id', $projects,['label'=> trans('subscription.project')]) !!} |
|||
{!! FormField::textarea('remark',['label'=> trans('subscription.remark')]) !!} |
|||
</div> |
|||
|
|||
<div class="panel-footer"> |
|||
{!! Form::submit(trans('subscription.update'), ['class'=>'btn btn-primary']) !!} |
|||
{!! link_to_route('subscriptions.show', trans('app.show'), [$subscription->id], ['class' => 'btn btn-info']) !!} |
|||
{!! link_to_route('subscriptions.index', trans('subscription.back_to_index'), [], ['class' => 'btn btn-default']) !!} |
|||
{!! link_to_route('subscriptions.delete', trans('subscription.delete'), [$subscription->id], ['class'=>'btn btn-danger pull-right']) !!} |
|||
</div> |
|||
</div> |
|||
{!! Form::close() !!} |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -0,0 +1,51 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.subscriptions')) |
|||
|
|||
@section('content') |
|||
<h1 class="page-header"> |
|||
{!! link_to_route('subscriptions.create', trans('subscription.create'), [], ['class'=>'btn btn-success pull-right']) !!} |
|||
{{ trans('subscription.subscriptions') }} <small>{{ $subscriptions->total() }} {{ trans('subscription.found') }}</small> |
|||
</h1> |
|||
<div class="well well-sm"> |
|||
{!! Form::open(['method'=>'get','class'=>'form-inline']) !!} |
|||
{!! Form::text('q', Request::get('q'), ['class'=>'form-control index-search-field','placeholder'=>trans('subscription.search'),'style' => 'width:350px']) !!} |
|||
{!! Form::submit(trans('subscription.search'), ['class' => 'btn btn-info btn-sm']) !!} |
|||
{!! link_to_route('subscriptions.index','Reset',[],['class' => 'btn btn-default btn-sm']) !!} |
|||
{!! Form::close() !!} |
|||
</div> |
|||
<table class="table table-condensed"> |
|||
<thead> |
|||
<th>{{ trans('app.table_no') }}</th> |
|||
<th>{{ trans('subscription.domain_name') }}</th> |
|||
<th>{{ trans('subscription.hosting_capacity') }}</th> |
|||
<th>{{ trans('subscription.start_date') }}</th> |
|||
<th>{{ trans('subscription.due_date') }}</th> |
|||
<th>{{ trans('subscription.extension_price') }}</th> |
|||
<th>{{ trans('app.action') }}</th> |
|||
</thead> |
|||
<tbody> |
|||
@forelse($subscriptions as $key => $subscription) |
|||
<tr {{ Carbon::parse($subscription->due_date)->diffInDays(Carbon::now()) < 60 ? 'class=bg-danger' : '' }}> |
|||
<td> |
|||
{{ $subscriptions->firstItem() + $key }} |
|||
</td> |
|||
<td>{{ $subscription->domain_name }}</td> |
|||
<td>{{ $subscription->hosting_capacity }}</td> |
|||
<td>{{ dateId($subscription->start_date) }}</td> |
|||
<td>{{ dateId($subscription->due_date) }}</td> |
|||
<td>{{ formatRp($subscription->domain_price + $subscription->hosting_price) }}</td> |
|||
<td> |
|||
{!! link_to_route('subscriptions.show',trans('app.show'),[$subscription->id],['class'=>'btn btn-info btn-xs']) !!} |
|||
{!! link_to_route('subscriptions.edit',trans('app.edit'),[$subscription->id],['class'=>'btn btn-warning btn-xs']) !!} |
|||
</td> |
|||
</tr> |
|||
@empty |
|||
<tr> |
|||
<td colspan="5">{{ trans('subscription.not_found') }}</td> |
|||
</tr> |
|||
@endforelse |
|||
</tbody> |
|||
</table> |
|||
{!! str_replace('/?', '?', $subscriptions->appends(Request::except('page'))->render()) !!} |
|||
@endsection |
|||
@ -0,0 +1,28 @@ |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ trans('subscription.show') }}</h3></div> |
|||
<table class="table table-condensed"> |
|||
<tbody> |
|||
<tr><td>{{ trans('subscription.project') }}</td><td>{{ $subscription->project->name }}</td></tr> |
|||
<tr><td>{{ trans('subscription.domain_name') }}</td><td>{{ $subscription->domain_name }}</td></tr> |
|||
<tr><td>{{ trans('subscription.domain_price') }}</td><td>{{ formatRp($subscription->domain_price) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.epp_code') }}</td><td>{{ $subscription->epp_code }}</td></tr> |
|||
<tr><td>{{ trans('subscription.hosting_capacity') }}</td><td>{{ $subscription->hosting_capacity }}</td></tr> |
|||
<tr><td>{{ trans('subscription.hosting_price') }}</td><td>{{ formatRp($subscription->hosting_price) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.start_date') }}</td><td>{{ dateId($subscription->start_date) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.due_date') }}</td><td>{{ dateId($subscription->due_date) }}</td></tr> |
|||
<tr> |
|||
<td>{{ trans('subscription.customer') }}</td> |
|||
<td> |
|||
{{ $subscription->present()->customerNameAndEmail }} |
|||
@if ($subscription->project->customer_id && auth()->id() == $subscription->project->owner_id) |
|||
{!! link_to_route('users.edit', 'Edit', [$subscription->customer_id], ['title' => 'Edit Data Customer']) !!} |
|||
@endif |
|||
</td> |
|||
</tr> |
|||
</tbody> |
|||
</table> |
|||
<div class="panel-footer"> |
|||
{!! link_to_route('subscriptions.edit', trans('subscription.edit'), [$subscription->id], ['class' => 'btn btn-warning']) !!} |
|||
{!! link_to_route('subscriptions.index', trans('subscription.back_to_index'), [], ['class' => 'btn btn-default']) !!} |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,12 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.show')) |
|||
|
|||
@section('content') |
|||
<h1 class="page-header">{{ $subscription->domain_name }} <small>{{ trans('subscription.show') }}</small></h1> |
|||
<div class="row"> |
|||
<div class="col-md-4"> |
|||
@include('subscriptions.partials.subscription-show') |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -0,0 +1,146 @@ |
|||
<?php |
|||
|
|||
use App\Entities\Projects\Project; |
|||
use App\Entities\Subscriptions\Subscription; |
|||
use App\Entities\Users\User; |
|||
use Illuminate\Foundation\Testing\DatabaseMigrations; |
|||
use Illuminate\Foundation\Testing\DatabaseTransactions; |
|||
use Illuminate\Foundation\Testing\WithoutMiddleware; |
|||
|
|||
class ManageSubscriptionsTest extends TestCase |
|||
{ |
|||
use DatabaseTransactions; |
|||
|
|||
/** @test */ |
|||
public function admin_can_entry_subscription() |
|||
{ |
|||
$user = factory(User::class)->create(); |
|||
$user->assignRole('admin'); |
|||
$this->actingAs($user); |
|||
|
|||
$project = factory(Project::class)->create(); |
|||
|
|||
$customer = factory(User::class)->create(); |
|||
$customer->assignRole('customer'); |
|||
|
|||
$this->visit('subscriptions'); |
|||
$this->seePageIs('subscriptions'); |
|||
$this->see(trans('subscription.subscriptions')); |
|||
$this->click(trans('subscription.create')); |
|||
$this->seePageIs('subscriptions/create'); |
|||
|
|||
// Fill Form
|
|||
$this->type('www.domain.com','domain_name'); |
|||
$this->type(100000,'domain_price'); |
|||
$this->type('100000','epp_code'); |
|||
$this->type('3GB','hosting_capacity'); |
|||
$this->type(500000,'hosting_price'); |
|||
$this->type('2015-05-02','start_date'); |
|||
$this->type('2016-05-02','due_date'); |
|||
$this->select($project->id, 'project_id'); |
|||
$this->select($customer->id, 'customer_id'); |
|||
$this->type('','remark'); |
|||
$this->press(trans('subscription.create')); |
|||
|
|||
$this->seePageIs('subscriptions'); |
|||
$this->see(trans('subscription.created')); |
|||
$this->seeInDatabase('subscriptions', ['project_id' => $project->id,'domain_price' => 100000,'start_date' => '2015-05-02','due_date' => '2016-05-02']); |
|||
} |
|||
|
|||
/** @test */ |
|||
public function admin_can_edit_subscription_data() |
|||
{ |
|||
$user = factory(User::class)->create(); |
|||
$user->assignRole('admin'); |
|||
$this->actingAs($user); |
|||
|
|||
$project = factory(Project::class)->create(); |
|||
|
|||
$customer = factory(User::class)->create(); |
|||
$customer->assignRole('customer'); |
|||
|
|||
$subscription = factory(Subscription::class)->create(['customer_id' => $customer->id, 'project_id' => $project->id]); |
|||
|
|||
$this->visit('subscriptions/' . $subscription->id . '/edit'); |
|||
$this->seePageIs('subscriptions/' . $subscription->id . '/edit'); |
|||
|
|||
// Fill Form
|
|||
$this->type($eppCode = str_random(10),'epp_code'); |
|||
$this->type('4GB','hosting_capacity'); |
|||
$this->type(500000,'hosting_price'); |
|||
$this->type('2015-05-02','start_date'); |
|||
$this->type('2016-05-02','due_date'); |
|||
$this->press(trans('subscription.update')); |
|||
|
|||
$this->seePageIs('subscriptions/' . $subscription->id . '/edit'); |
|||
$this->see(trans('subscription.updated')); |
|||
$this->seeInDatabase('subscriptions', [ |
|||
'epp_code' => $eppCode, |
|||
'customer_id' => $customer->id, |
|||
'project_id' => $project->id, |
|||
'hosting_capacity' => '4GB', |
|||
'hosting_price' => '500000', |
|||
'start_date' => '2015-05-02', |
|||
'due_date' => '2016-05-02', |
|||
]); |
|||
} |
|||
|
|||
/** @test */ |
|||
public function admin_can_delete_a_subscription() |
|||
{ |
|||
$user = factory(User::class)->create(); |
|||
$user->assignRole('admin'); |
|||
$this->actingAs($user); |
|||
|
|||
$subscription = factory(Subscription::class)->create(); |
|||
|
|||
$this->visit('/subscriptions'); |
|||
$this->click(trans('app.edit')); |
|||
$this->click(trans('subscription.delete')); |
|||
$this->press(trans('app.delete_confirm_button')); |
|||
$this->seePageIs('subscriptions'); |
|||
$this->see(trans('subscription.deleted')); |
|||
} |
|||
|
|||
/** @test */ |
|||
public function admin_can_see_a_subscription() |
|||
{ |
|||
$user = factory(User::class)->create(); |
|||
$user->assignRole('admin'); |
|||
$this->actingAs($user); |
|||
|
|||
$subscription = factory(Subscription::class)->create(); |
|||
|
|||
$this->visit('/subscriptions'); |
|||
$this->click(trans('app.show')); |
|||
$this->seePageIs('subscriptions/' . $subscription->id); |
|||
$this->see(trans('subscription.show')); |
|||
$this->see($subscription->domain_name); |
|||
$this->see(formatRp($subscription->domain_price)); |
|||
$this->see($subscription->hosting_capacity); |
|||
$this->see(formatRp($subscription->hosting_price)); |
|||
$this->see(dateId($subscription->start_date)); |
|||
$this->see(dateId($subscription->due_date)); |
|||
} |
|||
|
|||
/** @test */ |
|||
public function admin_can_see_all_subscriptions() |
|||
{ |
|||
$user = factory(User::class)->create(); |
|||
$user->assignRole('admin'); |
|||
$this->actingAs($user); |
|||
|
|||
$subscriptions = factory(Subscription::class, 30)->create(); |
|||
$this->assertEquals(30, $subscriptions->count()); |
|||
|
|||
$this->visit('/subscriptions'); |
|||
$this->see($subscriptions[1]->domain_name); |
|||
$this->see($subscriptions[1]->hosting_capacity); |
|||
$this->see(dateId($subscriptions[1]->start_date)); |
|||
$this->see(dateId($subscriptions[1]->due_date)); |
|||
$this->see(formatRp($subscriptions[1]->domain_price + $subscriptions[1]->hosting_price)); |
|||
|
|||
$this->click('2'); |
|||
$this->seePageIs('/subscriptions?page=2'); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue