Skip to content
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

Fix html in descriptions or datasets #1001

Merged
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
1 change: 1 addition & 0 deletions src/Concerns/Testable.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ protected function setUp(): void
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());

$description = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
$description = htmlspecialchars(html_entity_decode($description), ENT_NOQUOTES);

if ($method->repetitions > 1) {
$matches = [];
Expand Down
3 changes: 2 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@
✓ it show the correct description for mixed named and not-named datasets
✓ it shows the correct description for long texts with newlines
✓ it shows the correct description for arrays with many elements
✓ it shows the correct description of datasets with html

PASS Tests\Unit\Expectations\OppositeExpectation
✓ it throw expectation failed exception with string argument
Expand Down Expand Up @@ -1352,4 +1353,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output

Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 962 passed (2280 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 963 passed (2281 assertions)
10 changes: 10 additions & 0 deletions tests/Unit/DatasetsTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@

expect($descriptions[0])->toBe('([1, 2, 3, …])');
});

it('shows the correct description of datasets with html', function () {
$descriptions = array_keys(DatasetsRepository::resolve([
[
'<div class="flex items-center"></div>',
],
], __FILE__));

expect($descriptions[0])->toBe('(\'<div class="flex items-center"></div>\')');
});
4 changes: 2 additions & 2 deletions tests/Unit/TestName.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'卜竹弓一十山' => '__pest_evaluable_卜竹弓一十山',
'アゴデヸ' => '__pest_evaluable_アゴデヸ',
'!p8VrB' => '__pest_evaluable__p8VrB',
'&xe6VeKWF#n4' => '__pest_evaluable__xe6VeKWF_n4',
'&amp;xe6VeKWF#n4' => '__pest_evaluable__amp_xe6VeKWF_n4',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you had to change this?

Copy link
Contributor Author

@faissaloux faissaloux Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because $__latestDescription changes here after changing the description HTML tags to HTML entities.

$this->__description = self::$__latestDescription = $description;

'%%HurHUnw7zM!' => '__pest_evaluable___HurHUnw7zM_',
'rundeliekend' => '__pest_evaluable_rundeliekend',
'g%%c!Jt9$fy#Kf' => '__pest_evaluable_g__c_Jt9_fy_Kf',
Expand All @@ -33,7 +33,7 @@
'Каролин' => '__pest_evaluable_Каролин',
'অ্যান্টার্কটিকা' => '__pest_evaluable_অ্যান্টার্কটিকা',
'Frýdek-Místek"' => '__pest_evaluable_Frýdek_Místek_',
'Allingåbro&' => '__pest_evaluable_Allingåbro_',
'Allingåbro&amp;' => '__pest_evaluable_Allingåbro_amp_',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you had to change this?

'Κεντροαφρικανική Δημοκρατία' => '__pest_evaluable_Κεντροαφρικανική_Δημοκρατία',
'آذربایجان غربی' => '__pest_evaluable_آذربایجان_غربی',
'זימבבואה' => '__pest_evaluable_זימבבואה',
Expand Down
2 changes: 1 addition & 1 deletion tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

test('parallel', function () use ($run) {
expect($run('--exclude-group=integration'))
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 951 passed (2265 assertions)')
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 952 passed (2266 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();

Expand Down