initial commit
This commit is contained in:
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user