Skip to content

Commit 0d88dc5

Browse files
soumyaudobooth
andauthored
MQE-2078: [PHPUnit 9] assertContains and assertNotContains breaking c… (#673)
* MQE-2078: [PHPUnit 9] assertContains and assertNotContains breaking changes added new actions assertStringContainsString assertStringContainsStringIgnoringCase * MQE-2078: [PHPUnit 9] assertContains and assertNotContains breaking changes Added additional documentation for assertContains * Grammar fixes Co-authored-by: Donald Booth <[email protected]>
1 parent 6cae7aa commit 0d88dc5

File tree

7 files changed

+136
-12
lines changed

7 files changed

+136
-12
lines changed

dev/tests/verification/Resources/AssertTest.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class AssertTestCest
4545
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass"); // stepKey: assertArrayNotHasKey
4646
$I->assertArraySubset([1, 2], [1, 2, 3, 5], "pass"); // stepKey: assertArraySubset
4747
$I->assertContains("ab", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertContains
48+
$I->assertStringContainsString("apple", "apple", "pass"); // stepKey: assertStringContainsString
49+
$I->assertStringContainsStringIgnoringCase("Banana", "banana", "pass"); // stepKey: assertStringContainsStringIgnoringCase
4850
$I->assertCount(2, ['a', 'b'], "pass"); // stepKey: assertCount
4951
$I->assertEmpty([], "pass"); // stepKey: assertEmpty
5052
$I->assertEquals($text, "Copyright © 2013-2017 Magento, Inc. All rights reserved.", "pass"); // stepKey: assertEquals1
@@ -62,8 +64,9 @@ class AssertTestCest
6264
$I->assertLessOrEquals(5, 2, "pass"); // stepKey: assertLessOrEquals
6365
$I->assertLessThan(5, 2, "pass"); // stepKey: assertLessThan
6466
$I->assertLessThanOrEqual(5, 2, "pass"); // stepKey: assertLessThanOrEquals
65-
$I->assertNotContains("bc", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertNotContains1
66-
$I->assertNotContains("bc", $text, "pass"); // stepKey: assertNotContains2
67+
$I->assertNotContains("bc", ['item1' => 'a', 'item2' => 'ab'], "pass"); // stepKey: assertNotContains
68+
$I->assertStringNotContainsString("apple", "banana", "pass"); // stepKey: assertStringNotContainsString
69+
$I->assertStringNotContainsStringIgnoringCase("apple", "banana", "pass"); // stepKey: assertStringNotContainsStringIgnoringCase
6770
$I->assertNotEmpty([1, 2], "pass"); // stepKey: assertNotEmpty1
6871
$I->assertNotEmpty($text, "pass"); // stepKey: assertNotEmpty2
6972
$I->assertNotEquals(2, 5, "pass", 0); // stepKey: assertNotEquals

dev/tests/verification/TestModule/Test/AssertTest.xml

+17-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
<expectedResult type="string">ab</expectedResult>
4040
<actualResult type="const">['item1' => 'a', 'item2' => 'ab']</actualResult>
4141
</assertContains>
42+
<assertStringContainsString stepKey="assertStringContainsString" message="pass">
43+
<expectedResult type="string">apple</expectedResult>
44+
<actualResult type="string">apple</actualResult>
45+
</assertStringContainsString>
46+
<assertStringContainsStringIgnoringCase stepKey="assertStringContainsStringIgnoringCase" message="pass">
47+
<expectedResult type="string">Banana</expectedResult>
48+
<actualResult type="string">banana</actualResult>
49+
</assertStringContainsStringIgnoringCase>
4250
<assertCount stepKey="assertCount" message="pass">
4351
<expectedResult type="int">2</expectedResult>
4452
<actualResult type="const">['a', 'b']</actualResult>
@@ -103,14 +111,18 @@
103111
<expectedResult type="int">5</expectedResult>
104112
<actualResult type="int">2</actualResult>
105113
</assertLessThanOrEqual>
106-
<assertNotContains stepKey="assertNotContains1" message="pass">
114+
<assertNotContains stepKey="assertNotContains" message="pass">
107115
<expectedResult type="string">bc</expectedResult>
108116
<actualResult type="const">['item1' => 'a', 'item2' => 'ab']</actualResult>
109117
</assertNotContains>
110-
<assertNotContains stepKey="assertNotContains2" message="pass">
111-
<expectedResult type="string">bc</expectedResult>
112-
<actualResult type="variable">text</actualResult>
113-
</assertNotContains>
118+
<assertStringNotContainsString stepKey="assertStringNotContainsString" message="pass">
119+
<expectedResult type="string">apple</expectedResult>
120+
<actualResult type="string">banana</actualResult>
121+
</assertStringNotContainsString>
122+
<assertStringNotContainsStringIgnoringCase stepKey="assertStringNotContainsStringIgnoringCase" message="pass">
123+
<expectedResult type="string">apple</expectedResult>
124+
<actualResult type="string">banana</actualResult>
125+
</assertStringNotContainsStringIgnoringCase>
114126
<assertNotEmpty stepKey="assertNotEmpty1" message="pass">
115127
<actualResult type="const">[1, 2]</actualResult>
116128
</assertNotEmpty>

docs/test/assertions.md

+46-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Assertions
22

3-
43
Assertions serve to pass or fail the [test](../test.md#test-tag) if a condition is not met. These assertions will look familiar to you if you've used any other testing framework, like PHPUnit.
54

65
All assertions contain the same [common actions attributes](./actions.md#common-attributes): `stepKey`, `before`, and `after`.
@@ -31,6 +30,8 @@ To use variables embedded in a string in `expected` and `actual` of your asserti
3130

3231
`actual="A long assert string {$stepKeyOfGrab} with an embedded variable reference." actualType="variable"`
3332

33+
In case of `assertContains` actions, `<expectedResult>` is the needle and `<actualResult>` is the haystack.
34+
3435
## Example
3536

3637
The following example shows a common test that gets text from a page and asserts that it matches what we expect to see. If it does not, the test will fail at the assert step.
@@ -130,6 +131,28 @@ Attribute|Type|Use|Description
130131
`before`|string|optional| `stepKey` of action that must be executed next.
131132
`after`|string|optional| `stepKey` of the preceding action.
132133

134+
### assertStringContainsString
135+
136+
See [assertStringContainsString docs on codeception.com](http://codeception.com/docs/modules/Asserts#assertStringContainsString).
137+
138+
Attribute|Type|Use|Description
139+
---|---|---|---
140+
`message`|string|optional|Text describing the cause of the failure.
141+
`stepKey`|string|required| Unique identifier of the text step.
142+
`before`|string|optional| `stepKey` of the action that must be executed next.
143+
`after`|string|optional| `stepKey` of the preceding action.
144+
145+
### assertStringContainsStringIgnoringCase
146+
147+
See [assertStringContainsStringIgnoringCase docs on codeception.com](http://codeception.com/docs/modules/Asserts#assertStringContainsStringIgnoringCase).
148+
149+
Attribute|Type|Use|Description
150+
---|---|---|---
151+
`message`|string|optional|Message describing the cause of failure.
152+
`stepKey`|string|required| A unique identifier of the text step.
153+
`before`|string|optional| `stepKey` of the action that must be executed next.
154+
`after`|string|optional| `stepKey` of the preceding action.
155+
133156
### assertCount
134157

135158
See [assertCount docs on codeception.com](http://codeception.com/docs/modules/Asserts#assertCount).
@@ -307,6 +330,28 @@ Attribute|Type|Use|Description
307330
`before`|string|optional| `stepKey` of action that must be executed next.
308331
`after`|string|optional| `stepKey` of the preceding action.
309332

333+
### assertStringNotContainsString
334+
335+
See [assertStringNotContainsString docs on codeception.com](http://codeception.com/docs/modules/Asserts#assertStringNotContainsString).
336+
337+
Attribute|Type|Use|Description
338+
---|---|---|---
339+
`message`|string|optional|Text of informational message about a cause of failure.
340+
`stepKey`|string|required| A unique identifier of the text step.
341+
`before`|string|optional| `stepKey` of action that must be executed next.
342+
`after`|string|optional| `stepKey` of the preceding action.
343+
344+
### assertStringContainsStringIgnoringCase
345+
346+
See [assertStringNotContainsStringIgnoringCase docs on codeception.com](http://codeception.com/docs/modules/Asserts#assertStringNotContainsStringIgnoringCase).
347+
348+
Attribute|Type|Use|Description
349+
---|---|---|---
350+
`message`|string|optional|Text of informational message about a cause of failure.
351+
`stepKey`|string|required| A unique identifier of the text step.
352+
`before`|string|optional| `stepKey` of action that must be executed next.
353+
`after`|string|optional| `stepKey` of the preceding action.
354+
310355
### assertNotEmpty
311356

312357
See [assertNotEmpty docs on codeception.com](http://codeception.com/docs/modules/Asserts#assertNotEmpty).

etc/di.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- Entity value gets replaced in Dom.php before reading $xml -->
1010
<!DOCTYPE config [
11-
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSorted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|fillField|formatMoney|generateDate|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|magentoCron|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pause|parseFloat|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForPwaElementNotVisible|waitForPwaElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl|helper">
11+
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSortasserted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|fillField|formatMoney|generateDate|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|magentoCron|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pause|parseFloat|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForPwaElementNotVisible|waitForPwaElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertStringContainsString|assertStringContainsStringIgnoringCase|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertStringNotContainsString|assertStringNotContainsStringIgnoringCase|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl|helper">
1212
]>
1313

1414
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../src/Magento/FunctionalTestingFramework/ObjectManager/etc/config.xsd">

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function dontSeeInCurrentUrl($needle)
258258
$actualUrl = $this->webDriver->getCurrentURL();
259259
$comparison = "Expected: $needle\nActual: $actualUrl";
260260
AllureHelper::addAttachmentToCurrentStep($comparison, 'Comparison');
261-
$this->assertNotContains($needle, $actualUrl);
261+
$this->assertStringNotContainsString($needle, $actualUrl);
262262
}
263263

264264
/**
@@ -327,7 +327,7 @@ public function seeInCurrentUrl($needle)
327327
$actualUrl = $this->webDriver->getCurrentURL();
328328
$comparison = "Expected: $needle\nActual: $actualUrl";
329329
AllureHelper::addAttachmentToCurrentStep($comparison, 'Comparison');
330-
$this->assertContains($needle, $actualUrl);
330+
$this->assertStringContainsString($needle, $actualUrl);
331331
}
332332

333333
/**
@@ -710,7 +710,7 @@ public function assertElementContainsAttribute($selector, $attribute, $value)
710710
// When an "attribute" is blank or null it returns "true" so we assert that "true" is present.
711711
$this->assertEquals($attributes, 'true');
712712
} else {
713-
$this->assertContains($value, $attributes);
713+
$this->assertStringContainsString($value, $attributes);
714714
}
715715
}
716716

src/Magento/FunctionalTestingFramework/Test/etc/Actions/assertActions.xsd

+60
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<xs:element type="assertArrayNotHasKeyType" name="assertArrayNotHasKey" minOccurs="0" maxOccurs="unbounded"/>
1717
<xs:element type="assertArraySubsetType" name="assertArraySubset" minOccurs="0" maxOccurs="unbounded"/>
1818
<xs:element type="assertContainsType" name="assertContains" minOccurs="0" maxOccurs="unbounded"/>
19+
<xs:element type="assertStringContainsStringType" name="assertStringContainsString" minOccurs="0" maxOccurs="unbounded"/>
20+
<xs:element type="assertStringContainsStringIgnoringCaseType" name="assertStringContainsStringIgnoringCase" minOccurs="0" maxOccurs="unbounded"/>
1921
<xs:element type="assertCountType" name="assertCount" minOccurs="0" maxOccurs="unbounded"/>
2022
<xs:element type="assertEmptyType" name="assertEmpty" minOccurs="0" maxOccurs="unbounded"/>
2123
<xs:element type="assertEqualsType" name="assertEquals" minOccurs="0" maxOccurs="unbounded"/>
@@ -32,6 +34,8 @@
3234
<xs:element type="assertLessThanType" name="assertLessThan" minOccurs="0" maxOccurs="unbounded"/>
3335
<xs:element type="assertLessThanOrEqualType" name="assertLessThanOrEqual" minOccurs="0" maxOccurs="unbounded"/>
3436
<xs:element type="assertNotContainsType" name="assertNotContains" minOccurs="0" maxOccurs="unbounded"/>
37+
<xs:element type="assertStringNotContainsStringType" name="assertStringNotContainsString" minOccurs="0" maxOccurs="unbounded"/>
38+
<xs:element type="assertStringNotContainsStringIgnoringCaseType" name="assertStringNotContainsStringIgnoringCase" minOccurs="0" maxOccurs="unbounded"/>
3539
<xs:element type="assertNotEmptyType" name="assertNotEmpty" minOccurs="0" maxOccurs="unbounded"/>
3640
<xs:element type="assertNotEqualsType" name="assertNotEquals" minOccurs="0" maxOccurs="unbounded"/>
3741
<xs:element type="assertNotInstanceOfType" name="assertNotInstanceOf" minOccurs="0" maxOccurs="unbounded"/>
@@ -156,6 +160,34 @@
156160
<xs:attributeGroup ref="commonActionAttributes"/>
157161
</xs:complexType>
158162

163+
<xs:complexType name="assertStringContainsStringType">
164+
<xs:annotation>
165+
<xs:documentation>
166+
Asserts that given string contains a value.
167+
</xs:documentation>
168+
</xs:annotation>
169+
<xs:choice maxOccurs="unbounded">
170+
<xs:element name="expectedResult" type="expectedResultType" minOccurs="0"/>
171+
<xs:element name="actualResult" type="actualResultType" minOccurs="0"/>
172+
</xs:choice>
173+
<xs:attribute ref="message"/>
174+
<xs:attributeGroup ref="commonActionAttributes"/>
175+
</xs:complexType>
176+
177+
<xs:complexType name="assertStringContainsStringIgnoringCaseType">
178+
<xs:annotation>
179+
<xs:documentation>
180+
Asserts that given string contains a value ignoring case.
181+
</xs:documentation>
182+
</xs:annotation>
183+
<xs:choice maxOccurs="unbounded">
184+
<xs:element name="expectedResult" type="expectedResultType" minOccurs="0"/>
185+
<xs:element name="actualResult" type="actualResultType" minOccurs="0"/>
186+
</xs:choice>
187+
<xs:attribute ref="message"/>
188+
<xs:attributeGroup ref="commonActionAttributes"/>
189+
</xs:complexType>
190+
159191
<xs:complexType name="assertCountType">
160192
<xs:annotation>
161193
<xs:documentation>
@@ -376,6 +408,34 @@
376408
<xs:attributeGroup ref="commonActionAttributes"/>
377409
</xs:complexType>
378410

411+
<xs:complexType name="assertStringNotContainsStringType">
412+
<xs:annotation>
413+
<xs:documentation>
414+
Asserts that given string does not contain a value.
415+
</xs:documentation>
416+
</xs:annotation>
417+
<xs:choice maxOccurs="unbounded">
418+
<xs:element name="expectedResult" type="expectedResultType" minOccurs="0"/>
419+
<xs:element name="actualResult" type="actualResultType" minOccurs="0"/>
420+
</xs:choice>
421+
<xs:attribute ref="message"/>
422+
<xs:attributeGroup ref="commonActionAttributes"/>
423+
</xs:complexType>
424+
425+
<xs:complexType name="assertStringNotContainsStringIgnoringCaseType">
426+
<xs:annotation>
427+
<xs:documentation>
428+
Asserts that given string does not contain a value ignoring case.
429+
</xs:documentation>
430+
</xs:annotation>
431+
<xs:choice maxOccurs="unbounded">
432+
<xs:element name="expectedResult" type="expectedResultType" minOccurs="0"/>
433+
<xs:element name="actualResult" type="actualResultType" minOccurs="0"/>
434+
</xs:choice>
435+
<xs:attribute ref="message"/>
436+
<xs:attributeGroup ref="commonActionAttributes"/>
437+
</xs:complexType>
438+
379439
<xs:complexType name="assertNotEmptyType">
380440
<xs:annotation>
381441
<xs:documentation>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+4
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,10 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12941294
case "assertCount":
12951295
case "assertContains":
12961296
case "assertNotContains":
1297+
case "assertStringContainsString":
1298+
case "assertStringContainsStringIgnoringCase":
1299+
case "assertStringNotContainsString":
1300+
case "assertStringNotContainsStringIgnoringCase":
12971301
case "expectException":
12981302
$testSteps .= $this->wrapFunctionCall(
12991303
$actor,

0 commit comments

Comments
 (0)