SpecificityTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\CssSelector\Tests\Node;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\CssSelector\Node\Specificity;
  13. class SpecificityTest extends TestCase
  14. {
  15. /** @dataProvider getValueTestData */
  16. public function testValue(Specificity $specificity, $value)
  17. {
  18. $this->assertEquals($value, $specificity->getValue());
  19. }
  20. /** @dataProvider getValueTestData */
  21. public function testPlusValue(Specificity $specificity, $value)
  22. {
  23. $this->assertEquals($value + 123, $specificity->plus(new Specificity(1, 2, 3))->getValue());
  24. }
  25. public function getValueTestData()
  26. {
  27. return array(
  28. array(new Specificity(0, 0, 0), 0),
  29. array(new Specificity(0, 0, 2), 2),
  30. array(new Specificity(0, 3, 0), 30),
  31. array(new Specificity(4, 0, 0), 400),
  32. array(new Specificity(4, 3, 2), 432),
  33. );
  34. }
  35. /** @dataProvider getCompareTestData */
  36. public function testCompareTo(Specificity $a, Specificity $b, $result)
  37. {
  38. $this->assertEquals($result, $a->compareTo($b));
  39. }
  40. public function getCompareTestData()
  41. {
  42. return array(
  43. array(new Specificity(0, 0, 0), new Specificity(0, 0, 0), 0),
  44. array(new Specificity(0, 0, 1), new Specificity(0, 0, 1), 0),
  45. array(new Specificity(0, 0, 2), new Specificity(0, 0, 1), 1),
  46. array(new Specificity(0, 0, 2), new Specificity(0, 0, 3), -1),
  47. array(new Specificity(0, 4, 0), new Specificity(0, 4, 0), 0),
  48. array(new Specificity(0, 6, 0), new Specificity(0, 5, 11), 1),
  49. array(new Specificity(0, 7, 0), new Specificity(0, 8, 0), -1),
  50. array(new Specificity(9, 0, 0), new Specificity(9, 0, 0), 0),
  51. array(new Specificity(11, 0, 0), new Specificity(10, 11, 0), 1),
  52. array(new Specificity(12, 11, 0), new Specificity(13, 0, 0), -1),
  53. );
  54. }
  55. }