Skip to content

MQE-1974: Report used deprecated metadata in Test #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@
use Magento\FunctionalTestingFramework\ObjectManager;
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\TestLoggingUtil;

/**
* Class DataObjectHandlerTest
*/
class DataObjectHandlerTest extends MagentoTestCase
{
/**
* Setup method
*/
public function setUp(): void
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

// All tests share this array, feel free to add but be careful modifying or removing
const PARSER_OUTPUT = [
'entity' => [
Expand All @@ -44,6 +53,22 @@ class DataObjectHandlerTest extends MagentoTestCase
]
];

const PARSER_OUTPUT_DEPRECATED = [
'entity' => [
'EntityOne' => [
'type' => 'testType',
'data' => [
0 => [
'key' => 'testKey',
'value' => 'testValue'
]
],
'deprecated' => "deprecation message",
'filename' => "filename.xml"
],
]
];

const PARSER_OUTPUT_WITH_EXTEND = [
'entity' => [
'EntityOne' => [
Expand Down Expand Up @@ -134,6 +159,24 @@ public function testGetAllObjects()
$this->assertEquals($expected, $actual['EntityOne']);
}

/**
* test deprecated data object
*/
public function testDeprecatedDataObject()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_DEPRECATED);

// Call the method under test
$actual = DataObjectHandler::getInstance()->getAllObjects();

//validate deprecation warning
TestLoggingUtil::getInstance()->validateMockLogStatement(
'warning',
"DEPRECATION: The data entity 'EntityOne' is deprecated.",
["fileName" => "filename.xml", "deprecatedMessage" => "deprecation message"]
);
}

/**
* getObject should return the expected data object if it exists
*/
Expand Down Expand Up @@ -269,4 +312,12 @@ private function setUpMockDataObjectHander($entityDataArray)
'getObjectManager' => $mockObjectManager
]);
}

/**
* clean up function runs after all tests
*/
public static function tearDownAfterClass(): void
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\OperationDefinitionParser;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\TestLoggingUtil;

/**
* Class OperationDefinitionObjectHandlerTest
*/
class OperationDefinitionObjectHandlerTest extends MagentoTestCase
{
/**
* Setup method
*/
public function setUp(): void
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

public function testGetMultipleObjects()
{
// Data Variables for Assertions
Expand Down Expand Up @@ -72,6 +81,56 @@ public function testGetMultipleObjects()
$this->assertArrayHasKey($operationType2 . $dataType1, $operations);
}

public function testDeprecatedOperation()
{
// Data Variables for Assertions
$dataType1 = "type1";
$operationType1 = "create";

/**
* Parser Output. Just one metadata with 1 field
* operationName
* createType1
* has field
* key=id, value=integer
*/
$mockData = [OperationDefinitionObjectHandler::ENTITY_OPERATION_ROOT_TAG => [
"testOperationName" => [
OperationDefinitionObjectHandler::ENTITY_OPERATION_DATA_TYPE => $dataType1,
OperationDefinitionObjectHandler::ENTITY_OPERATION_TYPE => $operationType1,
OperationDefinitionObjectHandler::ENTITY_OPERATION_AUTH => "auth",
OperationDefinitionObjectHandler::ENTITY_OPERATION_URL => "V1/Type1",
OperationDefinitionObjectHandler::ENTITY_OPERATION_METHOD => "POST",
OperationDefinitionObjectHandler::ENTITY_OPERATION_ENTRY => [
0 => [
OperationDefinitionObjectHandler::ENTITY_OPERATION_ENTRY_KEY => "id",
OperationDefinitionObjectHandler::ENTITY_OPERATION_ENTRY_VALUE => "integer"
],
],
OperationDefinitionObjectHandler::OBJ_DEPRECATED => 'deprecation message'
]]];
$this->setMockParserOutput($mockData);

//Perform Assertions
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
$operations = $operationDefinitionManager->getAllObjects();

$this->assertArrayHasKey($operationType1 . $dataType1, $operations);
TestLoggingUtil::getInstance()->validateMockLogStatement(
'notice',
"NOTICE: 1 metadata operation name violations detected. See mftf.log for details.",
[]
);
// test run time deprecation notice
$operation = $operationDefinitionManager->getOperationDefinition($operationType1, $dataType1);
$operation->logDeprecated();
TestLoggingUtil::getInstance()->validateMockLogStatement(
'warning',
"DEPRECATION: The operation testOperationName is deprecated.",
['operationType' => 'create', 'deprecatedMessage' => 'deprecation message']
);
}

public function testObjectCreation()
{
// Data Variables for Assertions
Expand Down Expand Up @@ -379,4 +438,12 @@ private function setMockParserOutput($data)
$instance = AspectMock::double(ObjectManager::class, ['create' => $mockOperationParser])->make();
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
}

/**
* clean up function runs after all tests
*/
public static function tearDownAfterClass(): void
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
use Magento\FunctionalTestingFramework\XmlParser\PageParser;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\TestLoggingUtil;

class PageObjectHandlerTest extends MagentoTestCase
{
/**
* Setup method
*/
public function setUp(): void
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

public function testGetPageObject()
{
$mockData = [
Expand Down Expand Up @@ -70,6 +79,30 @@ public function testGetEmptyPage()
$this->addToAssertionCount(1);
}

public function testDeprecatedPage()
{
$mockData = [
"testPage1" => [
"url" => "testURL1",
"module" => "testModule1",
"section" => [
],
"area" => "test",
"deprecated" => "deprecation message",
"filename" => "filename.xml"
]];
$this->setMockParserOutput($mockData);

// get pages
$page = PageObjectHandler::getInstance()->getObject('testPage1');

TestLoggingUtil::getInstance()->validateMockLogStatement(
'notice',
"NOTICE: 1 Page name violations detected. See mftf.log for details.",
[]
);
}

/**
* Function used to set mock for parser return and force init method to run between tests.
*
Expand All @@ -86,4 +119,12 @@ private function setMockParserOutput($data)
$instance = AspectMock::double(ObjectManager::class, ['get' => $mockSectionParser])->make();
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
}

/**
* clean up function runs after all tests
*/
public static function tearDownAfterClass(): void
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
use Magento\FunctionalTestingFramework\XmlParser\SectionParser;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\TestLoggingUtil;

class SectionObjectHandlerTest extends MagentoTestCase
{
/**
* Setup method
*/
public function setUp(): void
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

public function testGetSectionObject()
{
$mockData = [
Expand Down Expand Up @@ -52,6 +61,36 @@ public function testGetSectionObject()
$this->assertNull($invalidSection);
}

public function testDeprecatedSection()
{
$mockData = [
"testSection1" => [
"element" => [
"testElement" => [
"type" => "input",
"selector" => "#element",
"deprecated" => "element deprecation message"
]
],
"filename" => "filename.xml",
"deprecated" => "section deprecation message"
]
];

$this->setMockParserOutput($mockData);

// get sections
$sectionHandler = SectionObjectHandler::getInstance();
$section = $sectionHandler->getObject("testSection1");

//validate deprecation warning
TestLoggingUtil::getInstance()->validateMockLogStatement(
'notice',
"NOTICE: 1 Section name violations detected. See mftf.log for details.",
[]
);
}

/**
* Set the mock parser return value
*
Expand All @@ -68,4 +107,12 @@ private function setMockParserOutput($data)
$instance = AspectMock::double(ObjectManager::class, ["get" => $mockSectionParser])->make();
AspectMock::double(ObjectManagerFactory::class, ["getObjectManager" => $instance]);
}

/**
* clean up function runs after all tests
*/
public static function tearDownAfterClass(): void
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,47 @@ public function testEmptyStepKey()
$this->testActionGroupObjectExtractor->extractActionGroup($this->createBasicActionObjectArray(""));
}

/**
* Tests deprecation message for an action group
*/
public function testDeprecationMessage()
{
$this->testActionGroupObjectExtractor->extractActionGroup(
$this->createBasicActionObjectArray(
"testDeprecatedAction1",
"actionGroup",
"filename1.xml",
"message"
)
);

TestLoggingUtil::getInstance()->validateMockLogStatement(
'warning',
"DEPRECATION: The action group 'actionGroup' is deprecated.",
["fileName" => "filename1.xml", "deprecatedMessage" => "message"]
);
}

/**
* Utility function to return mock parser output for testing extraction into ActionObjects.
*
* @param string $stepKey
* @param string $actionGroup
* @param string $filename
* @param string $deprecated
* @return array
*/
private function createBasicActionObjectArray(
$stepKey = 'testAction1',
$actionGroup = "actionGroup",
$filename = "filename.xml"
$filename = "filename.xml",
$deprecated = null
) {
$baseArray = [
'nodeName' => 'actionGroup',
'name' => $actionGroup,
'filename' => $filename,
'deprecated' => $deprecated,
$stepKey => [
"nodeName" => "sampleAction",
"stepKey" => $stepKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ private function processParserOutput($parserOutput)
if (array_key_exists(self::OBJ_DEPRECATED, $rawEntity)) {
$deprecated = $rawEntity[self::OBJ_DEPRECATED];
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
$deprecated,
["dataName" => $filename, "deprecatedEntity" => $deprecated]
"The data entity '{$name}' is deprecated.",
["fileName" => $filename, "deprecatedMessage" => $deprecated]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ private function initialize()

if ($deprecated !== null) {
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
$deprecated,
["operationName" => $dataDefName, "deprecatedOperation" => $deprecated]
$message = "The operation {$dataDefName} is deprecated.",
["operationType" => $operation, "deprecatedMessage" => $deprecated]
);
}

Expand Down
Loading