1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?php
/*
* The MIT License
*
* @author Brian Dayhoff <mopsyd@me.com>
* @copyright (c) 2017, Brian Dayhoff <mopsyd@me.com> all rights reserved.
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace oroboros\tests\psr\psr7;
use \PHPUnit\Framework\TestCase;
//add the initialization file
$init = realpath( __DIR__ . '/../../../../init.php' );
if ( $init && !in_array( $init, get_included_files() ) )
{
require_once $init;
}
unset( $init );
/**
* <Psr7 Uploaded File Test Cases>
* These tests prove the stable compliance of Psr-7 uris.
* @covers psr7/uri
*/
final class UploadedFileTest
extends TestCase
{
const CONCRETE_CLASS = '\\oroboros\\core\\libraries\\file\\FileUpload';
/**
* <Accept Cases>
* These should always assert true.
*/
/**
* This SHOULD assert true.
* @group request
* @covers \oroboros\core\libraries\file\FileUpload
* @covers \oroboros\core\abstracts\libraries\file\AbstractFileUpload
* @covers \oroboros\core\traits\libraries\file\UploadedFileTrait
* @covers \oroboros\core\interfaces\contract\libraries\file\UploadedFileContract
*/
public function testFileValid()
{
$class = $this::CONCRETE_CLASS;
$file = $this->_getDefaultObject();
$this->assertTrue( $file instanceof $class );
$this->assertTrue( $file instanceof \Psr\Http\Message\UploadedFileInterface );
// $this->assertTrue( $file->getClientFilename() === null ); //can't test this from the command line :(
$this->assertTrue( $file->getClientMediaType() === 'text/plain' );
$this->assertTrue( $file->getError() === 0 );
// $this->assertTrue( $file->getSize() === 20 ); //this returns (bool) true on the command line
$stream = $file->getStream();
$this->assertTrue( $stream instanceof \Psr\Http\Message\StreamInterface );
$this->assertTrue( (string) $stream === 'Test stream content.' );
var_dump((string) $stream);
}
/**
* This SHOULD assert true.
* @group request
* @covers \oroboros\core\libraries\uri\Uri
* @covers \oroboros\core\abstracts\libraries\uri\AbstractUri
* @covers \oroboros\core\traits\libraries\uri\UriTrait
* @covers \oroboros\core\interfaces\contract\libraries\uri\UriContract
*/
public function testUriValid()
{
$files = $this->_getDefaultObject();
// $this->assertTrue( $uri instanceof $class );
// $this->assertTrue( $uri instanceof \Psr\Http\Message\UriInterface );
$this->assertTrue( true );
}
/**
* Fetches the default test object
* @return \oroboros\core\libraries\file\FileUpload
*/
protected function _getDefaultObject()
{
$class = $this::CONCRETE_CLASS;
return new $class(
array(
'name' => 'streamfile.txt',
'type' => 'text/plain',
'tmp_name' => __DIR__ . '/streamfile.txt',
'error' => 0,
'size' => 20
)
);
}
}