UploadableMappingTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Gedmo\Mapping;
  3. use Doctrine\Common\Annotations\AnnotationReader;
  4. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  5. use Doctrine\Common\EventManager;
  6. use Doctrine\ORM\Mapping\Driver\DriverChain;
  7. use Doctrine\ORM\Mapping\Driver\YamlDriver;
  8. use Gedmo\Uploadable\UploadableListener;
  9. use Gedmo\Uploadable\Mapping\Validator;
  10. use Tool\BaseTestCaseOM;
  11. /**
  12. * These are mapping tests for Uploadable extension
  13. *
  14. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  15. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  16. * @link http://www.gediminasm.org
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. class UploadableMappingTest extends BaseTestCaseOM
  20. {
  21. /**
  22. * @var Doctrine\ORM\EntityManager
  23. */
  24. private $em;
  25. /**
  26. * @var Gedmo\SoftDeleteable\UploadableListener
  27. */
  28. private $listener;
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. Validator::$enableMimeTypesConfigException = false;
  33. $reader = new AnnotationReader();
  34. $annotationDriver = new AnnotationDriver($reader);
  35. $yamlDriver = new YamlDriver(__DIR__.'/Driver/Yaml');
  36. $chain = new DriverChain;
  37. $chain->addDriver($yamlDriver, 'Mapping\Fixture\Yaml');
  38. $chain->addDriver($annotationDriver, 'Mapping\Fixture');
  39. $this->listener = new UploadableListener();
  40. $this->evm = new EventManager;
  41. $this->evm->addEventSubscriber($this->listener);
  42. $this->em = $this->getMockSqliteEntityManager(array(
  43. 'Mapping\Fixture\Yaml\Uploadable'
  44. ), $chain);
  45. }
  46. public function testYamlMapping()
  47. {
  48. $meta = $this->em->getClassMetadata('Mapping\Fixture\Yaml\Uploadable');
  49. $config = $this->listener->getConfiguration($this->em, $meta->name);
  50. $this->assertTrue($config['uploadable']);
  51. $this->assertTrue($config['allowOverwrite']);
  52. $this->assertTrue($config['appendNumber']);
  53. $this->assertEquals('/my/path', $config['path']);
  54. $this->assertEquals('getPath', $config['pathMethod']);
  55. $this->assertEquals('mimeType', $config['fileMimeTypeField']);
  56. $this->assertEquals('path', $config['filePathField']);
  57. $this->assertEquals('size', $config['fileSizeField']);
  58. $this->assertEquals('callbackMethod', $config['callback']);
  59. $this->assertEquals('SHA1', $config['filenameGenerator']);
  60. $this->assertEquals(1500, $config['maxSize']);
  61. $this->assertContains('text/plain', $config['allowedTypes']);
  62. $this->assertContains('text/css', $config['allowedTypes']);
  63. $this->assertContains('video/jpeg', $config['disallowedTypes']);
  64. $this->assertContains('text/html', $config['disallowedTypes']);
  65. }
  66. }