ExporterTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. use Sonata\AdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase;
  14. /**
  15. * NEXT_MAJOR: remove this class.
  16. *
  17. * @group legacy
  18. */
  19. class ExporterTest extends PHPUnit_Framework_TestCase
  20. {
  21. /**
  22. * @expectedException \RuntimeException
  23. */
  24. public function testFilter()
  25. {
  26. $source = $this->createMock('Exporter\Source\SourceIteratorInterface');
  27. $exporter = new Exporter();
  28. $exporter->getResponse('foo', 'foo', $source);
  29. }
  30. /**
  31. * @dataProvider getGetResponseTests
  32. */
  33. public function testGetResponse($format, $filename, $contentType)
  34. {
  35. $source = new ArraySourceIterator(array(
  36. array('foo' => 'bar'),
  37. ));
  38. $exporter = new Exporter();
  39. $response = $exporter->getResponse($format, $filename, $source);
  40. $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  41. $this->assertSame($contentType, $response->headers->get('Content-Type'));
  42. // Quotes does not appear on some sonata versions.
  43. $this->assertRegExp('/attachment; filename="?'.$filename.'"?/', $response->headers->get('Content-Disposition'));
  44. }
  45. public function getGetResponseTests()
  46. {
  47. return array(
  48. array('json', 'foo.json', 'application/json'),
  49. array('xml', 'foo.xml', 'text/xml'),
  50. array('xls', 'foo.xls', 'application/vnd.ms-excel'),
  51. array('csv', 'foo.csv', 'text/csv'),
  52. );
  53. }
  54. }