/package/app/app/tests/thumbnailTests/convertImageProductionTest.php

https://github.com/richhl/kalturaCE · PHP · 110 lines · 67 code · 12 blank · 31 comment · 6 complexity · c025b03a79feed47a2f5778b99e48a9b MD5 · raw file

  1. <?php
  2. require_once 'convertImageTester.php';
  3. require_once 'bootstrap.php';
  4. /**
  5. * this class tests the compatibility of a new code with the code residing in producion.
  6. * the myConverter::convertImage function will run on a known set of image files and convert them
  7. * using some parameters. the same will be done by calling to URL request (production side). after that
  8. * the two outputs will be compared.
  9. * @author ori
  10. */
  11. class convertImageProductionTest
  12. {
  13. /**
  14. * arrays of input data for tests.
  15. * every element is a string file name (including or not including full path)
  16. * $sourceFiles[$i] output will be tested with respect to $outputReferenceFiles[$i]
  17. */
  18. private $sourceFiles = array(); // array of different sorce files
  19. private $outputReferenceFiles = array(); // array of different url requests
  20. /**
  21. * set up all needed parameters for the test
  22. * @param unknown_type $testsFile - test file path. the file contains the source file and
  23. * the output reference file for a specefic test
  24. * @param unknown_type $imagesDir - the directory of all the images to be tested
  25. */
  26. public function setUp($testsFile, $imagesDir)
  27. {
  28. $fileHundler = null;
  29. if (($fileHundler = fopen($testsFile, "r")) === false)
  30. die ('unable to read tests file [' . $testsFile . ']');
  31. fgets($fileHundler); // discard form header line
  32. while (!feof($fileHundler)) {
  33. $line = fgets($fileHundler);
  34. $line = explode("\t", $line);
  35. $this->sourceFiles[] = $imagesDir . '/' . trim($line[0]);
  36. $this->outputReferenceFiles[] = trim($line[1]);
  37. }
  38. }
  39. /**
  40. * test convertImage function (myFileConverter::convertImage)
  41. * the test is done by executing a number of different tests on different files and comparing result
  42. * to the produvtion servert results
  43. */
  44. public function testConvertImage()
  45. {
  46. $status = null;
  47. $tester = null;
  48. // test all source files and compare result to output reference file
  49. for ($i = 0; $i < count($this->sourceFiles); $i++) {
  50. $tester = new convertImageTester($this->sourceFiles[$i], $this->outputReferenceFiles[$i]);
  51. // extract convertion parameters from $outputReferenceFile and update $tester for those parameters
  52. $params = array();
  53. $tmp = array();
  54. $tmp = explode("/", $this->outputReferenceFiles[$i]);
  55. // get rid of source file name and extension of file
  56. for ($j = 0; $j < 8 ; $j++)
  57. array_shift($tmp);
  58. array_pop($tmp);
  59. $j = 0;
  60. while($j < count($tmp)) {
  61. $params["$tmp[$j]"] = $tmp[$j + 1];
  62. $j += 2;
  63. }
  64. array_key_exists('width', $params) ? $tester->setWidth($params['width']) : $tester->setWidth();
  65. array_key_exists('height', $params) ? $tester->setHeight($params['height']) : $tester->setHeight();
  66. array_key_exists('type', $params) ? $tester->setCropType($params['type']) : $tester->setCropType();
  67. array_key_exists('bgcolor', $params) ? $tester->setBGColor($params['bgcolor']) : $tester->setBGColor();
  68. array_key_exists('quality', $params) ? $tester->setQuality($params['quality']) : $tester->setQuality();
  69. array_key_exists('src_x', $params) ? $tester->setSrcX($params['src_x']) : $tester->setSrcX();
  70. array_key_exists('src_y', $params) ? $tester->setSrcY($params['src_y']) : $tester->setSrcY();
  71. array_key_exists('src_w', $params) ? $tester->setSrcW($params['src_w']) : $tester->setSrcW();
  72. array_key_exists('src_h', $params) ? $tester->setSrcH($params['src_h']) : $tester->setSrcH();
  73. // excute test and assert
  74. $status = $tester->execute();
  75. if ($status === false)
  76. echo 'unable to convert [' . $tester->getSourceFile() . '] with parameterrs: ' .
  77. print_r($tester->getParams()) . PHP_EOL;
  78. // assert(true === $status);
  79. // download from production the converted image (thumbnail) and
  80. // check if output is identical to reference output
  81. $tester->downloadUrlFile();
  82. $tester->setGraphicTol(0.33);
  83. $tester->setByteTol($tester->getByteTol() * 15);
  84. $status = $tester->compareTargetReference();
  85. $tester->deleteDownloadFile();
  86. if ($status === false)
  87. echo 'images files: [' . $tester->getOutputReferenceFile() . '], [' .
  88. $tester->getTargetFile(). '] are not identical' . PHP_EOL;
  89. // assert(true === $status);
  90. echo 'convertImage test completed on file [' . $tester->getOutputReferenceFile() . ']' . PHP_EOL;
  91. unset($tester);
  92. }
  93. }
  94. }
  95. $test = new convertImageProductionTest();
  96. $test->setUp("convertImageProductionTests.txt", dirname(__FILE__) . '/images');
  97. $test->testConvertImage();
  98. ?>