FileTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Tests Kohana File helper
  4. *
  5. * @group kohana
  6. * @group kohana.core
  7. * @group kohana.core.file
  8. *
  9. * @package Kohana
  10. * @category Tests
  11. * @author Kohana Team
  12. * @author Jeremy Bush <contractfrombelow@gmail.com>
  13. * @copyright (c) Kohana Team
  14. * @license https://koseven.ga/LICENSE.md
  15. */
  16. class Kohana_FileTest extends Unittest_TestCase
  17. {
  18. /**
  19. * Provides test data for test_sanitize()
  20. *
  21. * @return array
  22. */
  23. public function provider_mime()
  24. {
  25. return [
  26. // $value, $result
  27. [Kohana::find_file('tests', 'test_data/github', 'png'), 'image/png'],
  28. ];
  29. }
  30. /**
  31. * Tests File::mime()
  32. *
  33. * @test
  34. * @dataProvider provider_mime
  35. * @param boolean $input Input for File::mime
  36. * @param boolean $expected Output for File::mime
  37. */
  38. public function test_mime($input, $expected)
  39. {
  40. //@todo: File::mime coverage needs significant improvement or to be dropped for a composer package - it's a "horribly unreliable" method with very little testing
  41. $this->assertSame($expected, File::mime($input));
  42. }
  43. /**
  44. * Provides test data for test_split_join()
  45. *
  46. * @return array
  47. */
  48. public function provider_split_join()
  49. {
  50. return [
  51. // $value, $result
  52. [Kohana::find_file('tests', 'test_data/github', 'png'), .01, 1],
  53. ];
  54. }
  55. /**
  56. * Tests File::mime()
  57. *
  58. * @test
  59. * @dataProvider provider_split_join
  60. * @param boolean $input Input for File::split
  61. * @param boolean $peices Input for File::split
  62. * @param boolean $expected Output for File::splut
  63. */
  64. public function test_split_join($input, $peices, $expected)
  65. {
  66. $this->assertSame($expected, File::split($input, $peices));
  67. $this->assertSame($expected, File::join($input));
  68. foreach (glob(Kohana::find_file('tests', 'test_data/github', 'png').'.*') as $file)
  69. {
  70. unlink($file);
  71. }
  72. }
  73. }