UploadableEntityTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. namespace Gedmo\Uploadable;
  3. use Tool\BaseTestCaseORM,
  4. Doctrine\Common\EventManager,
  5. Doctrine\Common\Util\Debug,
  6. Uploadable\Fixture\Entity\Image,
  7. Uploadable\Fixture\Entity\Article,
  8. Uploadable\Fixture\Entity\File,
  9. Uploadable\Fixture\Entity\FileWithoutPath,
  10. Uploadable\Fixture\Entity\FileWithSha1Name,
  11. Uploadable\Fixture\Entity\FileWithAlphanumericName,
  12. Uploadable\Fixture\Entity\FileWithCustomFilenameGenerator,
  13. Uploadable\Fixture\Entity\FileAppendNumber,
  14. Uploadable\Fixture\Entity\FileWithMaxSize,
  15. Uploadable\Fixture\Entity\FileWithAllowedTypes,
  16. Uploadable\Fixture\Entity\FileWithDisallowedTypes,
  17. Gedmo\Uploadable\Stub\UploadableListenerStub,
  18. Gedmo\Uploadable\Stub\MimeTypeGuesserStub,
  19. Gedmo\Uploadable\FileInfo\FileInfoArray;
  20. /**
  21. * These are tests for Uploadable behavior
  22. *
  23. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  24. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  25. * @package Gedmo.Uploadable
  26. * @link http://www.gediminasm.org
  27. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  28. */
  29. class UploadableEntityTest extends BaseTestCaseORM
  30. {
  31. const IMAGE_CLASS = 'Uploadable\Fixture\Entity\Image';
  32. const ARTICLE_CLASS = 'Uploadable\Fixture\Entity\Article';
  33. const FILE_CLASS = 'Uploadable\Fixture\Entity\File';
  34. const FILE_APPEND_NUMBER_CLASS = 'Uploadable\Fixture\Entity\FileAppendNumber';
  35. const FILE_WITHOUT_PATH_CLASS = 'Uploadable\Fixture\Entity\FileWithoutPath';
  36. const FILE_WITH_SHA1_NAME_CLASS = 'Uploadable\Fixture\Entity\FileWithSha1Name';
  37. const FILE_WITH_ALPHANUMERIC_NAME_CLASS = 'Uploadable\Fixture\Entity\FileWithAlphanumericName';
  38. const FILE_WITH_CUSTOM_FILENAME_GENERATOR_CLASS = 'Uploadable\Fixture\Entity\FileWithCustomFilenameGenerator';
  39. const FILE_WITH_MAX_SIZE_CLASS = 'Uploadable\Fixture\Entity\FileWithMaxSize';
  40. const FILE_WITH_ALLOWED_TYPES_CLASS = 'Uploadable\Fixture\Entity\FileWithAllowedTypes';
  41. const FILE_WITH_DISALLOWED_TYPES_CLASS = 'Uploadable\Fixture\Entity\FileWithDisallowedTypes';
  42. private $listener;
  43. private $testFile;
  44. private $testFile2;
  45. private $testFile3;
  46. private $testFileWithoutExt;
  47. private $destinationTestDir;
  48. private $destinationTestFile;
  49. private $destinationTestFile2;
  50. private $destinationTestFile3;
  51. private $destinationTestFileWithoutExt;
  52. private $testFilename;
  53. private $testFilename2;
  54. private $testFilename3;
  55. private $testFilenameWithoutExt;
  56. private $testFileSize;
  57. private $testFileMimeType;
  58. protected function setUp()
  59. {
  60. parent::setUp();
  61. $evm = new EventManager;
  62. $this->listener = new UploadableListenerStub();
  63. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('text/plain'));
  64. $evm->addEventSubscriber($this->listener);
  65. $config = $this->getMockAnnotatedConfig();
  66. $this->em = $this->getMockSqliteEntityManager($evm, $config);
  67. $this->testFile = __DIR__.'/../../data/test.txt';
  68. $this->testFile2 = __DIR__.'/../../data/test2.txt';
  69. $this->testFile3 = __DIR__.'/../../data/test_3.txt';
  70. $this->testFileWithoutExt = __DIR__.'/../../data/test4';
  71. $this->destinationTestDir = __DIR__.'/../../temp/uploadable';
  72. $this->destinationTestFile = $this->destinationTestDir.'/test.txt';
  73. $this->destinationTestFile2 = $this->destinationTestDir.'/test2.txt';
  74. $this->destinationTestFile3 = $this->destinationTestDir.'/test_3.txt';
  75. $this->destinationTestFileWithoutExt = $this->destinationTestDir.'/test4';
  76. $this->testFilename = substr($this->testFile, strrpos($this->testFile, '/') + 1);
  77. $this->testFilename2 = substr($this->testFile2, strrpos($this->testFile2, '/') + 1);
  78. $this->testFilename3 = substr($this->testFile3, strrpos($this->testFile3, '/') + 1);
  79. $this->testFilenameWithoutExt = substr($this->testFileWithoutExt, strrpos($this->testFileWithoutExt, '/') + 1);
  80. $this->testFileSize = 4;
  81. $this->testFileMimeType = 'text/plain';
  82. $this->clearFilesAndDirectories();
  83. if (!is_dir($this->destinationTestDir)) {
  84. mkdir($this->destinationTestDir);
  85. };
  86. }
  87. public function tearDown()
  88. {
  89. $this->clearFilesAndDirectories();
  90. }
  91. public function testUploadableEntity()
  92. {
  93. // INSERTION of an Uploadable Entity
  94. // If there was no uploaded file, we do nothing
  95. $image = new Image();
  96. $image->setTitle('123');
  97. $this->em->persist($image);
  98. $this->em->flush();
  99. $this->assertNull($image->getFilePath());
  100. // If there is an uploaded file, we process it
  101. $fileInfo = $this->generateUploadedFile();
  102. $image2 = new Image();
  103. $image2->setTitle('456');
  104. $this->listener->addEntityFileInfo($image2, $fileInfo);
  105. $this->em->persist($image2);
  106. $this->em->flush();
  107. $this->em->refresh($image2);
  108. // We need to set this again because of the recent refresh
  109. $firstFile = $image2->getFilePath();
  110. $this->assertPathEquals($image2->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'], $image2->getFilePath());
  111. $this->assertTrue(is_file($firstFile));
  112. $this->assertEquals($fileInfo['size'], $image2->getSize());
  113. $this->assertEquals($fileInfo['type'], $image2->getMime());
  114. // UPDATE of an Uploadable Entity
  115. // We change the "uploaded" file
  116. $fileInfo['tmp_name'] = $this->testFile2;
  117. $fileInfo['name'] = $this->testFilename2;
  118. // We use a FileInfoInterface instance here
  119. $this->listener->addEntityFileInfo($image2, new FileInfoArray($fileInfo));
  120. $this->em->flush();
  121. $this->em->refresh($image2);
  122. $lastFile = $image2->getFilePath();
  123. $this->assertPathEquals($image2->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'], $image2->getFilePath());
  124. $this->assertTrue(is_file($lastFile));
  125. // First file should be removed on update
  126. $this->assertFalse(is_file($firstFile));
  127. // REMOVAL of an Uploadable Entity
  128. $this->em->remove($image2);
  129. $this->em->flush();
  130. $this->assertFalse(is_file($lastFile));
  131. }
  132. public function testEntityWithUploadableEntities()
  133. {
  134. $artRepo = $this->em->getRepository(self::ARTICLE_CLASS);
  135. $article = new Article();
  136. $article->setTitle('Test');
  137. $file1 = new File();
  138. $file2 = new File();
  139. $file3 = new File();
  140. $article->addFile($file1);
  141. $article->addFile($file2);
  142. $article->addFile($file3);
  143. $filesArrayIndex = 'file';
  144. $fileInfo = $this->generateUploadedFile($filesArrayIndex);
  145. $fileInfo2 = $this->generateUploadedFile($filesArrayIndex);
  146. $fileInfo3 = $this->generateUploadedFile($filesArrayIndex);
  147. $this->listener->addEntityFileInfo($file1, $fileInfo);
  148. $this->listener->addEntityFileInfo($file2, $fileInfo2);
  149. $this->listener->addEntityFileInfo($file3, $fileInfo3);
  150. $this->em->persist($article);
  151. $this->em->flush();
  152. $art = $artRepo->findOneByTitle('Test');
  153. $files = $art->getFiles();
  154. $file1Path = $file1->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  155. $file2Path = $file2->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  156. $file3Path = $file3->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  157. $this->assertPathEquals($file1Path, $files[0]->getFilePath());
  158. $this->assertPathEquals($file2Path, $files[1]->getFilePath());
  159. $this->assertPathEquals($file3Path, $files[2]->getFilePath());
  160. }
  161. /**
  162. * @expectedException Gedmo\Exception\UploadableNoPathDefinedException
  163. */
  164. public function testNoPathDefinedOnEntityOrListenerThrowsException()
  165. {
  166. $file = new FileWithoutPath();
  167. $fileInfo = $this->generateUploadedFile();
  168. $this->listener->addEntityFileInfo($file, $fileInfo);
  169. $this->em->persist($file);
  170. $this->em->flush();
  171. }
  172. public function testNoPathDefinedOnEntityButDefinedOnListenerUsesDefaultPath()
  173. {
  174. // We set the default path on the listener
  175. $this->listener->setDefaultPath($this->destinationTestDir);
  176. $file = new FileWithoutPath();
  177. $fileInfo = $this->generateUploadedFile();
  178. $this->listener->addEntityFileInfo($file, $fileInfo);
  179. $this->em->persist($file);
  180. $this->em->flush();
  181. $this->em->refresh($file);
  182. $this->assertPathEquals($this->destinationTestFile, $file->getFilePath());
  183. }
  184. public function testCallbackIsCalledIfItsSetOnEntity()
  185. {
  186. $file = new File();
  187. $fileInfo = $this->generateUploadedFile();
  188. $this->listener->addEntityFileInfo($file, $fileInfo);
  189. $this->em->persist($file);
  190. $this->em->flush();
  191. $this->assertTrue($file->callbackWasCalled);
  192. }
  193. /**
  194. * @dataProvider uploadExceptionsProvider
  195. */
  196. public function testUploadExceptions($error, $exceptionClass)
  197. {
  198. $this->setExpectedException($exceptionClass);
  199. $file = new File();
  200. $fileInfo = $this->generateUploadedFile();
  201. $fileInfo['error'] = $error;
  202. $this->listener->addEntityFileInfo($file, $fileInfo);
  203. $this->em->persist($file);
  204. $this->em->flush();
  205. }
  206. public function testSettingAnotherDefaultFileInfoClass()
  207. {
  208. $fileInfoStubClass = 'Gedmo\Uploadable\Stub\FileInfoStub';
  209. $this->listener->setDefaultFileInfoClass($fileInfoStubClass);
  210. $file = new File();
  211. $fileInfo = $this->generateUploadedFile();
  212. $this->listener->addEntityFileInfo($file, $fileInfo);
  213. $fileInfo = $this->listener->getEntityFileInfo($file);
  214. $this->assertInstanceOf($fileInfoStubClass, $fileInfo);
  215. }
  216. public function testFileWithFilenameSha1Generator()
  217. {
  218. $file = new FileWithSha1Name();
  219. $fileInfo = $this->generateUploadedFile();
  220. $this->listener->addEntityFileInfo($file, $fileInfo);
  221. $this->em->persist($file);
  222. $this->em->flush();
  223. $this->em->refresh($file);
  224. $sha1String = substr($file->getFilePath(), strrpos($file->getFilePath(), '/') + 1);
  225. $sha1String = str_replace('.txt', '', $sha1String);
  226. $this->assertRegExp('/[a-z0-9]{40}/', $sha1String);
  227. }
  228. public function testFileWithFilenameAlphanumericGenerator()
  229. {
  230. $file = new FileWithAlphanumericName();
  231. $fileInfo = $this->generateUploadedFile('image', $this->testFile3, $this->testFilename3);
  232. $this->listener->addEntityFileInfo($file, $fileInfo);
  233. $this->em->persist($file);
  234. $this->em->flush();
  235. $this->em->refresh($file);
  236. $filename = substr($file->getFilePath(), strrpos($this->fixWindowsPath($file->getFilePath()), '/') + 1);
  237. $this->assertEquals('test-3.txt', $filename);
  238. }
  239. public function testFileWithCustomFilenameGenerator()
  240. {
  241. $file = new FileWithCustomFilenameGenerator();
  242. $fileInfo = $this->generateUploadedFile();
  243. $this->listener->addEntityFileInfo($file, $fileInfo);
  244. $this->em->persist($file);
  245. $this->em->flush();
  246. $this->em->refresh($file);
  247. $filename = substr($file->getFilePath(), strrpos($this->fixWindowsPath($file->getFilePath()), '/') + 1);
  248. $this->assertEquals('123.txt', $filename);
  249. }
  250. public function testUploadFileWithoutExtension()
  251. {
  252. $file = new File();
  253. $fileInfo = $this->generateUploadedFile('image', $this->testFileWithoutExt, $this->testFilenameWithoutExt);
  254. $this->listener->addEntityFileInfo($file, $fileInfo);
  255. $this->em->persist($file);
  256. $this->em->flush();
  257. $this->em->refresh($file);
  258. $filePath = $file->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  259. $this->assertPathEquals($filePath, $file->getFilePath());
  260. }
  261. /**
  262. * @expectedException Gedmo\Exception\UploadableFileAlreadyExistsException
  263. */
  264. public function testFileAlreadyExistsException()
  265. {
  266. $file = new Image();
  267. $file->setTitle('test');
  268. $fileInfo = $this->generateUploadedFile('image', $this->testFileWithoutExt, $this->testFilenameWithoutExt);
  269. $this->listener->addEntityFileInfo($file, $fileInfo);
  270. $this->em->persist($file);
  271. $this->em->flush();
  272. $this->listener->addEntityFileInfo($file, $fileInfo);
  273. $this->em->flush();
  274. }
  275. public function test_removeFile_ifItsNotAFileThenReturnFalse()
  276. {
  277. $this->assertFalse($this->listener->removeFile('non_existent_file'));
  278. }
  279. public function test_moveFile_usingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists()
  280. {
  281. $file = new FileAppendNumber();
  282. $file2 = new FileAppendNumber();
  283. $file->setTitle('test');
  284. $file2->setTitle('test2');
  285. $fileInfo = $this->generateUploadedFile();
  286. $this->listener->addEntityFileInfo($file, $fileInfo);
  287. $this->em->persist($file);
  288. $this->em->flush();
  289. $this->listener->addEntityFileInfo($file2, $fileInfo);
  290. $this->em->persist($file2);
  291. $this->em->flush();
  292. $this->em->refresh($file2);
  293. $filename = substr($file2->getFilePath(), strrpos($this->fixWindowsPath($file2->getFilePath()), '/') + 1);
  294. $this->assertEquals('test-2.txt', $filename);
  295. }
  296. /**
  297. * @expectedException Gedmo\Exception\UploadableUploadException
  298. */
  299. public function test_moveFile_ifUploadedFileCantBeMovedThrowException()
  300. {
  301. $this->listener->returnFalseOnMoveUploadedFile = true;
  302. $file = new Image();
  303. $file->setTitle('test');
  304. $fileInfo = $this->generateUploadedFile();
  305. $this->listener->addEntityFileInfo($file, $fileInfo);
  306. $this->em->persist($file);
  307. $this->em->flush();
  308. }
  309. /**
  310. * @expectedException RuntimeException
  311. */
  312. public function test_addEntityFileInfo_ifFileInfoIsNotValidThrowException()
  313. {
  314. $this->listener->addEntityFileInfo(new Image, 'invalidFileInfo');
  315. }
  316. /**
  317. * @expectedException RuntimeException
  318. */
  319. public function test_getEntityFileInfo_ifTheresNoFileInfoForEntityThrowException()
  320. {
  321. $this->listener->getEntityFileInfo(new Image);
  322. }
  323. /**
  324. * @expectedException Gedmo\Exception\UploadableMaxSizeException
  325. */
  326. public function test_fileExceedingMaximumAllowedSizeThrowsException()
  327. {
  328. // We set the default path on the listener
  329. $this->listener->setDefaultPath($this->destinationTestDir);
  330. $file = new FileWithMaxSize();
  331. $fileInfo = $this->generateUploadedFile();
  332. $this->listener->addEntityFileInfo($file, $fileInfo);
  333. $this->em->persist($file);
  334. $this->em->flush();
  335. }
  336. public function test_fileNotExceedingMaximumAllowedSizeDoesntThrowException()
  337. {
  338. // We set the default path on the listener
  339. $this->listener->setDefaultPath($this->destinationTestDir);
  340. $file = new FileWithMaxSize();
  341. $size = 0.0001;
  342. $fileInfo = $this->generateUploadedFile('image', false, false, array('size' => $size));
  343. $this->listener->addEntityFileInfo($file, $fileInfo);
  344. $this->em->persist($file);
  345. $this->em->flush();
  346. $this->em->refresh($file);
  347. $this->assertEquals($size, $file->getFileSize());
  348. }
  349. /**
  350. * @expectedException Gedmo\Exception\UploadableCouldntGuessMimeTypeException
  351. */
  352. public function test_ifMimeTypeGuesserCantResolveTypeThrowException()
  353. {
  354. // We set the default path on the listener
  355. $this->listener->setDefaultPath($this->destinationTestDir);
  356. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub(null));
  357. $file = new FileWithAllowedTypes();
  358. $fileInfo = $this->generateUploadedFile();
  359. $this->listener->addEntityFileInfo($file, $fileInfo);
  360. $this->em->persist($file);
  361. $this->em->flush();
  362. }
  363. /**
  364. * @expectedException Gedmo\Exception\UploadableInvalidMimeTypeException
  365. */
  366. public function test_allowedTypesOption_ifMimeTypeIsInvalidThrowException()
  367. {
  368. // We set the default path on the listener
  369. $this->listener->setDefaultPath($this->destinationTestDir);
  370. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('text/css'));
  371. $file = new FileWithAllowedTypes();
  372. $fileInfo = $this->generateUploadedFile();
  373. $this->listener->addEntityFileInfo($file, $fileInfo);
  374. $this->em->persist($file);
  375. $this->em->flush();
  376. }
  377. public function test_allowedTypesOption_ifMimeTypeIsValidThenDontThrowException()
  378. {
  379. // We set the default path on the listener
  380. $this->listener->setDefaultPath($this->destinationTestDir);
  381. $file = new FileWithAllowedTypes();
  382. $fileInfo = $this->generateUploadedFile();
  383. $this->listener->addEntityFileInfo($file, $fileInfo);
  384. $this->em->persist($file);
  385. $this->em->flush();
  386. }
  387. /**
  388. * @expectedException Gedmo\Exception\UploadableInvalidMimeTypeException
  389. */
  390. public function test_disallowedTypesOption_ifMimeTypeIsInvalidThrowException()
  391. {
  392. // We set the default path on the listener
  393. $this->listener->setDefaultPath($this->destinationTestDir);
  394. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('text/css'));
  395. $file = new FileWithDisallowedTypes();
  396. $fileInfo = $this->generateUploadedFile();
  397. $this->listener->addEntityFileInfo($file, $fileInfo);
  398. $this->em->persist($file);
  399. $this->em->flush();
  400. }
  401. public function test_disallowedTypesOption_ifMimeTypeIsValidThenDontThrowException()
  402. {
  403. // We set the default path on the listener
  404. $this->listener->setDefaultPath($this->destinationTestDir);
  405. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('video/jpeg'));
  406. $file = new FileWithDisallowedTypes();
  407. $fileInfo = $this->generateUploadedFile();
  408. $this->listener->addEntityFileInfo($file, $fileInfo);
  409. $this->em->persist($file);
  410. $this->em->flush();
  411. }
  412. // Data Providers
  413. public function uploadExceptionsProvider()
  414. {
  415. return array(
  416. array(1, 'Gedmo\Exception\UploadableIniSizeException'),
  417. array(2, 'Gedmo\Exception\UploadableFormSizeException'),
  418. array(3, 'Gedmo\Exception\UploadablePartialException'),
  419. array(4, 'Gedmo\Exception\UploadableNoFileException'),
  420. array(6, 'Gedmo\Exception\UploadableNoTmpDirException'),
  421. array(7, 'Gedmo\Exception\UploadableCantWriteException'),
  422. array(8, 'Gedmo\Exception\UploadableExtensionException'),
  423. array(999, 'Gedmo\Exception\UploadableUploadException')
  424. );
  425. }
  426. // Util
  427. private function generateUploadedFile($index = 'image', $filePath = false, $filename = false, array $info = array())
  428. {
  429. $defaultInfo = array(
  430. 'tmp_name' => !$filePath ? $this->testFile : $filePath,
  431. 'name' => !$filename ? $this->testFilename : $filename,
  432. 'size' => $this->testFileSize,
  433. 'type' => $this->testFileMimeType,
  434. 'error' => 0
  435. );
  436. $info = array_merge($defaultInfo, $info);
  437. return $info;
  438. }
  439. protected function getUsedEntityFixtures()
  440. {
  441. return array(
  442. self::IMAGE_CLASS,
  443. self::ARTICLE_CLASS,
  444. self::FILE_CLASS,
  445. self::FILE_WITHOUT_PATH_CLASS,
  446. self::FILE_APPEND_NUMBER_CLASS,
  447. self::FILE_WITH_ALPHANUMERIC_NAME_CLASS,
  448. self::FILE_WITH_SHA1_NAME_CLASS,
  449. self::FILE_WITH_CUSTOM_FILENAME_GENERATOR_CLASS,
  450. self::FILE_WITH_MAX_SIZE_CLASS,
  451. self::FILE_WITH_ALLOWED_TYPES_CLASS,
  452. self::FILE_WITH_DISALLOWED_TYPES_CLASS
  453. );
  454. }
  455. private function clearFilesAndDirectories()
  456. {
  457. if (is_dir($this->destinationTestDir)) {
  458. $iter = new \DirectoryIterator($this->destinationTestDir);
  459. foreach ($iter as $fileInfo) {
  460. if (!$fileInfo->isDot()) {
  461. @unlink($fileInfo->getPathname());
  462. }
  463. }
  464. }
  465. }
  466. protected function assertPathEquals($expected, $path, $message = '')
  467. {
  468. $this->assertEquals($this->fixWindowsPath($expected), $this->fixWindowsPath($path), $message);
  469. }
  470. protected function fixWindowsPath($path)
  471. {
  472. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  473. $path = str_replace('\\', '/', $path);
  474. }
  475. return $path;
  476. }
  477. }
  478. class FakeFilenameGenerator implements \Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorInterface
  479. {
  480. public static function generate($filename, $extension)
  481. {
  482. return '123.txt';
  483. }
  484. }