SmallFileTest.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. use Mike42\GfxPhp\Image;
  3. use PHPUnit\Framework\TestCase;
  4. class SmallFileTest extends TestCase
  5. {
  6. function loadImage(string $filename) {
  7. $img = Image::fromFile(__DIR__ . "/../resources/small-files/$filename");
  8. return $img -> toBlackAndWhite();
  9. }
  10. function testWhite() {
  11. $expected = " \n";
  12. $width = 1;
  13. $height = 1;
  14. foreach(['canvas_white.gif', 'canvas_white.png'] as $fn) { // Also jpg and bmp
  15. $img = $this -> loadImage($fn);
  16. $this -> assertEquals($expected, $img -> toString());
  17. $this -> assertEquals($height, $img -> getHeight());
  18. $this -> assertEquals($width, $img -> getWidth());
  19. }
  20. }
  21. function testBlack() {
  22. $expected = "▀\n";
  23. $width = 1;
  24. $height = 1;
  25. foreach(['canvas_black.gif', 'canvas_black.png'] as $fn) { // Also jpg and bmp
  26. $img = $this -> loadImage($fn);
  27. $this -> assertEquals($expected, $img -> toString());
  28. $this -> assertEquals($height, $img -> getHeight());
  29. $this -> assertEquals($width, $img -> getWidth());
  30. }
  31. }
  32. function testBlackWhite() {
  33. $expected = "▀▀\n";
  34. $width = 2;
  35. $height = 2;
  36. foreach(['black_white.gif', 'black_white.png'] as $fn) { // Also jpg and bmp
  37. $img = $this -> loadImage($fn);
  38. $this -> assertEquals($expected, $img -> toString());
  39. $this -> assertEquals($height, $img -> getHeight());
  40. $this -> assertEquals($width, $img -> getWidth());
  41. }
  42. }
  43. function testBlackTransparent() {
  44. $expected = "▀▀\n";
  45. $width = 2;
  46. $height = 2;
  47. foreach(['black_transparent.gif', 'black_transparent.png'] as $fn) { // Also jpg and bmp
  48. $img = $this -> loadImage($fn);
  49. $this -> assertEquals($expected, $img -> toString());
  50. $this -> assertEquals($height, $img -> getHeight());
  51. $this -> assertEquals($width, $img -> getWidth());
  52. }
  53. }
  54. function testBlackWhiteTall() {
  55. $expected = "██\n" .
  56. "██\n" .
  57. "██\n" .
  58. "██\n" .
  59. " \n" .
  60. " \n" .
  61. " \n" .
  62. " \n";
  63. $width = 2;
  64. $height = 16;
  65. $img = $this -> loadImage('black_white_tall.png');
  66. $this -> assertEquals($expected, $img -> toString());
  67. $this -> assertEquals($height, $img -> getHeight());
  68. $this -> assertEquals($width, $img -> getWidth());
  69. }
  70. }