Files
abcParser/tests/unit/Laravel5/CollectionTest.php
2017-10-06 22:32:31 -04:00

524 lines
16 KiB
PHP

<?php
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use Faker\Test\Provider\BaseTest;
use XaiCorp\AbcParser\Models\Laravel5\Collection;
use XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute;
class CollectionTest extends BaseDbTest
{
// 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]);
}
}