-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REST API multiselect attribute BC break between 2.1.8 and 2.3.0.
Add conditions for multiselect attribute validation. REST API multiselect attribute BC break between 2.1.8 and 2.3.0. Create unit test for app/code/Magento/Eav/Model/TypeLocator/SimpleType.php. REST API multiselect attribute BC break between 2.1.8 and 2.3.0. Code refactoring. REST API multiselect attribute BC break between 2.1.8 and 2.3.0. Code refactoring. REST API multiselect attribute BC break between 2.1.8 and 2.3.0. Change unit test functionality for app/code/Magento/Eav/Model/TypeLocator/SimpleType.php. REST API multiselect attribute BC break between 2.1.8 and 2.3.0. Create api-functional test for the following case REST API multiselect attribute BC break between 2.1.8 and 2.3.0. Remove ObjectManager and setUp method.
- Loading branch information
Nikita Tychuk
authored and
Nikita Tychuk
committed
May 10, 2019
1 parent
7755eef
commit a8bcd7d
Showing
3 changed files
with
226 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
app/code/Magento/Eav/Test/Unit/Model/TypeLocator/SimpleTypeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Eav\Test\Unit\Model\TypeLocator; | ||
|
||
use Magento\Eav\Model\TypeLocator\SimpleType; | ||
use Magento\Eav\Model\AttributeRepository; | ||
use Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface; | ||
use Magento\Catalog\Model\ResourceModel\Eav\Attribute; | ||
use Magento\Framework\Reflection\TypeProcessor; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
/** | ||
* Class SimpleTypeTest | ||
* | ||
* @package Magento\Eav\Test\Unit\Model\TypeLocator | ||
*/ | ||
class SimpleTypeTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Test testGetType method | ||
* @return void | ||
*/ | ||
public function testGetTypeWithNonexistentAttribute() | ||
{ | ||
$getException = new NoSuchEntityException(); | ||
$expected = TypeProcessor::NORMALIZED_ANY_TYPE; | ||
|
||
/** @var AttributeRepository|\PHPUnit_Framework_MockObject_MockObject $attributeRepositoryMock */ | ||
$attributeRepositoryMock = $this->createMock(AttributeRepository::class); | ||
$attributeRepositoryMock->expects($this->any()) | ||
->method('get') | ||
->willThrowException($getException); | ||
|
||
/** @var ServiceTypeListInterface|\PHPUnit_Framework_MockObject_MockObject $serviceTypeListMock */ | ||
$serviceTypeListMock = $this->createMock(ServiceTypeListInterface::class); | ||
|
||
/** @var SimpleType|\PHPUnit_Framework_MockObject_MockObject $simpleType */ | ||
$simpleType = new SimpleType( | ||
$attributeRepositoryMock, | ||
$serviceTypeListMock | ||
); | ||
|
||
$this->assertSame($expected, $simpleType->getType('testAttributeCode', 'testEntityType')); | ||
} | ||
|
||
/** | ||
* Test testGetType method | ||
* @return void | ||
*/ | ||
public function testGetTypeWithMultiselectFrontendInput() | ||
{ | ||
$getFrontendInputReturn = 'multiselect'; | ||
$expected = TypeProcessor::NORMALIZED_ANY_TYPE; | ||
|
||
/** @var Attribute|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ | ||
$attributeMock = $this->createMock(Attribute::class); | ||
$attributeMock->expects($this->any()) | ||
->method('getFrontendInput') | ||
->willReturn($getFrontendInputReturn); | ||
|
||
/** @var AttributeRepository|\PHPUnit_Framework_MockObject_MockObject $attributeRepositoryMock */ | ||
$attributeRepositoryMock = $this->createMock(AttributeRepository::class); | ||
$attributeRepositoryMock->expects($this->any()) | ||
->method('get') | ||
->willReturn($attributeMock); | ||
|
||
/** @var ServiceTypeListInterface|\PHPUnit_Framework_MockObject_MockObject $serviceTypeListMock */ | ||
$serviceTypeListMock = $this->createMock(ServiceTypeListInterface::class); | ||
|
||
/** @var SimpleType|\PHPUnit_Framework_MockObject_MockObject $simpleType */ | ||
$simpleType = new SimpleType( | ||
$attributeRepositoryMock, | ||
$serviceTypeListMock | ||
); | ||
|
||
$this->assertSame($expected, $simpleType->getType('testAttributeCode', 'testEntityType')); | ||
} | ||
|
||
/** | ||
* Test testGetType method | ||
* @return void | ||
*/ | ||
public function testGetTypeWithBackendTypeInMap() | ||
{ | ||
$getFrontendInputReturn = 'textarea'; | ||
$getBackendTypeReturn = 'text'; | ||
$expected = TypeProcessor::NORMALIZED_STRING_TYPE; | ||
|
||
/** @var Attribute|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ | ||
$attributeMock = $this->createMock(Attribute::class); | ||
$attributeMock->expects($this->any()) | ||
->method('getFrontendInput') | ||
->willReturn($getFrontendInputReturn); | ||
$attributeMock->expects($this->any()) | ||
->method('getBackendType') | ||
->willReturn($getBackendTypeReturn); | ||
|
||
/** @var AttributeRepository|\PHPUnit_Framework_MockObject_MockObject $attributeRepositoryMock */ | ||
$attributeRepositoryMock = $this->createMock(AttributeRepository::class); | ||
$attributeRepositoryMock->expects($this->any()) | ||
->method('get') | ||
->willReturn($attributeMock); | ||
|
||
/** @var ServiceTypeListInterface|\PHPUnit_Framework_MockObject_MockObject $serviceTypeListMock */ | ||
$serviceTypeListMock = $this->createMock(ServiceTypeListInterface::class); | ||
|
||
/** @var SimpleType|\PHPUnit_Framework_MockObject_MockObject $simpleType */ | ||
$simpleType = new SimpleType( | ||
$attributeRepositoryMock, | ||
$serviceTypeListMock | ||
); | ||
|
||
$this->assertSame($expected, $simpleType->getType('testAttributeCode', 'testEntityType')); | ||
} | ||
|
||
/** | ||
* Test testGetType method | ||
* @return void | ||
*/ | ||
public function testGetTypeWithBackendTypeNotInMap() | ||
{ | ||
$getFrontendInputReturn = 'textarea'; | ||
$getBackendTypeReturn = 'testBackendTypeNotInMap'; | ||
$expected = TypeProcessor::NORMALIZED_ANY_TYPE; | ||
|
||
/** @var Attribute|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ | ||
$attributeMock = $this->createMock(Attribute::class); | ||
$attributeMock->expects($this->any()) | ||
->method('getFrontendInput') | ||
->willReturn($getFrontendInputReturn); | ||
$attributeMock->expects($this->any()) | ||
->method('getBackendType') | ||
->willReturn($getBackendTypeReturn); | ||
|
||
/** @var AttributeRepository|\PHPUnit_Framework_MockObject_MockObject $attributeRepositoryMock */ | ||
$attributeRepositoryMock = $this->createMock(AttributeRepository::class); | ||
$attributeRepositoryMock->expects($this->any()) | ||
->method('get') | ||
->willReturn($attributeMock); | ||
|
||
/** @var ServiceTypeListInterface|\PHPUnit_Framework_MockObject_MockObject $serviceTypeListMock */ | ||
$serviceTypeListMock = $this->createMock(ServiceTypeListInterface::class); | ||
|
||
/** @var SimpleType|\PHPUnit_Framework_MockObject_MockObject $simpleType */ | ||
$simpleType = new SimpleType( | ||
$attributeRepositoryMock, | ||
$serviceTypeListMock | ||
); | ||
|
||
$this->assertSame($expected, $simpleType->getType('testAttributeCode', 'testEntityType')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters