Skip to content

Commit 46bd72f

Browse files
committed
Refactor unit tests
1 parent 74ce7e7 commit 46bd72f

File tree

102 files changed

+1636
-787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1636
-787
lines changed

src/Type/AbstractValueType.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace SimpleSAML\XML\Type;
66

7+
use function preg_replace;
8+
use function trim;
9+
710
/**
811
* Abstract class to be implemented by all types
912
*
@@ -69,7 +72,7 @@ protected function sanitizeValue(string $value): string
6972
* @throws \Exception on failure
7073
* @return void
7174
*/
72-
protected function validateValue(/** @scrutinizer ignore-unused */ string $value): void
75+
protected function validateValue(/** @scrutinizer-ignore */string $value): void
7376
{
7477
/**
7578
* Perform no validation by default.
@@ -78,6 +81,28 @@ protected function validateValue(/** @scrutinizer ignore-unused */ string $value
7881
}
7982

8083

84+
/**
85+
* Normalize whitespace in the value
86+
*
87+
* @return string
88+
*/
89+
protected static function normalizeWhitespace(string $value): string
90+
{
91+
return preg_replace('/\s/', ' ', $value);
92+
}
93+
94+
95+
/**
96+
* Collapse whitespace
97+
*
98+
* @return string
99+
*/
100+
protected static function collapseWhitespace(string $value): string
101+
{
102+
return trim(preg_replace('/\s+/', ' ', $value));
103+
}
104+
105+
81106
/**
82107
* @param string $value
83108
* @return static

src/Type/AnyURIValue.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
*/
1313
class AnyURIValue extends AbstractValueType
1414
{
15+
/**
16+
* Sanitize the value.
17+
*
18+
* @param string $value The unsanitized value
19+
* @return string
20+
*/
21+
protected function sanitizeValue(string $value): string
22+
{
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
24+
}
25+
26+
1527
/**
1628
* Validate the value.
1729
*

src/Type/Base64BinaryValue.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use SimpleSAML\XML\Assert\Assert;
88
use SimpleSAML\XML\Exception\SchemaViolationException;
99

10-
use function str_replace;
11-
1210
/**
1311
* @package simplesaml/xml-common
1412
*/
@@ -17,14 +15,12 @@ class Base64BinaryValue extends AbstractValueType
1715
/**
1816
* Sanitize the value.
1917
*
20-
* Note: There are no processing rules for xs:base64 regarding whitespace. General consensus is to strip them
21-
*
2218
* @param string $value The unsanitized value
2319
* @return string
2420
*/
2521
protected function sanitizeValue(string $value): string
2622
{
27-
return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value);
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
2824
}
2925

3026

src/Type/BooleanValue.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use SimpleSAML\XML\Assert\Assert;
88
use SimpleSAML\XML\Exception\SchemaViolationException;
99

10-
use function str_replace;
11-
1210
/**
1311
* @package simplesaml/xml-common
1412
*/
@@ -22,7 +20,7 @@ class BooleanValue extends AbstractValueType
2220
*/
2321
protected function sanitizeValue(string $value): string
2422
{
25-
return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value);
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
2624
}
2725

2826

src/Type/DateTimeValue.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
use SimpleSAML\XML\Assert\Assert;
99
use SimpleSAML\XML\Exception\SchemaViolationException;
1010

11-
use function preg_replace;
12-
use function trim;
13-
1411
/**
1512
* @package simplesaml/xml-common
1613
*/
@@ -27,7 +24,7 @@ class DateTimeValue extends AbstractValueType
2724
*/
2825
protected function sanitizeValue(string $value): string
2926
{
30-
return trim(preg_replace('/\s+/', ' ', $value));
27+
return static::collapseWhitespace(static::normalizeWhitespace($value));
3128
}
3229

3330

src/Type/DateValue.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use SimpleSAML\XML\Assert\Assert;
88
use SimpleSAML\XML\Exception\SchemaViolationException;
99

10-
use function preg_replace;
11-
use function trim;
12-
1310
/**
1411
* @package simplesaml/xml-common
1512
*/
@@ -23,7 +20,7 @@ class DateValue extends AbstractValueType
2320
*/
2421
protected function sanitizeValue(string $value): string
2522
{
26-
return trim(preg_replace('/\s+/', ' ', $value));
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
2724
}
2825

2926

src/Type/DayValue.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use SimpleSAML\XML\Assert\Assert;
88
use SimpleSAML\XML\Exception\SchemaViolationException;
99

10-
use function preg_replace;
11-
use function trim;
12-
1310
/**
1411
* @package simplesaml/xml-common
1512
*/
@@ -23,7 +20,7 @@ class DayValue extends AbstractValueType
2320
*/
2421
protected function sanitizeValue(string $value): string
2522
{
26-
return trim(preg_replace('/\s+/', ' ', $value));
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
2724
}
2825

2926

src/Type/DecimalValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DecimalValue extends AbstractValueType
2020
*/
2121
protected function sanitizeValue(string $value): string
2222
{
23-
return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value);
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
2424
}
2525

2626

src/Type/DoubleValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DoubleValue extends AbstractValueType
2020
*/
2121
protected function sanitizeValue(string $value): string
2222
{
23-
return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value);
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
2424
}
2525

2626

src/Type/DurationValue.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use SimpleSAML\XML\Assert\Assert;
88
use SimpleSAML\XML\Exception\SchemaViolationException;
99

10-
use function preg_replace;
11-
use function trim;
12-
1310
/**
1411
* @package simplesaml/xml-common
1512
*/
@@ -23,7 +20,7 @@ class DurationValue extends AbstractValueType
2320
*/
2421
protected function sanitizeValue(string $value): string
2522
{
26-
return trim(preg_replace('/\s+/', ' ', $value));
23+
return static::collapseWhitespace(static::normalizeWhitespace($value));
2724
}
2825

2926

0 commit comments

Comments
 (0)