You are here

public function FustyRequestTest::testFustyRequest_ValidateUpload in One Click Upload 7.2

File

flowphp/test/Unit/FustyRequestTest.php, line 75

Class

FustyRequestTest
FustyRequest unit tests

Namespace

Unit

Code

public function testFustyRequest_ValidateUpload() {

  //// Setup test
  $firstChunk = vfsStream::newFile('temp_file');
  $firstChunk
    ->setContent('1234567890');
  $this->vfs
    ->addChild($firstChunk);
  $fileInfo = new \ArrayObject(array(
    'size' => 10,
    'error' => UPLOAD_ERR_OK,
    'tmp_name' => $firstChunk
      ->url(),
  ));
  $request = new \ArrayObject(array(
    'flowIdentifier' => '13632-prettifyjs',
    'flowFilename' => 'prettify.js',
    'flowRelativePath' => 'home/prettify.js',
  ));
  $fustyRequest = new FustyRequest($request, $fileInfo);
  $config = new Config();
  $config
    ->setTempDir($this->vfs
    ->url());

  /** @var File $file */
  $file = $this
    ->getMock('Flow\\File', array(
    '_move_uploaded_file',
  ), array(
    $config,
    $fustyRequest,
  ));

  /** @noinspection PhpUndefinedMethodInspection */
  $file
    ->expects($this
    ->once())
    ->method('_move_uploaded_file')
    ->will($this
    ->returnCallback(function ($filename, $destination) {
    return rename($filename, $destination);
  }));

  //// Actual test
  $this
    ->assertTrue($file
    ->validateChunk());
  $this
    ->assertFalse($file
    ->validateFile());
  $this
    ->assertTrue($file
    ->saveChunk());
  $this
    ->assertTrue($file
    ->validateFile());
  $path = $this->vfs
    ->url() . DIRECTORY_SEPARATOR . 'new';
  $this
    ->assertTrue($file
    ->save($path));
  $this
    ->assertEquals(10, filesize($path));
}