StyleTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Fabien
  5. * Date: 13/04/14
  6. * Time: 17:42
  7. */
  8. namespace Svg\Tests;
  9. use Svg\Style;
  10. use PHPUnit\Framework\TestCase;
  11. class StyleTest extends TestCase
  12. {
  13. public function test_parseColor()
  14. {
  15. $this->assertEquals("none", Style::parseColor("none"));
  16. $this->assertEquals(array(255, 0, 0), Style::parseColor("RED"));
  17. $this->assertEquals(array(0, 0, 255), Style::parseColor("blue"));
  18. $this->assertEquals(null, Style::parseColor("foo"));
  19. $this->assertEquals(array(0, 0, 0), Style::parseColor("black"));
  20. $this->assertEquals(array(255, 255, 255), Style::parseColor("white"));
  21. $this->assertEquals(array(0, 0, 0), Style::parseColor("#000000"));
  22. $this->assertEquals(array(255, 255, 255), Style::parseColor("#ffffff"));
  23. $this->assertEquals(array(0, 0, 0), Style::parseColor("rgb(0,0,0)"));
  24. $this->assertEquals(array(255, 255, 255), Style::parseColor("rgb(255,255,255)"));
  25. $this->assertEquals(array(0, 0, 0), Style::parseColor("rgb(0, 0, 0)"));
  26. $this->assertEquals(array(255, 255, 255), Style::parseColor("rgb(255, 255, 255)"));
  27. }
  28. public function test_fromAttributes()
  29. {
  30. $style = new Style();
  31. $attributes = array(
  32. "color" => "blue",
  33. "fill" => "#fff",
  34. "stroke" => "none",
  35. );
  36. $style->fromAttributes($attributes);
  37. $this->assertEquals(array(0, 0, 255), $style->color);
  38. $this->assertEquals(array(255, 255, 255), $style->fill);
  39. $this->assertEquals("none", $style->stroke);
  40. }
  41. public function test_convertSize()
  42. {
  43. $this->assertEquals(1, Style::convertSize(1));
  44. $this->assertEquals(10, Style::convertSize("10px")); // FIXME
  45. $this->assertEquals(10, Style::convertSize("10pt"));
  46. $this->assertEquals(8, Style::convertSize("80%", 10, 72));
  47. }
  48. }