ExporterTest.php 1.7 KB

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