ImagePageTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. class ImagePageTest extends MediaWikiMediaTestCase {
  3. function setUp() {
  4. $this->setMwGlobals( 'wgImageLimits', [
  5. [ 320, 240 ],
  6. [ 640, 480 ],
  7. [ 800, 600 ],
  8. [ 1024, 768 ],
  9. [ 1280, 1024 ]
  10. ] );
  11. parent::setUp();
  12. }
  13. function getImagePage( $filename ) {
  14. $title = Title::makeTitleSafe( NS_FILE, $filename );
  15. $file = $this->dataFile( $filename );
  16. $iPage = new ImagePage( $title );
  17. $iPage->setFile( $file );
  18. return $iPage;
  19. }
  20. /**
  21. * @covers ImagePage::getDisplayWidthHeight
  22. * @dataProvider providerGetDisplayWidthHeight
  23. * @param array $dim Array [maxWidth, maxHeight, width, height]
  24. * @param array $expected Array [width, height] The width and height we expect to display at
  25. */
  26. function testGetDisplayWidthHeight( $dim, $expected ) {
  27. $iPage = $this->getImagePage( 'animated.gif' );
  28. $reflection = new ReflectionClass( $iPage );
  29. $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
  30. $reflMethod->setAccessible( true );
  31. $actual = $reflMethod->invoke( $iPage, $dim[0], $dim[1], $dim[2], $dim[3] );
  32. $this->assertEquals( $actual, $expected );
  33. }
  34. function providerGetDisplayWidthHeight() {
  35. return [
  36. [
  37. [ 1024.0, 768.0, 600.0, 600.0 ],
  38. [ 600.0, 600.0 ]
  39. ],
  40. [
  41. [ 1024.0, 768.0, 1600.0, 600.0 ],
  42. [ 1024.0, 384.0 ]
  43. ],
  44. [
  45. [ 1024.0, 768.0, 1024.0, 768.0 ],
  46. [ 1024.0, 768.0 ]
  47. ],
  48. [
  49. [ 1024.0, 768.0, 800.0, 1000.0 ],
  50. [ 614.0, 768.0 ]
  51. ],
  52. [
  53. [ 1024.0, 768.0, 0, 1000 ],
  54. [ 0, 0 ]
  55. ],
  56. [
  57. [ 1024.0, 768.0, 2000, 0 ],
  58. [ 0, 0 ]
  59. ],
  60. ];
  61. }
  62. /**
  63. * @covers ImagePage::getThumbSizes
  64. * @dataProvider providerGetThumbSizes
  65. * @param string $filename
  66. * @param int $expectedNumberThumbs How many thumbnails to show
  67. */
  68. function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
  69. $iPage = $this->getImagePage( $filename );
  70. $reflection = new ReflectionClass( $iPage );
  71. $reflMethod = $reflection->getMethod( 'getThumbSizes' );
  72. $reflMethod->setAccessible( true );
  73. $actual = $reflMethod->invoke( $iPage, 545, 700 );
  74. $this->assertEquals( count( $actual ), $expectedNumberThumbs );
  75. }
  76. function providerGetThumbSizes() {
  77. return [
  78. [ 'animated.gif', 2 ],
  79. [ 'Toll_Texas_1.svg', 1 ],
  80. [ '80x60-Greyscale.xcf', 1 ],
  81. [ 'jpeg-comment-binary.jpg', 2 ],
  82. ];
  83. }
  84. }