| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833 |
- <?php
- declare(strict_types=1);
- /**
- * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link https://cakephp.org CakePHP(tm) Project
- * @since 3.3.0
- * @license https://opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Http;
- use Cake\Core\Configure;
- use Cake\Http\ServerRequestFactory;
- use Cake\Http\Session;
- use Cake\TestSuite\TestCase;
- use Laminas\Diactoros\Exception\InvalidArgumentException;
- use Laminas\Diactoros\UploadedFile;
- use Psr\Http\Message\UploadedFileInterface;
- /**
- * Test case for the server factory.
- */
- class ServerRequestFactoryTest extends TestCase
- {
- /**
- * @var array|null
- */
- protected $server;
- /**
- * @var array|null
- */
- protected $post;
- /**
- * @var array|null
- */
- protected $files;
- /**
- * @var array|null
- */
- protected $cookies;
- /**
- * @var array|null
- */
- protected $get;
- /**
- * setup
- *
- * @return void
- */
- public function setUp(): void
- {
- parent::setUp();
- $this->server = $_SERVER;
- $this->post = $_POST;
- $this->files = $_FILES;
- $this->cookies = $_COOKIE;
- $this->get = $_GET;
- }
- /**
- * teardown
- *
- * @return void
- */
- public function tearDown(): void
- {
- parent::tearDown();
- $_SERVER = $this->server;
- $_POST = $this->post;
- $_FILES = $this->files;
- $_COOKIE = $this->cookies;
- $_GET = $this->get;
- }
- /**
- * Test fromGlobals reads super globals
- *
- * @return void
- */
- public function testFromGlobalsSuperGlobals()
- {
- $_POST = [
- 'title' => 'custom',
- ];
- $_FILES = [
- 'image' => [
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'name' => 'cats.png',
- 'type' => 'image/png',
- 'size' => 2112,
- ],
- ];
- $_COOKIE = ['key' => 'value'];
- $_GET = ['query' => 'string'];
- $res = ServerRequestFactory::fromGlobals();
- $this->assertSame($_COOKIE['key'], $res->getCookie('key'));
- $this->assertSame($_GET['query'], $res->getQuery('query'));
- $this->assertArrayHasKey('title', $res->getData());
- $this->assertArrayHasKey('image', $res->getData());
- $this->assertCount(1, $res->getUploadedFiles());
- /** @var \Laminas\Diactoros\UploadedFile $expected */
- $expected = $res->getData('image');
- $this->assertInstanceOf(UploadedFileInterface::class, $expected);
- $this->assertSame($_FILES['image']['size'], $expected->getSize());
- $this->assertSame($_FILES['image']['error'], $expected->getError());
- $this->assertSame($_FILES['image']['name'], $expected->getClientFilename());
- $this->assertSame($_FILES['image']['type'], $expected->getClientMediaType());
- }
- /**
- * Test fromGlobals includes the session
- *
- * @preserveGlobalState disabled
- * @runInSeparateProcess
- * @return void
- */
- public function testFromGlobalsUrlSession()
- {
- Configure::write('App.base', '/basedir');
- $server = [
- 'DOCUMENT_ROOT' => '/cake/repo/branches/1.2.x.x/webroot',
- 'PHP_SELF' => '/index.php',
- 'REQUEST_URI' => '/posts/add',
- ];
- $res = ServerRequestFactory::fromGlobals($server);
- $session = $res->getAttribute('session');
- $this->assertInstanceOf(Session::class, $session);
- $this->assertSame('/basedir/', ini_get('session.cookie_path'), 'Needs trailing / for cookie to work');
- }
- /**
- * Test fromGlobals with App.base defined.
- *
- * @return void
- */
- public function testFromGlobalsUrlBaseDefined()
- {
- Configure::write('App.base', 'basedir');
- $server = [
- 'DOCUMENT_ROOT' => '/cake/repo/branches/1.2.x.x/webroot',
- 'PHP_SELF' => '/index.php',
- 'REQUEST_URI' => '/posts/add',
- ];
- $res = ServerRequestFactory::fromGlobals($server);
- $this->assertSame('basedir', $res->getAttribute('base'));
- $this->assertSame('basedir/', $res->getAttribute('webroot'));
- $this->assertSame('/posts/add', $res->getUri()->getPath());
- }
- /**
- * Test fromGlobals with mod-rewrite server configuration.
- *
- * @return void
- */
- public function testFromGlobalsUrlModRewrite()
- {
- Configure::write('App.baseUrl', false);
- $server = [
- 'DOCUMENT_ROOT' => '/cake/repo/branches',
- 'PHP_SELF' => '/urlencode me/webroot/index.php',
- 'REQUEST_URI' => '/posts/view/1',
- ];
- $res = ServerRequestFactory::fromGlobals($server);
- $this->assertSame('/urlencode%20me', $res->getAttribute('base'));
- $this->assertSame('/urlencode%20me/', $res->getAttribute('webroot'));
- $this->assertSame('/posts/view/1', $res->getUri()->getPath());
- }
- /**
- * Test fromGlobals with mod-rewrite in the root dir.
- *
- * @return void
- */
- public function testFromGlobalsUrlModRewriteRootDir()
- {
- $server = [
- 'DOCUMENT_ROOT' => '/cake/repo/branches/1.2.x.x/webroot',
- 'PHP_SELF' => '/index.php',
- 'REQUEST_URI' => '/posts/add',
- ];
- $res = ServerRequestFactory::fromGlobals($server);
- $this->assertSame('', $res->getAttribute('base'));
- $this->assertSame('/', $res->getAttribute('webroot'));
- $this->assertSame('/posts/add', $res->getUri()->getPath());
- }
- /**
- * Test fromGlobals with App.baseUrl defined implying no
- * mod-rewrite and no virtual path.
- *
- * @return void
- */
- public function testFromGlobalsUrlNoModRewriteWebrootDir()
- {
- Configure::write('App', [
- 'dir' => 'app',
- 'webroot' => 'www',
- 'base' => false,
- 'baseUrl' => '/cake/index.php',
- ]);
- $server = [
- 'DOCUMENT_ROOT' => '/Users/markstory/Sites',
- 'SCRIPT_FILENAME' => '/Users/markstory/Sites/cake/www/index.php',
- 'PHP_SELF' => '/cake/www/index.php/posts/index',
- 'REQUEST_URI' => '/cake/www/index.php',
- ];
- $res = ServerRequestFactory::fromGlobals($server);
- $this->assertSame('/cake/www/', $res->getAttribute('webroot'));
- $this->assertSame('/cake/index.php', $res->getAttribute('base'));
- $this->assertSame('/', $res->getUri()->getPath());
- }
- /**
- * Test fromGlobals with App.baseUrl defined implying no
- * mod-rewrite
- *
- * @return void
- */
- public function testFromGlobalsUrlNoModRewrite()
- {
- Configure::write('App', [
- 'dir' => 'app',
- 'webroot' => 'webroot',
- 'base' => false,
- 'baseUrl' => '/cake/index.php',
- ]);
- $server = [
- 'DOCUMENT_ROOT' => '/Users/markstory/Sites',
- 'SCRIPT_FILENAME' => '/Users/markstory/Sites/cake/index.php',
- 'PHP_SELF' => '/cake/index.php/posts/index',
- 'REQUEST_URI' => '/cake/index.php/posts/index',
- ];
- $res = ServerRequestFactory::fromGlobals($server);
- $this->assertSame('/cake/webroot/', $res->getAttribute('webroot'));
- $this->assertSame('/cake/index.php', $res->getAttribute('base'));
- $this->assertSame('/posts/index', $res->getUri()->getPath());
- }
- /**
- * Test fromGlobals with App.baseUrl defined implying no
- * mod-rewrite in the root dir.
- *
- * @return void
- */
- public function testFromGlobalsUrlNoModRewriteRootDir()
- {
- Configure::write('App', [
- 'dir' => 'cake',
- 'webroot' => 'webroot',
- 'base' => false,
- 'baseUrl' => '/index.php',
- ]);
- $server = [
- 'DOCUMENT_ROOT' => '/Users/markstory/Sites/cake',
- 'SCRIPT_FILENAME' => '/Users/markstory/Sites/cake/index.php',
- 'PHP_SELF' => '/index.php/posts/add',
- 'REQUEST_URI' => '/index.php/posts/add',
- ];
- $res = ServerRequestFactory::fromGlobals($server);
- $this->assertSame('/webroot/', $res->getAttribute('webroot'));
- $this->assertSame('/index.php', $res->getAttribute('base'));
- $this->assertSame('/posts/add', $res->getUri()->getPath());
- }
- /**
- * @return void
- */
- public function testFormUrlEncodedBodyParsing()
- {
- $data = [
- 'Article' => ['title'],
- ];
- $request = ServerRequestFactory::fromGlobals([
- 'REQUEST_METHOD' => 'PUT',
- 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=UTF-8',
- 'CAKE_PHP_INPUT' => 'Article[]=title',
- ]);
- $this->assertEquals($data, $request->getData());
- $data = ['one' => 1, 'two' => 'three'];
- $request = ServerRequestFactory::fromGlobals([
- 'REQUEST_METHOD' => 'PUT',
- 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=UTF-8',
- 'CAKE_PHP_INPUT' => 'one=1&two=three',
- ]);
- $this->assertEquals($data, $request->getData());
- $request = ServerRequestFactory::fromGlobals([
- 'REQUEST_METHOD' => 'DELETE',
- 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=UTF-8',
- 'CAKE_PHP_INPUT' => 'Article[title]=Testing&action=update',
- ]);
- $expected = [
- 'Article' => ['title' => 'Testing'],
- 'action' => 'update',
- ];
- $this->assertEquals($expected, $request->getData());
- $data = [
- 'Article' => ['title'],
- 'Tag' => ['Tag' => [1, 2]],
- ];
- $request = ServerRequestFactory::fromGlobals([
- 'REQUEST_METHOD' => 'PATCH',
- 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=UTF-8',
- 'CAKE_PHP_INPUT' => 'Article[]=title&Tag[Tag][]=1&Tag[Tag][]=2',
- ]);
- $this->assertEquals($data, $request->getData());
- }
- /**
- * Test method overrides coming in from POST data.
- *
- * @return void
- */
- public function testMethodOverrides()
- {
- $post = ['_method' => 'POST'];
- $request = ServerRequestFactory::fromGlobals([], [], $post);
- $this->assertSame('POST', $request->getEnv('REQUEST_METHOD'));
- $post = ['_method' => 'DELETE'];
- $request = ServerRequestFactory::fromGlobals([], [], $post);
- $this->assertSame('DELETE', $request->getEnv('REQUEST_METHOD'));
- $request = ServerRequestFactory::fromGlobals(['HTTP_X_HTTP_METHOD_OVERRIDE' => 'PUT']);
- $this->assertSame('PUT', $request->getEnv('REQUEST_METHOD'));
- $request = ServerRequestFactory::fromGlobals(
- ['REQUEST_METHOD' => 'POST'],
- [],
- ['_method' => 'PUT']
- );
- $this->assertSame('PUT', $request->getEnv('REQUEST_METHOD'));
- $this->assertSame('POST', $request->getEnv('ORIGINAL_REQUEST_METHOD'));
- }
- /**
- * Test getServerParams
- *
- * @return void
- */
- public function testGetServerParams()
- {
- $vars = [
- 'REQUEST_METHOD' => 'PUT',
- 'HTTPS' => 'on',
- ];
- $request = ServerRequestFactory::fromGlobals($vars);
- $expected = $vars + [
- 'CONTENT_TYPE' => null,
- 'HTTP_CONTENT_TYPE' => null,
- 'ORIGINAL_REQUEST_METHOD' => 'PUT',
- ];
- $this->assertSame($expected, $request->getServerParams());
- }
- /**
- * Tests that overriding the method to GET will clean all request
- * data, to better simulate a GET request.
- *
- * @return void
- */
- public function testMethodOverrideEmptyParsedBody()
- {
- $body = ['_method' => 'GET', 'foo' => 'bar'];
- $request = ServerRequestFactory::fromGlobals(
- ['REQUEST_METHOD' => 'POST'],
- [],
- $body
- );
- $this->assertEmpty($request->getParsedBody());
- $request = ServerRequestFactory::fromGlobals(
- [
- 'REQUEST_METHOD' => 'POST',
- 'HTTP_X_HTTP_METHOD_OVERRIDE' => 'GET',
- ],
- [],
- ['foo' => 'bar']
- );
- $this->assertEmpty($request->getParsedBody());
- }
- /**
- * Tests the default file upload merging behavior.
- *
- * @return void
- */
- public function testFromGlobalsWithFilesAsObjectsDefault()
- {
- $this->assertNull(Configure::read('App.uploadedFilesAsObjects'));
- $files = [
- 'file' => [
- 'name' => 'file.txt',
- 'type' => 'text/plain',
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'size' => 1234,
- ],
- ];
- $request = ServerRequestFactory::fromGlobals(null, null, null, null, $files);
- /** @var \Laminas\Diactoros\UploadedFile $expected */
- $expected = $request->getData('file');
- $this->assertSame($files['file']['size'], $expected->getSize());
- $this->assertSame($files['file']['error'], $expected->getError());
- $this->assertSame($files['file']['name'], $expected->getClientFilename());
- $this->assertSame($files['file']['type'], $expected->getClientMediaType());
- }
- /**
- * Tests the "as arrays" file upload merging behavior.
- *
- * @return void
- */
- public function testFromGlobalsWithFilesAsObjectsDisabled()
- {
- Configure::write('App.uploadedFilesAsObjects', false);
- $files = [
- 'file' => [
- 'name' => 'file.txt',
- 'type' => 'text/plain',
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'size' => 1234,
- ],
- ];
- $request = ServerRequestFactory::fromGlobals(null, null, null, null, $files);
- $expected = [
- 'file' => [
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'name' => 'file.txt',
- 'type' => 'text/plain',
- 'size' => 1234,
- ],
- ];
- $this->assertEquals($expected, $request->getData());
- }
- /**
- * Tests the "as objects" file upload merging behavior.
- *
- * @return void
- */
- public function testFromGlobalsWithFilesAsObjectsEnabled()
- {
- Configure::write('App.uploadedFilesAsObjects', true);
- $files = [
- 'file' => [
- 'name' => 'file.txt',
- 'type' => 'text/plain',
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'size' => 1234,
- ],
- ];
- $request = ServerRequestFactory::fromGlobals(null, null, null, null, $files);
- $expected = [
- 'file' => new UploadedFile(
- __FILE__,
- 1234,
- 0,
- 'file.txt',
- 'text/plain'
- ),
- ];
- $this->assertEquals($expected, $request->getData());
- }
- /**
- * Test processing files with `file` field names.
- *
- * @return void
- */
- public function testFilesNested()
- {
- $files = [
- 'image_main' => [
- 'name' => ['file' => 'born on.txt'],
- 'type' => ['file' => 'text/plain'],
- 'tmp_name' => ['file' => __FILE__],
- 'error' => ['file' => 0],
- 'size' => ['file' => 17178],
- ],
- 0 => [
- 'name' => ['image' => 'scratch.text'],
- 'type' => ['image' => 'text/plain'],
- 'tmp_name' => ['image' => __FILE__],
- 'error' => ['image' => 0],
- 'size' => ['image' => 1490],
- ],
- 'pictures' => [
- 'name' => [
- 0 => ['file' => 'a-file.png'],
- 1 => ['file' => 'a-moose.png'],
- ],
- 'type' => [
- 0 => ['file' => 'image/png'],
- 1 => ['file' => 'image/jpg'],
- ],
- 'tmp_name' => [
- 0 => ['file' => __FILE__],
- 1 => ['file' => __FILE__],
- ],
- 'error' => [
- 0 => ['file' => 0],
- 1 => ['file' => 0],
- ],
- 'size' => [
- 0 => ['file' => 17188],
- 1 => ['file' => 2010],
- ],
- ],
- ];
- $post = [
- 'pictures' => [
- 0 => ['name' => 'A cat'],
- 1 => ['name' => 'A moose'],
- ],
- 0 => [
- 'name' => 'A dog',
- ],
- ];
- $request = ServerRequestFactory::fromGlobals(null, null, $post, null, $files);
- $expected = [
- 'image_main' => [
- 'file' => new UploadedFile(
- __FILE__,
- 17178,
- 0,
- 'born on.txt',
- 'text/plain'
- ),
- ],
- 'pictures' => [
- 0 => [
- 'name' => 'A cat',
- 'file' => new UploadedFile(
- __FILE__,
- 17188,
- 0,
- 'a-file.png',
- 'image/png'
- ),
- ],
- 1 => [
- 'name' => 'A moose',
- 'file' => new UploadedFile(
- __FILE__,
- 2010,
- 0,
- 'a-moose.png',
- 'image/jpg'
- ),
- ],
- ],
- 0 => [
- 'name' => 'A dog',
- 'image' => new UploadedFile(
- __FILE__,
- 1490,
- 0,
- 'scratch.text',
- 'text/plain'
- ),
- ],
- ];
- $this->assertEquals($expected, $request->getData());
- $uploads = $request->getUploadedFiles();
- $this->assertCount(3, $uploads);
- $this->assertArrayHasKey(0, $uploads);
- $this->assertSame('scratch.text', $uploads[0]['image']->getClientFilename());
- $this->assertArrayHasKey('pictures', $uploads);
- $this->assertSame('a-file.png', $uploads['pictures'][0]['file']->getClientFilename());
- $this->assertSame('a-moose.png', $uploads['pictures'][1]['file']->getClientFilename());
- $this->assertArrayHasKey('image_main', $uploads);
- $this->assertSame('born on.txt', $uploads['image_main']['file']->getClientFilename());
- }
- /**
- * Test processing a file input with no .'s in it.
- *
- * @return void
- */
- public function testFilesFlat()
- {
- $files = [
- 'birth_cert' => [
- 'name' => 'born on.txt',
- 'type' => 'application/octet-stream',
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'size' => 123,
- ],
- ];
- Configure::write('App.uploadedFilesAsObjects', false);
- $request = ServerRequestFactory::fromGlobals([], [], [], [], $files);
- $this->assertEquals($files, $request->getData());
- Configure::write('App.uploadedFilesAsObjects', true);
- $uploads = $request->getUploadedFiles();
- $this->assertCount(1, $uploads);
- $this->assertArrayHasKey('birth_cert', $uploads);
- $this->assertSame('born on.txt', $uploads['birth_cert']->getClientFilename());
- $this->assertSame(0, $uploads['birth_cert']->getError());
- $this->assertSame('application/octet-stream', $uploads['birth_cert']->getClientMediaType());
- $this->assertEquals(123, $uploads['birth_cert']->getSize());
- }
- /**
- * Test that files in the 0th index work.
- *
- * @return void
- */
- public function testFilesZeroithIndex()
- {
- $files = [
- 0 => [
- 'name' => 'cake_sqlserver_patch.patch',
- 'type' => 'text/plain',
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'size' => 6271,
- ],
- ];
- Configure::write('App.uploadedFilesAsObjects', false);
- $request = ServerRequestFactory::fromGlobals([], [], [], [], $files);
- $this->assertEquals($files, $request->getData());
- Configure::write('App.uploadedFilesAsObjects', true);
- $uploads = $request->getUploadedFiles();
- $this->assertCount(1, $uploads);
- $this->assertEquals($files[0]['name'], $uploads[0]->getClientFilename());
- }
- /**
- * Tests that file uploads are merged into the post data as objects instead of as arrays.
- *
- * @return void
- */
- public function testFilesAsObjectsInRequestData()
- {
- $files = [
- 'flat' => [
- 'name' => 'flat.txt',
- 'type' => 'text/plain',
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'size' => 1,
- ],
- 'nested' => [
- 'name' => ['file' => 'nested.txt'],
- 'type' => ['file' => 'text/plain'],
- 'tmp_name' => ['file' => __FILE__],
- 'error' => ['file' => 0],
- 'size' => ['file' => 12],
- ],
- 0 => [
- 'name' => 'numeric.txt',
- 'type' => 'text/plain',
- 'tmp_name' => __FILE__,
- 'error' => 0,
- 'size' => 123,
- ],
- 1 => [
- 'name' => ['file' => 'numeric-nested.txt'],
- 'type' => ['file' => 'text/plain'],
- 'tmp_name' => ['file' => __FILE__],
- 'error' => ['file' => 0],
- 'size' => ['file' => 1234],
- ],
- 'deep' => [
- 'name' => [
- 0 => ['file' => 'deep-1.txt'],
- 1 => ['file' => 'deep-2.txt'],
- ],
- 'type' => [
- 0 => ['file' => 'text/plain'],
- 1 => ['file' => 'text/plain'],
- ],
- 'tmp_name' => [
- 0 => ['file' => __FILE__],
- 1 => ['file' => __FILE__],
- ],
- 'error' => [
- 0 => ['file' => 0],
- 1 => ['file' => 0],
- ],
- 'size' => [
- 0 => ['file' => 12345],
- 1 => ['file' => 123456],
- ],
- ],
- ];
- $post = [
- 'flat' => ['existing'],
- 'nested' => [
- 'name' => 'nested',
- 'file' => ['existing'],
- ],
- 'deep' => [
- 0 => [
- 'name' => 'deep 1',
- 'file' => ['existing'],
- ],
- 1 => [
- 'name' => 'deep 2',
- ],
- ],
- 1 => [
- 'name' => 'numeric nested',
- ],
- ];
- $expected = [
- 'flat' => new UploadedFile(
- __FILE__,
- 1,
- 0,
- 'flat.txt',
- 'text/plain'
- ),
- 'nested' => [
- 'name' => 'nested',
- 'file' => new UploadedFile(
- __FILE__,
- 12,
- 0,
- 'nested.txt',
- 'text/plain'
- ),
- ],
- 'deep' => [
- 0 => [
- 'name' => 'deep 1',
- 'file' => new UploadedFile(
- __FILE__,
- 12345,
- 0,
- 'deep-1.txt',
- 'text/plain'
- ),
- ],
- 1 => [
- 'name' => 'deep 2',
- 'file' => new UploadedFile(
- __FILE__,
- 123456,
- 0,
- 'deep-2.txt',
- 'text/plain'
- ),
- ],
- ],
- 0 => new UploadedFile(
- __FILE__,
- 123,
- 0,
- 'numeric.txt',
- 'text/plain'
- ),
- 1 => [
- 'name' => 'numeric nested',
- 'file' => new UploadedFile(
- __FILE__,
- 1234,
- 0,
- 'numeric-nested.txt',
- 'text/plain'
- ),
- ],
- ];
- $request = ServerRequestFactory::fromGlobals([], [], $post, [], $files);
- $this->assertEquals($expected, $request->getData());
- }
- /**
- * Test passing invalid files list structure.
- *
- * @return void
- */
- public function testFilesWithInvalidStructure()
- {
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage('Invalid value in files specification');
- ServerRequestFactory::fromGlobals([], [], [], [], [
- [
- 'invalid' => [
- 'data',
- ],
- ],
- ]);
- }
- }
|