Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/mcoil.corals.io/tests/Unit/AttributeValues/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mcoil.corals.io/tests/Unit/AttributeValues/AttributeValueUnitTest.php
<?php

namespace Tests\Unit\AttributeValues;

use App\Shop\Attributes\Attribute;
use App\Shop\AttributeValues\AttributeValue;
use App\Shop\AttributeValues\Repositories\AttributeValueRepository;
use Tests\TestCase;

class AttributeValueUnitTest extends TestCase
{
    /** @test */
    public function it_can_be_dissociated_from_the_attribute()
    {
        $attributeValue = new AttributeValue(['value' => 'small']);
        $attributeValueRepo = new AttributeValueRepository($attributeValue);

        $attribute = factory(Attribute::class)->create();
        $createdValue = $attributeValueRepo->associateToAttribute($attribute);

        $attributeValueRepo2 = new AttributeValueRepository($createdValue);
        $removedAttribute = $attributeValueRepo2->dissociateFromAttribute();

        $this->assertTrue($removedAttribute);
    }
    
    /** @test */
    public function it_can_be_associated_with_the_attribute()
    {
        $attributeValue = new AttributeValue(['value' => 'sizes']);
        $attributeValueRepo = new AttributeValueRepository($attributeValue);

        $attribute = factory(Attribute::class)->create();
        $attributeValueRepo->associateToAttribute($attribute);

        $this->assertCount(1, $attribute->values->all());
    }

     /** @test */
    public function it_can_add_child_attributevalue(){
        $attributeValue = new AttributeValue(['value' => 'sizes']);
        $attributeValueRepo = new AttributeValueRepository($attributeValue);

        $attribute = factory(Attribute::class)->create();
        $attributeValueRepo->associateToAttribute($attribute);

        $child = new AttributeValue(['value' => 'L']);
        $childRepo = new AttributeValueRepository($child);
        $childRepo->associateToAttribute($attribute);

        $attributeValueRepo->addChildAttributeValue($child);


        $attributeValue = $attributeValueRepo -> findAttributeValueById($attributeValue -> id);

        $foundChild = $attributeValue -> children() -> first();

        $this->assertInstanceOf(AttributeValue::class, $foundChild);
        $this->assertEquals($child -> value,$foundChild -> value);


        $child1 = new AttributeValue(['value' => 'M']);
        $child1Repo = new AttributeValueRepository($child1);
        $child1Repo->associateToAttribute($attribute);
        $attributeValueRepo->addChildAttributeValue($child1);

        $this->assertCount(2,$attributeValue -> children()->get()->toArray());

    }

    /** @test */
    public function it_can_add_array_of_child_attributevalues(){
        $attributeValue = new AttributeValue(['value' => 'sizes']);
        $attributeValueRepo = new AttributeValueRepository($attributeValue);

        $attribute = factory(Attribute::class)->create();
        $attributeValueRepo->associateToAttribute($attribute);
        
        $children = factory(AttributeValue::class,10)->create();
        $attributeValueRepo -> addChildren ($children);

        $allChildren = $attributeValueRepo -> allChildrenAttributeValues();

        $this->assertCount(10,$allChildren ->toArray());

    }

    /** @test */
    public function it_can_get_all_children_attributevalues(){
        $attributeValue = factory(AttributeValue::class)->create();
        $attributeValueRepo = new AttributeValueRepository($attributeValue);
        $child = factory(AttributeValue::class)->create();
        $child1 = factory(AttributeValue::class)->create();
        $child2 = factory(AttributeValue::class)->create();

        $attributeValueRepo -> addChildAttributeValue ($child);
        $attributeValueRepo -> addChildAttributeValue ($child1);
        $attributeValueRepo -> addChildAttributeValue ($child2);

        $allChildren = $attributeValueRepo -> allChildrenAttributeValues();

        $this->assertCount(3,$allChildren ->toArray());

    }

    /** @test */
    public function it_can_delete_child(){
        $attributeValue = factory(AttributeValue::class)->create();
        $attributeValueRepo = new AttributeValueRepository($attributeValue);

        $child = factory(AttributeValue::class)->create();

        $attributeValueRepo -> addChildAttributeValue ($child);


        $allChildren = $attributeValueRepo -> allChildrenAttributeValues();

        $this->assertCount(1,$allChildren ->toArray());

        $attributeValueRepo -> deleteChild($child);
        $allChildren = $attributeValueRepo -> allChildrenAttributeValues();


        $this->assertCount(0,$allChildren ->toArray());

    }
}

Spamworldpro Mini