FileTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Tests KO7 File helper
  4. *
  5. * @group ko7
  6. * @group ko7.core
  7. * @group ko7.core.file
  8. *
  9. * @package KO7
  10. * @category Tests
  11. *
  12. * @author Jeremy Bush <contractfrombelow@gmail.com>
  13. * @copyright (c) 2007-2016 Kohana Team
  14. * @copyright (c) since 2016 Koseven Team
  15. * @license https://koseven.dev/LICENSE
  16. */
  17. class KO7_FileTest extends Unittest_TestCase
  18. {
  19. /**
  20. * Provides test data for test_sanitize()
  21. *
  22. * @return array
  23. */
  24. public function provider_mime()
  25. {
  26. return [
  27. // $value, $result
  28. [KO7::find_file('tests', 'test_data/github', 'png'), 'image/png'],
  29. ];
  30. }
  31. /**
  32. * Tests File::mime()
  33. *
  34. * @test
  35. * @dataProvider provider_mime
  36. * @param boolean $input Input for File::mime
  37. * @param boolean $expected Output for File::mime
  38. */
  39. public function test_mime($input, $expected)
  40. {
  41. //@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
  42. $this->assertSame($expected, File::mime($input));
  43. }
  44. /**
  45. * Provides test data for test_split_join()
  46. *
  47. * @return array
  48. */
  49. public function provider_split_join()
  50. {
  51. return [
  52. // $value, $result
  53. [KO7::find_file('tests', 'test_data/github', 'png'), .01, 1],
  54. ];
  55. }
  56. /**
  57. * Tests File::mime()
  58. *
  59. * @test
  60. * @dataProvider provider_split_join
  61. * @param boolean $input Input for File::split
  62. * @param boolean $peices Input for File::split
  63. * @param boolean $expected Output for File::splut
  64. */
  65. public function test_split_join($input, $peices, $expected)
  66. {
  67. $this->assertSame($expected, File::split($input, $peices));
  68. $this->assertSame($expected, File::join($input));
  69. foreach (glob(KO7::find_file('tests', 'test_data/github', 'png').'.*') as $file)
  70. {
  71. unlink($file);
  72. }
  73. }
  74. }