ExporterTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Sonata 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 Sonata\AdminBundle\Export\Exporter;
  12. use Exporter\Source\SourceIteratorInterface;
  13. use Exporter\Source\ArraySourceIterator;
  14. use Symfony\Component\HttpFoundation\Response;
  15. class ExporterTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @expectedException RuntimeException
  19. */
  20. public function testFilter()
  21. {
  22. $source = $this->getMock('Exporter\Source\SourceIteratorInterface');
  23. $exporter = new Exporter();
  24. $exporter->getResponse('foo', 'foo', $source);
  25. }
  26. /**
  27. * @dataProvider getGetResponseTests
  28. */
  29. public function testGetResponse($format, $filename, $contentType)
  30. {
  31. $source = new ArraySourceIterator(array(
  32. array('foo' => 'bar')
  33. ));
  34. $exporter = new Exporter();
  35. $response = $exporter->getResponse($format, $filename, $source);
  36. $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  37. $this->assertEquals($contentType, $response->headers->get('Content-Type'));
  38. $this->assertEquals('attachment; filename='.$filename, $response->headers->get('Content-Disposition'));
  39. }
  40. public function getGetResponseTests()
  41. {
  42. return array(
  43. array('json', 'foo.json', 'application/json'),
  44. array('xml', 'foo.xml', 'text/xml'),
  45. array('xls', 'foo.xls', 'application/vnd.ms-excel'),
  46. array('csv', 'foo.csv', 'text/csv'),
  47. );
  48. }
  49. }