Skip to content

Commit

Permalink
Add browser test stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
pboivin committed Aug 10, 2021
1 parent 969e800 commit deeaf4e
Show file tree
Hide file tree
Showing 31 changed files with 515 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/stubs/browsers/2021_08_10_0001_create_authors_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateAuthorsTables extends Migration
{
public function up()
{
Schema::create('authors', function (Blueprint $table) {
createDefaultTableFields($table);
$table->string('title', 200)->nullable();
$table->text('description')->nullable();
});
}

public function down()
{
Schema::dropIfExists('authors');
}
}
26 changes: 26 additions & 0 deletions tests/stubs/browsers/2021_08_10_0002_create_articles_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateArticlesTables extends Migration
{
public function up()
{
Schema::create('articles', function (Blueprint $table) {
createDefaultTableFields($table);
$table->string('title', 200)->nullable();
$table->text('description')->nullable();
});

Schema::create('article_revisions', function (Blueprint $table) {
createDefaultRevisionsTableFields($table, 'article');
});
}

public function down()
{
Schema::dropIfExists('article_revisions');
Schema::dropIfExists('articles');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateArticleAuthorTable extends Migration
{
public function up()
{
Schema::create('article_author', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->integer('position')->unsigned();
createDefaultRelationshipTableFields($table, 'article', 'author');
});
}

public function down()
{
Schema::dropIfExists('article_author');
}
}
27 changes: 27 additions & 0 deletions tests/stubs/browsers/2021_08_10_0004_create_bios_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateBiosTables extends Migration
{
public function up()
{
Schema::create('bios', function (Blueprint $table) {
createDefaultTableFields($table);
$table->string('title', 200)->nullable();
$table->text('description')->nullable();
$table->foreignId('author_id')->nullable()->onUpdate('cascade')->onDelete('cascade');
});

Schema::create('bio_revisions', function (Blueprint $table) {
createDefaultRevisionsTableFields($table, 'bio');
});
}

public function down()
{
Schema::dropIfExists('bio_revisions');
Schema::dropIfExists('bios');
}
}
26 changes: 26 additions & 0 deletions tests/stubs/browsers/2021_08_10_0005_create_books_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateBooksTables extends Migration
{
public function up()
{
Schema::create('books', function (Blueprint $table) {
createDefaultTableFields($table);
$table->string('title', 200)->nullable();
$table->text('description')->nullable();
});

Schema::create('book_revisions', function (Blueprint $table) {
createDefaultRevisionsTableFields($table, 'book');
});
}

public function down()
{
Schema::dropIfExists('book_revisions');
Schema::dropIfExists('books');
}
}
22 changes: 22 additions & 0 deletions tests/stubs/browsers/Article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Models;

use A17\Twill\Models\Behaviors\HasRevisions;
use A17\Twill\Models\Model;

class Article extends Model
{
use HasRevisions;

protected $fillable = [
'published',
'title',
'description',
];

public function authors()
{
return $this->belongsToMany(Author::class);
}
}
10 changes: 10 additions & 0 deletions tests/stubs/browsers/ArticleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Http\Controllers\Admin;

use A17\Twill\Http\Controllers\Admin\ModuleController;

class ArticleController extends ModuleController
{
protected $moduleName = 'articles';
}
30 changes: 30 additions & 0 deletions tests/stubs/browsers/ArticleRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Repositories;

use A17\Twill\Repositories\Behaviors\HandleRevisions;
use A17\Twill\Repositories\ModuleRepository;
use App\Models\Article;

class ArticleRepository extends ModuleRepository
{
use HandleRevisions;

public function __construct(Article $model)
{
$this->model = $model;
}

public function afterSave($object, $fields)
{
$this->updateBrowser($object, $fields, 'authors');
parent::afterSave($object, $fields);
}

public function getFormFields($object)
{
$fields = parent::getFormFields($object);
$fields['browsers']['authors'] = $this->getFormFieldsForBrowser($object, 'authors');
return $fields;
}
}
18 changes: 18 additions & 0 deletions tests/stubs/browsers/ArticleRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Requests\Admin;

use A17\Twill\Http\Requests\Admin\Request;

class ArticleRequest extends Request
{
public function rulesForCreate()
{
return [];
}

public function rulesForUpdate()
{
return [];
}
}
10 changes: 10 additions & 0 deletions tests/stubs/browsers/ArticleRevision.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models\Revisions;

use A17\Twill\Models\Revision;

class ArticleRevision extends Revision
{
protected $table = "article_revisions";
}
15 changes: 15 additions & 0 deletions tests/stubs/browsers/Author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Models;


use A17\Twill\Models\Model;

class Author extends Model
{
protected $fillable = [
'published',
'title',
'description',
];
}
10 changes: 10 additions & 0 deletions tests/stubs/browsers/AuthorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Http\Controllers\Admin;

use A17\Twill\Http\Controllers\Admin\ModuleController;

class AuthorController extends ModuleController
{
protected $moduleName = 'authors';
}
14 changes: 14 additions & 0 deletions tests/stubs/browsers/AuthorRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Repositories;

use A17\Twill\Repositories\ModuleRepository;
use App\Models\Author;

class AuthorRepository extends ModuleRepository
{
public function __construct(Author $model)
{
$this->model = $model;
}
}
18 changes: 18 additions & 0 deletions tests/stubs/browsers/AuthorRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Requests\Admin;

use A17\Twill\Http\Requests\Admin\Request;

class AuthorRequest extends Request
{
public function rulesForCreate()
{
return [];
}

public function rulesForUpdate()
{
return [];
}
}
23 changes: 23 additions & 0 deletions tests/stubs/browsers/Bio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Models;

use A17\Twill\Models\Behaviors\HasRevisions;
use A17\Twill\Models\Model;

class Bio extends Model
{
use HasRevisions;

protected $fillable = [
'published',
'title',
'description',
'author_id',
];

public function author()
{
return $this->belongsTo(Author::class);
}
}
10 changes: 10 additions & 0 deletions tests/stubs/browsers/BioController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Http\Controllers\Admin;

use A17\Twill\Http\Controllers\Admin\ModuleController;

class BioController extends ModuleController
{
protected $moduleName = 'bios';
}
19 changes: 19 additions & 0 deletions tests/stubs/browsers/BioRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Repositories;

use A17\Twill\Repositories\Behaviors\HandleRevisions;
use A17\Twill\Repositories\ModuleRepository;
use App\Models\Bio;

class BioRepository extends ModuleRepository
{
use HandleRevisions;

protected $browsers = ['author'];

public function __construct(Bio $model)
{
$this->model = $model;
}
}
18 changes: 18 additions & 0 deletions tests/stubs/browsers/BioRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Requests\Admin;

use A17\Twill\Http\Requests\Admin\Request;

class BioRequest extends Request
{
public function rulesForCreate()
{
return [];
}

public function rulesForUpdate()
{
return [];
}
}
10 changes: 10 additions & 0 deletions tests/stubs/browsers/BioRevision.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models\Revisions;

use A17\Twill\Models\Revision;

class BioRevision extends Revision
{
protected $table = "bio_revisions";
}
18 changes: 18 additions & 0 deletions tests/stubs/browsers/Book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use A17\Twill\Models\Behaviors\HasRevisions;
use A17\Twill\Models\Behaviors\HasRelated;
use A17\Twill\Models\Model;

class Book extends Model
{
use HasRevisions, HasRelated;

protected $fillable = [
'published',
'title',
'description',
];
}
10 changes: 10 additions & 0 deletions tests/stubs/browsers/BookController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Http\Controllers\Admin;

use A17\Twill\Http\Controllers\Admin\ModuleController;

class BookController extends ModuleController
{
protected $moduleName = 'books';
}
Loading

0 comments on commit deeaf4e

Please sign in to comment.