public function testMoveUploadedFileDuplicates() { $app = $this->getApp(); $this->getExtension($app)->config['uploads']['base_directory'] = sys_get_temp_dir(); $this->getExtension($app)->config['uploads']['filename_handling'] = 'keep'; $this->getExtension($app)->config['testing_form']['uploads']['subdirectory'] = 'testing_form'; $srcFile = EXTENSION_TEST_ROOT . '/tests/data/bolt-logo.png'; $tmpFile = sys_get_temp_dir() . '/' . uniqid('php_'); $tmpDir = sys_get_temp_dir() . '/testing_form'; $fs = new Filesystem(); if ($fs->exists($tmpDir)) { $fs->remove($tmpDir); } $fs->copy($srcFile, $tmpFile, true); $fileUpload = new UploadedFile($tmpFile, 'bolt-logo.png', null, null, null, true); $upload = new FileUpload($app, 'testing_form', $fileUpload); $upload->move(); $fs->copy($srcFile, $tmpFile, true); $fileUpload = new UploadedFile($tmpFile, 'bolt-logo.png', null, null, null, true); $upload = new FileUpload($app, 'testing_form', $fileUpload); $upload->move(); $this->assertFileExists($upload->fullPath()); $this->assertSame(basename($upload->fullPath()), 'bolt-logo(1).png'); }
public function testUnwritableDirectoryException() { $app = $this->getApp(); $this->getExtension()->config['uploads']['base_directory'] = '/proc'; $tmpFile = tempnam(sys_get_temp_dir(), 'koala'); $e = new FileException(); $fileUpload = $this->getMock('Symfony\\Component\\HttpFoundation\\File\\UploadedFile', array('move'), array($tmpFile, 'bolt-logo.png', null, null, UPLOAD_ERR_OK, true)); $fileUpload->method('move')->will($this->throwException($e)); $this->setExpectedException('\\Bolt\\Extension\\Bolt\\BoltForms\\Exception\\FileUploadException'); // Keep an eye on the logger $logger = $this->getMock('\\Monolog\\Logger', array('error', 'debug'), array('testlogger')); $logger->expects($this->atLeastOnce())->method('error'); $app['logger.system'] = $logger; $upload = new FileUpload($app, 'testing_form', $fileUpload); $upload->move(); }