ExporterTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Tests\Filter;
  11. use Exporter\Source\ArraySourceIterator;
  12. use Sonata\AdminBundle\Export\Exporter;
  13. /**
  14. * @group legacy
  15. */
  16. class ExporterTest extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * @expectedException \RuntimeException
  20. */
  21. public function testFilter()
  22. {
  23. $source = $this->getMock('Exporter\Source\SourceIteratorInterface');
  24. $exporter = new Exporter();
  25. $exporter->getResponse('foo', 'foo', $source);
  26. }
  27. /**
  28. * @dataProvider getGetResponseTests
  29. */
  30. public function testGetResponse($format, $filename, $contentType)
  31. {
  32. $source = new ArraySourceIterator(array(
  33. array('foo' => 'bar'),
  34. ));
  35. $exporter = new Exporter();
  36. $response = $exporter->getResponse($format, $filename, $source);
  37. $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  38. $this->assertSame($contentType, $response->headers->get('Content-Type'));
  39. // Quotes does not appear on some sonata versions.
  40. $this->assertRegExp('/attachment; filename="?'.$filename.'"?/', $response->headers->get('Content-Disposition'));
  41. }
  42. public function getGetResponseTests()
  43. {
  44. return array(
  45. array('json', 'foo.json', 'application/json'),
  46. array('xml', 'foo.xml', 'text/xml'),
  47. array('xls', 'foo.xls', 'application/vnd.ms-excel'),
  48. array('csv', 'foo.csv', 'text/csv'),
  49. );
  50. }
  51. }