PageRenderTime 34ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/tests/lib/ezfile/ezfiledownload_test.php

http://github.com/ezsystems/ezpublish
PHP | 77 lines | 59 code | 10 blank | 8 comment | 0 complexity | 13d99965a8f326498a7132fe686308ee MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * File containing the eZFileDownloadTest class
  4. *
  5. * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  6. * @license For full copyright and license information view LICENSE file distributed with this source code.
  7. * @version //autogentag//
  8. * @package tests
  9. */
  10. class eZFileDownloadTest extends ezpTestCase
  11. {
  12. public function setUp()
  13. {
  14. parent::setUp();
  15. $this->file = dirname( __FILE__ ) . "/data/file.txt";
  16. $this->content = file_get_contents( $this->file );
  17. }
  18. public function testDownload()
  19. {
  20. ob_start();
  21. $this->assertTrue( eZFile::downloadContent( $this->file ) );
  22. $this->assertEquals( $this->content , ob_get_clean() );
  23. }
  24. public function testDownloadOffset()
  25. {
  26. ob_start();
  27. $this->assertTrue( eZFile::downloadContent( $this->file, 8000 ) );
  28. $this->assertEquals( substr( $this->content, -192 ) , ob_get_clean() );
  29. }
  30. public function testDownloadSize()
  31. {
  32. ob_start();
  33. $this->assertTrue( eZFile::downloadContent( $this->file, 0, 100 ) );
  34. $this->assertEquals( substr( $this->content, 0, 100 ) , ob_get_clean() );
  35. }
  36. public function testDownloadOffsetSize()
  37. {
  38. ob_start();
  39. $this->assertTrue( eZFile::downloadContent( $this->file, 8000, 100 ) );
  40. $this->assertEquals( substr( $this->content, 8000, 100 ) , ob_get_clean() );
  41. }
  42. public function testDownloadOffsetSizeTooHigh()
  43. {
  44. ob_start();
  45. $this->assertTrue( eZFile::downloadContent( $this->file, 8000, 192 ) );
  46. $this->assertEquals( substr( $this->content, 8000 ) , ob_get_clean() );
  47. }
  48. public function testDownloadOffsetSizeWayTooHigh()
  49. {
  50. ob_start();
  51. $this->assertTrue( eZFile::downloadContent( $this->file, 8000, 1e5 ) );
  52. $this->assertEquals( substr( $this->content, 8000 ) , ob_get_clean() );
  53. }
  54. public function testDownloadOffsetTooBig()
  55. {
  56. ob_start();
  57. $this->assertTrue( eZFile::downloadContent( $this->file, 8193 ) );
  58. $this->assertEquals( "" , ob_get_clean() );
  59. }
  60. public function testDownloadNoFile()
  61. {
  62. ob_start();
  63. $this->assertFalse( eZFile::downloadContent( "unexisting.txt" ) );
  64. $this->assertEquals( "" , ob_get_clean() );
  65. }
  66. }
  67. ?>