ResourceTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use UnitTester;
  7. class ResourceTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testInvalidResourceLoading()
  14. {
  15. $data = new Data();
  16. $this->tester->expectException('\Exception', function() use ($data) {
  17. $data->loadPalette('nonExistantPalette');
  18. });
  19. $image = new Image(700, 230, $data);
  20. $this->tester->expectException('\Exception', function() use ($image) {
  21. $image->setResourcePath('nonExistantDirectory');
  22. });
  23. $this->tester->expectException('\Exception', function() use ($image) {
  24. $image->setFontProperties(["FontName" => "nonExistantFont"]);
  25. });
  26. $this->tester->expectException('\Exception', function() use ($image) {
  27. $image->getLegendSize(['Font' => 'nonExistantFont']);
  28. });
  29. }
  30. public function testValidPaletteLoading()
  31. {
  32. $data = new Data();
  33. $data->loadPalette(sprintf('%s/../_data/test_palette.txt', __DIR__), true);
  34. $image = new Image(700, 230, $data);
  35. $firstCoordinates = [[40, 80], [280, 60], [340, 166], [590, 120]];
  36. $fistSplineSettings = ["R" => 255, "G" => 255, "B" => 255, "ShowControl" => true];
  37. $image->drawSpline($firstCoordinates, $fistSplineSettings);
  38. $filename = $this->tester->getOutputPathForChart('drawSpline.png');
  39. $image->render($filename);
  40. $this->tester->seeFileFound($filename);
  41. }
  42. public function testInvalidPaletteLoading()
  43. {
  44. $data = new Data();
  45. $this->tester->expectException('\Exception', function() use ($data) {
  46. $data->loadPalette(sprintf('non_existant_palette', __DIR__), true);
  47. });
  48. }
  49. }