File: D:/HostingSpaces/zipwire/zipwire.nl/app/KommaApp/Shop/Tests/Unit/PropertyTest.php
<?php
namespace App\KommaApp\Shop\Tests\Unit;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Shop\Factories\Fakers\PropertyFaker;
use App\KommaApp\Shop\Products\Product\Product;
use App\KommaApp\Shop\Properties\Models\PropertyKey;
use App\KommaApp\Shop\Properties\Models\PropertyKeyTranslation;
use App\KommaApp\Shop\Properties\Models\Property;
use App\KommaApp\Shop\Properties\Models\PropertyValue;
use App\KommaApp\Shop\Properties\Models\PropertyValueTranslation;
use App\KommaApp\Shop\Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class PropertyTest extends TestCase
{
use DatabaseTransactions; //Automatically rolls back database actions after tests
/**
* This method is being run before each test
*/
protected function setUp()
{
parent::setUp();
}
/**
* @group Properties
* @test
*/
public function testPropertyValue()
{
$value = new PropertyValue();
$value->save();
$this->assertDatabaseHas($value->getTable(), ['id' => $value->id]);
}
/**
* @group Properties
* @test
*/
public function testPropertyKey()
{
$key = new PropertyKey();
$key->save();
$this->assertDatabaseHas($key->getTable(), ['id' => $key->id]);
}
/**
* @group Properties
* @test
*/
public function testPropertyValueTranslation()
{
$value = new PropertyValue();
$value->save();
$propertyData = PropertyFaker::property();
$language = Language::find(104);
$translation = new PropertyValueTranslation();
$translation->value = $propertyData[PropertyFaker::VALUE];
$translation->language()->associate($language);
$translation->translatable()->associate($value);
$translation->save();
$this->assertDatabaseHas($translation->getTable(), ['id' => $translation->id]);
}
/**
* @group Properties
* @test
*/
public function testPropertyKeyTranslation()
{
$key = new PropertyKey();
$key->save();
$propertyData = PropertyFaker::property();
$language = Language::find(104);
$translation = new PropertyKeyTranslation();
$translation->value = $propertyData[PropertyFaker::KEY];
$translation->language()->associate($language);
$translation->translatable()->associate($key);
$translation->save();
$this->assertDatabaseHas($translation->getTable(), ['id' => $translation->id]);
}
/**
* @group Properties
* @test
*/
public function testProperty()
{
$propertyData = PropertyFaker::property();
$language = Language::find(104);
$value = new PropertyValue();
$value->save();
$key = new PropertyKey();
$key->save();
$valueTranslation = new PropertyValueTranslation();
$valueTranslation->value = $propertyData[PropertyFaker::VALUE];
$valueTranslation->language()->associate($language);
$valueTranslation->translatable()->associate($value);
$valueTranslation->save();
$keyTranslation = new PropertyKeyTranslation();
$keyTranslation->value = $propertyData[PropertyFaker::KEY];
$keyTranslation->language()->associate($language);
$keyTranslation->translatable()->associate($key);
$keyTranslation->save();
$property = new Property();
$property->code_name = str_random();
$property->key()->associate($key);
$property->value()->associate($value);
$property->save();
$this->assertDatabaseHas($property->getTable(), ['id' => $property->id]);
}
/**
* @group Properties
* @test
*/
public function testPropertyLinkageToPropertizable()
{
$propertyData = PropertyFaker::property();
$language = Language::find(104);
$value = new PropertyValue();
$value->save();
$key = new PropertyKey();
$key->save();
$valueTranslation = new PropertyValueTranslation();
$valueTranslation->value = $propertyData[PropertyFaker::VALUE];
$valueTranslation->language()->associate($language);
$valueTranslation->translatable()->associate($value);
$valueTranslation->save();
$keyTranslation = new PropertyKeyTranslation();
$keyTranslation->value = $propertyData[PropertyFaker::KEY];
$keyTranslation->language()->associate($language);
$keyTranslation->translatable()->associate($key);
$keyTranslation->save();
$property = new Property();
$property->code_name = str_random();
$property->key()->associate($key);
$property->value()->associate($value);
$property->save();
$this->assertDatabaseHas($property->getTable(), ['id' => $property->id]);
/** @var Product $product */
$product = factory(Product::class)->create();
$product->properties()->save($property);
$this->assertDatabaseHas('propertizables', [
'property_id' => $property->id,
'propertizable_id' => $product->id,
'propertizable_type' => get_class($product),
]);
}
}