initial commit
This commit is contained in:
19
.env-testing
Normal file
19
.env-testing
Normal file
@@ -0,0 +1,19 @@
|
||||
APP_ENV=local
|
||||
APP_DEBUG=true
|
||||
APP_KEY=S6JJudOP9dL7UMcES84rim02cW2tKKQl
|
||||
|
||||
DB_HOST=localhost
|
||||
DB_DATABASE=abc-api
|
||||
DB_USERNAME=abc-api
|
||||
DB_PASSWORD=sio2nf0d
|
||||
|
||||
#CACHE_DRIVER=file
|
||||
#SESSION_DRIVER=file
|
||||
#QUEUE_DRIVER=sync
|
||||
|
||||
#MAIL_DRIVER=smtp
|
||||
#MAIL_HOST=mailtrap.io
|
||||
#AIL_PORT=2525
|
||||
#MAIL_USERNAME=null
|
||||
#MAIL_PASSWORD=null
|
||||
#MAIL_ENCRYPTION=null
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/.idea
|
||||
/vendor
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
AbcParser Library
|
||||
|
||||
convert abc music to and from php objects
|
||||
21
codeception.yml
Normal file
21
codeception.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
actor: Tester
|
||||
paths:
|
||||
tests: tests
|
||||
log: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
envs: tests/_envs
|
||||
settings:
|
||||
bootstrap: _bootstrap.php
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
extensions:
|
||||
enabled:
|
||||
- Codeception\Extension\RunFailed
|
||||
modules:
|
||||
config:
|
||||
Db:
|
||||
dsn: ''
|
||||
user: ''
|
||||
password: ''
|
||||
dump: tests/_data/dump.sql
|
||||
23
composer.json
Normal file
23
composer.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "xai-corp/abc-parser",
|
||||
"description": "convert abc music to and from php objects",
|
||||
"minimum-stability": "stable",
|
||||
"license": "proprietary",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Richard Morgan",
|
||||
"email": "richard@xai-corp.net"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"codeception/codeception": "2.1.6",
|
||||
"laravel/laravel": "^5.2",
|
||||
"aedart/testing-laravel": "1.6.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"XaiCorp\\AbcParser\\": "src/"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
3625
composer.lock
generated
Normal file
3625
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
0
database/migrations/.gitkeep
Normal file
0
database/migrations/.gitkeep
Normal file
34
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
34
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->string('password', 60);
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePasswordResetsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('password_resets', function (Blueprint $table) {
|
||||
$table->string('email')->index();
|
||||
$table->string('token')->index();
|
||||
$table->timestamp('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('password_resets');
|
||||
}
|
||||
}
|
||||
135
database/migrations/2015_11_07_012716_create_parseabc_tables.php
Normal file
135
database/migrations/2015_11_07_012716_create_parseabc_tables.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateParseabcTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('collections', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name', 255)->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('collection_attributes', function (Blueprint $table) {
|
||||
$table->bigInteger('collection_id')->unsigned();
|
||||
$table->enum('type', ['Author','Composer','Discography','Rhythm','History','File','Book','Note','Source','Transcriber']);
|
||||
$table->string('string', 255);
|
||||
$table->tinyInteger('ordering')->unsigned()->default(0);
|
||||
$table->timestamps();
|
||||
$table->primary(['collection_id','type','ordering']);
|
||||
$table->foreign('collection_id')->references('id')->on('collections')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
// user profiles/roles/groups
|
||||
// Schema::create('Groups', function (Blueprint $table) {
|
||||
// $table->bigIncrements('id');
|
||||
// $table->string('name', 20);
|
||||
// $table->string('description', 100);
|
||||
// $table->timestamps();
|
||||
// });
|
||||
|
||||
Schema::create('persons', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name', 63);
|
||||
$table->string('email', 255);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('tunes', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->tinyInteger('x_id')->default('1');
|
||||
$table->timestamps();
|
||||
|
||||
});
|
||||
|
||||
Schema::create('tune_settings', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('tune_id')->unsigned();
|
||||
$table->string('meter', 3)->default('C');
|
||||
$table->string('keysig',5)->default('C');
|
||||
$table->string('filename', 255)->nullable();
|
||||
$table->string('tempo', 10)->nullable();
|
||||
$table->string('L', 5)->nullable();
|
||||
$table->text('music')->nullable();
|
||||
$table->string('parts', 255)->nullable();
|
||||
$table->timestamps();
|
||||
$table->foreign('tune_id')->references('id')->on('tunes')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
Schema::create('tune_attributes', function (Blueprint $table) {
|
||||
$table->bigInteger('tune_id')->unsigned();
|
||||
$table->enum('type', ['Title','Group','Origin','Rhythm','History']);
|
||||
$table->string('string', 255);
|
||||
$table->tinyInteger('ordering')->unsigned()->default(0);
|
||||
$table->timestamps();
|
||||
$table->primary(['tune_id','type','ordering']);
|
||||
$table->foreign('tune_id')->references('id')->on('tunes')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Schema::create('tune_books', function (Blueprint $table) {
|
||||
$table->bigInteger('collection_id')->unsigned();
|
||||
$table->bigInteger('setting_id')->unsigned();
|
||||
$table->timestamps();
|
||||
$table->primary(['collection_id','setting_id']);
|
||||
$table->foreign('collection_id')->references('id')->on('collections')->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreign('setting_id')->references('id')->on('tune_settings')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Schema::create('tune_persons', function (Blueprint $table) {
|
||||
$table->bigInteger('tune_id')->unsigned();
|
||||
$table->bigInteger('person_id')->unsigned();
|
||||
$table->enum('type', ['Author','Composer','Transcriber','']);
|
||||
$table->tinyInteger('ordering')->unsigned()->default(0);
|
||||
$table->timestamps();
|
||||
$table->primary(['tune_id','person_id','type','ordering']);
|
||||
$table->foreign('tune_id')->references('id')->on('tunes')->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreign('person_id')->references('id')->on('persons')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Schema::create('tune_setting_attributes', function (Blueprint $table) {
|
||||
$table->bigInteger('setting_id')->unsigned();
|
||||
$table->enum('type', ['Transcriber','Note','Discography','Source','Word','Book']);
|
||||
$table->string('string', 255);
|
||||
$table->tinyInteger('ordering')->unsigned()->default(0);
|
||||
$table->timestamps();
|
||||
$table->primary(['setting_id','type','ordering']);
|
||||
$table->foreign('setting_id')->references('id')->on('tune_settings')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Schema::create('tune_setting_persons', function (Blueprint $table) {
|
||||
$table->bigInteger('setting_id')->unsigned();
|
||||
$table->bigInteger('person_id')->unsigned();
|
||||
$table->tinyInteger('ordering')->unsigned()->default(0);
|
||||
$table->timestamps();
|
||||
$table->primary(['setting_id','person_id','ordering']);
|
||||
$table->foreign('setting_id')->references('id')->on('tune_settings')->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreign('person_id')->references('id')->on('persons')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('tune_setting_persons');
|
||||
Schema::drop('tune_setting_attributes');
|
||||
Schema::drop('tune_persons');
|
||||
Schema::drop('tune_books');
|
||||
Schema::drop('tune_attributes');
|
||||
// Schema::drop('Groups');
|
||||
Schema::drop('tune_settings');
|
||||
Schema::drop('tunes');
|
||||
Schema::drop('persons');
|
||||
Schema::drop('collections');
|
||||
}
|
||||
}
|
||||
37
database/migrations/2016_03_06_021725_create_jobs_table.php
Normal file
37
database/migrations/2016_03_06_021725_create_jobs_table.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateJobsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue');
|
||||
$table->longText('payload');
|
||||
$table->tinyInteger('attempts')->unsigned();
|
||||
$table->tinyInteger('reserved')->unsigned();
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
$table->index(['queue', 'reserved', 'reserved_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('jobs');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateFailedJobsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->timestamp('failed_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('failed_jobs');
|
||||
}
|
||||
}
|
||||
31
src/AbstractBuilder.php
Normal file
31
src/AbstractBuilder.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser;
|
||||
|
||||
/**
|
||||
* outline the functions and parameters available in the concrete builders
|
||||
* Class AbstractBuilder
|
||||
*/
|
||||
abstract class AbstractBuilder
|
||||
{
|
||||
|
||||
protected $classMap;
|
||||
|
||||
protected $collection;
|
||||
protected $currentTune;
|
||||
protected $currentSetting;
|
||||
protected $currentPerson;
|
||||
|
||||
public abstract function newCollection();
|
||||
public abstract function appendToCollection($key, $data);
|
||||
|
||||
public abstract function newTune();
|
||||
public abstract function appendToTune($key, $data);
|
||||
public abstract function newSetting();
|
||||
|
||||
public abstract function appendToSetting($key, $data);
|
||||
public abstract function newPerson($data);
|
||||
|
||||
public function storeTune() {
|
||||
$this->appendToCollection('tune', $this->tune);
|
||||
}
|
||||
}
|
||||
23
src/Factory.php
Normal file
23
src/Factory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser;
|
||||
|
||||
class Factory
|
||||
{
|
||||
protected $classMap = [
|
||||
'TuneCollection' => null,
|
||||
];
|
||||
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
}
|
||||
|
||||
public static function create($type)
|
||||
{
|
||||
return call_user_func([self, 'createInstance']);
|
||||
}
|
||||
|
||||
public function createInstance($type)
|
||||
{
|
||||
return isset($this->classMap[$type])? new $this->classMap[$type]() : null;
|
||||
}
|
||||
}
|
||||
26
src/Interfaces/Builder.php
Normal file
26
src/Interfaces/Builder.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Interfaces;
|
||||
|
||||
/**
|
||||
* outline the functions and parameters available in the concrete builders
|
||||
* Class AbstractBuilder
|
||||
*/
|
||||
interface Builder
|
||||
{
|
||||
public function newCollection();
|
||||
public function appendToCollection($key, $data);
|
||||
public function setOnCollection($key, $data);
|
||||
public function getCollection();
|
||||
|
||||
public function newTune();
|
||||
public function appendToTune($key, $data);
|
||||
public function setOnTune($key, $data);
|
||||
|
||||
public function newSetting();
|
||||
public function appendToSetting($key, $data);
|
||||
public function setOnSetting($key, $data);
|
||||
|
||||
public function newPerson(array $data);
|
||||
|
||||
public function storeTune($music);
|
||||
}
|
||||
9
src/Interfaces/Exporter.php
Normal file
9
src/Interfaces/Exporter.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Interfaces;
|
||||
|
||||
interface Exporter
|
||||
{
|
||||
public function toAbc();
|
||||
|
||||
public function toJson();
|
||||
}
|
||||
9
src/Interfaces/Manipulator.php
Normal file
9
src/Interfaces/Manipulator.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Interfaces;
|
||||
|
||||
interface Manipulator
|
||||
{
|
||||
public function getTunes();
|
||||
|
||||
public function removeTune($tuneIndex);
|
||||
}
|
||||
93
src/Models/Arr/Abc.php
Normal file
93
src/Models/Arr/Abc.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Arr;
|
||||
|
||||
use XaiCorp\AbcParser\Interfaces\Builder;
|
||||
use XaiCorp\AbcParser\Interfaces\Exporter;
|
||||
use XaiCorp\AbcParser\Interfaces\Manipulator;
|
||||
|
||||
class Abc implements Builder, Manipulator, Exporter
|
||||
{
|
||||
protected $abc = [];
|
||||
protected $tunedIdx = 0;
|
||||
|
||||
public function newCollection()
|
||||
{
|
||||
$this->abc = [];
|
||||
}
|
||||
|
||||
public function appendToCollection($key, $data)
|
||||
{
|
||||
$this->abc[$key][] = $data;
|
||||
}
|
||||
|
||||
public function setOnCollection($key, $data)
|
||||
{
|
||||
$this->abc[$key] = $data;
|
||||
}
|
||||
|
||||
public function getCollection()
|
||||
{
|
||||
return $this->abc;
|
||||
}
|
||||
|
||||
public function newTune()
|
||||
{
|
||||
$this->abc[++$this->tunedIdx] = [];
|
||||
}
|
||||
|
||||
public function appendToTune($key, $data)
|
||||
{
|
||||
$this->abc[$this->tunedIdx][$key][] = $data;
|
||||
}
|
||||
|
||||
public function setOnTune($key, $data)
|
||||
{
|
||||
$this->abc[$this->tunedIdx][$key] = $data;
|
||||
}
|
||||
|
||||
public function newSetting()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function appendToSetting($key, $data)
|
||||
{
|
||||
$this->appendToTune($key, $data);
|
||||
}
|
||||
|
||||
public function setOnSetting($key, $data)
|
||||
{
|
||||
$this->setOnTune($key, $data);
|
||||
}
|
||||
|
||||
public function newPerson(array $data)
|
||||
{
|
||||
return $data['name'];
|
||||
}
|
||||
|
||||
public function getTunes()
|
||||
{
|
||||
return $this->abc;
|
||||
}
|
||||
|
||||
public function removeTune($tuneIndex)
|
||||
{
|
||||
unset($this->abc[$tuneIndex]);
|
||||
}
|
||||
|
||||
public function toAbc()
|
||||
{
|
||||
//TODO: translate to abc not json;
|
||||
return json_encode($this->abc);
|
||||
}
|
||||
|
||||
public function toJson()
|
||||
{
|
||||
return json_encode($this->abc);
|
||||
}
|
||||
|
||||
public function storeTune($music)
|
||||
{
|
||||
$this->abc[$this->tunedIdx]['music'] = trim($music);
|
||||
}
|
||||
}
|
||||
133
src/Models/Laravel5/Abc.php
Normal file
133
src/Models/Laravel5/Abc.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use XaiCorp\AbcParser\Interfaces\Builder;
|
||||
use XaiCorp\AbcParser\Interfaces\Exporter;
|
||||
use XaiCorp\AbcParser\Interfaces\Manipulator;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Collection;
|
||||
|
||||
class Abc implements Builder, Manipulator, Exporter
|
||||
{
|
||||
/**
|
||||
* @var \XaiCorp\AbcParser\Models\Laravel5\Collection
|
||||
*/
|
||||
public $collection;
|
||||
|
||||
/**
|
||||
* @var Tune
|
||||
*/
|
||||
public $tune;
|
||||
|
||||
/**
|
||||
* @var TuneSetting
|
||||
*/
|
||||
public $setting;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->collection = new Collection();
|
||||
}
|
||||
|
||||
public function newCollection()
|
||||
{
|
||||
$this->collection = new Collection();
|
||||
}
|
||||
public function appendToCollection($key, $data)
|
||||
{
|
||||
$allowedKeys = ['A', 'C', 'D', 'H', 'R', 'F', 'B', 'M', 'L', 'N', 'O', 'S', 'Z'];
|
||||
|
||||
if (in_array($key, $allowedKeys)) {
|
||||
$array = $this->collection->$key;
|
||||
$array[] = $data;
|
||||
$this->setOnCollection($key, $array);
|
||||
}
|
||||
}
|
||||
|
||||
public function setOnCollection($key, $data)
|
||||
{
|
||||
$allowedKeys = ['A', 'C', 'D', 'H', 'R', 'F', 'B', 'M', 'L', 'N', 'O', 'S', 'Z'];
|
||||
|
||||
if (in_array($key, $allowedKeys)) {
|
||||
$this->collection->$key = $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function getCollection()
|
||||
{
|
||||
return $this->collection;
|
||||
}
|
||||
|
||||
|
||||
public function newTune()
|
||||
{
|
||||
$this->tune = new Tune();
|
||||
}
|
||||
|
||||
public function appendToTune($key, $data)
|
||||
{
|
||||
$array = $this->tune->$key;
|
||||
$array[] = $data;
|
||||
$this->setOnTune($key, $array);
|
||||
}
|
||||
|
||||
public function setOnTune($key, $data)
|
||||
{
|
||||
$this->tune->$key = $data;
|
||||
}
|
||||
|
||||
|
||||
public function newSetting()
|
||||
{
|
||||
$this->setting = new TuneSetting();
|
||||
}
|
||||
|
||||
public function appendToSetting($key, $data)
|
||||
{
|
||||
$array = $this->setting->$key;
|
||||
$array[] = $data;
|
||||
$this->setOnSetting($key, $array);
|
||||
}
|
||||
|
||||
public function setOnSetting($key, $data)
|
||||
{
|
||||
$this->setting->$key = $data;
|
||||
}
|
||||
|
||||
|
||||
public function newPerson(array $data)
|
||||
{
|
||||
$person = new Person();
|
||||
foreach ($data as $key => $value) {
|
||||
$person->{$key} = $value;
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
public function storeTune($music)
|
||||
{
|
||||
$this->setting->music = $music;
|
||||
$this->setting->tune = $this->tune;
|
||||
$this->collection->appendSetting($this->setting);
|
||||
}
|
||||
|
||||
|
||||
public function getTunes()
|
||||
{
|
||||
$this->collection->getSettings();
|
||||
}
|
||||
|
||||
public function removeTune($tuneIndex)
|
||||
{}
|
||||
|
||||
public function toAbc()
|
||||
{
|
||||
$this->toJson();
|
||||
}
|
||||
|
||||
public function toJson()
|
||||
{
|
||||
$this->collection->toJson();
|
||||
}
|
||||
|
||||
}
|
||||
75
src/Models/Laravel5/AttributesTrait.php
Normal file
75
src/Models/Laravel5/AttributesTrait.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
trait AttributesTrait
|
||||
{
|
||||
|
||||
public function getAttr($type)
|
||||
{
|
||||
return $this->$type;
|
||||
}
|
||||
|
||||
public function loadAttr($type)
|
||||
{
|
||||
$result = [];
|
||||
call_user_func([$this->attributesClass, $type.'s'], [$this->id])
|
||||
->get()
|
||||
->each(function ($item, $key) use (&$result) {
|
||||
$result[] = $item->string;
|
||||
});
|
||||
if (! empty($result)) {
|
||||
$this->setAttr($type, $result);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAttr($type, array $values)
|
||||
{
|
||||
$this->$type = $values;
|
||||
}
|
||||
|
||||
public function saveAttr($type)
|
||||
{
|
||||
$values = $this->$type;
|
||||
if (! empty($values)) {
|
||||
$instance = new $this->attributesClass();
|
||||
foreach ($values as $key => $value) {
|
||||
$attr = $instance->attr($type, $value, $this)->first();
|
||||
if (!$attr) {
|
||||
$attr = new $this->attributesClass();
|
||||
}
|
||||
|
||||
$attr->fill([
|
||||
'tune_id' => $this->id,
|
||||
'setting_id' => $this->id,
|
||||
'collection_id' => $this->id,
|
||||
'type' => $type,
|
||||
'string' => $value,
|
||||
'ordering' => $key,
|
||||
]);
|
||||
$attr->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function newFromBuilder($attributes = [], $connection = null)
|
||||
{
|
||||
$class = new \ReflectionClass($this->attributesClass);
|
||||
$model = parent::newFromBuilder($attributes, $connection);
|
||||
foreach ($class->getStaticPropertyValue('types') as $attribute) {
|
||||
$model = $model->loadAttr($attribute);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function save(array $options = [])
|
||||
{
|
||||
$class = new \ReflectionClass($this->attributesClass);
|
||||
foreach ($class->getStaticPropertyValue('types') as $attribute) {
|
||||
$this->saveAttr($attribute);
|
||||
}
|
||||
$saved = parent::save($options);
|
||||
|
||||
return $saved;
|
||||
}
|
||||
}
|
||||
228
src/Models/Laravel5/Collection.php
Normal file
228
src/Models/Laravel5/Collection.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
|
||||
class Collection extends ValidatingModel implements \Countable
|
||||
{
|
||||
use AttributesTrait;
|
||||
|
||||
/**
|
||||
* for AttributesTrait
|
||||
* @var string
|
||||
*/
|
||||
protected $attributesClass = CollectionAttribute::class;
|
||||
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'collections';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['name'];
|
||||
|
||||
protected $hidden = [
|
||||
'Author',
|
||||
'Composer',
|
||||
'Discography',
|
||||
'Rhythm',
|
||||
'History',
|
||||
'File',
|
||||
'Book',
|
||||
'Note',
|
||||
'Origin',
|
||||
'Source',
|
||||
'Transcriber',
|
||||
];
|
||||
|
||||
protected $appends = ['A','C','D','H','R','F','B','N', 'O','S','Z',];
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
public function appendSetting($setting)
|
||||
{
|
||||
if (! $this->settings) {
|
||||
$this->settings = new \Illuminate\Support\Collection();
|
||||
}
|
||||
|
||||
$this->settings->push($setting);
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
public function getSettings()
|
||||
{
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
* mutators and accessors
|
||||
*/
|
||||
|
||||
protected $Author;
|
||||
public function getAAttribute()
|
||||
{
|
||||
return $this->getAttr('Author');
|
||||
}
|
||||
|
||||
public function setAAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Author', $values);
|
||||
}
|
||||
|
||||
protected $Composer;
|
||||
public function getCAttribute()
|
||||
{
|
||||
return $this->getAttr('Composer');
|
||||
}
|
||||
|
||||
public function setCAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Composer', $values);
|
||||
}
|
||||
|
||||
protected $Discography;
|
||||
public function getDAttribute()
|
||||
{
|
||||
return $this->getAttr('Discography');
|
||||
}
|
||||
|
||||
public function setDAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Discography', $values);
|
||||
}
|
||||
|
||||
protected $Rhythm;
|
||||
public function getRAttribute()
|
||||
{
|
||||
return $this->getAttr('Rhythm');
|
||||
}
|
||||
|
||||
public function setRAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Rhythm', $values);
|
||||
}
|
||||
|
||||
protected $History;
|
||||
public function getHAttribute()
|
||||
{
|
||||
return $this->getAttr('History');
|
||||
}
|
||||
|
||||
public function setHAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('History', $values);
|
||||
}
|
||||
|
||||
protected $File;
|
||||
public function getFAttribute()
|
||||
{
|
||||
return $this->getAttr('File');
|
||||
}
|
||||
|
||||
public function setFAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('File', $values);
|
||||
}
|
||||
|
||||
protected $Book;
|
||||
public function getBAttribute()
|
||||
{
|
||||
return $this->getAttr('Book');
|
||||
}
|
||||
|
||||
public function setBAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Book', $values);
|
||||
}
|
||||
|
||||
protected $Note;
|
||||
public function getNAttribute()
|
||||
{
|
||||
return $this->getAttr('Note');
|
||||
}
|
||||
|
||||
public function setNAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Note', $values);
|
||||
}
|
||||
|
||||
protected $Origin;
|
||||
public function getOAttribute()
|
||||
{
|
||||
return $this->getAttr('Origin');
|
||||
}
|
||||
|
||||
public function setOAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Origin', $values);
|
||||
}
|
||||
|
||||
protected $Source;
|
||||
public function getSAttribute()
|
||||
{
|
||||
return $this->getAttr('Source');
|
||||
}
|
||||
|
||||
public function setSAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Source', $values);
|
||||
}
|
||||
|
||||
protected $Transcriber;
|
||||
public function getZAttribute()
|
||||
{
|
||||
return $this->getAttr('Transcriber');
|
||||
}
|
||||
|
||||
public function setZAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Transcriber', $values);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* implementation of Countable::count()
|
||||
*
|
||||
* @return int the number of tunes in the collection
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->settings);
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$arr = parent::toArray();
|
||||
|
||||
foreach ($this->settings->toArray() as $key => $setting) {
|
||||
$arr[$key+1] = $setting;
|
||||
}
|
||||
|
||||
foreach (['A', 'C', 'Z'] as $attr) {
|
||||
if (isset($arr[$attr])) {
|
||||
foreach ($arr[$attr] as $key => $person) {
|
||||
$arr[$attr][$key] = $person->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($arr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
unset($arr[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
}
|
||||
190
src/Models/Laravel5/CollectionAttribute.php
Normal file
190
src/Models/Laravel5/CollectionAttribute.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class CollectionAttribute extends ValidatingModel
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'collection_attributes';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [
|
||||
'collection_id' => 'required|integer|exists:collections,id',
|
||||
'type' => 'required|string|in:Author,Composer,Discography,Rhythm,History,File,Book,Note,Source,Transcriber',
|
||||
'string' => 'required|string|max:255',
|
||||
'ordering' => 'required|integer'
|
||||
];
|
||||
|
||||
/**
|
||||
* supported attribute types
|
||||
* @var array
|
||||
*/
|
||||
public static $types = [
|
||||
'Author',
|
||||
'Composer',
|
||||
'Discography',
|
||||
'Rhythm',
|
||||
'History',
|
||||
'File',
|
||||
'Book',
|
||||
'Note',
|
||||
'Origin',
|
||||
'Source',
|
||||
'Transcriber',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['collection_id', 'type', 'string', 'ordering'];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['collection_id', 'type', 'ordering'];
|
||||
|
||||
public static function getTypes()
|
||||
{
|
||||
return self::$types;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* Scopes
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAuthors($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Author')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeComposers($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Composer')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeDiscographys($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Discography')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeFiles($query, $id)
|
||||
{
|
||||
return $query->where('type', 'File')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeRhythms($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Rhythm')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeHistorys($query, $id)
|
||||
{
|
||||
return $query->where('type', 'History')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeBooks($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Book')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeNotes($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Note')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeOrigins($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Origin')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeSources($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Source')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTranscribers($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Transcriber')->where('collection_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $attr
|
||||
* @param mixed $value
|
||||
* @param \XaiCorp\AbcParser\Models\Laravel5\Tune|null $collection
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAttr($query, $attr, $value, Collection $collection = null)
|
||||
{
|
||||
if ($collection) {
|
||||
$query = $query->where('collection_id', $collection->id);
|
||||
}
|
||||
return $query->where('type', strtolower($attr))->where('string', $value);
|
||||
}
|
||||
}
|
||||
34
src/Models/Laravel5/Person.php
Normal file
34
src/Models/Laravel5/Person.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model as BaseModel;
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class Person extends BaseModel
|
||||
{
|
||||
use ValidationTrait;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'persons';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['name', 'email'];
|
||||
|
||||
protected $hidden = ['email'];
|
||||
|
||||
//Relationships
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
121
src/Models/Laravel5/Tune.php
Normal file
121
src/Models/Laravel5/Tune.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model as BaseModel;
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class Tune extends ValidatingModel
|
||||
{
|
||||
use AttributesTrait;
|
||||
|
||||
/**
|
||||
* for AttributesTrait
|
||||
* @var string
|
||||
*/
|
||||
protected $attributesClass = TuneAttribute::class;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tunes';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [
|
||||
'x_id' => 'integer|min:1',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['x_id', 'X', 'T'];
|
||||
|
||||
protected $hidden = ['x_id', 'Title', 'Group', 'Origin', 'Rhythm', 'History'];
|
||||
|
||||
protected $appends = ['T', 'G', 'O', 'R', 'H'];
|
||||
|
||||
|
||||
/**************************************************************
|
||||
* mutators and accessors
|
||||
*/
|
||||
|
||||
protected $Title;
|
||||
public function getTAttribute()
|
||||
{
|
||||
return $this->getAttr('Title');
|
||||
}
|
||||
|
||||
public function setTAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Title', $values);
|
||||
}
|
||||
|
||||
protected $Group;
|
||||
public function getGAttribute()
|
||||
{
|
||||
return $this->getAttr('Group');
|
||||
}
|
||||
public function setGAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Group', $values);
|
||||
}
|
||||
|
||||
public function getOAttribute()
|
||||
{
|
||||
return $this->getAttr('Origin');
|
||||
}
|
||||
|
||||
protected $Origin;
|
||||
public function setOAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Origin', $values);
|
||||
}
|
||||
|
||||
protected $Rhythm;
|
||||
public function getRAttribute()
|
||||
{
|
||||
return $this->getAttr('Rhythm');
|
||||
}
|
||||
|
||||
public function setRAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Rhythm', $values);
|
||||
}
|
||||
|
||||
protected $History;
|
||||
public function getHAttribute()
|
||||
{
|
||||
return $this->getAttr('History');
|
||||
}
|
||||
|
||||
public function setHAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('History', $values);
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$arr = parent::toArray();
|
||||
|
||||
foreach (['A','C'] as $attr) {
|
||||
if (isset($arr[$attr])) {
|
||||
foreach ($arr[$attr] as $key => $person) {
|
||||
$arr[$attr][$key] = $person->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($arr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
unset($arr[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
134
src/Models/Laravel5/TuneAttribute.php
Normal file
134
src/Models/Laravel5/TuneAttribute.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class TuneAttribute extends ValidatingModel
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tune_attributes';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [
|
||||
'tune_id' => 'required|integer|exists:tunes,id',
|
||||
'type' => 'required|string|in:Title,Group,Origin,Rhythm,History',
|
||||
'string' => 'required|string|max:255',
|
||||
'ordering' => 'required|integer'
|
||||
];
|
||||
|
||||
/**
|
||||
* supported attribute types
|
||||
* @var array
|
||||
*/
|
||||
public static $types = [
|
||||
'Title',
|
||||
'Group',
|
||||
'Origin',
|
||||
'Rhythm',
|
||||
'History'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['tune_id', 'type', 'string', 'ordering'];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['tune_id', 'type', 'ordering'];
|
||||
|
||||
public static function getTypes()
|
||||
{
|
||||
return self::$types;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* Scopes
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTitle($query, $value)
|
||||
{
|
||||
return $query->where('type', 'Title')->where('string', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTitles($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Title')->where('tune_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeGroups($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Group')->where('tune_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeOrigins($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Origin')->where('tune_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeRhythms($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Rhythm')->where('tune_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeHistorys($query, $id)
|
||||
{
|
||||
return $query->where('type', 'History')->where('tune_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $attr
|
||||
* @param mixed $value
|
||||
* @param \XaiCorp\AbcParser\Models\Laravel5\Tune|null $tune
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAttr($query, $attr, $value, Tune $tune = null)
|
||||
{
|
||||
if ($tune) {
|
||||
$query = $query->where('tune_id', $tune->id);
|
||||
}
|
||||
return $query->where('type', strtolower($attr))->where('string', $value);
|
||||
}
|
||||
}
|
||||
168
src/Models/Laravel5/TuneSetting.php
Normal file
168
src/Models/Laravel5/TuneSetting.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model as BaseModel;
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class TuneSetting extends ValidatingModel
|
||||
{
|
||||
use AttributesTrait;
|
||||
|
||||
/**
|
||||
* for AttributesTrait
|
||||
* @var string
|
||||
*/
|
||||
protected $attributesClass = TuneSettingAttribute::class;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tune_settings';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [
|
||||
'tune_id' => 'required|integer|min:1|exists:tunes,id',
|
||||
'meter' => 'string|max:3',
|
||||
'keysig' => 'string|max:5',
|
||||
'filename' => 'string|max:255',
|
||||
'tempo' => 'string|max:10',
|
||||
'L' => 'string|max:5',
|
||||
'music' => 'string',
|
||||
'parts' => 'string|max:255'
|
||||
];
|
||||
|
||||
public static $regex_Q = '/\d\/\d\d?=\d{2,3}/i';
|
||||
public static $regex_L = '/\d\/\d{1,2}/i';
|
||||
public static $regex_M = '/((C|C\|)|\d{1,2}\/\d{1,3})/i';
|
||||
public static $regex_K = '/[a-zA-G]{1,5}/i';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['tune_id', 'meter', 'keysig', 'filename', 'tempo', 'L', 'music', 'parts'];
|
||||
|
||||
protected $hidden = ['Transcriber', 'Note', 'Discography', 'Source', 'Word', 'Book'];
|
||||
|
||||
protected $appends = ['Z', 'N', 'D', 'S', 'W', 'B'];
|
||||
|
||||
|
||||
/**************************************************************
|
||||
* mutators and accessors
|
||||
*/
|
||||
|
||||
public function setMusicAttribute($value)
|
||||
{
|
||||
$this->attributes['music'] = trim($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Tune
|
||||
*/
|
||||
protected $tune;
|
||||
|
||||
public function setTuneAttribute(Tune $tune)
|
||||
{
|
||||
$this->tune = $tune;
|
||||
}
|
||||
|
||||
public function getTuneAttribute()
|
||||
{
|
||||
return $this->tune;
|
||||
}
|
||||
|
||||
protected $Transcriber;
|
||||
public function getZAttribute()
|
||||
{
|
||||
return $this->getAttr('Transcriber');
|
||||
}
|
||||
|
||||
public function setZAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Transcriber', $values);
|
||||
}
|
||||
|
||||
protected $Note;
|
||||
public function getNAttribute()
|
||||
{
|
||||
return $this->getAttr('Note');
|
||||
}
|
||||
|
||||
public function setNAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Note', $values);
|
||||
}
|
||||
|
||||
protected $Discography;
|
||||
public function getDAttribute()
|
||||
{
|
||||
return $this->getAttr('Discography');
|
||||
}
|
||||
|
||||
public function setDAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Discography', $values);
|
||||
}
|
||||
|
||||
protected $Source;
|
||||
public function getSAttribute()
|
||||
{
|
||||
return $this->getAttr('Source');
|
||||
}
|
||||
|
||||
public function setSAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Source', $values);
|
||||
}
|
||||
|
||||
protected $Word;
|
||||
public function getWAttribute()
|
||||
{
|
||||
return $this->getAttr('Word');
|
||||
}
|
||||
|
||||
public function setWAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Word', $values);
|
||||
}
|
||||
|
||||
protected $Book;
|
||||
public function getBAttribute()
|
||||
{
|
||||
return $this->getAttr('Book');
|
||||
}
|
||||
|
||||
public function setBAttribute(array $values)
|
||||
{
|
||||
$this->setAttr('Book', $values);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$arr = parent::toArray();
|
||||
|
||||
if (isset($arr['Z'])) {
|
||||
foreach ($arr['Z'] as $key => $person) {
|
||||
$arr['Z'][$key] = $person->name;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($arr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
unset($arr[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$tune = $this->tune->toArray();
|
||||
return array_merge($this->tune->toArray(), $arr);
|
||||
}
|
||||
}
|
||||
145
src/Models/Laravel5/TuneSettingAttribute.php
Normal file
145
src/Models/Laravel5/TuneSettingAttribute.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class TuneSettingAttribute extends ValidatingModel
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tune_setting_attributes';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [
|
||||
'setting_id' => 'required|integer|exists:tune_settings,id',
|
||||
'type' => 'required|string|in:Transcriber,Note,Discography,Source,Word,Book',
|
||||
'string' => 'required|string|max:255',
|
||||
'ordering' => 'required|integer'
|
||||
];
|
||||
|
||||
/**
|
||||
* supported attribute types
|
||||
* @var array
|
||||
*/
|
||||
public static $types = [
|
||||
'Transcriber',
|
||||
'Note',
|
||||
'Discography',
|
||||
'Source',
|
||||
'Word',
|
||||
'Book'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['setting_id', 'type', 'string', 'ordering'];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['setting_id', 'type', 'ordering'];
|
||||
|
||||
public static function getTypes()
|
||||
{
|
||||
return self::$types;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* Scopes
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTranscriber($query, $value)
|
||||
{
|
||||
return $query->where('type', 'Transcriber')->where('string', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTranscribers($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Transcriber')->where('setting_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeNotes($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Note')->where('setting_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeDiscographys($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Discography')->where('setting_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeSources($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Source')->where('setting_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeWords($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Word')->where('setting_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeBooks($query, $id)
|
||||
{
|
||||
return $query->where('type', 'Book')->where('setting_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $attr
|
||||
* @param mixed $value
|
||||
* @param \XaiCorp\AbcParser\Models\Laravel5\Tune|null $setting
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAttr($query, $attr, $value, TuneSetting $setting = null)
|
||||
{
|
||||
if ($setting) {
|
||||
$query = $query->where('setting_id', $setting->id);
|
||||
}
|
||||
return $query->where('type', strtolower($attr))->where('string', $value);
|
||||
}
|
||||
}
|
||||
28
src/Models/Laravel5/ValidatingModel.php
Normal file
28
src/Models/Laravel5/ValidatingModel.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model as BaseModel;
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class ValidatingModel extends BaseModel
|
||||
{
|
||||
use ValidationTrait;
|
||||
|
||||
/**
|
||||
* validation rules to apply to model attributes
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [];
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function save(array $options = [])
|
||||
{
|
||||
if ($this->validate()) {
|
||||
return parent::save($options);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
67
src/Models/Memory/Abc.php
Normal file
67
src/Models/Memory/Abc.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Memory;
|
||||
|
||||
use XaiCorp\AbcParser\Interfaces\Builder;
|
||||
use XaiCorp\AbcParser\Interfaces\Exporter;
|
||||
use XaiCorp\AbcParser\Interfaces\Manipulator;
|
||||
|
||||
class Abc implements Builder
|
||||
{
|
||||
protected $collection;
|
||||
|
||||
protected $currentTune;
|
||||
|
||||
protected $currentSetting;
|
||||
|
||||
public function newCollection()
|
||||
{
|
||||
$this->collection = new TuneCollection();
|
||||
}
|
||||
|
||||
public function appendToCollection($key, $data)
|
||||
{
|
||||
$this->collection->append($key, $data);
|
||||
}
|
||||
|
||||
public function getCollection()
|
||||
{
|
||||
return count($this->collection) ? $this->collection : FALSE;
|
||||
}
|
||||
|
||||
public function newTune()
|
||||
{
|
||||
$this->currentTune = new Tune();
|
||||
}
|
||||
|
||||
public function appendToTune($key, $data)
|
||||
{
|
||||
$this->currentTune->append($key, $data);
|
||||
}
|
||||
|
||||
public function setOnTune($key, $data)
|
||||
{
|
||||
$this->currentTune->set($key, $data);
|
||||
}
|
||||
|
||||
public function newSetting()
|
||||
{
|
||||
$this->currentSetting = new Setting();
|
||||
}
|
||||
|
||||
public function appendToSetting($key, $data)
|
||||
{
|
||||
$this->currentSetting->append($key, $data);
|
||||
}
|
||||
|
||||
public function newPerson(array $data)
|
||||
{
|
||||
return new Person($data);
|
||||
}
|
||||
|
||||
public function storeTune($music)
|
||||
{
|
||||
$this->currentSetting->set('music', trim($music));
|
||||
$this->currentTune->append('collection', $this->currentSetting);
|
||||
$this->collection->append('collection', $this->currentTune);
|
||||
}
|
||||
}
|
||||
113
src/Models/Memory/BaseIterator.php
Normal file
113
src/Models/Memory/BaseIterator.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Memory;
|
||||
|
||||
abstract class BaseIterator extends BaseObject implements \Iterator, \Countable, \ArrayAccess {
|
||||
|
||||
private $position = 0;
|
||||
protected $collection = array();
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Implementation of Countable
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* implementation of Countable::count()
|
||||
*
|
||||
* @return int the number of tunes in the collection
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->collection);
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Implementation of ArrayAccess
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
public function offsetExists ( $offset )
|
||||
{
|
||||
return isset($this->collection[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet ( $offset )
|
||||
{
|
||||
return isset($this->collection[$offset])? $this->collection[$offset] : null;
|
||||
}
|
||||
|
||||
public function offsetSet ( $offset, $value )
|
||||
{
|
||||
$offset = ($offset === NULL) ? count($this->collection) : $offset;
|
||||
if(is_a($value, BaseObject::class)) { $this->collection[$offset] = $value; }
|
||||
}
|
||||
|
||||
public function offsetUnset ( $offset )
|
||||
{
|
||||
unset($this->collection[$offset]);
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Implementation of Iterator
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* implementation of Iterator::current()
|
||||
*
|
||||
* @return Tune
|
||||
*/
|
||||
public function current ()
|
||||
{
|
||||
return $this->collection[$this->position];
|
||||
}
|
||||
|
||||
/**
|
||||
* implementation of Iterator::key()
|
||||
*
|
||||
* @return Scalar the current index
|
||||
*/
|
||||
public function key ()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* implementation of Iterator::next()
|
||||
*
|
||||
* sets the position to the next index
|
||||
*/
|
||||
public function next ()
|
||||
{
|
||||
++$this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* implementation of Iterator::rewind()
|
||||
*
|
||||
* sets the position to the beginning of the collection
|
||||
*/
|
||||
public function rewind ()
|
||||
{
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* implementation of Iterator::valid()
|
||||
*
|
||||
* tests that there is a tune at the current position
|
||||
* @return boolean
|
||||
*/
|
||||
public function valid ()
|
||||
{
|
||||
$is_valid = isset($this->collection[$this->position]);
|
||||
if(! $is_valid) { $this->rewind(); }
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
34
src/Models/Memory/BaseObject.php
Normal file
34
src/Models/Memory/BaseObject.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Memory;
|
||||
|
||||
abstract class BaseObject
|
||||
{
|
||||
public static $propertyNames = [];
|
||||
protected $change_hash;
|
||||
|
||||
/**
|
||||
* return true if the public property values are equal
|
||||
*
|
||||
* @param $ob1 first tune to check
|
||||
* @param $ob2 2nd tune
|
||||
* @return (Boolean) TRUE if the 2 tunes are identical, FALSE otherwise
|
||||
*/
|
||||
public function equals ($ob1, $ob2)
|
||||
{
|
||||
if( serialize($ob1) != serialize($ob2) ) { return FALSE; }
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->change_hash = $this->generate_hash();
|
||||
}
|
||||
|
||||
public static function propertyNames()
|
||||
{
|
||||
return static::propertyNames;
|
||||
}
|
||||
|
||||
protected abstract function generate_hash();
|
||||
|
||||
}
|
||||
130
src/Models/Memory/Person.php
Normal file
130
src/Models/Memory/Person.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Memory;
|
||||
|
||||
class Person extends BaseObject
|
||||
{
|
||||
private $person_id = 0;
|
||||
|
||||
private $name = '';
|
||||
private $email = '';
|
||||
|
||||
// private $change_hash;
|
||||
|
||||
/**
|
||||
* Person constructor
|
||||
*
|
||||
* @param $params (array) list of parameters to set at initialization
|
||||
*/
|
||||
function __construct($params = array()) {
|
||||
//Init parameters
|
||||
foreach($params as $key=>$val)
|
||||
{
|
||||
$this->set($key, $val);
|
||||
}
|
||||
|
||||
$this->change_hash = $this->generate_hash();
|
||||
}
|
||||
|
||||
/**
|
||||
* magic setter
|
||||
* just passes to regular set method which contains validation
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$this->set($key, $value);
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$retVar = FALSE;
|
||||
switch($key)
|
||||
{
|
||||
case 'person_id' :
|
||||
if( $this->person_id === 0 && is_numeric($value) && intval($value) > 0 )
|
||||
{
|
||||
$this->{$key} = intval($value);
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
if(is_string($value) && ! is_null($value))
|
||||
{
|
||||
$this->{$key} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
case 'email':
|
||||
if(filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->{$key} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $retVar;
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
if ( is_string($key) && isset($this->$key) )
|
||||
{
|
||||
return $this->$key;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* set default values for the person
|
||||
* used when creating a new person from scratch
|
||||
*/
|
||||
// public function init()
|
||||
// {
|
||||
// $this->change_hash = $this->generate_hash();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Test if the data has changed
|
||||
*
|
||||
* @return (bool) True if the data has changed since last load/save
|
||||
*/
|
||||
public function is_changed()
|
||||
{
|
||||
return $this->change_hash !== $this->generate_hash();
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Private functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* generate hash for the whole person object
|
||||
*
|
||||
* @returns (string) md5 hash of all attributes
|
||||
*/
|
||||
protected function generate_hash()
|
||||
{
|
||||
$data = array(
|
||||
$this->person_id,
|
||||
$this->name,
|
||||
$this->email
|
||||
);
|
||||
|
||||
return md5(serialize($data));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Static functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
|
||||
}
|
||||
281
src/Models/Memory/Setting.php
Normal file
281
src/Models/Memory/Setting.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Memory;
|
||||
|
||||
class Setting extends BaseObject {
|
||||
|
||||
private $settingID = 0;
|
||||
private $tuneID;
|
||||
|
||||
//fields that support multiple values
|
||||
private $Z = array(); //transcriber
|
||||
private $N = array(); //notes
|
||||
private $D = array(); //discography
|
||||
private $S = array(); //source
|
||||
private $W = array();
|
||||
private $B = array(); //Book
|
||||
private $F = array(); //file name
|
||||
|
||||
//fields that only ever have one value
|
||||
private $P = ''; //Parts;
|
||||
private $Q = ''; //tempo
|
||||
private $L = '1/8'; //default note length
|
||||
private $M = '4/4'; //meter
|
||||
|
||||
private $K = 'C'; //key
|
||||
private $music = ''; //multiline string
|
||||
|
||||
// private $music_hash;
|
||||
// private $change_hash;
|
||||
|
||||
public static $regex_Q = '/\d\/\d\d?=\d{2,3}/i';
|
||||
public static $regex_L = '/\d\/\d{1,2}/i';
|
||||
public static $regex_M = '/((C|C\|)|\d{1,2}\/\d{1,3})/i';
|
||||
public static $regex_K = '/[a-zA-G]{1,5}/i';
|
||||
|
||||
public static $propertyNames = array(
|
||||
'Z' => 'Transcriber',
|
||||
'N' => 'Notes',
|
||||
'D' => 'Discography',
|
||||
'S' => 'Source',
|
||||
'W' => 'Words,',
|
||||
'B' => 'Book',
|
||||
'F' => 'Filename',
|
||||
'P' => 'Parts',
|
||||
'Q' => 'Tempo,',
|
||||
'L' => 'default note length',
|
||||
'M' => 'Meter',
|
||||
'K' => 'Key',
|
||||
);
|
||||
|
||||
/**
|
||||
* Tune constructor
|
||||
*
|
||||
* @param $params (array) list of parameters to set at initialization
|
||||
*/
|
||||
function __construct(array $params = array()) {
|
||||
//Init parameters
|
||||
foreach($params as $key=>$val)
|
||||
{
|
||||
$this->set($key, $val);
|
||||
}
|
||||
|
||||
$this->change_hash = $this->generate_hash();
|
||||
}
|
||||
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* public functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* get the value of a private property
|
||||
*
|
||||
* @return (mixed) value of the property or FALSE if property does not exist
|
||||
*/
|
||||
public function get($property)
|
||||
{
|
||||
if(isset($this->{$property})) { return $this->{$property}; }
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* magic setter
|
||||
* just passes to regular set method which contains validation
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$this->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* set new value for a property
|
||||
* overwrites the existing value
|
||||
*
|
||||
* @return (boolean) TRUE on success, FALSE otherwise
|
||||
*/
|
||||
public function set($property, $value)
|
||||
{
|
||||
$retVar = FALSE;
|
||||
|
||||
switch($property)
|
||||
{
|
||||
case 'settingID':
|
||||
if($this->settingID !== 0) { // if settingID is not 0 don't allow setting it
|
||||
$retVar = FALSE;
|
||||
break;
|
||||
}
|
||||
//follow through since this is also a numeric value
|
||||
case 'tuneID':
|
||||
if(is_numeric($value) && $value > 0)
|
||||
{
|
||||
$this->{$property} = (int)$value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Q':
|
||||
case 'L':
|
||||
case 'M':
|
||||
if ( ! Setting::validate_line($property, $value) ) { return FALSE; }
|
||||
case 'K':
|
||||
case 'P':
|
||||
case 'music':
|
||||
if( ! is_array($value) && ! is_int($value) )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
if( is_array($value) && count($value) > 0)
|
||||
{
|
||||
$contains_only = TRUE;
|
||||
foreach($value as $person)
|
||||
{
|
||||
if(! is_a($person, __NAMESPACE__."\Person"))
|
||||
{
|
||||
$contains_only = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( $contains_only )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
case 'N':
|
||||
case 'D':
|
||||
case 'S':
|
||||
case 'W':
|
||||
case 'B':
|
||||
if( is_array($value) )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default: // non-existant or non-editable property
|
||||
break;
|
||||
}
|
||||
|
||||
return $retVar;
|
||||
}
|
||||
|
||||
/**
|
||||
* append a value to a property's array
|
||||
*
|
||||
* @param (string) $property name
|
||||
* @param (mixed) $value to add to the array
|
||||
*
|
||||
* @return (Boolean) TRUE on success, FALSE otherwise
|
||||
*/ public function append($property, $value)
|
||||
{
|
||||
if( ! is_array($value) )
|
||||
{
|
||||
switch($property)
|
||||
{
|
||||
case 'Z':
|
||||
if( ! is_a($value, __NAMESPACE__."\Person") ) {
|
||||
break;
|
||||
}
|
||||
case 'N':
|
||||
case 'D':
|
||||
case 'S':
|
||||
case 'W':
|
||||
case 'B':
|
||||
case 'F':
|
||||
$this->{$property}[] = $value;
|
||||
return TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->set($property, $value);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the data has changed
|
||||
*
|
||||
* @return (bool) True if the data has changed since last load/save
|
||||
*/
|
||||
public function is_changed()
|
||||
{
|
||||
return $this->change_hash !== $this->generate_hash();
|
||||
}
|
||||
|
||||
// public function init()
|
||||
// {
|
||||
// $this->change_hash = $this->generate_hash();
|
||||
// }
|
||||
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Private functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* generate hash for the whole person object
|
||||
*
|
||||
* @returns (string) md5 hash of all attributes
|
||||
*/
|
||||
protected function generate_hash()
|
||||
{
|
||||
$data = array(
|
||||
$this->tuneID,
|
||||
$this->settingID,
|
||||
//TODO: take into account the transcribers
|
||||
//$this->Z,
|
||||
$this->N,
|
||||
$this->D,
|
||||
$this->S,
|
||||
$this->W,
|
||||
$this->B,
|
||||
$this->F,
|
||||
$this->P,
|
||||
$this->Q,
|
||||
$this->L,
|
||||
$this->M,
|
||||
$this->K,
|
||||
$this->music,
|
||||
);
|
||||
|
||||
return md5(serialize($data));
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Static functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
|
||||
|
||||
protected static function validate_line($key, $data)
|
||||
{
|
||||
$result = TRUE;
|
||||
if(isset(Setting::${"regex_$key"}))
|
||||
{
|
||||
$regex = Setting::${"regex_$key"};
|
||||
$result = preg_match($regex, serialize($data));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
254
src/Models/Memory/Tune.php
Normal file
254
src/Models/Memory/Tune.php
Normal file
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Memory;
|
||||
|
||||
class Tune extends BaseIterator {
|
||||
|
||||
protected $tuneID = 0;
|
||||
// private $position = 0;
|
||||
|
||||
protected $X = "1"; //index
|
||||
protected $T = array(); //titles
|
||||
protected $A = array(); //Author of Lyrics
|
||||
protected $C = array(); //Composer
|
||||
protected $G = array(); //Group
|
||||
protected $H = array(); //History - multiline string
|
||||
protected $O = array(); //Origin
|
||||
protected $R = array(); //Rhythm
|
||||
|
||||
// private $settings = array();
|
||||
|
||||
//Use md5 hashes to check if data has been modified
|
||||
// protected $change_hash;
|
||||
|
||||
public static $propertyNames = array(
|
||||
'X' => 'id',
|
||||
'T' => 'Title',
|
||||
'A' => 'Author',
|
||||
'C' => 'Composer',
|
||||
'G' => 'Group,',
|
||||
'H' => 'History',
|
||||
'O' => 'Origin',
|
||||
'R' => 'Rhythm',
|
||||
);
|
||||
|
||||
/**
|
||||
* Tune constructor
|
||||
*
|
||||
* @param $params (array) list of parameters to set at initialization
|
||||
*/
|
||||
function __construct(array $params = array()) {
|
||||
//Init parameters
|
||||
foreach($params as $key=>$val)
|
||||
{
|
||||
$this->set($key, $val);
|
||||
}
|
||||
|
||||
$this->change_hash = $this->generate_hash();
|
||||
}
|
||||
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* public functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* get the value of a private property
|
||||
*
|
||||
* @return (mixed) value of the property or FALSE if property does not exist
|
||||
*/
|
||||
public function get($property)
|
||||
{
|
||||
if(isset($this->{$property})) { return $this->{$property}; }
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* magic setter
|
||||
* just passes to regular set method which contains validation
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$this->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* set new value for a property
|
||||
* overwrites the existing value
|
||||
*
|
||||
* @return (boolean) TRUE on success, FALSE otherwise
|
||||
*/
|
||||
public function set($property, $value)
|
||||
{
|
||||
$retVar = FALSE;
|
||||
|
||||
switch($property)
|
||||
{
|
||||
case 'tuneID':
|
||||
if($this->tuneID !== 0) { // if tuneID is not 0 don't allow setting it
|
||||
$retVar = FALSE;
|
||||
break;
|
||||
}
|
||||
//follow through since this is also a numeric value
|
||||
case 'X':
|
||||
if(is_numeric($value) && $value > 0)
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
case 'C':
|
||||
if( is_array($value) && count($value) > 0)
|
||||
{
|
||||
$contains_only = TRUE;
|
||||
foreach($value as $key=>$person)
|
||||
{
|
||||
if(! is_a($person, __NAMESPACE__ . '\\' ."Person"))
|
||||
{
|
||||
$contains_only = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( $contains_only )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
case 'G':
|
||||
case 'H':
|
||||
case 'O':
|
||||
case 'R':
|
||||
if(is_array($value))
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'collection':
|
||||
if( is_array($value) && count($value) > 0)
|
||||
{
|
||||
$only_settings = TRUE;
|
||||
foreach($value as $key=>$setting)
|
||||
{
|
||||
if(! is_a($setting, __NAMESPACE__ . '\\' ."Setting"))
|
||||
{
|
||||
$only_settings = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( $only_settings )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default: // non-existant or non-editable property
|
||||
break;
|
||||
}
|
||||
|
||||
return $retVar;
|
||||
}
|
||||
|
||||
/**
|
||||
* append a value to a property's array
|
||||
*
|
||||
* @param (string) $property name
|
||||
* @param (mixed) $value to add to the array
|
||||
*
|
||||
* @return (Boolean) TRUE on success, FALSE otherwise
|
||||
*/ public function append($property, $value)
|
||||
{
|
||||
if( ! is_array($value) )
|
||||
{
|
||||
switch($property)
|
||||
{
|
||||
case 'T':
|
||||
case 'A':
|
||||
case 'C':
|
||||
case 'G':
|
||||
case 'H':
|
||||
case 'O':
|
||||
case 'R':
|
||||
$this->{$property}[] = $value;
|
||||
return TRUE;
|
||||
break;
|
||||
|
||||
case 'collection':
|
||||
if( is_a($value, __NAMESPACE__ . '\\' ."Setting") )
|
||||
{
|
||||
$this->{$property}[] = $value;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->set($property, $value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if the data has changed
|
||||
*
|
||||
* @return (bool) True if the data has changed since last load/save
|
||||
*/
|
||||
public function is_changed()
|
||||
{
|
||||
return $this->change_hash !== $this->generate_hash();
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Private functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* generate hash for the whole person object
|
||||
*
|
||||
* @returns (string) md5 hash of all attributes
|
||||
*/
|
||||
protected function generate_hash()
|
||||
{
|
||||
$data = array(
|
||||
$this->tuneID,
|
||||
$this->X,
|
||||
$this->T,
|
||||
// $this->A,
|
||||
// $this->C,
|
||||
$this->G,
|
||||
$this->H,
|
||||
$this->O,
|
||||
$this->R,
|
||||
// $this->collection,
|
||||
);
|
||||
|
||||
return md5(serialize($data));
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* Static functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
|
||||
|
||||
}
|
||||
271
src/Models/Memory/TuneCollection.php
Normal file
271
src/Models/Memory/TuneCollection.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Memory;
|
||||
|
||||
/**
|
||||
* TuneCollection represents a collection of tunes, such a book, manuscript
|
||||
* or abc file.
|
||||
*
|
||||
* a collection can have various parameters to define the collection
|
||||
* in addition to the list of tunes
|
||||
*/
|
||||
class TuneCollection extends BaseIterator {
|
||||
|
||||
private $tc_id = 0; // collection id
|
||||
private $cOwner; // collection owner. The user that uploaded it
|
||||
|
||||
// private $tunes = array();
|
||||
|
||||
//abc tunebook header fields
|
||||
private $A = array(); //Author / Area
|
||||
private $B = array(); //Book
|
||||
private $C = array(); //Composer
|
||||
private $D = array(); //Discography
|
||||
private $F = array(); //file url
|
||||
private $H = array(); //History
|
||||
private $L; //note length
|
||||
private $M; //Meter
|
||||
private $N = array(); //Notes
|
||||
private $O = array(); //Origin
|
||||
private $R; //Rhythm
|
||||
private $S = array(); //Source
|
||||
private $Z = array(); //Transcription
|
||||
|
||||
|
||||
// public function __construct()
|
||||
// {}
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* public functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* add a tune to the collection
|
||||
*
|
||||
* @param Tune the tune to add
|
||||
*/
|
||||
public function push(Tune $tune)
|
||||
{
|
||||
$this->collection[] = $tune;
|
||||
}
|
||||
|
||||
/**
|
||||
* pop last tune from the end of the collection
|
||||
*
|
||||
* @return Tune
|
||||
*/
|
||||
public function pop()
|
||||
{
|
||||
return array_pop($this->collection);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* magic setter
|
||||
* just passes to regular set method which contains validation
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$this->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* set new value for a property
|
||||
* overwrites the existing value
|
||||
*
|
||||
* @return (boolean) TRUE on success, FALSE otherwise
|
||||
*/
|
||||
public function set($property, $value)
|
||||
{
|
||||
$retVar = FALSE;
|
||||
|
||||
switch($property)
|
||||
{
|
||||
case 'change_hash':
|
||||
$this->generate_hash();
|
||||
break;
|
||||
|
||||
case 'tc_id':
|
||||
if($this->tc_id !== 0) { // if tc_ID is not 0 don't allow setting it
|
||||
$retVar = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if(is_numeric($value) && $value > 0)
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
case 'C':
|
||||
case 'Z':
|
||||
if( is_array($value) && count($value) > 0)
|
||||
{
|
||||
$contains_only = TRUE;
|
||||
foreach($value as $key=>$person)
|
||||
{
|
||||
if(! is_a($person, __NAMESPACE__ . '\\' ."Person"))
|
||||
{
|
||||
$contains_only = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( $contains_only )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
case 'D':
|
||||
case 'F':
|
||||
case 'H':
|
||||
case 'N':
|
||||
case 'O':
|
||||
case 'S':
|
||||
if(is_array($value))
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'collection':
|
||||
if( is_array($value) && count($value) > 0)
|
||||
{
|
||||
$contains_only_tunes = TRUE;
|
||||
foreach($value as $key=>$tune)
|
||||
{
|
||||
if(! is_a($tune, __NAMESPACE__ . '\\' ."Tune"))
|
||||
{
|
||||
$contains_only_tunes = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( $contains_only_tunes )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'L' :
|
||||
case 'M' :
|
||||
case 'R' :
|
||||
if(is_numeric($value)) { break; }
|
||||
case 'cOwner' :
|
||||
if(! is_array($value) )
|
||||
{
|
||||
$this->{$property} = $value;
|
||||
$retVar = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default: // non-existant or non-editable property
|
||||
break;
|
||||
}
|
||||
|
||||
return $retVar;
|
||||
}
|
||||
|
||||
/**
|
||||
* append a value to a property's array
|
||||
*
|
||||
* @param (string) $property name
|
||||
* @param (mixed) $value to add to the array
|
||||
*
|
||||
* @return (Boolean) TRUE on success, FALSE otherwise
|
||||
*/
|
||||
public function append($property, $value)
|
||||
{
|
||||
switch($property)
|
||||
{
|
||||
case 'A':
|
||||
case 'C':
|
||||
case 'Z':
|
||||
if(! is_a($value, __NAMESPACE__ . '\\' .'Person')) { break; }
|
||||
//Fall through if we pass the check
|
||||
case 'B':
|
||||
case 'D':
|
||||
case 'F':
|
||||
case 'H':
|
||||
case 'N':
|
||||
case 'O':
|
||||
case 'S':
|
||||
$this->{$property}[] = $value;
|
||||
return TRUE;
|
||||
break;
|
||||
|
||||
case 'collection':
|
||||
if( is_a($value, __NAMESPACE__."\Tune") )
|
||||
{
|
||||
$this->{$property}[] = $value;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return $this->set($property, $value);
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the value of a private property
|
||||
*
|
||||
* @return (mixed) value of the property or FALSE if property does not exist
|
||||
*/
|
||||
public function get($property)
|
||||
{
|
||||
if(isset($this->{$property})) { return $this->{$property}; }
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
* private functions
|
||||
*
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* generate hash for the whole person object
|
||||
*
|
||||
* @returns (string) md5 hash of all attributes
|
||||
*/
|
||||
protected function generate_hash()
|
||||
{
|
||||
$data = array(
|
||||
$this->tc_id,
|
||||
$this->cOwner,
|
||||
$this->A,
|
||||
$this->B,
|
||||
$this->C,
|
||||
$this->D,
|
||||
$this->F,
|
||||
$this->H,
|
||||
$this->L,
|
||||
$this->M,
|
||||
$this->N,
|
||||
$this->O,
|
||||
$this->R,
|
||||
$this->S,
|
||||
$this->Z,
|
||||
// $this->collection,
|
||||
);
|
||||
|
||||
return md5(serialize($data));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
149
src/Parser.php
Normal file
149
src/Parser.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser;
|
||||
|
||||
use XaiCorp\AbcParser\Interfaces\Builder;
|
||||
|
||||
class Parser {
|
||||
/**
|
||||
* the abc passed to the parser might be a single tune or
|
||||
* it might be a collection of tunes, with extra data outside
|
||||
* of each tune. This external data should be applied to each
|
||||
* tune and the collection.
|
||||
*
|
||||
* When reading the abc, the parser should create a new collection
|
||||
* and a new Tune object for each tune encountered in the abc.
|
||||
* External tools can then deal with that collection as they like.
|
||||
*
|
||||
*/
|
||||
|
||||
//regexp patterns for different lines
|
||||
const LN_VERSION = '/^%abc(-\d\.\d)?$/';
|
||||
const LN_BLANK = '/^\s*$/';
|
||||
const LN_FIELD = '/^\w:(.+)$/';
|
||||
|
||||
const MODE_NO_DATA = 0;
|
||||
const MODE_FILE_HEADER = 1;
|
||||
const MODE_TUNE_HEADER = 2;
|
||||
const MODE_TUNE_BODY = 3;
|
||||
|
||||
const SINGLE_VALUE_KEYS = ['P','Q','L','M','K'];
|
||||
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* extract the attibutes from the raw abc
|
||||
* @param <string> $abc string containing the raw abc
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function parseABC($abc) {
|
||||
//tune is either new or existing data has been loaded
|
||||
//create new setting
|
||||
$mode = self::MODE_FILE_HEADER;
|
||||
$this->builder->newCollection();
|
||||
$tune = null;
|
||||
$setting = null;
|
||||
$inHistory = false;
|
||||
$inTunes = false;
|
||||
$music = "";
|
||||
$keys_for_Settings = '/K|L|M|P|Q|B|N|D|S|W|Z|F/';
|
||||
$keys_for_Tunes = '/H|A|C|G|R|T|O/';
|
||||
//scan abc by line and see what the first char is
|
||||
foreach (preg_split("/(\r?\n)/", $abc) as $line) {
|
||||
|
||||
if (preg_match(self::LN_BLANK, $line)) {
|
||||
if ($mode === self::MODE_TUNE_BODY || $mode === self::MODE_TUNE_HEADER) {
|
||||
$this->builder->storeTune($music);
|
||||
$music = '';
|
||||
}
|
||||
|
||||
$mode = self::MODE_NO_DATA;
|
||||
} else if ($mode === self::MODE_TUNE_BODY) {
|
||||
$music .= $line . PHP_EOL;
|
||||
} else if (preg_match(self::LN_VERSION, $line)) {
|
||||
//this line might contain the abc version.
|
||||
//What do we want to do with it?
|
||||
} else if (preg_match(self::LN_FIELD, $line) || $inHistory) {
|
||||
if (preg_match(self::LN_FIELD, $line)) { $inHistory = FALSE; }
|
||||
//split the line "key:data"
|
||||
if($inHistory) {
|
||||
$key = 'H';
|
||||
$data = $line;
|
||||
} else {
|
||||
$key = substr($line, 0, 1);
|
||||
$data = trim(substr($line, 2));
|
||||
}
|
||||
|
||||
if ($key === 'X') {
|
||||
$mode = self::MODE_TUNE_HEADER;
|
||||
$inTunes = true;
|
||||
$this->builder->newTune();
|
||||
$this->builder->newSetting();
|
||||
$music = '';
|
||||
|
||||
$this->builder->setOnTune('X', $data);
|
||||
|
||||
} else if (preg_match($keys_for_Tunes, $key)) {
|
||||
if ($key === 'H') {
|
||||
$inHistory = TRUE;
|
||||
} else {
|
||||
$inHistory = FALSE;
|
||||
}
|
||||
if ($key === 'A' || $key === 'C') {
|
||||
$data = $this->builder->newPerson(['name'=>$data]);
|
||||
}
|
||||
if ($mode === self::MODE_FILE_HEADER) {
|
||||
if (in_array($key, self::SINGLE_VALUE_KEYS)) {
|
||||
$this->builder->setOnCollection($key, $data);
|
||||
} else {
|
||||
$this->builder->appendToCollection($key, $data);
|
||||
}
|
||||
} else if($inTunes) {
|
||||
if (in_array($key, self::SINGLE_VALUE_KEYS)) {
|
||||
$this->builder->setOnTune($key, $data);
|
||||
} else {
|
||||
$this->builder->appendToTune($key, $data);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (preg_match($keys_for_Settings, $key)) {
|
||||
if ($key === 'K' && $mode === self::MODE_TUNE_HEADER) {
|
||||
$mode = self::MODE_TUNE_BODY;
|
||||
}
|
||||
|
||||
if ($key === 'Z') {
|
||||
$data = $this->builder->newPerson(['name'=>$data]);
|
||||
}
|
||||
|
||||
|
||||
if ($mode == self::MODE_FILE_HEADER) {
|
||||
if (in_array($key, self::SINGLE_VALUE_KEYS)) {
|
||||
$this->builder->setOnCollection($key, $data);
|
||||
} else {
|
||||
$this->builder->appendToCollection($key, $data);
|
||||
}
|
||||
} else if($inTunes){
|
||||
if (in_array($key, self::SINGLE_VALUE_KEYS)) {
|
||||
$this->builder->setOnSetting($key, $data);
|
||||
} else {
|
||||
$this->builder->appendToSetting($key, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->builder->getCollection();
|
||||
}
|
||||
|
||||
// private static function _storeTune($music, &$setting, &$tune, &$tuneCollection) {
|
||||
// $setting -> set('music', trim($music));
|
||||
// $tune -> append('collection', $setting);
|
||||
// $tuneCollection -> append('collection', $tune);
|
||||
// }
|
||||
|
||||
}
|
||||
60
src/Traits/ValidationTrait.php
Normal file
60
src/Traits/ValidationTrait.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Traits;
|
||||
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
Trait ValidationTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* @var MessageBag
|
||||
*/
|
||||
protected $messages;
|
||||
|
||||
public function validate()
|
||||
{
|
||||
// validation
|
||||
$data = $this->getAttributes();
|
||||
|
||||
$validator = Validator::make($data, $this->validationRules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
if (! $this->messages) {
|
||||
$this->messages = new MessageBag();
|
||||
}
|
||||
$this->messages = $validator->getMessageBag();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|MessageBag
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages?$this->messages->toArray():[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidationRules()
|
||||
{
|
||||
return $this->validationRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the validation rules for a model class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRules()
|
||||
{
|
||||
$class = get_called_class();
|
||||
$instance = new $class();
|
||||
return $instance->getValidationRules();
|
||||
}
|
||||
}
|
||||
4
tests/_bootstrap.php
Normal file
4
tests/_bootstrap.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
// This is global bootstrap for autoloading
|
||||
|
||||
include_once 'vendor/autoload.php';
|
||||
9
tests/_data/abc/valid_abc_1.abc
Normal file
9
tests/_data/abc/valid_abc_1.abc
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
//blank first line means this isn't a file header anymore!
|
||||
A: trad
|
||||
B: Traditional English tunes
|
||||
C: trad.
|
||||
X:3
|
||||
M:4/4
|
||||
K:C
|
||||
gaab babc :|
|
||||
28
tests/_data/abc/valid_abc_2.abc
Normal file
28
tests/_data/abc/valid_abc_2.abc
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
X:40
|
||||
T:Abbotts Bromley Horn Dance
|
||||
A: trad
|
||||
C: trad.
|
||||
D: None
|
||||
G:lute
|
||||
H: Thousand year old tradition
|
||||
The Horns live in the church and are removed for the dance once a year
|
||||
R:Jig
|
||||
F:none.abc
|
||||
B: Traditional English tunes
|
||||
W:None
|
||||
Q:1/8=80
|
||||
L:1/8
|
||||
M:6/8
|
||||
N:Traditional English
|
||||
O:England
|
||||
Z:Andy Hornby
|
||||
%%TUNEURL: http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
||||
%%ID:00000dab
|
||||
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
||||
P:ABC
|
||||
K:G
|
||||
e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
||||
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
||||
e2g efg|c2e cde|dcB AGF|E3E2
|
||||
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]
|
||||
19
tests/_data/abc/valid_abc_3.abc
Normal file
19
tests/_data/abc/valid_abc_3.abc
Normal file
@@ -0,0 +1,19 @@
|
||||
A: trad
|
||||
B: Traditional English tunes
|
||||
C: trad.
|
||||
D: None
|
||||
F:none.abc
|
||||
H: Thousand year old tradition
|
||||
The Horns live in the church and are removed for the dance once a year
|
||||
L:1/8
|
||||
M:6/8
|
||||
N:Traditional English
|
||||
O:England
|
||||
R:Jig
|
||||
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
||||
Z:Andy Hornby
|
||||
|
||||
X:3
|
||||
M:4/4
|
||||
K:C
|
||||
gaab babc :|
|
||||
1
tests/_data/dump.sql
Normal file
1
tests/_data/dump.sql
Normal file
@@ -0,0 +1 @@
|
||||
/* Replace this file with actual dump of your database */
|
||||
26
tests/_support/AcceptanceTester.php
Normal file
26
tests/_support/AcceptanceTester.php
Normal 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 AcceptanceTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\AcceptanceTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
||||
26
tests/_support/FunctionalTester.php
Normal file
26
tests/_support/FunctionalTester.php
Normal 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
|
||||
*/
|
||||
}
|
||||
10
tests/_support/Helper/Acceptance.php
Normal file
10
tests/_support/Helper/Acceptance.php
Normal 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 Acceptance extends \Codeception\Module
|
||||
{
|
||||
|
||||
}
|
||||
36
tests/_support/Helper/ExtraAsserts.php
Normal file
36
tests/_support/Helper/ExtraAsserts.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Helper;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ExtraAsserts extends \Codeception\Module
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertInstanceOf($expected, $actual, $message = '')
|
||||
{
|
||||
\PHPUnit_Framework_Assert::assertInstanceOf($expected, $actual, $message);
|
||||
}
|
||||
|
||||
public function assertCanSave(Model $model)
|
||||
{
|
||||
\PHPUnit_Framework_Assert::assertTrue($model->save(), json_encode($model->getMessages()));
|
||||
}
|
||||
|
||||
public function assertCanNotSave(Model $model, $message = '')
|
||||
{
|
||||
\PHPUnit_Framework_Assert::assertNotTrue($model->save(), $message);
|
||||
}
|
||||
|
||||
public function haveNotFinishedTest()
|
||||
{
|
||||
\PHPUnit_Framework_Assert::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
10
tests/_support/Helper/Functional.php
Normal file
10
tests/_support/Helper/Functional.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
||||
10
tests/_support/Helper/Unit.php
Normal file
10
tests/_support/Helper/Unit.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
||||
26
tests/_support/UnitTester.php
Normal file
26
tests/_support/UnitTester.php
Normal 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
|
||||
*/
|
||||
}
|
||||
2173
tests/_support/_generated/AcceptanceTesterActions.php
Normal file
2173
tests/_support/_generated/AcceptanceTesterActions.php
Normal file
File diff suppressed because it is too large
Load Diff
2861
tests/_support/_generated/FunctionalTesterActions.php
Normal file
2861
tests/_support/_generated/FunctionalTesterActions.php
Normal file
File diff suppressed because it is too large
Load Diff
391
tests/_support/_generated/UnitTesterActions.php
Normal file
391
tests/_support/_generated/UnitTesterActions.php
Normal file
@@ -0,0 +1,391 @@
|
||||
<?php //[STAMP] e5fb1777708efe70c0e9573bd3d7b4f7
|
||||
namespace _generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
// You should not change it manually as it will be overwritten on next build
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
use Codeception\Module\Asserts;
|
||||
use Helper\ExtraAsserts;
|
||||
use Helper\Unit;
|
||||
|
||||
trait UnitTesterActions
|
||||
{
|
||||
/**
|
||||
* @return \Codeception\Scenario
|
||||
*/
|
||||
abstract protected function getScenario();
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are equal.
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertEquals()
|
||||
*/
|
||||
public function assertEquals($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are not equal
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotEquals()
|
||||
*/
|
||||
public function assertNotEquals($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are same
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertSame()
|
||||
*/
|
||||
public function assertSame($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are not same
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotSame()
|
||||
*/
|
||||
public function assertNotSame($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is greater than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertGreaterThan()
|
||||
*/
|
||||
public function assertGreaterThan($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @deprecated
|
||||
* @see \Codeception\Module\Asserts::assertGreaterThen()
|
||||
*/
|
||||
public function assertGreaterThen($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThen', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is greater or equal than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertGreaterThanOrEqual()
|
||||
*/
|
||||
public function assertGreaterThanOrEqual($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @deprecated
|
||||
* @see \Codeception\Module\Asserts::assertGreaterThenOrEqual()
|
||||
*/
|
||||
public function assertGreaterThenOrEqual($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThenOrEqual', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is less than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertLessThan()
|
||||
*/
|
||||
public function assertLessThan($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is less or equal than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertLessThanOrEqual()
|
||||
*/
|
||||
public function assertLessThanOrEqual($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that haystack contains needle
|
||||
*
|
||||
* @param $needle
|
||||
* @param $haystack
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertContains()
|
||||
*/
|
||||
public function assertContains($needle, $haystack, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that haystack doesn't contain needle.
|
||||
*
|
||||
* @param $needle
|
||||
* @param $haystack
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotContains()
|
||||
*/
|
||||
public function assertNotContains($needle, $haystack, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that string match with pattern
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertRegExp()
|
||||
*/
|
||||
public function assertRegExp($pattern, $string, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that string not match with pattern
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotRegExp()
|
||||
*/
|
||||
public function assertNotRegExp($pattern, $string, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is empty.
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertEmpty()
|
||||
*/
|
||||
public function assertEmpty($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is not empty.
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotEmpty()
|
||||
*/
|
||||
public function assertNotEmpty($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is NULL
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNull()
|
||||
*/
|
||||
public function assertNull($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is not NULL
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotNull()
|
||||
*/
|
||||
public function assertNotNull($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that condition is positive.
|
||||
*
|
||||
* @param $condition
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertTrue()
|
||||
*/
|
||||
public function assertTrue($condition, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that condition is negative.
|
||||
*
|
||||
* @param $condition
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertFalse()
|
||||
*/
|
||||
public function assertFalse($condition, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks if file exists
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertFileExists()
|
||||
*/
|
||||
public function assertFileExists($filename, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks if file doesn't exist
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertFileNotExists()
|
||||
*/
|
||||
public function assertFileNotExists($filename, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Fails the test with message.
|
||||
*
|
||||
* @param $message
|
||||
* @see \Codeception\Module\Asserts::fail()
|
||||
*/
|
||||
public function fail($message) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @see \Helper\ExtraAsserts::assertInstanceOf()
|
||||
*/
|
||||
public function assertInstanceOf($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
*
|
||||
* @see \Helper\ExtraAsserts::assertCanSave()
|
||||
*/
|
||||
public function assertCanSave($model) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCanSave', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
*
|
||||
* @see \Helper\ExtraAsserts::assertCanNotSave()
|
||||
*/
|
||||
public function assertCanNotSave($model, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCanNotSave', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
*
|
||||
* @see \Helper\ExtraAsserts::haveNotFinishedTest()
|
||||
*/
|
||||
public function haveNotFinishedTest() {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('haveNotFinishedTest', func_get_args()));
|
||||
}
|
||||
}
|
||||
12
tests/acceptance.suite.yml
Normal file
12
tests/acceptance.suite.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
# 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.
|
||||
|
||||
class_name: AcceptanceTester
|
||||
modules:
|
||||
enabled:
|
||||
- PhpBrowser:
|
||||
url: http://localhost/myapp
|
||||
- \Helper\Acceptance
|
||||
2
tests/acceptance/_bootstrap.php
Normal file
2
tests/acceptance/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will be available to your tests
|
||||
13
tests/functional.suite.yml
Normal file
13
tests/functional.suite.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
# Codeception Test Suite Configuration
|
||||
#
|
||||
# Suite for functional (integration) tests
|
||||
# Emulate web requests and make application process them
|
||||
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
|
||||
|
||||
class_name: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
# add framework module here
|
||||
- \Helper\Functional
|
||||
- Laravel5:
|
||||
environment_file: .env.testing
|
||||
2
tests/functional/_bootstrap.php
Normal file
2
tests/functional/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will be available to your tests
|
||||
160
tests/functional/laravel5/AbcParserCest.php
Normal file
160
tests/functional/laravel5/AbcParserCest.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
namespace laravel5;
|
||||
|
||||
use \UnitTester;
|
||||
use \Codeception\Util\Stub;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Abc;
|
||||
use XaiCorp\AbcParser\Parser;
|
||||
use XaiCorp\AbcParser\Interfaces\Builder;
|
||||
//use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
|
||||
|
||||
class AbcParserCest
|
||||
{
|
||||
// use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dataDir;
|
||||
|
||||
/**
|
||||
* @var \XaiCorp\AbcParser\Interfaces\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var Parser;
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dataDir = codecept_data_dir();
|
||||
}
|
||||
|
||||
public function _before(UnitTester $I)
|
||||
{
|
||||
$this->builder = new Abc();
|
||||
}
|
||||
|
||||
public function _after(UnitTester $I)
|
||||
{
|
||||
unset($builder);
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
public function createParser(UnitTester $I)
|
||||
{
|
||||
$parser = new Parser($this->builder);
|
||||
|
||||
$I->assertInstanceOf(Parser::class, $parser);
|
||||
}
|
||||
|
||||
public function seeParseEmptyAbcWithoutErrors(UnitTester $I)
|
||||
{
|
||||
$abc = '';
|
||||
$parser = new Parser($this->builder);
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function seeParseABCExample1(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_1.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
1 => [
|
||||
'X' => '3',
|
||||
'M' => '4/4',
|
||||
'K' => 'C',
|
||||
'music' => 'gaab babc :|'
|
||||
],
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$I->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function seeParseABCExample2(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_2.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
1 => [
|
||||
'X' => '40',
|
||||
'T' => ['Abbotts Bromley Horn Dance'],
|
||||
'A' => ['trad'],
|
||||
'C' => ['trad.'],
|
||||
'D' => ['None'],
|
||||
'G' => ['lute'],
|
||||
'H' => [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year'
|
||||
],
|
||||
'R' => ['Jig'],
|
||||
'F' => ['none.abc'],
|
||||
'B' => ['Traditional English tunes'],
|
||||
'W' => ['None'],
|
||||
'Q' => '1/8=80',
|
||||
'L' => '1/8',
|
||||
'M' => '6/8',
|
||||
'N' => ['Traditional English'],
|
||||
'O' => ['England'],
|
||||
'Z' => ['Andy Hornby'],
|
||||
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
|
||||
'P' => 'ABC',
|
||||
'K' => 'G',
|
||||
'music' => 'e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
||||
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
||||
e2g efg|c2e cde|dcB AGF|E3E2
|
||||
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]'
|
||||
],
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$I->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
|
||||
public function seeParseABCExample3(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_3.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
'A' => ['trad'],
|
||||
'C' => ['trad.'],
|
||||
'D' => ['None'],
|
||||
'H' => [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year'
|
||||
],
|
||||
'R' => ['Jig'],
|
||||
'F' => ['none.abc'],
|
||||
'B' => ['Traditional English tunes'],
|
||||
'L' => '1/8',
|
||||
'M' => '6/8',
|
||||
'N' => ['Traditional English'],
|
||||
'O' => ['England'],
|
||||
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
|
||||
'Z' => ['Andy Hornby'],
|
||||
|
||||
1 => [
|
||||
'X' => '3',
|
||||
'M' => '4/4',
|
||||
'K' => 'C',
|
||||
'music' => 'gaab babc :|'
|
||||
]
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$I->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
20
tests/functional/laravel5/CollectionCest.php
Normal file
20
tests/functional/laravel5/CollectionCest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace laravel5;
|
||||
|
||||
use \FunctionalTester;
|
||||
|
||||
class CollectionCest
|
||||
{
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
}
|
||||
|
||||
public function _after(FunctionalTester $I)
|
||||
{
|
||||
}
|
||||
|
||||
// tests
|
||||
public function tryToTest(FunctionalTester $I)
|
||||
{
|
||||
}
|
||||
}
|
||||
28
tests/functional/laravel5/TuneAttributeCest.php
Normal file
28
tests/functional/laravel5/TuneAttributeCest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace laravel5;
|
||||
|
||||
use \FunctionalTester;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
|
||||
|
||||
class TuneAttributeCest
|
||||
{
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
}
|
||||
|
||||
public function _after(FunctionalTester $I)
|
||||
{
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
public function saveModel(FunctionalTester $I)
|
||||
{
|
||||
$model = new TuneAttribute();
|
||||
|
||||
$model->tune_id = 1;
|
||||
$model->type = 'Title';
|
||||
$model->string = 'a title';
|
||||
$model->ordering = 1;
|
||||
$I->assertCanSave($model);
|
||||
}
|
||||
}
|
||||
10
tests/unit.suite.yml
Normal file
10
tests/unit.suite.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
# Codeception Test Suite Configuration
|
||||
#
|
||||
# Suite for unit (internal) tests.
|
||||
|
||||
class_name: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
- \Helper\ExtraAsserts
|
||||
- \Helper\Unit
|
||||
78
tests/unit/AbcParserCest.php
Normal file
78
tests/unit/AbcParserCest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use \Codeception\Util\Stub;
|
||||
use \XaiCorp\AbcParser\Parser;
|
||||
use \XaiCorp\AbcParser\Interfaces\Builder;
|
||||
|
||||
class AbcParserCest
|
||||
{
|
||||
/**
|
||||
* @var \XaiCorp\AbcParser\Interfaces\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var Parser;
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
public function _before(UnitTester $I)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function _after(UnitTester $I)
|
||||
{
|
||||
unset($builder);
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
public function createParser(UnitTester $I)
|
||||
{
|
||||
$builder = \Mockery::mock(Builder::Class)
|
||||
->shouldReceive('newCollection')->once()
|
||||
->shouldreceive('getCollection')->once()->andreturn(true)
|
||||
->mock();
|
||||
|
||||
$parser = new Parser($builder);
|
||||
|
||||
$I->assertInstanceOf(Parser::class, $parser);
|
||||
}
|
||||
|
||||
public function seeParseABCCallNewCollection(UnitTester $I)
|
||||
{
|
||||
$abc = '';
|
||||
$builder = \Mockery::mock(Builder::Class)
|
||||
->shouldReceive('newCollection')->once()
|
||||
->shouldreceive('getCollection')->once()->andreturn(true)
|
||||
->mock();
|
||||
|
||||
$parser = new Parser($builder);
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertTrue($result);
|
||||
}
|
||||
|
||||
public function seeParseABCExample1(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents(__DIR__.'/../_data/abc/valid_abc_1.abc');
|
||||
$builder = \Mockery::mock(Builder::Class)
|
||||
->shouldReceive('newCollection')->once()
|
||||
->shouldReceive('newPerson')->once()
|
||||
->shouldReceive('newTune')->once()
|
||||
->shouldReceive('newSetting')->once()
|
||||
->shouldReceive('appendToSetting')->once()
|
||||
->shouldReceive('storeTune')->once()
|
||||
->shouldreceive('getCollection')->once()->andreturn(true);
|
||||
$builder->shouldReceive('setOnTune')
|
||||
->with('X', '3')
|
||||
->atMost()->times(4);
|
||||
$builder = $builder->mock();
|
||||
|
||||
|
||||
$parser = new Parser($builder);
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertTrue($result);
|
||||
}
|
||||
}
|
||||
156
tests/unit/Laravel5/AbcParserCest.php
Normal file
156
tests/unit/Laravel5/AbcParserCest.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
namespace arr;
|
||||
|
||||
use \UnitTester;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Abc;
|
||||
use XaiCorp\AbcParser\Parser;
|
||||
|
||||
class AbcParserCest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dataDir;
|
||||
|
||||
/**
|
||||
* @var \XaiCorp\AbcParser\Interfaces\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var Parser;
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dataDir = codecept_data_dir();
|
||||
}
|
||||
|
||||
public function _before(UnitTester $I)
|
||||
{
|
||||
$this->builder = new Abc();
|
||||
}
|
||||
|
||||
public function _after(UnitTester $I)
|
||||
{
|
||||
unset($builder);
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
public function createParser(UnitTester $I)
|
||||
{
|
||||
$parser = new Parser($this->builder);
|
||||
|
||||
$I->assertInstanceOf(Parser::class, $parser);
|
||||
}
|
||||
|
||||
public function seeParseEmptyAbcWithoutErrors(UnitTester $I)
|
||||
{
|
||||
$abc = '';
|
||||
$parser = new Parser($this->builder);
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function seeParseABCExample1(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_1.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
1 => [
|
||||
'X' => '3',
|
||||
'M' => '4/4',
|
||||
'K' => 'C',
|
||||
'music' => 'gaab babc :|'
|
||||
],
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$resultArray = $result->toArray();
|
||||
$I->assertEquals($expected, $resultArray);
|
||||
}
|
||||
|
||||
public function seeParseABCExample2(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_2.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
1 => [
|
||||
'X' => '40',
|
||||
'T' => ['Abbotts Bromley Horn Dance'],
|
||||
'A' => ['trad'],
|
||||
'C' => ['trad.'],
|
||||
'D' => ['None'],
|
||||
'G' => ['lute'],
|
||||
'H' => [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year'
|
||||
],
|
||||
'R' => ['Jig'],
|
||||
'F' => ['none.abc'],
|
||||
'B' => ['Traditional English tunes'],
|
||||
'W' => ['None'],
|
||||
'Q' => '1/8=80',
|
||||
'L' => '1/8',
|
||||
'M' => '6/8',
|
||||
'N' => ['Traditional English'],
|
||||
'O' => ['England'],
|
||||
'Z' => ['Andy Hornby'],
|
||||
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
|
||||
'P' => 'ABC',
|
||||
'K' => 'G',
|
||||
'music' => 'e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
||||
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
||||
e2g efg|c2e cde|dcB AGF|E3E2
|
||||
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]'
|
||||
],
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$resultArray = $result->toArray();
|
||||
$I->assertEquals($expected, $resultArray);
|
||||
}
|
||||
|
||||
|
||||
public function seeParseABCExample3(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_3.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
'A' => ['trad'],
|
||||
'C' => ['trad.'],
|
||||
'D' => ['None'],
|
||||
'H' => [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year'
|
||||
],
|
||||
'R' => ['Jig'],
|
||||
'F' => ['none.abc'],
|
||||
'B' => ['Traditional English tunes'],
|
||||
'L' => '1/8',
|
||||
'M' => '6/8',
|
||||
'N' => ['Traditional English'],
|
||||
'O' => ['England'],
|
||||
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
|
||||
'Z' => ['Andy Hornby'],
|
||||
|
||||
1 => [
|
||||
'X' => '3',
|
||||
'M' => '4/4',
|
||||
'K' => 'C',
|
||||
'music' => 'gaab babc :|'
|
||||
]
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result->toArray());
|
||||
|
||||
$I->assertEquals($expected, $result->toArray());
|
||||
}
|
||||
}
|
||||
155
tests/unit/Laravel5/CollectionAttributeTest.php
Normal file
155
tests/unit/Laravel5/CollectionAttributeTest.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace Laravel5;
|
||||
|
||||
use Codeception\TestCase\Test;
|
||||
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Collection;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Person;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Tune;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
|
||||
|
||||
class CollectionAttributeTest extends Test
|
||||
{
|
||||
use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
|
||||
$Artisan = $app->make('Artisan');
|
||||
$Artisan::call('migrate');
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->startApplication();
|
||||
$db = app()->make('db');
|
||||
$db->beginTransaction();
|
||||
|
||||
$this->withFactories(__DIR__.'/factories');
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$db = app()->make('db');
|
||||
$db->rollBack();
|
||||
$this->stopApplication();
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
|
||||
public function testMakeModel()
|
||||
{
|
||||
$collection = factory(Collection::class)->create();
|
||||
$type = 'Note';
|
||||
$value = 'a title';
|
||||
$ordering = 1;
|
||||
$model = new CollectionAttribute();
|
||||
$model->collection_id = $collection->id;
|
||||
$model->type = $type;
|
||||
$model->string = $value;
|
||||
$model->ordering = $ordering;
|
||||
|
||||
$this->assertInstanceOf(CollectionAttribute::class, $model);
|
||||
$this->assertEquals($collection->id, $model->collection_id);
|
||||
$this->assertEquals($type, $model->type);
|
||||
$this->assertEquals($value, $model->string);
|
||||
$this->assertEquals($ordering, $model->ordering);
|
||||
}
|
||||
|
||||
public function testMassAssignable()
|
||||
{
|
||||
$collection = factory(Collection::class)->create();
|
||||
$type = 'Note';
|
||||
$value = 'a title';
|
||||
$ordering = 1;
|
||||
$model = CollectionAttribute::create([
|
||||
'collection_id' => $collection->id,
|
||||
'type' => $type,
|
||||
'string' => $value,
|
||||
'ordering' => $ordering
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(CollectionAttribute::class, $model);
|
||||
$this->assertEquals($collection->id, $model->collection_id);
|
||||
$this->assertEquals($type, $model->type);
|
||||
$this->assertEquals($value, $model->string);
|
||||
$this->assertEquals($ordering, $model->ordering);
|
||||
}
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$model = factory(CollectionAttribute::class)->make([]);
|
||||
|
||||
$this->assertInstanceOf(CollectionAttribute::class, $model);
|
||||
$this->assertNotNull($model->collection_id);
|
||||
$this->assertNotNull($model->type);
|
||||
$this->assertNotNull($model->string);
|
||||
$this->assertNotNull($model->ordering);
|
||||
$this->assertTrue($model->save(), json_encode($model->getMessages()));
|
||||
}
|
||||
|
||||
public function testValidationAppliedOnSave()
|
||||
{
|
||||
$model = factory(CollectionAttribute::class)->make([]);
|
||||
$model->type = 'NotType';
|
||||
|
||||
$this->assertFalse($model->save());
|
||||
}
|
||||
|
||||
public function testTypeValidation()
|
||||
{
|
||||
$model = factory(CollectionAttribute::class)->make([]);
|
||||
$model->type = 'NotType';
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testTuneIdValidation()
|
||||
{
|
||||
$model = factory(CollectionAttribute::class)->make([]);
|
||||
$model->collection_id += 1;
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testStringValidation()
|
||||
{
|
||||
$longString = '';
|
||||
for ($i=0; $i < 300; $i++) {
|
||||
$longString .= 's';
|
||||
}
|
||||
$model = factory(CollectionAttribute::class)->make([]);
|
||||
$model->string = $longString;
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testOrderingValidation()
|
||||
{
|
||||
$model = factory(CollectionAttribute::class)->make([]);
|
||||
$model->ordering = "fourth";
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
}
|
||||
522
tests/unit/Laravel5/CollectionTest.php
Normal file
522
tests/unit/Laravel5/CollectionTest.php
Normal file
@@ -0,0 +1,522 @@
|
||||
<?php
|
||||
namespace Laravel5;
|
||||
|
||||
use Codeception\TestCase\Test;
|
||||
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Collection;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute;
|
||||
|
||||
class CollectionTest extends Test
|
||||
{
|
||||
use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
|
||||
$Artisan = $app->make('Artisan');
|
||||
$Artisan::call('migrate');
|
||||
}
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->startApplication();
|
||||
$db = app()->make('db');
|
||||
$db->beginTransaction();
|
||||
|
||||
$this->withFactories(__DIR__.'/factories');
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$db = app()->make('db');
|
||||
$db->rollBack();
|
||||
$this->stopApplication();
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
|
||||
public function testMakeModel()
|
||||
{
|
||||
$name = "test1";
|
||||
$model = new Collection();
|
||||
$model->name = $name;
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEquals($name, $model->name);
|
||||
}
|
||||
|
||||
public function testNameIsMassAssignable()
|
||||
{
|
||||
$name = "test1";
|
||||
$model = Collection::create(['name'=>$name]);
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEquals($name, $model->name);
|
||||
}
|
||||
|
||||
public function testFactorySetsName()
|
||||
{
|
||||
$model = factory(Collection::class)->make([]);
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertNotEmpty($model->name);
|
||||
}
|
||||
|
||||
public function testAppendToCollection()
|
||||
{
|
||||
$setting = new \stdClass();
|
||||
|
||||
$model = factory(Collection::class)->make([]);
|
||||
|
||||
$result = $model->appendSetting($setting);
|
||||
|
||||
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
|
||||
$this->assertContains($setting, $result);
|
||||
}
|
||||
|
||||
public function testCanGetAuthorAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Author',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->A[0]);
|
||||
}
|
||||
|
||||
public function testSetAuthorAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->A = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->A[0]);
|
||||
$this->assertEquals($values[1], $model->A[1]);
|
||||
}
|
||||
|
||||
public function testAuthorAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->A = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->A[0]);
|
||||
$this->assertEquals($values[1], $model->A[1]);
|
||||
}
|
||||
|
||||
public function testCanGetComposerAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Composer',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->C[0]);
|
||||
}
|
||||
|
||||
public function testSetComposerAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->C = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->C[0]);
|
||||
$this->assertEquals($values[1], $model->C[1]);
|
||||
}
|
||||
|
||||
public function testComposerAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->C = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->C[0]);
|
||||
$this->assertEquals($values[1], $model->C[1]);
|
||||
}
|
||||
|
||||
public function testCanGetDiscographyAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Discography',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->D[0]);
|
||||
}
|
||||
|
||||
public function testSetDiscographyAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->D = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->D[0]);
|
||||
$this->assertEquals($values[1], $model->D[1]);
|
||||
}
|
||||
|
||||
public function testDiscographyAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->D = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->D[0]);
|
||||
$this->assertEquals($values[1], $model->D[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testCanGetRhythmAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Rhythm',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->R[0]);
|
||||
}
|
||||
|
||||
public function testSetRhythmAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->R = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->R[0]);
|
||||
$this->assertEquals($values[1], $model->R[1]);
|
||||
}
|
||||
|
||||
public function testRhythmAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->R = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->R[0]);
|
||||
$this->assertEquals($values[1], $model->R[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testCanGetHistoryAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'History',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->H[0]);
|
||||
}
|
||||
|
||||
public function testSetHistoryAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->H = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->H[0]);
|
||||
$this->assertEquals($values[1], $model->H[1]);
|
||||
}
|
||||
|
||||
public function testHistoryAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->A = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->A[0]);
|
||||
$this->assertEquals($values[1], $model->A[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testCanGetFileAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'File',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->F[0]);
|
||||
}
|
||||
|
||||
public function testSetFileAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->F = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->F[0]);
|
||||
$this->assertEquals($values[1], $model->F[1]);
|
||||
}
|
||||
|
||||
public function testFileAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->F = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->F[0]);
|
||||
$this->assertEquals($values[1], $model->F[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testCanGetBookAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Book',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->B[0]);
|
||||
}
|
||||
|
||||
public function testSetBookAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->B = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->B[0]);
|
||||
$this->assertEquals($values[1], $model->B[1]);
|
||||
}
|
||||
|
||||
public function testBookAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->B = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->B[0]);
|
||||
$this->assertEquals($values[1], $model->B[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testCanGetNoteAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Note',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->N[0]);
|
||||
}
|
||||
|
||||
public function testSetNoteAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->N = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->N[0]);
|
||||
$this->assertEquals($values[1], $model->N[1]);
|
||||
}
|
||||
|
||||
public function testNoteAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->N = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->N[0]);
|
||||
$this->assertEquals($values[1], $model->N[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testCanGetSourceAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Source',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->S[0]);
|
||||
}
|
||||
|
||||
public function testSetSourceAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->S = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->S[0]);
|
||||
$this->assertEquals($values[1], $model->S[1]);
|
||||
}
|
||||
|
||||
public function testSourceAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->S = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->S[0]);
|
||||
$this->assertEquals($values[1], $model->S[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testCanGetTranscriberAttribute()
|
||||
{
|
||||
$string = 'Arthur';
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$attr = factory(CollectionAttribute::class)->create([
|
||||
'collection_id' => $model->id,
|
||||
'type' => 'Transcriber',
|
||||
'string' => $string,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($string, $model->Z[0]);
|
||||
}
|
||||
|
||||
public function testSetTranscriberAttribute()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->Z = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->Z[0]);
|
||||
$this->assertEquals($values[1], $model->Z[1]);
|
||||
}
|
||||
|
||||
public function testTranscriberAttributeSaves()
|
||||
{
|
||||
$values = ['England', 'Scotland'];
|
||||
$model = factory(Collection::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->Z = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->Z[0]);
|
||||
$this->assertEquals($values[1], $model->Z[1]);
|
||||
}
|
||||
}
|
||||
86
tests/unit/Laravel5/PersonTest.php
Normal file
86
tests/unit/Laravel5/PersonTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace Laravel5;
|
||||
|
||||
use Codeception\TestCase\Test;
|
||||
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Person;
|
||||
|
||||
class PersonTest extends Test
|
||||
{
|
||||
use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'database' => 'abc-api-testing',
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
'strict' => false,
|
||||
'username' => 'abc-api',
|
||||
'password' => 'sio2nf0d'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->startApplication();
|
||||
$db = app()->make('db');
|
||||
$db->beginTransaction();
|
||||
|
||||
$this->withFactories(__DIR__.'/factories');
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$db = app()->make('db');
|
||||
$db->rollBack();
|
||||
$this->stopApplication();
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
|
||||
public function testMakeModel()
|
||||
{
|
||||
$name = "test1";
|
||||
$model = new Person();
|
||||
$model->name = $name;
|
||||
|
||||
$this->assertInstanceOf(Person::class, $model);
|
||||
$this->assertEquals($name, $model->name);
|
||||
}
|
||||
|
||||
public function testNameIsMassAssignable()
|
||||
{
|
||||
$name = "test1";
|
||||
$model = Person::create(['name'=>$name]);
|
||||
|
||||
$this->assertInstanceOf(Person::class, $model);
|
||||
$this->assertEquals($name, $model->name);
|
||||
}
|
||||
|
||||
public function testFactorySetsName()
|
||||
{
|
||||
$model = factory(Person::class)->make([]);
|
||||
|
||||
$this->assertInstanceOf(Person::class, $model);
|
||||
$this->assertNotEmpty($model->name);
|
||||
}
|
||||
}
|
||||
156
tests/unit/Laravel5/TuneAttributeTest.php
Normal file
156
tests/unit/Laravel5/TuneAttributeTest.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
namespace Laravel5;
|
||||
|
||||
use Codeception\TestCase\Test;
|
||||
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Person;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Tune;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
|
||||
|
||||
class TuneAttributeTest extends Test
|
||||
{
|
||||
use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'database' => 'abc-api-testing',
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
'strict' => false,
|
||||
'username' => 'abc-api',
|
||||
'password' => 'sio2nf0d'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->startApplication();
|
||||
$db = app()->make('db');
|
||||
$db->beginTransaction();
|
||||
|
||||
$this->withFactories(__DIR__.'/factories');
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$db = app()->make('db');
|
||||
$db->rollBack();
|
||||
$this->stopApplication();
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
|
||||
public function testMakeModel()
|
||||
{
|
||||
$tune = factory(Tune::class)->create();
|
||||
$type = 'Title';
|
||||
$title = 'a title';
|
||||
$ordering = 1;
|
||||
$model = new TuneAttribute();
|
||||
$model->tune_id = $tune->id;
|
||||
$model->type = $type;
|
||||
$model->string = $title;
|
||||
$model->ordering = $ordering;
|
||||
|
||||
$this->assertInstanceOf(TuneAttribute::class, $model);
|
||||
$this->assertEquals($tune->id, $model->tune_id);
|
||||
$this->assertEquals($type, $model->type);
|
||||
$this->assertEquals($title, $model->string);
|
||||
$this->assertEquals($ordering, $model->ordering);
|
||||
}
|
||||
|
||||
public function testMassAssignable()
|
||||
{
|
||||
$tune = factory(Tune::class)->create();
|
||||
$type = 'Title';
|
||||
$title = 'a title';
|
||||
$ordering = 1;
|
||||
$model = TuneAttribute::create([
|
||||
'tune_id' => $tune->id,
|
||||
'type' => $type,
|
||||
'string' => $title,
|
||||
'ordering' => $ordering
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(TuneAttribute::class, $model);
|
||||
$this->assertEquals($tune->id, $model->tune_id);
|
||||
$this->assertEquals($type, $model->type);
|
||||
$this->assertEquals($title, $model->string);
|
||||
$this->assertEquals($ordering, $model->ordering);
|
||||
}
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$model = factory(TuneAttribute::class)->make([]);
|
||||
|
||||
$this->assertInstanceOf(TuneAttribute::class, $model);
|
||||
$this->assertNotNull($model->tune_id);
|
||||
$this->assertNotNull($model->type);
|
||||
$this->assertNotNull($model->string);
|
||||
$this->assertNotNull($model->ordering);
|
||||
$this->assertTrue($model->save(), json_encode($model->getMessages()));
|
||||
}
|
||||
|
||||
public function testValidationAppliedOnSave()
|
||||
{
|
||||
$model = factory(TuneAttribute::class)->make([]);
|
||||
$model->type = 'NotType';
|
||||
|
||||
$this->assertFalse($model->save());
|
||||
}
|
||||
|
||||
public function testTypeValidation()
|
||||
{
|
||||
$model = factory(TuneAttribute::class)->make([]);
|
||||
$model->type = 'NotType';
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testTuneIdValidation()
|
||||
{
|
||||
$model = factory(TuneAttribute::class)->make([]);
|
||||
$model->tune_id += 1;
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testStringValidation()
|
||||
{
|
||||
$longString = '';
|
||||
for ($i=0; $i < 300; $i++) {
|
||||
$longString .= 's';
|
||||
}
|
||||
$model = factory(TuneAttribute::class)->make([]);
|
||||
$model->string = $longString;
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testOrderingValidation()
|
||||
{
|
||||
$model = factory(TuneAttribute::class)->make([]);
|
||||
$model->ordering = "fourth";
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
}
|
||||
156
tests/unit/Laravel5/TuneSettingAttributeTest.php
Normal file
156
tests/unit/Laravel5/TuneSettingAttributeTest.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
namespace Laravel5;
|
||||
|
||||
use Codeception\TestCase\Test;
|
||||
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Person;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneSetting;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute;
|
||||
|
||||
class TuneSettingAttributeTest extends Test
|
||||
{
|
||||
use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'database' => 'abc-api-testing',
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
'strict' => false,
|
||||
'username' => 'abc-api',
|
||||
'password' => 'sio2nf0d'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->startApplication();
|
||||
$db = app()->make('db');
|
||||
$db->beginTransaction();
|
||||
|
||||
$this->withFactories(__DIR__.'/factories');
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$db = app()->make('db');
|
||||
$db->rollBack();
|
||||
$this->stopApplication();
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
|
||||
public function testMakeModel()
|
||||
{
|
||||
$tune = factory(TuneSetting::class)->create();
|
||||
$type = 'Title';
|
||||
$title = 'a title';
|
||||
$ordering = 1;
|
||||
$model = new TuneSettingAttribute();
|
||||
$model->tune_id = $tune->id;
|
||||
$model->type = $type;
|
||||
$model->string = $title;
|
||||
$model->ordering = $ordering;
|
||||
|
||||
$this->assertInstanceOf(TuneSettingAttribute::class, $model);
|
||||
$this->assertEquals($tune->id, $model->tune_id);
|
||||
$this->assertEquals($type, $model->type);
|
||||
$this->assertEquals($title, $model->string);
|
||||
$this->assertEquals($ordering, $model->ordering);
|
||||
}
|
||||
|
||||
public function testMassAssignable()
|
||||
{
|
||||
$setting = factory(TuneSetting::class)->create();
|
||||
$type = 'Notes';
|
||||
$value = 'a little note';
|
||||
$ordering = 1;
|
||||
$model = TuneSettingAttribute::create([
|
||||
'setting_id' => $setting->id,
|
||||
'type' => $type,
|
||||
'string' => $value,
|
||||
'ordering' => $ordering
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(TuneSettingAttribute::class, $model);
|
||||
$this->assertEquals($setting->id, $model->setting_id);
|
||||
$this->assertEquals($type, $model->type);
|
||||
$this->assertEquals($value, $model->string);
|
||||
$this->assertEquals($ordering, $model->ordering);
|
||||
}
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$model = factory(TuneSettingAttribute::class)->make([]);
|
||||
|
||||
$this->assertInstanceOf(TuneSettingAttribute::class, $model);
|
||||
$this->assertNotNull($model->setting_id);
|
||||
$this->assertNotNull($model->type);
|
||||
$this->assertNotNull($model->string);
|
||||
$this->assertNotNull($model->ordering);
|
||||
$this->assertTrue($model->save(), json_encode($model->getMessages()));
|
||||
}
|
||||
|
||||
public function testValidationAppliedOnSave()
|
||||
{
|
||||
$model = factory(TuneSettingAttribute::class)->make([]);
|
||||
$model->type = 'NotType';
|
||||
|
||||
$this->assertFalse($model->save());
|
||||
}
|
||||
|
||||
public function testTypeValidation()
|
||||
{
|
||||
$model = factory(TuneSettingAttribute::class)->make([]);
|
||||
$model->type = 'NotType';
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testTuneSettingIdValidation()
|
||||
{
|
||||
$model = factory(TuneSettingAttribute::class)->make([]);
|
||||
$model->setting_id += 1;
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testStringValidation()
|
||||
{
|
||||
$longString = '';
|
||||
for ($i=0; $i < 300; $i++) {
|
||||
$longString .= 's';
|
||||
}
|
||||
$model = factory(TuneSettingAttribute::class)->make([]);
|
||||
$model->string = $longString;
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
|
||||
public function testOrderingValidation()
|
||||
{
|
||||
$model = factory(TuneSettingAttribute::class)->make([]);
|
||||
$model->ordering = "fourth";
|
||||
|
||||
$this->assertFalse($model->validate());
|
||||
}
|
||||
}
|
||||
378
tests/unit/Laravel5/TuneSettingTest.php
Normal file
378
tests/unit/Laravel5/TuneSettingTest.php
Normal file
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
namespace Laravel5;
|
||||
|
||||
use Codeception\TestCase\Test;
|
||||
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Person;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Tune;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneSetting;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute;
|
||||
|
||||
class TuneSettingTest extends Test
|
||||
{
|
||||
use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
// $app['config']->set('database.connections.testbench', [
|
||||
// 'driver' => 'mysql',
|
||||
// 'host' => 'localhost',
|
||||
// 'database' => 'abc-api-testing',
|
||||
// 'charset' => 'utf8',
|
||||
// 'collation' => 'utf8_unicode_ci',
|
||||
// 'prefix' => '',
|
||||
// 'strict' => true,
|
||||
// 'username' => 'abc-api',
|
||||
// 'password' => 'sio2nf0d'
|
||||
// ]);
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
|
||||
$Artisan = $app->make('Artisan');
|
||||
$Artisan::call('migrate');
|
||||
}
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->startApplication();
|
||||
$db = app()->make('db');
|
||||
$db->beginTransaction();
|
||||
|
||||
$this->withFactories(__DIR__.'/factories');
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$db = app()->make('db');
|
||||
$db->rollBack();
|
||||
$this->stopApplication();
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
|
||||
public function testMakeModel()
|
||||
{
|
||||
$model = new TuneSetting();
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
}
|
||||
|
||||
public function testMassAssignable()
|
||||
{
|
||||
$tune = factory(Tune::class)->create();
|
||||
$data = [
|
||||
'tune_id' => $tune->id,
|
||||
'meter' => 'C',
|
||||
'keysig' => 'C',
|
||||
'filename' => 'filename',
|
||||
'tempo' => '1/8=200',
|
||||
'L' => '1/8',
|
||||
'music' => '',
|
||||
'parts' => 'abcbc'
|
||||
];
|
||||
$model = TuneSetting::create($data);
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($data['meter'], $model->meter);
|
||||
$this->assertEquals($data['keysig'], $model->keysig);
|
||||
$this->assertEquals($data['filename'], $model->filename);
|
||||
$this->assertEquals($data['tempo'], $model->tempo);
|
||||
$this->assertEquals($data['L'], $model->L);
|
||||
$this->assertEquals($data['music'], $model->music);
|
||||
$this->assertEquals($data['parts'], $model->parts);
|
||||
}
|
||||
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$model = factory(TuneSetting::class)->make([]);
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertNotNull($model->tune_id);
|
||||
$this->assertNotNull($model->meter);
|
||||
$this->assertNotNull($model->keysig);
|
||||
}
|
||||
|
||||
public function testValidationAppliedOnSave()
|
||||
{
|
||||
$model = factory(TuneSetting::class)->make([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$model->meter = 'NotType';
|
||||
|
||||
$this->assertFalse($model->save());
|
||||
}
|
||||
|
||||
public function testCanGetTranscriberAttribute()
|
||||
{
|
||||
$value = 'C';
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$attr = factory(TuneSettingAttribute::class)->create([
|
||||
'setting_id' => $model->id,
|
||||
'type' => 'Transcriber',
|
||||
'string' => $value,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($value, $model->Z[0]);
|
||||
}
|
||||
|
||||
public function testSetTranscriberAttribute()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->Z = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->Z[0]);
|
||||
$this->assertEquals($values[1], $model->Z[1]);
|
||||
}
|
||||
|
||||
public function testTranscriberAttributeSaves()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->Z = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->Z[0]);
|
||||
$this->assertEquals($values[1], $model->Z[1]);
|
||||
}
|
||||
|
||||
public function testCanGetNoteAttribute()
|
||||
{
|
||||
$value = 'A note';
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$attr = factory(TuneSettingAttribute::class)->create([
|
||||
'setting_id' => $model->id,
|
||||
'type' => 'Note',
|
||||
'string' => $value,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($value, $model->N[0]);
|
||||
}
|
||||
|
||||
public function testSetNoteAttribute()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->N = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->N[0]);
|
||||
$this->assertEquals($values[1], $model->N[1]);
|
||||
}
|
||||
|
||||
public function testNoteAttributeSaves()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->N = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->N[0]);
|
||||
$this->assertEquals($values[1], $model->N[1]);
|
||||
}
|
||||
|
||||
public function testCanGetDiscographyAttribute()
|
||||
{
|
||||
$value = 'A recording';
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$attr = factory(TuneSettingAttribute::class)->create([
|
||||
'setting_id' => $model->id,
|
||||
'type' => 'Discography',
|
||||
'string' => $value,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($value, $model->D[0]);
|
||||
}
|
||||
|
||||
public function testSetDiscographyAttribute()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->D = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->D[0]);
|
||||
$this->assertEquals($values[1], $model->D[1]);
|
||||
}
|
||||
|
||||
public function testDiscographyAttributeSaves()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->D = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->D[0]);
|
||||
$this->assertEquals($values[1], $model->D[1]);
|
||||
}
|
||||
|
||||
public function testCanGetSourceAttribute()
|
||||
{
|
||||
$value = 'A feel';
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$attr = factory(TuneSettingAttribute::class)->create([
|
||||
'setting_id' => $model->id,
|
||||
'type' => 'Source',
|
||||
'string' => $value,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($value, $model->S[0]);
|
||||
}
|
||||
|
||||
public function testSetSourceAttribute()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->S = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->S[0]);
|
||||
$this->assertEquals($values[1], $model->S[1]);
|
||||
}
|
||||
|
||||
public function testSourceAttributeSaves()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->S = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->S[0]);
|
||||
$this->assertEquals($values[1], $model->S[1]);
|
||||
}
|
||||
|
||||
public function testCanGetWordAttribute()
|
||||
{
|
||||
$value = 'A feel';
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$attr = factory(TuneSettingAttribute::class)->create([
|
||||
'setting_id' => $model->id,
|
||||
'type' => 'Word',
|
||||
'string' => $value,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($value, $model->W[0]);
|
||||
}
|
||||
|
||||
public function testSetWordAttribute()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->W = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->W[0]);
|
||||
$this->assertEquals($values[1], $model->W[1]);
|
||||
}
|
||||
|
||||
public function testWordAttributeSaves()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->W = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->W[0]);
|
||||
$this->assertEquals($values[1], $model->W[1]);
|
||||
}
|
||||
|
||||
public function testCanGetBookAttribute()
|
||||
{
|
||||
$value = 'A feel';
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$attr = factory(TuneSettingAttribute::class)->create([
|
||||
'setting_id' => $model->id,
|
||||
'type' => 'Book',
|
||||
'string' => $value,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(TuneSetting::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($value, $model->B[0]);
|
||||
}
|
||||
|
||||
public function testSetBookAttribute()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->B = $values;
|
||||
|
||||
$this->assertEquals($values[0], $model->B[0]);
|
||||
$this->assertEquals($values[1], $model->B[1]);
|
||||
}
|
||||
|
||||
public function testBookAttributeSaves()
|
||||
{
|
||||
$values = ['Me', 'Womble2'];
|
||||
$model = factory(TuneSetting::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->B = $values;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($values[0], $model->B[0]);
|
||||
$this->assertEquals($values[1], $model->B[1]);
|
||||
}
|
||||
|
||||
}
|
||||
319
tests/unit/Laravel5/TuneTest.php
Normal file
319
tests/unit/Laravel5/TuneTest.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
namespace Laravel5;
|
||||
|
||||
use Codeception\TestCase\Test;
|
||||
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Person;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\Tune;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
|
||||
|
||||
class TuneTest extends Test
|
||||
{
|
||||
use TestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
// $app['config']->set('database.connections.testbench', [
|
||||
// 'driver' => 'mysql',
|
||||
// 'host' => 'localhost',
|
||||
// 'database' => 'abc-api-testing',
|
||||
// 'charset' => 'utf8',
|
||||
// 'collation' => 'utf8_unicode_ci',
|
||||
// 'prefix' => '',
|
||||
// 'strict' => true,
|
||||
// 'username' => 'abc-api',
|
||||
// 'password' => 'sio2nf0d'
|
||||
// ]);
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
|
||||
$Artisan = $app->make('Artisan');
|
||||
$Artisan::call('migrate');
|
||||
}
|
||||
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->startApplication();
|
||||
$db = app()->make('db');
|
||||
$db->beginTransaction();
|
||||
|
||||
$this->withFactories(__DIR__.'/factories');
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$db = app()->make('db');
|
||||
$db->rollBack();
|
||||
$this->stopApplication();
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
|
||||
public function testMakeModel()
|
||||
{
|
||||
$model = new Tune();
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
}
|
||||
|
||||
public function testMassAssignable()
|
||||
{
|
||||
$xId = 44;
|
||||
$model = Tune::create([
|
||||
'x_id' => $xId,
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($xId, $model->x_id);
|
||||
}
|
||||
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$model = factory(Tune::class)->make([]);
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertNotNull($model->x_id);
|
||||
}
|
||||
|
||||
public function testCanGetTitleAttribute()
|
||||
{
|
||||
$title = 'Wombles Forever';
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$attr = factory(TuneAttribute::class)->create([
|
||||
'tune_id' => $model->id,
|
||||
'type' => 'Title',
|
||||
'string' => $title,
|
||||
]);
|
||||
|
||||
$model = $model->fresh();
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($title, $model->T[0]);
|
||||
}
|
||||
|
||||
public function testSetTitleAttribute()
|
||||
{
|
||||
$titles = ['Title1', 'Womble2'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->T = $titles;
|
||||
|
||||
$this->assertEquals($titles[0], $model->T[0]);
|
||||
$this->assertEquals($titles[1], $model->T[1]);
|
||||
}
|
||||
|
||||
public function testTitleAttributeSaves()
|
||||
{
|
||||
$titles = ['Title1', 'Womble2'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->T = $titles;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($titles[0], $model->T[0]);
|
||||
$this->assertEquals($titles[1], $model->T[1]);
|
||||
}
|
||||
|
||||
public function testCanGetGroupAttribute()
|
||||
{
|
||||
$group = 'Flute';
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$attr = factory(TuneAttribute::class)->create([
|
||||
'tune_id' => $model->id,
|
||||
'type' => 'Group',
|
||||
'string' => $group,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($group, $model->G[0]);
|
||||
}
|
||||
|
||||
public function testSetGroupAttribute()
|
||||
{
|
||||
$groups = ['Flute', 'Oboe'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->G = $groups;
|
||||
|
||||
$this->assertEquals($groups[0], $model->G[0]);
|
||||
$this->assertEquals($groups[1], $model->G[1]);
|
||||
}
|
||||
|
||||
public function testGroupAttributeSaves()
|
||||
{
|
||||
$groups = ['Flute', 'Oboe'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->G = $groups;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($groups[0], $model->G[0]);
|
||||
$this->assertEquals($groups[1], $model->G[1]);
|
||||
}
|
||||
|
||||
public function testCanGetOriginAttribute()
|
||||
{
|
||||
$origin = 'England';
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$attr = factory(TuneAttribute::class)->create([
|
||||
'tune_id' => $model->id,
|
||||
'type' => 'Origin',
|
||||
'string' => $origin,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($origin, $model->O[0]);
|
||||
}
|
||||
|
||||
public function testSetOriginAttribute()
|
||||
{
|
||||
$origins = ['England', 'Scotland'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->O = $origins;
|
||||
|
||||
$this->assertEquals($origins[0], $model->O[0]);
|
||||
$this->assertEquals($origins[1], $model->O[1]);
|
||||
}
|
||||
|
||||
public function testOriginAttributeSaves()
|
||||
{
|
||||
$origins = ['England', 'Scotland'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->O = $origins;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($origins[0], $model->O[0]);
|
||||
$this->assertEquals($origins[1], $model->O[1]);
|
||||
}
|
||||
|
||||
public function testCanGetRhythmAttribute()
|
||||
{
|
||||
$rhythm = 'Reel';
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$attr = factory(TuneAttribute::class)->create([
|
||||
'tune_id' => $model->id,
|
||||
'type' => 'Rhythm',
|
||||
'string' => $rhythm,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($rhythm, $model->R[0]);
|
||||
}
|
||||
|
||||
public function testSetRhythmAttribute()
|
||||
{
|
||||
$rhythms = ['Reel', 'March'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->R = $rhythms;
|
||||
|
||||
$this->assertEquals($rhythms[0], $model->R[0]);
|
||||
$this->assertEquals($rhythms[1], $model->R[1]);
|
||||
}
|
||||
|
||||
public function testRhythmAttributeSaves()
|
||||
{
|
||||
$rhythms = ['England', 'Scotland'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->R = $rhythms;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($rhythms[0], $model->R[0]);
|
||||
$this->assertEquals($rhythms[1], $model->R[1]);
|
||||
}
|
||||
|
||||
public function testCanGetHistoryAttribute()
|
||||
{
|
||||
$history = 'England';
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$attr = factory(TuneAttribute::class)->create([
|
||||
'tune_id' => $model->id,
|
||||
'type' => 'History',
|
||||
'string' => $history,
|
||||
]);
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $model);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$this->assertEquals($history, $model->H[0]);
|
||||
}
|
||||
|
||||
public function testSetHistoryAttribute()
|
||||
{
|
||||
$history = ['some ', 'lines'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->H = $history;
|
||||
|
||||
$this->assertEquals($history[0], $model->H[0]);
|
||||
$this->assertEquals($history[1], $model->H[1]);
|
||||
}
|
||||
|
||||
|
||||
public function testHistoryAttributeSaved()
|
||||
{
|
||||
$history = ['some ', 'lines'];
|
||||
$model = factory(Tune::class)->create([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
|
||||
$model->H = $history;
|
||||
$model->save();
|
||||
$model = $model->fresh();
|
||||
|
||||
$this->assertEquals($history[0], $model->H[0]);
|
||||
$this->assertEquals($history[1], $model->H[1]);
|
||||
}
|
||||
|
||||
public function testValidationAppliedOnSave()
|
||||
{
|
||||
$model = factory(Tune::class)->make([]);
|
||||
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
|
||||
$model->x_id = 'NotType';
|
||||
|
||||
$this->assertFalse($model->save());
|
||||
}
|
||||
|
||||
}
|
||||
56
tests/unit/Laravel5/factories/ModelFactory.php
Normal file
56
tests/unit/Laravel5/factories/ModelFactory.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model Factories
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of your model factories. Model factories give
|
||||
| you a convenient way to create models for testing and seeding your
|
||||
| database. Just tell the factory how a default model should look.
|
||||
|
|
||||
*/
|
||||
|
||||
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\Collection::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\Tune::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'x_id' => $faker->numberBetween(1, 10),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\Person::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
'email'=> $faker->safeEmail,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\TuneAttribute::class, function (Faker\Generator $faker) {
|
||||
$types = \XaiCorp\AbcParser\Models\Laravel5\TuneAttribute::getTypes();
|
||||
return [
|
||||
'tune_id' => function () {
|
||||
return factory(\XaiCorp\AbcParser\Models\Laravel5\Tune::class)->create()->id;
|
||||
},
|
||||
'type' => $types[random_int(0, count($types)-1)],
|
||||
'string' => $faker->words(3, true),
|
||||
'ordering' => $faker->numberBetween(1, 5),
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute::class, function (Faker\Generator $faker) {
|
||||
$types = \XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute::getTypes();
|
||||
return [
|
||||
'collection_id' => function () {
|
||||
return factory(\XaiCorp\AbcParser\Models\Laravel5\Collection::class)->create()->id;
|
||||
},
|
||||
'type' => $types[random_int(0, count($types)-1)],
|
||||
'string' => $faker->words(3, true),
|
||||
'ordering' => $faker->numberBetween(1, 5),
|
||||
];
|
||||
});
|
||||
24
tests/unit/Laravel5/factories/TuneSettingFactory.php
Normal file
24
tests/unit/Laravel5/factories/TuneSettingFactory.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
|
||||
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\TuneSetting::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'tune_id' => function () {
|
||||
return factory(\XaiCorp\AbcParser\Models\Laravel5\Tune::class)->create()->id;
|
||||
},
|
||||
'meter' => 'C',
|
||||
'keysig' => '6/8',
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute::class, function (Faker\Generator $faker) {
|
||||
$types = \XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute::getTypes();
|
||||
return [
|
||||
'setting_id' => function () {
|
||||
return factory(\XaiCorp\AbcParser\Models\Laravel5\TuneSetting::class)->create()->id;
|
||||
},
|
||||
'type' => $types[random_int(0, count($types)-1)],
|
||||
'string' => $faker->words(3, true),
|
||||
'ordering' => $faker->numberBetween(1, 5),
|
||||
];
|
||||
});
|
||||
2
tests/unit/_bootstrap.php
Normal file
2
tests/unit/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will be available to your tests
|
||||
154
tests/unit/arr/AbcParserCest.php
Normal file
154
tests/unit/arr/AbcParserCest.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace arr;
|
||||
|
||||
use \UnitTester;
|
||||
use XaiCorp\AbcParser\Models\Arr\Abc;
|
||||
use XaiCorp\AbcParser\Parser;
|
||||
|
||||
class AbcParserCest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dataDir;
|
||||
|
||||
/**
|
||||
* @var \XaiCorp\AbcParser\Interfaces\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var Parser;
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dataDir = codecept_data_dir();
|
||||
}
|
||||
|
||||
public function _before(UnitTester $I)
|
||||
{
|
||||
$this->builder = new Abc();
|
||||
}
|
||||
|
||||
public function _after(UnitTester $I)
|
||||
{
|
||||
unset($builder);
|
||||
}
|
||||
|
||||
// tests: trying to...
|
||||
public function createParser(UnitTester $I)
|
||||
{
|
||||
$parser = new Parser($this->builder);
|
||||
|
||||
$I->assertInstanceOf(Parser::class, $parser);
|
||||
}
|
||||
|
||||
public function seeParseEmptyAbcWithoutErrors(UnitTester $I)
|
||||
{
|
||||
$abc = '';
|
||||
$parser = new Parser($this->builder);
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function seeParseABCExample1(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_1.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
1 => [
|
||||
'X' => '3',
|
||||
'M' => '4/4',
|
||||
'K' => 'C',
|
||||
'music' => 'gaab babc :|'
|
||||
],
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$I->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function seeParseABCExample2(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_2.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
1 => [
|
||||
'X' => '40',
|
||||
'T' => ['Abbotts Bromley Horn Dance'],
|
||||
'A' => ['trad'],
|
||||
'C' => ['trad.'],
|
||||
'D' => ['None'],
|
||||
'G' => ['lute'],
|
||||
'H' => [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year'
|
||||
],
|
||||
'R' => ['Jig'],
|
||||
'F' => ['none.abc'],
|
||||
'B' => ['Traditional English tunes'],
|
||||
'W' => ['None'],
|
||||
'Q' => '1/8=80',
|
||||
'L' => '1/8',
|
||||
'M' => '6/8',
|
||||
'N' => ['Traditional English'],
|
||||
'O' => ['England'],
|
||||
'Z' => ['Andy Hornby'],
|
||||
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
|
||||
'P' => 'ABC',
|
||||
'K' => 'G',
|
||||
'music' => 'e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
||||
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
||||
e2g efg|c2e cde|dcB AGF|E3E2
|
||||
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]'
|
||||
],
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$I->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
|
||||
public function seeParseABCExample3(UnitTester $I)
|
||||
{
|
||||
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_3.abc');
|
||||
$parser = new Parser($this->builder);
|
||||
$expected = [
|
||||
'A' => ['trad'],
|
||||
'C' => ['trad.'],
|
||||
'D' => ['None'],
|
||||
'H' => [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year'
|
||||
],
|
||||
'R' => ['Jig'],
|
||||
'F' => ['none.abc'],
|
||||
'B' => ['Traditional English tunes'],
|
||||
'L' => '1/8',
|
||||
'M' => '6/8',
|
||||
'N' => ['Traditional English'],
|
||||
'O' => ['England'],
|
||||
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
|
||||
'Z' => ['Andy Hornby'],
|
||||
|
||||
1 => [
|
||||
'X' => '3',
|
||||
'M' => '4/4',
|
||||
'K' => 'C',
|
||||
'music' => 'gaab babc :|'
|
||||
]
|
||||
];
|
||||
|
||||
$result = $parser->parseABC($abc);
|
||||
$I->assertNotEmpty($result);
|
||||
|
||||
$I->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
158
tests/unit/memory/AbcParserTest.php
Normal file
158
tests/unit/memory/AbcParserTest.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\AbcParser;
|
||||
|
||||
class AbcParserTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
private $_facade;
|
||||
|
||||
private $valid_abc_1 = "
|
||||
//blank first line means this isn't a file header anymore!
|
||||
A: trad
|
||||
B: Traditional English tunes
|
||||
C: trad.
|
||||
X:3
|
||||
M:4/4
|
||||
K:C
|
||||
gaab babc :|
|
||||
";
|
||||
|
||||
private $valid_abc_2 = "
|
||||
X:40
|
||||
T:Abbotts Bromley Horn Dance
|
||||
A: trad
|
||||
C: trad.
|
||||
D: None
|
||||
G:lute
|
||||
H: Thousand year old tradition
|
||||
The Horns live in the church and are removed for the dance once a year
|
||||
R:Jig
|
||||
F:none.abc
|
||||
B: Traditional English tunes
|
||||
W:None
|
||||
Q:1/8=80
|
||||
L:1/8
|
||||
M:6/8
|
||||
N:Traditional English
|
||||
O:England
|
||||
Z:Andy Hornby
|
||||
%%TUNEURL: http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
||||
%%ID:00000dab
|
||||
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
||||
P:ABC
|
||||
K:G
|
||||
e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
||||
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
||||
e2g efg|c2e cde|dcB AGF|E3E2
|
||||
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]
|
||||
";
|
||||
|
||||
private $valid_abc_3 = "A: trad
|
||||
B: Traditional English tunes
|
||||
C: trad.
|
||||
D: None
|
||||
F:none.abc
|
||||
H: Thousand year old tradition
|
||||
The Horns live in the church and are removed for the dance once a year
|
||||
L:1/8
|
||||
M:6/8
|
||||
N:Traditional English
|
||||
O:England
|
||||
R:Jig
|
||||
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
||||
Z:Andy Hornby
|
||||
|
||||
X:3
|
||||
M:4/4
|
||||
K:C
|
||||
gaab babc :|
|
||||
";
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setup();
|
||||
$this->_facade = new AbcParser();
|
||||
}
|
||||
|
||||
public function test_not_header_data_no_crash()
|
||||
{
|
||||
$result = $this->_facade->parseABC($this->valid_abc_1);
|
||||
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
|
||||
}
|
||||
|
||||
|
||||
public function test_all_parameters_for_tune()
|
||||
{
|
||||
$result = $this->_facade->parseABC($this->valid_abc_2);
|
||||
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
|
||||
|
||||
// Tune details
|
||||
$tune = $result[0];
|
||||
// var_dump($tune); die();
|
||||
$this->assertEquals('40', $result[0]->get('X'));
|
||||
$this->assertEquals('Abbotts Bromley Horn Dance', array_shift($tune->get('T')) );
|
||||
$this->assertEquals('England', array_shift($tune->get('O')) );
|
||||
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad')), array_shift($tune->get('A')) );
|
||||
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad.')), array_shift($tune->get('C')) );
|
||||
$this->assertEquals('England', array_shift($tune->get('O')) );
|
||||
$this->assertEquals('lute', array_shift($tune->get('G')) );
|
||||
$history = $tune->get('H');
|
||||
$this->assertEquals(2, count($history));
|
||||
$this->assertEquals('Thousand year old tradition', $history[0] );
|
||||
$this->assertEquals('The Horns live in the church and are removed for the dance once a year', $history[1] );
|
||||
$this->assertEquals('Jig', array_shift($tune->get('R')) );
|
||||
|
||||
// setting details
|
||||
$setting = $tune[0];
|
||||
// var_dump($setting);die;
|
||||
$this->assertEquals('Traditional English', array_shift($setting->get('N')) );
|
||||
$this->assertEquals('1/8', $setting->get('L') );
|
||||
$this->assertEquals('6/8', $setting->get('M') );
|
||||
$this->assertEquals('G', $setting->get('K') );
|
||||
$expectedMusic = "
|
||||
e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
||||
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
||||
e2g efg|c2e cde|dcB AGF|E3E2
|
||||
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]
|
||||
";
|
||||
$this->assertEquals(trim($expectedMusic), $setting->get('music'), "music strings should match" );
|
||||
|
||||
$Z = new App\Libraries\abcParse\Person(array('name'=>'Andy Hornby'));
|
||||
$this->assertEquals($Z, array_shift($setting->get('Z')) );
|
||||
|
||||
$this->assertEquals('None', array_shift($setting->get('D')) );
|
||||
$this->assertEquals('http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html', array_shift($setting->get('S')) );
|
||||
$this->assertEquals('None', array_shift($setting->get('W')) );
|
||||
$this->assertEquals('Traditional English tunes', array_shift($setting->get('B')) );
|
||||
$this->assertEquals('none.abc', array_shift($setting->get('F')) );
|
||||
$this->assertEquals('ABC', $setting->get('P') );
|
||||
$this->assertEquals('1/8=80', $setting->get('Q') );
|
||||
}
|
||||
|
||||
|
||||
public function test_all_parameters_for_collection()
|
||||
{
|
||||
$collection = $this->_facade->parseABC($this->valid_abc_3);
|
||||
$this->assertTrue(is_a($collection, 'App\Libraries\abcParse\TuneCollection'));
|
||||
|
||||
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad')), array_shift($collection->get('A')) );
|
||||
$this->assertEquals('Traditional English tunes', array_shift($collection->get('B')) );
|
||||
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad.')), array_shift($collection->get('C')) );
|
||||
$this->assertEquals('None', array_shift($collection->get('D')) );
|
||||
$this->assertEquals('none.abc', array_shift($collection->get('F')) );
|
||||
$this->assertEquals('Thousand year old tradition', array_shift($collection->get('H')) );
|
||||
$this->assertEquals('1/8', $collection->get('L') );
|
||||
$this->assertEquals('6/8', $collection->get('M') );
|
||||
$this->assertEquals('Traditional English', array_shift($collection->get('N')) );
|
||||
$this->assertEquals('England', array_shift($collection->get('O')) );
|
||||
$this->assertEquals('Jig', $collection->get('R') );
|
||||
$this->assertEquals('http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html', array_shift($collection->get('S')) );
|
||||
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'Andy Hornby')), array_shift($collection->get('Z')) );
|
||||
}
|
||||
}
|
||||
104
tests/unit/memory/PabcTest.php
Normal file
104
tests/unit/memory/PabcTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\Pabc;
|
||||
use App\Models\abcParse\Tune;
|
||||
use App\Models\abcParse\TuneSetting as Setting;
|
||||
use App\Models\abcParse\Person;
|
||||
use App\Libraries\abcParse\TuneCollection;
|
||||
|
||||
class PabcTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
private $_facade;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_facade = new Pabc();
|
||||
}
|
||||
|
||||
private $valid_abc_1 = "
|
||||
X:1
|
||||
M:C
|
||||
K:C
|
||||
gaab babc :|
|
||||
";
|
||||
|
||||
|
||||
/**
|
||||
* test the parse_abc function
|
||||
*
|
||||
* This method receives abc in a string
|
||||
* and converts it into a Tune object.
|
||||
* If the string is not valid abc no Tune object is created
|
||||
* and the method returns false.
|
||||
*
|
||||
* @dataProvider provider_parse_abc
|
||||
*/
|
||||
public function test_parse_abc($string, $isValid)
|
||||
{
|
||||
$result = $this->_facade->parse_abc($string);
|
||||
$this->assertEquals($isValid, is_a($result, TuneCollection::class));
|
||||
}
|
||||
|
||||
public function provider_parse_abc()
|
||||
{
|
||||
return array(
|
||||
array('not an abc', FALSE),
|
||||
array($this->valid_abc_1, TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function test_load_models()
|
||||
{
|
||||
$params = array(
|
||||
'tuneModel' => new Tune(),
|
||||
'settingModel' => new Setting(),
|
||||
'personModel' => new Person(),
|
||||
);
|
||||
|
||||
$this->_facade = new Pabc($params);
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $this->_facade->tuneModel);
|
||||
$this->assertInstanceOf(Setting::class, $this->_facade->settingModel);
|
||||
$this->assertInstanceOf(Person::class, $this->_facade->personModel);
|
||||
}
|
||||
|
||||
|
||||
public function test_save_no_models()
|
||||
{
|
||||
$this->assertNull($this->_facade->tuneModel);
|
||||
|
||||
$result = $this->_facade->parse_abc($this->valid_abc_1);
|
||||
$this->assertInstanceOf(TuneCollection::class, $result);
|
||||
|
||||
$this->assertFalse($result->get('change_hash'));
|
||||
$saved = $this->_facade->save_collection($result);
|
||||
$this->assertFalse($saved);
|
||||
$this->assertFalse($result->get('change_hash'));
|
||||
}
|
||||
|
||||
public function test_save()
|
||||
{
|
||||
$params = array(
|
||||
'tuneModel' => Mockery::mock(Tune::Class, ['store'=>true]),
|
||||
'settingModel' => Mockery::mock(Setting::class, ['store'=>true]),
|
||||
'personModel' => Mockery::mock(Person::class, ['store'=>true]),
|
||||
);
|
||||
|
||||
$this->_facade = new Pabc($params);
|
||||
|
||||
$result = $this->_facade->parse_abc($this->valid_abc_1);
|
||||
$this->assertInstanceOf(TuneCollection::class, $result);
|
||||
|
||||
$this->assertFalse($result->get('change_hash'));
|
||||
$saved = $this->_facade->save_collection($result);
|
||||
$this->assertTrue($saved);
|
||||
$this->assertNotNull($result->get('change_hash'));
|
||||
}
|
||||
|
||||
}
|
||||
189
tests/unit/memory/PersonTest.php
Normal file
189
tests/unit/memory/PersonTest.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\Person;
|
||||
use \Codeception\TestCase\Test;
|
||||
|
||||
class PersonTest extends Test
|
||||
{
|
||||
private $_person;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_person = new Person();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the model contains the correct attributes
|
||||
*/
|
||||
public function test_model_definition()
|
||||
{
|
||||
$this->assertClassHasAttribute('person_id', Person::class);
|
||||
$this->assertClassHasAttribute('name', Person::class);
|
||||
$this->assertClassHasAttribute('email', Person::class);
|
||||
}
|
||||
|
||||
public function test_construct()
|
||||
{
|
||||
$params = array('person_id' => 5);
|
||||
$this->_person = new Person($params);
|
||||
|
||||
$this->assertEquals(5, $this->_person->get('person_id'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the set property method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to set
|
||||
* @param (Boolean) expected value for return value of set method
|
||||
*
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_set($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_person->set($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_person->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_magic_set($property, $value, $expected)
|
||||
{
|
||||
$this->test_set($property, $value, $expected);
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('person_id', 'not', FALSE),
|
||||
array('person_id', 11, TRUE),
|
||||
array('person_id', '11', TRUE),
|
||||
array('name', null, FALSE),
|
||||
array('name', 1, FALSE),
|
||||
array('name', 'anything', TRUE),
|
||||
array('email', 'anything', FALSE),
|
||||
array('email', 1, FALSE),
|
||||
array('email', 'mail@example.com', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_person_get
|
||||
*/
|
||||
public function test_person_get($key, $expected)
|
||||
{
|
||||
$result = $this->_person->set($key, $expected);
|
||||
$result = $this->_person->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_person_get()
|
||||
{
|
||||
return array(
|
||||
array('', FALSE),
|
||||
array('me', FALSE),
|
||||
array(array('of','me'), FALSE),
|
||||
array(new Person(), FALSE),
|
||||
array('name', 'Richard Morgan'),
|
||||
array('email', 'r_morgan@sympatico.ca'),
|
||||
array('person_id', 0)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_is_changed()
|
||||
{
|
||||
$person = new Person(array('name'=>'Richard Morgan'));
|
||||
|
||||
$this->assertInstanceOf(Person::class, $person);
|
||||
|
||||
$this->assertFalse($person->is_changed(), 'after load should be no changes');
|
||||
|
||||
$person->set('name','Richard Armitage');
|
||||
$this->assertTrue($person->is_changed(), 'updating the name changes the data');
|
||||
}
|
||||
|
||||
/**
|
||||
* test the static function equals
|
||||
* returns true if the data properties of 2 Person objects
|
||||
* are identical
|
||||
*
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
*/
|
||||
public function test_equals($params)
|
||||
{
|
||||
// $this->markTestIncomplete();
|
||||
|
||||
$ob1 = new Person();
|
||||
$ob2 = new Person();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
$ob1->append($key, $val);
|
||||
$ob2->append($key, $val);
|
||||
}
|
||||
else {
|
||||
$ob1->set($key, $val);
|
||||
$ob2->set($key, $val);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue(Person::equals($ob1, $ob2));
|
||||
}
|
||||
/**
|
||||
* test the static function equals
|
||||
* returns true if the data properties of 2 Person objects
|
||||
* are identical
|
||||
*
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
*/
|
||||
public function test_equals_fails($params)
|
||||
{
|
||||
$ob1 = new Person();
|
||||
$ob2 = new Person();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
$ob1->append($key, $val);
|
||||
$ob2->append($key, $val." hello");
|
||||
}
|
||||
else {
|
||||
$ob1->set($key, $val);
|
||||
$ob2->set($key, $val+1);
|
||||
}
|
||||
}
|
||||
// print_r($ob1); print_r($ob2); die;
|
||||
$this->assertFalse(Person::equals($ob1, $ob2));
|
||||
}
|
||||
public function provider_equals()
|
||||
{
|
||||
return array(
|
||||
// array( array('person_id'=>'2') ),
|
||||
array( array('name'=>'a title') ),
|
||||
array( array('email'=>'mail@example.com') ),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
364
tests/unit/memory/SettingTest.php
Normal file
364
tests/unit/memory/SettingTest.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
|
||||
use App\Libraries\abcParse\Setting;
|
||||
use App\Libraries\abcParse\Person;
|
||||
use \Codeception\TestCase\Test as TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
*/
|
||||
class SettingTest extends TestCase
|
||||
{
|
||||
private $_setting;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_setting = new Setting();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the model contains the correct attributes
|
||||
*/
|
||||
public function test_model_definition()
|
||||
{
|
||||
$this->assertClassHasAttribute('settingID', Setting::class);
|
||||
$this->assertClassHasAttribute('tuneID', Setting::class);
|
||||
|
||||
$this->assertClassHasAttribute('Z', Setting::class);
|
||||
$this->assertClassHasAttribute('N', Setting::class);
|
||||
$this->assertClassHasAttribute('D', Setting::class);
|
||||
$this->assertClassHasAttribute('S', Setting::class);
|
||||
$this->assertClassHasAttribute('W', Setting::class);
|
||||
$this->assertClassHasAttribute('B', Setting::class);
|
||||
|
||||
$this->assertClassHasAttribute('F', Setting::class);
|
||||
$this->assertClassHasAttribute('P', Setting::class);
|
||||
$this->assertClassHasAttribute('Q', Setting::class);
|
||||
$this->assertClassHasAttribute('L', Setting::class);
|
||||
$this->assertClassHasAttribute('M', Setting::class);
|
||||
$this->assertClassHasAttribute('K', Setting::class);
|
||||
$this->assertClassHasAttribute('music', Setting::class);
|
||||
// $this->assertClassHasAttribute('music_hash', Setting::class);
|
||||
|
||||
$this->assertClassHasAttribute('propertyNames', Setting::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the set property method
|
||||
*
|
||||
* also tests the validate_line protected method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to set
|
||||
* @param (Boolean) expected value for return value of set method
|
||||
*
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_set($property, $value, $expected_success, $expected_value = FALSE)
|
||||
{
|
||||
$success = $this->_setting->set($property, $value);
|
||||
$this->assertEquals($expected_success, $success);
|
||||
if($success)
|
||||
{
|
||||
if(! $expected_value ) { $expected_value = $value; }
|
||||
$this->assertEquals($expected_value, $this->_setting->get($property));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_magic_set($property, $value, $expected_success, $expected_value = FALSE)
|
||||
{
|
||||
$this->_setting->$property = $value;
|
||||
if($expected_success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_setting->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('settingID', 1, TRUE),
|
||||
array('tuneID', array('alpha'), FALSE),
|
||||
array('tuneID', 'alpha', FALSE),
|
||||
array('tuneID', '1', TRUE),
|
||||
array('tuneID', 1, TRUE),
|
||||
array('f', 1, FALSE),
|
||||
array('F', 1, FALSE),
|
||||
array('F', '1',FALSE),
|
||||
array('F', array('aplha'), TRUE),
|
||||
array('P', array('string'), FALSE),
|
||||
array('P', 10, FALSE),
|
||||
array('P', 'string', TRUE),
|
||||
array('Q', array('string'), FALSE),
|
||||
array('Q', 10, FALSE),
|
||||
array('Q', 'string', FALSE),
|
||||
array('Q', '1/8=200', TRUE),
|
||||
array('L', array('string'), FALSE),
|
||||
array('L', 10, FALSE),
|
||||
array('L', 'string', FALSE),
|
||||
array('L', '1/8', TRUE),
|
||||
array('M', array('string'), FALSE),
|
||||
array('M', 10, FALSE),
|
||||
array('M', 'string', FALSE),
|
||||
array('M', '6/8', TRUE),
|
||||
array('M', 'C', TRUE),
|
||||
array('M', 'c', TRUE),
|
||||
array('M', 'C|', TRUE),
|
||||
array('K', array('string'), FALSE),
|
||||
array('K', 10, FALSE),
|
||||
array('K', 'C', TRUE),
|
||||
array('K', 'Am', TRUE),
|
||||
array('K', 'A minor', TRUE),
|
||||
array('K', 'E dorian', TRUE),
|
||||
array('music', 'GABc:|\\', TRUE),
|
||||
|
||||
array('Z', new Person(), FALSE),
|
||||
array('Z', array(new Person(), 'not a person'), FALSE),
|
||||
array('Z', array(new Person()), TRUE),
|
||||
array('Z', 111, FALSE),
|
||||
array('N', array('a string'), TRUE),
|
||||
array('D', array('a string'), TRUE),
|
||||
array('S', array('a string'), TRUE),
|
||||
array('W', array('a string'), TRUE),
|
||||
array('B', array('a string'), TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* the settingID can only be set if it's value is currently 0
|
||||
* this ensures that we can't change a setting's id once it's set.
|
||||
* the default, unset value for settingID is 0
|
||||
*/
|
||||
public function test_set_settingID()
|
||||
{
|
||||
$success = $this->_setting->set('settingID', 1);
|
||||
$this->assertTrue($success, 'first attempt should succeed');
|
||||
|
||||
$success = $this->_setting->set('settingID', 2);
|
||||
$this->assertFalse($success, 'second attempt should fail');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the append value method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to append
|
||||
* @param (Boolean) expected value for return value of append method
|
||||
*
|
||||
* @dataProvider provider_append
|
||||
*/
|
||||
public function test_append($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_setting->append($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertContains($value, $this->_setting->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_append()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('settingID', 1, FALSE),
|
||||
array('tuneID', array('alpha'), FALSE),
|
||||
array('tuneID', 'alpha', FALSE),
|
||||
array('tuneID', '1', FALSE),
|
||||
array('tuneID', 1, FALSE),
|
||||
array('f', 1, FALSE),
|
||||
array('F', 1, TRUE),
|
||||
array('F', '1', TRUE),
|
||||
array('F', array('aplha'), FALSE),
|
||||
array('P', array('string'), FALSE),
|
||||
array('P', 10, FALSE),
|
||||
array('P', 'string', FALSE),
|
||||
array('Q', array('string'), FALSE),
|
||||
array('Q', 10, FALSE),
|
||||
array('Q', 'string', FALSE),
|
||||
array('Q', '1/8=200', FALSE),
|
||||
array('L', array('string'), FALSE),
|
||||
array('L', 10, FALSE),
|
||||
array('L', 'string', FALSE),
|
||||
array('L', '1/8', FALSE),
|
||||
array('M', array('string'), FALSE),
|
||||
array('M', 10, FALSE),
|
||||
array('M', 'string', FALSE),
|
||||
array('M', '6/8', FALSE),
|
||||
array('M', 'C', FALSE),
|
||||
array('M', 'c', FALSE),
|
||||
array('M', 'C|', FALSE),
|
||||
array('K', array('string'), FALSE),
|
||||
array('K', 10, FALSE),
|
||||
array('K', 'C', FALSE),
|
||||
array('K', 'Am', FALSE),
|
||||
array('K', 'A minor', FALSE),
|
||||
array('K', 'E dorian', FALSE),
|
||||
array('music', 'GABc:|\\', FALSE),
|
||||
|
||||
array('Z', new Person(), TRUE),
|
||||
array('Z', array(new Person()), FALSE),
|
||||
array('Z', 111, FALSE),
|
||||
array('N', array('a string'), FALSE),
|
||||
array('D', array('a string'), FALSE),
|
||||
array('S', array('a string'), FALSE),
|
||||
array('W', array('a string'), FALSE),
|
||||
array('B', array('a string'), FALSE),
|
||||
array('N', 'more notes', TRUE),
|
||||
array('D', 'another record', TRUE),
|
||||
array('S', 'another source', TRUE),
|
||||
array('W', 'words', TRUE),
|
||||
array('B', 'another book', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_get
|
||||
*/
|
||||
public function test_get($key, $expected)
|
||||
{
|
||||
$result = $this->_setting->set($key, $expected);
|
||||
$result = $this->_setting->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_get()
|
||||
{
|
||||
return array(
|
||||
array('', FALSE),
|
||||
array('me', FALSE),
|
||||
array('settingID', 1),
|
||||
array('tuneID', 2),
|
||||
array('Q', '1/8=100'),
|
||||
array('L', '1/8'),
|
||||
array('M', '6/8'),
|
||||
array('K', 'Am'),
|
||||
array('music', 'GABc:|\\'),
|
||||
|
||||
array('Z', array(new Person())),
|
||||
array('N', array('a string')),
|
||||
array('D', array('a string')),
|
||||
array('S', array('a string')),
|
||||
array('W', array('a string')),
|
||||
array('B', array('a string')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the static function equals
|
||||
* returns true if the data properties of 2 Setting Objects
|
||||
* are identical
|
||||
*
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
*/
|
||||
public function test_equals($params)
|
||||
{
|
||||
// $this->markTestIncomplete();
|
||||
|
||||
$ob1 = new Setting();
|
||||
$ob2 = new Setting();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
$ob1->append($key, $val);
|
||||
$ob2->append($key, $val);
|
||||
}
|
||||
else {
|
||||
$ob1->set($key, $val);
|
||||
$ob2->set($key, $val);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue(Setting::equals($ob1, $ob2));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the static function equals
|
||||
* returns true if the data properties of 2 Abc_Tunes
|
||||
* are identical
|
||||
*
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
*/
|
||||
public function test_equals_fails($params)
|
||||
{
|
||||
$ob1 = new Setting();
|
||||
$ob2 = new Setting();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
$ob1->append($key, $val);
|
||||
// $ob2->append($key, $val);
|
||||
}
|
||||
else {
|
||||
$ob1->set($key, $val);
|
||||
$ob2->set($key, $val+1);
|
||||
}
|
||||
}
|
||||
$this->assertFalse(Setting::equals($ob1, $ob2));
|
||||
}
|
||||
public function provider_equals()
|
||||
{
|
||||
return array(
|
||||
array( array('settingID'=>'2') ),
|
||||
array( array('tuneID'=>'2') ),
|
||||
array( array('Z'=> new Person()) ),
|
||||
array( array('N'=>'an author') ),
|
||||
array( array('D'=>'a composer') ),
|
||||
array( array('S'=>'a group') ),
|
||||
array( array('W'=>'some history') ),
|
||||
array( array('B'=>'Plymouth') ),
|
||||
array( array('F'=>'Jig') ),
|
||||
array( array('P'=>'ABB') ),
|
||||
array( array('Q'=>'1/8=100') ),
|
||||
array( array('L'=>'1/4') ),
|
||||
array( array('M'=>'2/4') ),
|
||||
array( array('K'=>'G') ),
|
||||
array( array('music'=>'a|cab|') ),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_isChanged()
|
||||
{
|
||||
$setting = new Setting();
|
||||
|
||||
$this->assertInstanceOf(Setting::class, $setting);
|
||||
|
||||
$this->assertFalse($setting->is_changed(), 'after load should be no changes');
|
||||
|
||||
$setting->set('K','G');
|
||||
$this->assertTrue($setting->is_changed(), 'updating the name changes the data');
|
||||
}
|
||||
|
||||
|
||||
public function test_construct()
|
||||
{
|
||||
$params = array(
|
||||
'settingID' => 3,
|
||||
'Z' => array(new Person()),
|
||||
'P' => 'ABC'
|
||||
);
|
||||
|
||||
$this->_setting = new Setting ($params);
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
$this->assertEquals($val, $this->_setting->get($key));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
210
tests/unit/memory/TuneCollectionTest.php
Normal file
210
tests/unit/memory/TuneCollectionTest.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\Tune;
|
||||
//use App\Libraries\memory\Setting;
|
||||
use App\Libraries\abcParse\Person;
|
||||
use App\Libraries\abcParse\TuneCollection;
|
||||
use \Codeception\TestCase\Test as TestCase;
|
||||
|
||||
class TuneCollectionTest extends TestCase
|
||||
{
|
||||
private $_tunes;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_tunes = new TuneCollection();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the implementation of the Iterator interface
|
||||
* 100% coverage! ;)
|
||||
*/
|
||||
public function test_iterator()
|
||||
{
|
||||
$t = new Tune();
|
||||
$this->assertEquals(0, count($this->_tunes));
|
||||
$this->_tunes[] = $t;
|
||||
$this->_tunes->push($t);
|
||||
$this->assertEquals(2, count($this->_tunes));
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $this->_tunes[0], 'first tune');
|
||||
$this->assertInstanceOf(Tune::class, $this->_tunes[1], 'second tune');
|
||||
|
||||
foreach($this->_tunes as $key=>$val)
|
||||
{
|
||||
$this->assertInternalType('scalar', $key);
|
||||
$this->assertInstanceOf(Tune::class, $val);
|
||||
$this->assertTrue(isset($this->_tunes[$key]), 'key is set');
|
||||
|
||||
unset($this->_tunes[$key]);
|
||||
$this->assertFalse(isset($this->_tunes[$key]), 'key should have been unset');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test the ability to remove the last tune from collection
|
||||
*
|
||||
* tests the implementation of the Countable interface
|
||||
*/
|
||||
public function test_pop()
|
||||
{
|
||||
$this->assertEquals(0, count($this->_tunes), 'no tunes in collection to begin with');
|
||||
|
||||
$t = new Tune();
|
||||
$this->_tunes->push($t);
|
||||
|
||||
$this->assertEquals(1, count($this->_tunes), '1 tune added to collection');
|
||||
|
||||
$result = $this->_tunes->pop();
|
||||
$this->assertEquals(0, count($this->_tunes), 'no tunes left in collection');
|
||||
$this->assertInstanceOf(Tune::class, $result);
|
||||
}
|
||||
|
||||
// public function test_construct()
|
||||
// {
|
||||
// $params = array(
|
||||
// 'tc_id' => 5,
|
||||
// 'cOwner' => 'me',
|
||||
// 'B' => array('my tune book'),
|
||||
// 'R' => 'reel'
|
||||
// );
|
||||
//
|
||||
// $this->_tunes = new TuneCollection($params);
|
||||
//
|
||||
// foreach($params as $key => $val)
|
||||
// {
|
||||
// $this->assertEquals($val, $this->_tunes->get($key));
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* test the set property method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to set
|
||||
* @param (Boolean) expected value for return value of set method
|
||||
*
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_set($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tunes->set($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tunes->get($property));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* test the set property method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to set
|
||||
* @param (Boolean) expected value for return value of set method
|
||||
*
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_magic_setter($property, $value, $expected)
|
||||
{
|
||||
$this->_tunes->$property = $value;
|
||||
if($expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tunes->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('A', 10, FALSE),
|
||||
array('A', array('1','2'), FALSE),
|
||||
array('A', array(new Person(),new Person()), TRUE),
|
||||
array('C', 10, FALSE),
|
||||
array('C', array('1','2'), FALSE),
|
||||
array('C', array(new Person(),new Person()), TRUE),
|
||||
array('H', 10, FALSE),
|
||||
array('H', array('1','2'), TRUE),
|
||||
array('O', 10, FALSE),
|
||||
array('O', array('1','2'), TRUE),
|
||||
array('R', 10, FALSE),
|
||||
array('R', 'reel', TRUE),
|
||||
array('collection', 10, FALSE),
|
||||
array('collection', '10', FALSE),
|
||||
array('collection', array(), FALSE),
|
||||
array('collection', array('1','2'), FALSE),
|
||||
array('collection', array(new Tune(), 'not a tune'), FALSE),
|
||||
array('collection', array(new Tune()), TRUE),
|
||||
array('tc_id', 'abc', FALSE),
|
||||
array('tc_id', '11', TRUE),
|
||||
array('tc_id', 15, TRUE),
|
||||
array('cOwner', 'me', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_set_tc_id()
|
||||
{
|
||||
//we should start with tc_id = 0
|
||||
$this->assertEquals(0, $this->_tunes->get('tc_id'), 'should start at 0');
|
||||
|
||||
//because tc_id == 0 we can change value
|
||||
$this->_tunes->set('tc_id', 4);
|
||||
$this->assertEquals(4, $this->_tunes->get('tc_id'), 'should have changed to 4');
|
||||
|
||||
//tc_id is not 0 so we cannot change value
|
||||
$this->_tunes->set('tc_id', 11);
|
||||
$this->assertEquals(4, $this->_tunes->get('tc_id'), 'should not have changed from 4');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the append value method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to append
|
||||
* @param (Boolean) expected value for return value of append method
|
||||
*
|
||||
* @dataProvider provider_append
|
||||
*/
|
||||
public function test_append($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tunes->append($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertContains($value, $this->_tunes->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_append()
|
||||
{
|
||||
return array(
|
||||
array('Y', 1, FALSE),
|
||||
array('H', 'history', TRUE),
|
||||
array('R', 'reel', TRUE),
|
||||
array('r', 'reel', FALSE),
|
||||
array('collection', 'setting', FALSE),
|
||||
array('collection', new Tune(), TRUE),
|
||||
array('collection', array(new Tune()), FALSE),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function test_get()
|
||||
{
|
||||
//R is a valid property so we should get it's value
|
||||
$this->_tunes->set('R', 'reel');
|
||||
$this->assertEquals('reel', $this->_tunes->get('R'));
|
||||
|
||||
//X is not a property, so we should get FALSE
|
||||
$this->assertFalse($this->_tunes->get('X'));
|
||||
}
|
||||
|
||||
}
|
||||
310
tests/unit/memory/TuneTest.php
Normal file
310
tests/unit/memory/TuneTest.php
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
use App\Libraries\abcParse\Tune;
|
||||
use App\Libraries\abcParse\Setting;
|
||||
use App\Libraries\abcParse\Person;
|
||||
use \Codeception\TestCase\Test as TestCase;
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
class TuneTest extends TestCase
|
||||
{
|
||||
private $_tune;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_tune = new Tune();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the model contains the correct attributes
|
||||
*/
|
||||
public function test_model_definition()
|
||||
{
|
||||
//Private attributes, probably shouldn't be tested
|
||||
$this->assertClassHasAttribute('tuneID', Tune::class);
|
||||
$this->assertClassHasAttribute('A', Tune::class);
|
||||
$this->assertClassHasAttribute('C', Tune::class);
|
||||
$this->assertClassHasAttribute('T', Tune::class);
|
||||
$this->assertClassHasAttribute('G', Tune::class);
|
||||
$this->assertClassHasAttribute('O', Tune::class);
|
||||
$this->assertClassHasAttribute('R', Tune::class);
|
||||
$this->assertClassHasAttribute('H', Tune::class);
|
||||
$this->assertClassHasAttribute('X', Tune::class);
|
||||
$this->assertClassHasAttribute('propertyNames', Tune::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the set property method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to set
|
||||
* @param (Boolean) expected value for return value of set method
|
||||
*
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_set($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tune->set($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tune->get($property));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* test the set property method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to set
|
||||
* @param (Boolean) expected value for return value of set method
|
||||
*
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_magic_setter($property, $value, $expected)
|
||||
{
|
||||
$this->_tune->$property = $value;
|
||||
// $this->assertEquals($expected, $success);
|
||||
if($expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tune->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_construct($property, $value, $expected)
|
||||
{
|
||||
$params = array($property => $value);
|
||||
$this->_tune = new Tune($params);
|
||||
|
||||
if($expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tune->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('x', 1, FALSE),
|
||||
array('X', 1, TRUE),
|
||||
array('X', 'aplha', FALSE),
|
||||
array('X', '2', TRUE),
|
||||
array('T', 'string', FALSE),
|
||||
array('T', 10, FALSE),
|
||||
array('T', array('1','2'), TRUE),
|
||||
array('A', 10, FALSE),
|
||||
array('A', array('1','2'), FALSE),
|
||||
array('A', array(new Person(),new Person()), TRUE),
|
||||
array('C', 10, FALSE),
|
||||
array('C', array('1','2'), FALSE),
|
||||
array('C', array(new Person(),new Person()), TRUE),
|
||||
array('G', 10, FALSE),
|
||||
array('G', array('1','2'), TRUE),
|
||||
array('H', 10, FALSE),
|
||||
array('H', array('1','2'), TRUE),
|
||||
array('O', 10, FALSE),
|
||||
array('O', array('1','2'), TRUE),
|
||||
array('R', 10, FALSE),
|
||||
array('R', array('1','2'), TRUE),
|
||||
array('collection', 10, FALSE),
|
||||
array('collection', '10', FALSE),
|
||||
array('collection', array(), FALSE),
|
||||
array('collection', array('1','2'), FALSE),
|
||||
array('collection', array(new Setting()), TRUE),
|
||||
array('tuneHash', 10, FALSE),
|
||||
array('tuneHash', '10', FALSE),
|
||||
array('tuneHash', array(), FALSE),
|
||||
array('tuneHash', array('1','2'), FALSE),
|
||||
array('tuneID', 'abc', FALSE),
|
||||
array('tuneID', '11', TRUE),
|
||||
array('tuneID', 15, TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_set_tuneID()
|
||||
{
|
||||
//we should start with tuneID = 0
|
||||
$this->assertEquals(0, $this->_tune->get('tuneID'), 'should start at 0');
|
||||
|
||||
//because tuneID == 0 we can change value
|
||||
$this->_tune->set('tuneID', 4);
|
||||
$this->assertEquals(4, $this->_tune->get('tuneID'), 'should have changed to 4');
|
||||
|
||||
//tuneID is not 0 so we cannot change value
|
||||
$this->_tune->set('tuneID', 11);
|
||||
$this->assertEquals(4, $this->_tune->get('tuneID'), 'should not have changed from 4');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the append value method
|
||||
*
|
||||
* @param (string) $property, the name of the property to set
|
||||
* @param (mixed) value to append
|
||||
* @param (Boolean) expected value for return value of append method
|
||||
*
|
||||
* @dataProvider provider_append
|
||||
*/
|
||||
public function test_append($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tune->append($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertContains($value, $this->_tune->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_append()
|
||||
{
|
||||
return array(
|
||||
array('Y', 1, FALSE),
|
||||
array('X', 1, FALSE),
|
||||
array('T','title', TRUE),
|
||||
array('T', array('of','titles'), FALSE),
|
||||
array('A', 'author', TRUE),
|
||||
array('C', 'composer', TRUE),
|
||||
array('G', 'Group', TRUE),
|
||||
array('H', 'history', TRUE),
|
||||
array('O', 'Origin', TRUE),
|
||||
array('R', 'Rhythm', TRUE),
|
||||
array('collection', 'setting', FALSE),
|
||||
array('collection', new Setting(), TRUE),
|
||||
array('collection', array(new Setting()), FALSE),
|
||||
array('tuneHash', 'tuneHash', FALSE),
|
||||
array('tuneHash', new Setting(), FALSE),
|
||||
array('tuneHash', array(new Setting()), FALSE),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the static function equals
|
||||
* returns true if the data properties of 2 Abc_Tunes
|
||||
* are identical
|
||||
*
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
*/
|
||||
public function test_equals($params)
|
||||
{
|
||||
// $this->markTestIncomplete();
|
||||
|
||||
$ob1 = new Tune();
|
||||
$ob2 = new Tune();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
$ob1->append($key, $val);
|
||||
$ob2->append($key, $val);
|
||||
}
|
||||
else {
|
||||
$ob1->set($key, $val);
|
||||
$ob2->set($key, $val);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue(Tune::equals($ob1, $ob2));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the static function equals
|
||||
* returns true if the data properties of 2 Abc_Tunes
|
||||
* are identical
|
||||
*
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
*/
|
||||
public function test_equals_fails($params)
|
||||
{
|
||||
$ob1 = new Tune();
|
||||
$ob2 = new Tune();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if($key === 'collection')
|
||||
{
|
||||
$ob1->set($key, $val);
|
||||
}
|
||||
else if(is_array($ob1->get($key)))
|
||||
{
|
||||
$ob1->append($key, $val);
|
||||
}
|
||||
else {
|
||||
$ob1->set($key, $val);
|
||||
}
|
||||
}
|
||||
$this->assertFalse(Tune::equals($ob1, $ob2));
|
||||
}
|
||||
public function provider_equals()
|
||||
{
|
||||
$setting1 = new Setting(array('settingID'=>5, 'tuneID'=>444));
|
||||
$setting2 = new Setting(array('settingID'=>3, 'tuneID'=>2244));
|
||||
return array(
|
||||
array( array('X'=>'2') ),
|
||||
array( array('T'=>'a title') ),
|
||||
array( array('A'=>'an author') ),
|
||||
array( array('C'=>'a composer') ),
|
||||
array( array('G'=>'a group') ),
|
||||
array( array('H'=>'some history') ),
|
||||
array( array('O'=>'Plymouth') ),
|
||||
array( array('R'=>'Jig') ),
|
||||
array( array('collection' => array($setting1, $setting2) ))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function test_isChanged()
|
||||
{
|
||||
$tune = new Tune();
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $tune);
|
||||
|
||||
$this->assertFalse($tune->is_changed(), 'after load should be no changes');
|
||||
|
||||
$tune->set('X','5');
|
||||
$this->assertTrue($tune->is_changed(), 'updating the name changes the data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_get
|
||||
*/
|
||||
public function test_get($key, $expected)
|
||||
{
|
||||
$result = $this->_tune->set($key, $expected);
|
||||
$result = $this->_tune->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_get()
|
||||
{
|
||||
return array(
|
||||
array('', FALSE),
|
||||
array('me', FALSE),
|
||||
array('tuneID', 2),
|
||||
array('X', '2'),
|
||||
array('T', array('1','2')),
|
||||
array('A', array(new Person(),new Person())),
|
||||
array('C', array(new Person(),new Person())),
|
||||
array('G', array('1','2')),
|
||||
array('H', array('1','2')),
|
||||
array('O', array('1','2')),
|
||||
array('R', array('1','2')),
|
||||
array('collection', array(new Setting())),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user