117 lines
3.4 KiB
PHP
117 lines
3.4 KiB
PHP
<?php
|
|
namespace Tests\Laravel5;
|
|
|
|
use Codeception\TestCase\Test;
|
|
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
|
|
use Webpatser\Uuid\Uuid;
|
|
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 BaseDbTest
|
|
{
|
|
/**
|
|
* @var \UnitTester
|
|
*/
|
|
protected $tester;
|
|
|
|
// 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 = Uuid::generate(4);
|
|
|
|
$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());
|
|
}
|
|
}
|