nulib/php/tests/web/uploadsTest.php

201 lines
3.6 KiB
PHP

<?php
namespace nulib\web;
use PHPUnit\Framework\TestCase;
class uploadsTest extends TestCase {
const _FILES = [
# name="simple"
'simple' => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
# name=multiple[], name=multiple[]
'multiple' => [
'name' => [
0 => '',
1 => '',
],
'type' => [
0 => '',
1 => '',
],
'tmp_name' => [
0 => '',
1 => '',
],
'error' => [
0 => 4,
1 => 4,
],
'size' => [
0 => 0,
1 => 0,
],
],
# name=onelevel[a], name=onelevel[b]
'onelevel' => [
'name' => [
'a' => '',
'b' => '',
],
'type' => [
'a' => '',
'b' => '',
],
'tmp_name' => [
'a' => '',
'b' => '',
],
'error' => [
'a' => 4,
'b' => 4,
],
'size' => [
'a' => 0,
'b' => 0,
],
],
# name=multiplelevel[a][], name=multiplelevel[a][], name=multiplelevel[b][], name=multiplelevel[b][]
'multiplelevel' => [
'name' => [
'a' => [
0 => '',
1 => '',
],
'b' => [
0 => '',
1 => '',
],
],
'type' => [
'a' => [
0 => '',
1 => '',
],
'b' => [
0 => '',
1 => '',
],
],
'tmp_name' => [
'a' => [
0 => '',
1 => '',
],
'b' => [
0 => '',
1 => '',
],
],
'error' => [
'a' => [
0 => 4,
1 => 4,
],
'b' => [
0 => 4,
1 => 4,
],
],
'size' => [
'a' => [
0 => 0,
1 => 0,
],
'b' => [
0 => 0,
1 => 0,
],
],
],
];
const PARSED = [
# name="simple"
'simple' => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
# name=multiple[], name=multiple[]
'multiple' => [
0 => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
1 => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
],
# name=onelevel[a], name=onelevel[b]
'onelevel' => [
'a' => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
'b' => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
],
# name=multiplelevel[a][], name=multiplelevel[a][], name=multiplelevel[b][], name=multiplelevel[b][]
'multiplelevel' => [
'a' => [
0 => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
1 => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
],
'b' => [
0 => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
1 => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
],
],
],
];
function test_files() {
self::assertSame(self::PARSED, uploads::_files(self::_FILES));
}
}