/apps/principal/lib/Graph/tests/background_test.php

https://github.com/proyectoalba/alba · PHP · 346 lines · 269 code · 62 blank · 15 comment · 1 complexity · 21db67029ae0e6b90894c5b52229de1d MD5 · raw file

  1. <?php
  2. /**
  3. * ezcGraphBackgroundTest
  4. *
  5. * @package Graph
  6. * @version 1.2
  7. * @subpackage Tests
  8. * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
  9. * @license http://ez.no/licenses/new_bsd New BSD License
  10. */
  11. require_once dirname( __FILE__ ) . '/test_case.php';
  12. /**
  13. * Tests for ezcGraph class.
  14. *
  15. * @package Graph
  16. * @subpackage Tests
  17. */
  18. class ezcGraphBackgroundTest extends ezcGraphTestCase
  19. {
  20. protected $testFiles = array(
  21. 'jpeg' => 'jpeg.jpg',
  22. 'nonexistant' => 'nonexisting.jpg',
  23. 'invalid' => 'text.txt',
  24. );
  25. public static function suite()
  26. {
  27. return new PHPUnit_Framework_TestSuite( "ezcGraphBackgroundTest" );
  28. }
  29. protected function setUp()
  30. {
  31. static $i = 0;
  32. $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/';
  33. $this->basePath = dirname( __FILE__ ) . '/data/';
  34. }
  35. protected function tearDown()
  36. {
  37. if ( !$this->hasFailed() )
  38. {
  39. $this->removeTempDir();
  40. }
  41. }
  42. public function testSetOptionsInvalidBackgroundImage()
  43. {
  44. try
  45. {
  46. $pieChart = new ezcGraphPieChart();
  47. $pieChart->background->image = $this->basePath . $this->testFiles['invalid'];
  48. }
  49. catch ( ezcGraphInvalidImageFileException $e )
  50. {
  51. return true;
  52. }
  53. $this->fail( 'Expected ezcGraphInvalidImageFileException' );
  54. }
  55. public function testSetOptionsNonexistantBackgroundImage()
  56. {
  57. try
  58. {
  59. $pieChart = new ezcGraphPieChart();
  60. $pieChart->background->image = $this->basePath . $this->testFiles['nonexistant'];
  61. }
  62. catch ( ezcBaseFileNotFoundException $e )
  63. {
  64. return true;
  65. }
  66. $this->fail( 'Expected ezcBaseFileNotFoundException' );
  67. }
  68. public function testSetOptionsBackground()
  69. {
  70. $pieChart = new ezcGraphPieChart();
  71. $pieChart->background->color = '#FF0000';
  72. $this->assertEquals(
  73. ezcGraphColor::fromHex( 'FF0000' ),
  74. $pieChart->background->color
  75. );
  76. }
  77. public function testSetOptionsBorder()
  78. {
  79. $pieChart = new ezcGraphPieChart();
  80. $pieChart->background->border = '#FF0000';
  81. $this->assertEquals(
  82. ezcGraphColor::fromHex( 'FF0000' ),
  83. $pieChart->background->border
  84. );
  85. }
  86. public function testSetOptionsBorderWidth()
  87. {
  88. $pieChart = new ezcGraphPieChart();
  89. $pieChart->background->borderWidth = 3;
  90. $this->assertSame( 3, $pieChart->background->borderWidth );
  91. }
  92. public function testRenderPieChartWithBackgroundBorder()
  93. {
  94. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  95. $chart = new ezcGraphPieChart();
  96. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  97. 'Mozilla' => 4375,
  98. 'IE' => 345,
  99. 'Opera' => 1204,
  100. 'wget' => 231,
  101. 'Safari' => 987,
  102. ) );
  103. $chart->background->border = '#000000';
  104. $chart->background->borderWidth = 1;
  105. $chart->driver = new ezcGraphSvgDriver();
  106. $chart->render( 500, 200, $filename );
  107. $this->compare(
  108. $filename,
  109. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  110. );
  111. }
  112. public function testRenderPieChartWithBigBackgroundBorder()
  113. {
  114. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  115. $chart = new ezcGraphPieChart();
  116. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  117. 'Mozilla' => 4375,
  118. 'IE' => 345,
  119. 'Opera' => 1204,
  120. 'wget' => 231,
  121. 'Safari' => 987,
  122. ) );
  123. $chart->background->border = '#000000';
  124. $chart->background->borderWidth = 5;
  125. $chart->driver = new ezcGraphSvgDriver();
  126. $chart->render( 500, 200, $filename );
  127. $this->compare(
  128. $filename,
  129. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  130. );
  131. }
  132. public function testRenderPieChartWithBackgroundBorderAndPadding()
  133. {
  134. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  135. $chart = new ezcGraphPieChart();
  136. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  137. 'Mozilla' => 4375,
  138. 'IE' => 345,
  139. 'Opera' => 1204,
  140. 'wget' => 231,
  141. 'Safari' => 987,
  142. ) );
  143. $chart->background->border = '#000000';
  144. $chart->background->borderWidth = 1;
  145. $chart->background->padding = 2;
  146. $chart->driver = new ezcGraphSvgDriver();
  147. $chart->render( 500, 200, $filename );
  148. $this->compare(
  149. $filename,
  150. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  151. );
  152. }
  153. public function testRenderPieChartWithBackgroundBorderAndMargin()
  154. {
  155. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  156. $chart = new ezcGraphPieChart();
  157. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  158. 'Mozilla' => 4375,
  159. 'IE' => 345,
  160. 'Opera' => 1204,
  161. 'wget' => 231,
  162. 'Safari' => 987,
  163. ) );
  164. $chart->background->border = '#000000';
  165. $chart->background->borderWidth = 1;
  166. $chart->background->margin = 3;
  167. $chart->driver = new ezcGraphSvgDriver();
  168. $chart->render( 500, 200, $filename );
  169. $this->compare(
  170. $filename,
  171. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  172. );
  173. }
  174. public function testRenderPieChartWithBackgroundBorderAll()
  175. {
  176. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  177. $chart = new ezcGraphPieChart();
  178. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  179. 'Mozilla' => 4375,
  180. 'IE' => 345,
  181. 'Opera' => 1204,
  182. 'wget' => 231,
  183. 'Safari' => 987,
  184. ) );
  185. $chart->background->border = '#000000';
  186. $chart->background->borderWidth = 2;
  187. $chart->background->padding = 3;
  188. $chart->background->margin = 3;
  189. $chart->driver = new ezcGraphSvgDriver();
  190. $chart->render( 500, 200, $filename );
  191. $this->compare(
  192. $filename,
  193. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  194. );
  195. }
  196. public function testRenderPieChartWithBackgroundBottomRight()
  197. {
  198. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  199. $chart = new ezcGraphPieChart();
  200. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  201. 'Mozilla' => 4375,
  202. 'IE' => 345,
  203. 'Opera' => 1204,
  204. 'wget' => 231,
  205. 'Safari' => 987,
  206. ) );
  207. $chart->background->color = '#FFFFFFDD';
  208. $chart->background->image = dirname( __FILE__ ) . '/data/ez.png';
  209. $chart->background->position = ezcGraph::BOTTOM | ezcGraph::RIGHT;
  210. $chart->driver = new ezcGraphSvgDriver();
  211. $chart->render( 500, 200, $filename );
  212. $this->compare(
  213. $filename,
  214. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  215. );
  216. }
  217. public function testRenderPieChartWithTextureBackground()
  218. {
  219. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  220. $chart = new ezcGraphPieChart();
  221. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  222. 'Mozilla' => 4375,
  223. 'IE' => 345,
  224. 'Opera' => 1204,
  225. 'wget' => 231,
  226. 'Safari' => 987,
  227. ) );
  228. $chart->background->color = '#FFFFFFDD';
  229. $chart->background->image = dirname( __FILE__ ) . '/data/texture.png';
  230. $chart->background->repeat = ezcGraph::HORIZONTAL | ezcGraph::VERTICAL;
  231. $chart->driver = new ezcGraphSvgDriver();
  232. $chart->render( 500, 200, $filename );
  233. $this->compare(
  234. $filename,
  235. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  236. );
  237. }
  238. public function testRenderPieChartWithBackgroundBottomCenter()
  239. {
  240. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  241. $chart = new ezcGraphPieChart();
  242. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  243. 'Mozilla' => 4375,
  244. 'IE' => 345,
  245. 'Opera' => 1204,
  246. 'wget' => 231,
  247. 'Safari' => 987,
  248. ) );
  249. $chart->background->color = '#FFFFFFDD';
  250. $chart->background->image = dirname( __FILE__ ) . '/data/ez.png';
  251. $chart->background->position = ezcGraph::BOTTOM | ezcGraph::CENTER;
  252. $chart->driver = new ezcGraphSvgDriver();
  253. $chart->renderer = new ezcGraphRenderer3d();
  254. $chart->render( 500, 200, $filename );
  255. $this->compare(
  256. $filename,
  257. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  258. );
  259. }
  260. public function testRenderPieChartWithHorizontalTextureBackground()
  261. {
  262. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  263. $chart = new ezcGraphPieChart();
  264. $chart->data['sample'] = new ezcGraphArrayDataSet( array(
  265. 'Mozilla' => 4375,
  266. 'IE' => 345,
  267. 'Opera' => 1204,
  268. 'wget' => 231,
  269. 'Safari' => 987,
  270. ) );
  271. $chart->background->color = '#FFFFFFDD';
  272. $chart->background->image = dirname( __FILE__ ) . '/data/texture.png';
  273. $chart->background->repeat = ezcGraph::HORIZONTAL;
  274. $chart->background->position = ezcGraph::BOTTOM;
  275. $chart->driver = new ezcGraphSvgDriver();
  276. $chart->renderer = new ezcGraphRenderer3d();
  277. $chart->render( 500, 200, $filename );
  278. $this->compare(
  279. $filename,
  280. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  281. );
  282. }
  283. }
  284. ?>