|
2 | 2 |
|
3 | 3 | namespace Sabberworm\CSS\Tests\CSSList;
|
4 | 4 |
|
| 5 | +use Generator; |
5 | 6 | use PHPUnit\Framework\TestCase;
|
6 | 7 | use Sabberworm\CSS\Comment\Commentable;
|
7 | 8 | use Sabberworm\CSS\CSSList\Document;
|
@@ -85,4 +86,72 @@ public function setContentsReplacesContentsSetInPreviousCall()
|
85 | 86 |
|
86 | 87 | self::assertSame($contents2, $this->subject->getContents());
|
87 | 88 | }
|
| 89 | + |
| 90 | + /** |
| 91 | + * @return Generator |
| 92 | + */ |
| 93 | + public static function insertDataProvider(): Generator |
| 94 | + { |
| 95 | + |
| 96 | + $bogusOne = new DeclarationBlock(); |
| 97 | + $bogusOne->setSelectors('.bogus-one'); |
| 98 | + $bogusTwo = new DeclarationBlock(); |
| 99 | + $bogusTwo->setSelectors('.bogus-two'); |
| 100 | + |
| 101 | + $oItem = new DeclarationBlock(); |
| 102 | + $oItem->setSelectors('.item'); |
| 103 | + |
| 104 | + $oSibling = new DeclarationBlock(); |
| 105 | + $oSibling->setSelectors('.sibling'); |
| 106 | + |
| 107 | + $oOrphan = new DeclarationBlock(); |
| 108 | + $oOrphan->setSelectors('.forever-alone'); |
| 109 | + |
| 110 | + yield 'insert before' => [ |
| 111 | + 'initialContent' => [$bogusOne, $oSibling, $bogusTwo], |
| 112 | + 'oItem' => $oItem, |
| 113 | + 'oSibling' => $oSibling, |
| 114 | + 'position' => 'before', |
| 115 | + 'expectedContent' => [$bogusOne, $oItem, $oSibling, $bogusTwo], |
| 116 | + ]; |
| 117 | + yield 'insert after' => [ |
| 118 | + 'initialContent' => [$bogusOne, $oSibling, $bogusTwo], |
| 119 | + 'oItem' => $oItem, |
| 120 | + 'oSibling' => $oSibling, |
| 121 | + 'position' => 'after', |
| 122 | + 'expectedContent' => [$bogusOne, $oSibling, $oItem, $bogusTwo], |
| 123 | + ]; |
| 124 | + yield 'append if not found' => [ |
| 125 | + 'initialContent' => [$bogusOne, $oSibling, $bogusTwo], |
| 126 | + 'oItem' => $oItem, |
| 127 | + 'oSibling' => $oOrphan, |
| 128 | + 'position' => 'before', |
| 129 | + 'expectedContent' => [$bogusOne, $oSibling, $bogusTwo, $oItem], |
| 130 | + ]; |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * @test |
| 135 | + * |
| 136 | + * @param array $contents |
| 137 | + * |
| 138 | + * @dataProvider insertDataProvider |
| 139 | + */ |
| 140 | + public function insertContent( |
| 141 | + array $initialContent, |
| 142 | + DeclarationBlock $oItem, |
| 143 | + DeclarationBlock $oSibling, |
| 144 | + string $sPosition, |
| 145 | + array $expectedContent |
| 146 | + ) { |
| 147 | + |
| 148 | + $this->subject->setContents($initialContent); |
| 149 | + |
| 150 | + $this->assertCount(3, $this->subject->getContents()); |
| 151 | + |
| 152 | + $this->subject->insert($oItem, $oSibling, $sPosition); |
| 153 | + |
| 154 | + $this->assertCount(4, $this->subject->getContents()); |
| 155 | + $this->assertSame($expectedContent, $this->subject->getContents()); |
| 156 | + } |
88 | 157 | }
|
0 commit comments