StyleTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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("currentcolor", Style::parseColor("currentcolor"));
  17. $this->assertEquals(array(0.0, 0.0, 0.0, 0.0), Style::parseColor("transparent"));
  18. $this->assertEquals(array(255.0, 0.0, 0.0, 1.0), Style::parseColor("RED"));
  19. $this->assertEquals(array(0.0, 0.0, 255.0, 1.0), Style::parseColor("blue"));
  20. $this->assertEquals(array(0.0, 0.0, 0.0, 1.0), Style::parseColor("black"));
  21. $this->assertEquals(array(255.0, 255.0, 255.0, 1.0), Style::parseColor("white"));
  22. $this->assertEquals(null, Style::parseColor("foo"));
  23. $this->assertEquals(array(0.0, 0.0, 0.0, 1.0), Style::parseColor("#000000"));
  24. $this->assertEquals(array(255.0, 255.0, 255.0, 1.0), Style::parseColor("#ffffff"));
  25. $this->assertEquals(array(0.0, 0.0, 0.0, .5), Style::parseColor("#00000080"));
  26. $this->assertEquals(array(0.0, 0.0, 0.0, 1.0), Style::parseColor("rgb(0,0,0)"));
  27. $this->assertEquals(array(255.0, 255.0, 255.0, 1.0), Style::parseColor("rgb(255,255,255)"));
  28. $this->assertEquals(array(0.0, 0.0, 0.0, 1.0), Style::parseColor("rgb(0, 0, 0)"));
  29. $this->assertEquals(array(255.0, 255.0, 255.0, 1.0), Style::parseColor("rgb(255, 255, 255)"));
  30. $this->assertEquals(array(255.0, 255.0, 255.0, .5), Style::parseColor("rgb(255, 255, 255, .5)"));
  31. $this->assertEquals(array(255.0, 0.0, 0.0, 1.0), Style::parseColor("hsl(0, 100%, 50%)"));
  32. $this->assertEquals(array(255.0, 0.0, 0.0, .5), Style::parseColor("hsl(0, 100%, 50%, .5)"));
  33. }
  34. public function test_fromAttributes()
  35. {
  36. $style = new Style();
  37. $attributes = array(
  38. "color" => "blue",
  39. "fill" => "#fff",
  40. "stroke" => "none",
  41. );
  42. $style->fromAttributes($attributes);
  43. $this->assertEquals(array(0.0, 0.0, 255.0, 1.0), $style->color);
  44. $this->assertEquals(array(255.0, 255.0, 255.0, 1.0), $style->fill);
  45. $this->assertEquals("none", $style->stroke);
  46. }
  47. }