SpecificityTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 [
  28. [new Specificity(0, 0, 0), 0],
  29. [new Specificity(0, 0, 2), 2],
  30. [new Specificity(0, 3, 0), 30],
  31. [new Specificity(4, 0, 0), 400],
  32. [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 [
  43. [new Specificity(0, 0, 0), new Specificity(0, 0, 0), 0],
  44. [new Specificity(0, 0, 1), new Specificity(0, 0, 1), 0],
  45. [new Specificity(0, 0, 2), new Specificity(0, 0, 1), 1],
  46. [new Specificity(0, 0, 2), new Specificity(0, 0, 3), -1],
  47. [new Specificity(0, 4, 0), new Specificity(0, 4, 0), 0],
  48. [new Specificity(0, 6, 0), new Specificity(0, 5, 11), 1],
  49. [new Specificity(0, 7, 0), new Specificity(0, 8, 0), -1],
  50. [new Specificity(9, 0, 0), new Specificity(9, 0, 0), 0],
  51. [new Specificity(11, 0, 0), new Specificity(10, 11, 0), 1],
  52. [new Specificity(12, 11, 0), new Specificity(13, 0, 0), -1],
  53. ];
  54. }
  55. }