UploadableEntityTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. // For now, we need to force the update changing one of the managed fields. If we don't do this,
  121. // entity won't be marked for update
  122. $image2->setTitle($image2->getTitle().'7892');
  123. $this->em->flush();
  124. $this->em->refresh($image2);
  125. $lastFile = $image2->getFilePath();
  126. $this->assertPathEquals($image2->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'], $image2->getFilePath());
  127. $this->assertTrue(is_file($lastFile));
  128. // First file should be removed on update
  129. $this->assertFalse(is_file($firstFile));
  130. // REMOVAL of an Uploadable Entity
  131. $this->em->remove($image2);
  132. $this->em->flush();
  133. $this->assertFalse(is_file($lastFile));
  134. }
  135. public function testEntityWithUploadableEntities()
  136. {
  137. $artRepo = $this->em->getRepository(self::ARTICLE_CLASS);
  138. $article = new Article();
  139. $article->setTitle('Test');
  140. $file1 = new File();
  141. $file2 = new File();
  142. $file3 = new File();
  143. $article->addFile($file1);
  144. $article->addFile($file2);
  145. $article->addFile($file3);
  146. $filesArrayIndex = 'file';
  147. $fileInfo = $this->generateUploadedFile($filesArrayIndex);
  148. $fileInfo2 = $this->generateUploadedFile($filesArrayIndex);
  149. $fileInfo3 = $this->generateUploadedFile($filesArrayIndex);
  150. $this->listener->addEntityFileInfo($file1, $fileInfo);
  151. $this->listener->addEntityFileInfo($file2, $fileInfo2);
  152. $this->listener->addEntityFileInfo($file3, $fileInfo3);
  153. $this->em->persist($article);
  154. $this->em->flush();
  155. $art = $artRepo->findOneByTitle('Test');
  156. $files = $art->getFiles();
  157. $file1Path = $file1->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  158. $file2Path = $file2->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  159. $file3Path = $file3->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  160. $this->assertPathEquals($file1Path, $files[0]->getFilePath());
  161. $this->assertPathEquals($file2Path, $files[1]->getFilePath());
  162. $this->assertPathEquals($file3Path, $files[2]->getFilePath());
  163. }
  164. /**
  165. * @expectedException Gedmo\Exception\UploadableNoPathDefinedException
  166. */
  167. public function testNoPathDefinedOnEntityOrListenerThrowsException()
  168. {
  169. $file = new FileWithoutPath();
  170. $fileInfo = $this->generateUploadedFile();
  171. $this->listener->addEntityFileInfo($file, $fileInfo);
  172. $this->em->persist($file);
  173. $this->em->flush();
  174. }
  175. public function testNoPathDefinedOnEntityButDefinedOnListenerUsesDefaultPath()
  176. {
  177. // We set the default path on the listener
  178. $this->listener->setDefaultPath($this->destinationTestDir);
  179. $file = new FileWithoutPath();
  180. $fileInfo = $this->generateUploadedFile();
  181. $this->listener->addEntityFileInfo($file, $fileInfo);
  182. $this->em->persist($file);
  183. $this->em->flush();
  184. $this->em->refresh($file);
  185. $this->assertPathEquals($this->destinationTestFile, $file->getFilePath());
  186. }
  187. public function testCallbackIsCalledIfItsSetOnEntity()
  188. {
  189. $file = new File();
  190. $fileInfo = $this->generateUploadedFile();
  191. $this->listener->addEntityFileInfo($file, $fileInfo);
  192. $this->em->persist($file);
  193. $this->em->flush();
  194. $this->assertTrue($file->callbackWasCalled);
  195. }
  196. /**
  197. * @dataProvider uploadExceptionsProvider
  198. */
  199. public function testUploadExceptions($error, $exceptionClass)
  200. {
  201. $this->setExpectedException($exceptionClass);
  202. $file = new File();
  203. $fileInfo = $this->generateUploadedFile();
  204. $fileInfo['error'] = $error;
  205. $this->listener->addEntityFileInfo($file, $fileInfo);
  206. $this->em->persist($file);
  207. $this->em->flush();
  208. }
  209. public function testSettingAnotherDefaultFileInfoClass()
  210. {
  211. $fileInfoStubClass = 'Gedmo\Uploadable\Stub\FileInfoStub';
  212. $this->listener->setDefaultFileInfoClass($fileInfoStubClass);
  213. $file = new File();
  214. $fileInfo = $this->generateUploadedFile();
  215. $this->listener->addEntityFileInfo($file, $fileInfo);
  216. $fileInfo = $this->listener->getEntityFileInfo($file);
  217. $this->assertInstanceOf($fileInfoStubClass, $fileInfo);
  218. }
  219. public function testFileWithFilenameSha1Generator()
  220. {
  221. $file = new FileWithSha1Name();
  222. $fileInfo = $this->generateUploadedFile();
  223. $this->listener->addEntityFileInfo($file, $fileInfo);
  224. $this->em->persist($file);
  225. $this->em->flush();
  226. $this->em->refresh($file);
  227. $sha1String = substr($file->getFilePath(), strrpos($file->getFilePath(), '/') + 1);
  228. $sha1String = str_replace('.txt', '', $sha1String);
  229. $this->assertRegExp('/[a-z0-9]{40}/', $sha1String);
  230. }
  231. public function testFileWithFilenameAlphanumericGenerator()
  232. {
  233. $file = new FileWithAlphanumericName();
  234. $fileInfo = $this->generateUploadedFile('image', $this->testFile3, $this->testFilename3);
  235. $this->listener->addEntityFileInfo($file, $fileInfo);
  236. $this->em->persist($file);
  237. $this->em->flush();
  238. $this->em->refresh($file);
  239. $filename = substr($file->getFilePath(), strrpos($this->fixWindowsPath($file->getFilePath()), '/') + 1);
  240. $this->assertEquals('test-3.txt', $filename);
  241. }
  242. public function testFileWithCustomFilenameGenerator()
  243. {
  244. $file = new FileWithCustomFilenameGenerator();
  245. $fileInfo = $this->generateUploadedFile();
  246. $this->listener->addEntityFileInfo($file, $fileInfo);
  247. $this->em->persist($file);
  248. $this->em->flush();
  249. $this->em->refresh($file);
  250. $filename = substr($file->getFilePath(), strrpos($this->fixWindowsPath($file->getFilePath()), '/') + 1);
  251. $this->assertEquals('123.txt', $filename);
  252. }
  253. public function testUploadFileWithoutExtension()
  254. {
  255. $file = new File();
  256. $fileInfo = $this->generateUploadedFile('image', $this->testFileWithoutExt, $this->testFilenameWithoutExt);
  257. $this->listener->addEntityFileInfo($file, $fileInfo);
  258. $this->em->persist($file);
  259. $this->em->flush();
  260. $this->em->refresh($file);
  261. $filePath = $file->getPath().DIRECTORY_SEPARATOR.$fileInfo['name'];
  262. $this->assertPathEquals($filePath, $file->getFilePath());
  263. }
  264. /**
  265. * @expectedException Gedmo\Exception\UploadableFileAlreadyExistsException
  266. */
  267. public function testFileAlreadyExistsException()
  268. {
  269. $file = new Image();
  270. $file->setTitle('test');
  271. $fileInfo = $this->generateUploadedFile('image', $this->testFileWithoutExt, $this->testFilenameWithoutExt);
  272. $this->listener->addEntityFileInfo($file, $fileInfo);
  273. $this->em->persist($file);
  274. $this->em->flush();
  275. $this->listener->addEntityFileInfo($file, $fileInfo);
  276. $this->em->flush();
  277. }
  278. public function test_removeFile_ifItsNotAFileThenReturnFalse()
  279. {
  280. $this->assertFalse($this->listener->removeFile('non_existent_file'));
  281. }
  282. public function test_moveFile_usingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists()
  283. {
  284. $file = new FileAppendNumber();
  285. $file2 = new FileAppendNumber();
  286. $file->setTitle('test');
  287. $file2->setTitle('test2');
  288. $fileInfo = $this->generateUploadedFile();
  289. $this->listener->addEntityFileInfo($file, $fileInfo);
  290. $this->em->persist($file);
  291. $this->em->flush();
  292. $this->listener->addEntityFileInfo($file2, $fileInfo);
  293. $this->em->persist($file2);
  294. $this->em->flush();
  295. $this->em->refresh($file2);
  296. $filename = substr($file2->getFilePath(), strrpos($this->fixWindowsPath($file2->getFilePath()), '/') + 1);
  297. $this->assertEquals('test-2.txt', $filename);
  298. }
  299. /**
  300. * @expectedException Gedmo\Exception\UploadableUploadException
  301. */
  302. public function test_moveFile_ifUploadedFileCantBeMovedThrowException()
  303. {
  304. $this->listener->returnFalseOnMoveUploadedFile = true;
  305. $file = new Image();
  306. $file->setTitle('test');
  307. $fileInfo = $this->generateUploadedFile();
  308. $this->listener->addEntityFileInfo($file, $fileInfo);
  309. $this->em->persist($file);
  310. $this->em->flush();
  311. }
  312. /**
  313. * @expectedException RuntimeException
  314. */
  315. public function test_addEntityFileInfo_ifFileInfoIsNotValidThrowException()
  316. {
  317. $this->listener->addEntityFileInfo(new Image, 'invalidFileInfo');
  318. }
  319. /**
  320. * @expectedException RuntimeException
  321. */
  322. public function test_getEntityFileInfo_ifTheresNoFileInfoForEntityThrowException()
  323. {
  324. $this->listener->getEntityFileInfo(new Image);
  325. }
  326. /**
  327. * @expectedException Gedmo\Exception\UploadableMaxSizeException
  328. */
  329. public function test_fileExceedingMaximumAllowedSizeThrowsException()
  330. {
  331. // We set the default path on the listener
  332. $this->listener->setDefaultPath($this->destinationTestDir);
  333. $file = new FileWithMaxSize();
  334. $fileInfo = $this->generateUploadedFile();
  335. $this->listener->addEntityFileInfo($file, $fileInfo);
  336. $this->em->persist($file);
  337. $this->em->flush();
  338. }
  339. public function test_fileNotExceedingMaximumAllowedSizeDoesntThrowException()
  340. {
  341. // We set the default path on the listener
  342. $this->listener->setDefaultPath($this->destinationTestDir);
  343. $file = new FileWithMaxSize();
  344. $size = 0.0001;
  345. $fileInfo = $this->generateUploadedFile('image', false, false, array('size' => $size));
  346. $this->listener->addEntityFileInfo($file, $fileInfo);
  347. $this->em->persist($file);
  348. $this->em->flush();
  349. $this->em->refresh($file);
  350. $this->assertEquals($size, $file->getFileSize());
  351. }
  352. /**
  353. * @expectedException Gedmo\Exception\UploadableCouldntGuessMimeTypeException
  354. */
  355. public function test_ifMimeTypeGuesserCantResolveTypeThrowException()
  356. {
  357. // We set the default path on the listener
  358. $this->listener->setDefaultPath($this->destinationTestDir);
  359. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub(null));
  360. $file = new FileWithAllowedTypes();
  361. $fileInfo = $this->generateUploadedFile();
  362. $this->listener->addEntityFileInfo($file, $fileInfo);
  363. $this->em->persist($file);
  364. $this->em->flush();
  365. }
  366. /**
  367. * @expectedException Gedmo\Exception\UploadableInvalidMimeTypeException
  368. */
  369. public function test_allowedTypesOption_ifMimeTypeIsInvalidThrowException()
  370. {
  371. // We set the default path on the listener
  372. $this->listener->setDefaultPath($this->destinationTestDir);
  373. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('text/css'));
  374. $file = new FileWithAllowedTypes();
  375. $fileInfo = $this->generateUploadedFile();
  376. $this->listener->addEntityFileInfo($file, $fileInfo);
  377. $this->em->persist($file);
  378. $this->em->flush();
  379. }
  380. public function test_allowedTypesOption_ifMimeTypeIsValidThenDontThrowException()
  381. {
  382. // We set the default path on the listener
  383. $this->listener->setDefaultPath($this->destinationTestDir);
  384. $file = new FileWithAllowedTypes();
  385. $fileInfo = $this->generateUploadedFile();
  386. $this->listener->addEntityFileInfo($file, $fileInfo);
  387. $this->em->persist($file);
  388. $this->em->flush();
  389. }
  390. /**
  391. * @expectedException Gedmo\Exception\UploadableInvalidMimeTypeException
  392. */
  393. public function test_disallowedTypesOption_ifMimeTypeIsInvalidThrowException()
  394. {
  395. // We set the default path on the listener
  396. $this->listener->setDefaultPath($this->destinationTestDir);
  397. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('text/css'));
  398. $file = new FileWithDisallowedTypes();
  399. $fileInfo = $this->generateUploadedFile();
  400. $this->listener->addEntityFileInfo($file, $fileInfo);
  401. $this->em->persist($file);
  402. $this->em->flush();
  403. }
  404. public function test_disallowedTypesOption_ifMimeTypeIsValidThenDontThrowException()
  405. {
  406. // We set the default path on the listener
  407. $this->listener->setDefaultPath($this->destinationTestDir);
  408. $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('video/jpeg'));
  409. $file = new FileWithDisallowedTypes();
  410. $fileInfo = $this->generateUploadedFile();
  411. $this->listener->addEntityFileInfo($file, $fileInfo);
  412. $this->em->persist($file);
  413. $this->em->flush();
  414. }
  415. // Data Providers
  416. public function uploadExceptionsProvider()
  417. {
  418. return array(
  419. array(1, 'Gedmo\Exception\UploadableIniSizeException'),
  420. array(2, 'Gedmo\Exception\UploadableFormSizeException'),
  421. array(3, 'Gedmo\Exception\UploadablePartialException'),
  422. array(4, 'Gedmo\Exception\UploadableNoFileException'),
  423. array(6, 'Gedmo\Exception\UploadableNoTmpDirException'),
  424. array(7, 'Gedmo\Exception\UploadableCantWriteException'),
  425. array(8, 'Gedmo\Exception\UploadableExtensionException'),
  426. array(999, 'Gedmo\Exception\UploadableUploadException')
  427. );
  428. }
  429. // Util
  430. private function generateUploadedFile($index = 'image', $filePath = false, $filename = false, array $info = array())
  431. {
  432. $defaultInfo = array(
  433. 'tmp_name' => !$filePath ? $this->testFile : $filePath,
  434. 'name' => !$filename ? $this->testFilename : $filename,
  435. 'size' => $this->testFileSize,
  436. 'type' => $this->testFileMimeType,
  437. 'error' => 0
  438. );
  439. $info = array_merge($defaultInfo, $info);
  440. return $info;
  441. }
  442. protected function getUsedEntityFixtures()
  443. {
  444. return array(
  445. self::IMAGE_CLASS,
  446. self::ARTICLE_CLASS,
  447. self::FILE_CLASS,
  448. self::FILE_WITHOUT_PATH_CLASS,
  449. self::FILE_APPEND_NUMBER_CLASS,
  450. self::FILE_WITH_ALPHANUMERIC_NAME_CLASS,
  451. self::FILE_WITH_SHA1_NAME_CLASS,
  452. self::FILE_WITH_CUSTOM_FILENAME_GENERATOR_CLASS,
  453. self::FILE_WITH_MAX_SIZE_CLASS,
  454. self::FILE_WITH_ALLOWED_TYPES_CLASS,
  455. self::FILE_WITH_DISALLOWED_TYPES_CLASS
  456. );
  457. }
  458. private function clearFilesAndDirectories()
  459. {
  460. if (is_dir($this->destinationTestDir)) {
  461. $iter = new \DirectoryIterator($this->destinationTestDir);
  462. foreach ($iter as $fileInfo) {
  463. if (!$fileInfo->isDot()) {
  464. @unlink($fileInfo->getPathname());
  465. }
  466. }
  467. }
  468. }
  469. protected function assertPathEquals($expected, $path, $message = '')
  470. {
  471. $this->assertEquals($this->fixWindowsPath($expected), $this->fixWindowsPath($path), $message);
  472. }
  473. protected function fixWindowsPath($path)
  474. {
  475. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  476. $path = str_replace('\\', '/', $path);
  477. }
  478. return $path;
  479. }
  480. }
  481. class FakeFilenameGenerator implements \Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorInterface
  482. {
  483. public static function generate($filename, $extension)
  484. {
  485. return '123.txt';
  486. }
  487. }