Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ActionObjectExtractorTest.php
Go to the documentation of this file.
1 <?php
7 
12 
14 {
16  private $testActionObjectExtractor;
17 
21  public function setUp()
22  {
23  $this->testActionObjectExtractor = new ActionObjectExtractor();
24  TestLoggingUtil::getInstance()->setMockLoggingUtil();
25  }
26 
30  public function testBasicActionObjectExtration()
31  {
32  $actionObjects = $this->testActionObjectExtractor->extractActions($this->createBasicActionObjectArray());
33  $this->assertCount(1, $actionObjects);
34 
36  $firstElement = array_values($actionObjects)[0];
37  $this->assertEquals('testAction1', $firstElement->getStepKey());
38  $this->assertCount(1, $firstElement->getCustomActionAttributes());
39  }
40 
45  {
46  $invalidArray = $this->createBasicActionObjectArray('invalidTestAction1', 'invalidTestAction1');
47  $this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestReferenceException::class);
48  try {
49  $this->testActionObjectExtractor->extractActions($invalidArray, 'TestWithSelfReferencingStepKey');
50  } catch (\Exception $e) {
51  TestLoggingUtil::getInstance()->validateMockLogStatmentRegex(
52  'error',
53  '/Line \d*: Invalid ordering configuration in test/',
54  [
55  'test' => 'TestWithSelfReferencingStepKey',
56  'stepKey' => ['invalidTestAction1']
57  ]
58  );
59 
60  throw $e;
61  }
62  }
63 
68  {
69  $ambiguousArray = $this->createBasicActionObjectArray('testAction1');
70  $ambiguousArray = array_merge(
71  $ambiguousArray,
72  $this->createBasicActionObjectArray('testAction2', 'testAction1')
73  );
74 
75  $ambiguousArray = array_merge(
76  $ambiguousArray,
77  $this->createBasicActionObjectArray('testAction3', null, 'testAction1')
78  );
79 
80  $this->testActionObjectExtractor->extractActions($ambiguousArray, 'AmbiguousRefTest');
81  TestLoggingUtil::getInstance()->validateMockLogStatement(
82  'warning',
83  'multiple actions referencing step key',
84  [
85  'test' => 'AmbiguousRefTest',
86  'stepKey' => 'testAction1',
87  'ref' => ['testAction2', 'testAction3']
88  ]
89  );
90  }
91 
95  public function testEmptyStepKey()
96  {
97  $this->expectExceptionMessage("StepKeys cannot be empty. Action='sampleAction'");
98  $this->testActionObjectExtractor->extractActions($this->createBasicActionObjectArray(""));
99  }
100 
109  private function createBasicActionObjectArray($stepKey = 'testAction1', $before = null, $after = null)
110  {
111  $baseArray = [
112  $stepKey => [
113  "nodeName" => "sampleAction",
114  "stepKey" => $stepKey,
115  "someAttribute" => "someAttributeValue"
116  ]
117  ];
118 
119  if ($before) {
120  $baseArray[$stepKey] = array_merge($baseArray[$stepKey], ['before' => $before]);
121  }
122 
123  if ($after) {
124  $baseArray[$stepKey] = array_merge($baseArray[$stepKey], ['after' => $after]);
125  }
126 
127  return $baseArray;
128  }
129 
133  public static function tearDownAfterClass()
134  {
135  TestLoggingUtil::getInstance()->clearMockLoggingUtil();
136  }
137 }