function BytesTest::providerTestValidate

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Component/Utility/BytesTest.php \Drupal\Tests\Component\Utility\BytesTest::providerTestValidate()
  2. 11.x core/tests/Drupal/Tests/Component/Utility/BytesTest.php \Drupal\Tests\Component\Utility\BytesTest::providerTestValidate()

Provides data for testValidate().

Return value

array An array of arrays, each containing the argument for \Drupal\Component\Utility\Bytes::validate(): string, and the expected return value with the expected type (bool).

File

core/tests/Drupal/Tests/Component/Utility/BytesTest.php, line 119

Class

BytesTest
Tests bytes size parsing helper methods.

Namespace

Drupal\Tests\Component\Utility

Code

public function providerTestValidate() : array {
    return [
        // String not starting with a number.
[
            'foo',
            FALSE,
        ],
        [
            'fifty megabytes',
            FALSE,
        ],
        [
            'five',
            FALSE,
        ],
        // Test spaces and capital combinations.
[
            5,
            TRUE,
        ],
        [
            '5M',
            TRUE,
        ],
        [
            '5m',
            TRUE,
        ],
        [
            '5 M',
            TRUE,
        ],
        [
            '5 m',
            TRUE,
        ],
        [
            '5Mb',
            TRUE,
        ],
        [
            '5mb',
            TRUE,
        ],
        [
            '5 Mb',
            TRUE,
        ],
        [
            '5 mb',
            TRUE,
        ],
        [
            '5Gb',
            TRUE,
        ],
        [
            '5gb',
            TRUE,
        ],
        [
            '5 Gb',
            TRUE,
        ],
        [
            '5 gb',
            TRUE,
        ],
        // Test all allowed suffixes.
[
            '5',
            TRUE,
        ],
        [
            '5 b',
            TRUE,
        ],
        [
            '5 byte',
            TRUE,
        ],
        [
            '5 bytes',
            TRUE,
        ],
        [
            '5 k',
            TRUE,
        ],
        [
            '5 kb',
            TRUE,
        ],
        [
            '5 kilobyte',
            TRUE,
        ],
        [
            '5 kilobytes',
            TRUE,
        ],
        [
            '5 m',
            TRUE,
        ],
        [
            '5 mb',
            TRUE,
        ],
        [
            '5 megabyte',
            TRUE,
        ],
        [
            '5 megabytes',
            TRUE,
        ],
        [
            '5 g',
            TRUE,
        ],
        [
            '5 gb',
            TRUE,
        ],
        [
            '5 gigabyte',
            TRUE,
        ],
        [
            '5 gigabytes',
            TRUE,
        ],
        [
            '5 t',
            TRUE,
        ],
        [
            '5 tb',
            TRUE,
        ],
        [
            '5 terabyte',
            TRUE,
        ],
        [
            '5 terabytes',
            TRUE,
        ],
        [
            '5 p',
            TRUE,
        ],
        [
            '5 pb',
            TRUE,
        ],
        [
            '5 petabyte',
            TRUE,
        ],
        [
            '5 petabytes',
            TRUE,
        ],
        [
            '5 e',
            TRUE,
        ],
        [
            '5 eb',
            TRUE,
        ],
        [
            '5 exabyte',
            TRUE,
        ],
        [
            '5 exabytes',
            TRUE,
        ],
        [
            '5 z',
            TRUE,
        ],
        [
            '5 zb',
            TRUE,
        ],
        [
            '5 zettabyte',
            TRUE,
        ],
        [
            '5 zettabytes',
            TRUE,
        ],
        [
            '5 y',
            TRUE,
        ],
        [
            '5 yb',
            TRUE,
        ],
        [
            '5 yottabyte',
            TRUE,
        ],
        [
            '5 yottabytes',
            TRUE,
        ],
        // Test with decimal.
[
            5.1,
            TRUE,
        ],
        [
            '5.1M',
            TRUE,
        ],
        [
            '5.1mb',
            TRUE,
        ],
        [
            '5.1 M',
            TRUE,
        ],
        [
            '5.1 Mb',
            TRUE,
        ],
        [
            '5.1 megabytes',
            TRUE,
        ],
        // Test with an unauthorized string.
[
            '1five',
            FALSE,
        ],
        [
            '1 1 byte',
            FALSE,
        ],
        [
            '1,1 byte',
            FALSE,
        ],
        // Test with leading and trailing spaces.
[
            ' 5.1mb',
            FALSE,
        ],
        [
            '5.1mb ',
            TRUE,
        ],
        [
            ' 5.1mb ',
            FALSE,
        ],
        [
            ' 5.1 megabytes',
            FALSE,
        ],
        [
            '5.1 megabytes ',
            TRUE,
        ],
        [
            ' 5.1 megabytes ',
            FALSE,
        ],
        [
            '300 0',
            FALSE,
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.