HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/vangogh.komma.pro/app/Komma/Shop/Tests/Unit/PropertyTest.php
<?php

namespace App\Komma\Shop\Tests\Unit;

use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Shop\Development\Fakers\PropertyFaker;
use App\Komma\Shop\Products\Product\Product;
use App\Komma\Shop\Properties\Models\PropertyKey;
use App\Komma\Shop\Properties\Models\PropertyKeyTranslation;
use App\Komma\Shop\Properties\Models\Property;
use App\Komma\Shop\Properties\Models\PropertyValue;
use App\Komma\Shop\Properties\Models\PropertyValueTranslation;
use App\Komma\Shop\Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class PropertyTest extends TestCase
{
    use DatabaseTransactions; //Automatically rolls back database actions after tests

    /**
     * @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),
        ]);
    }
}