|
19 | 19 | use Gedmo\Tests\IpTraceable\Fixture\Article;
|
20 | 20 | use Gedmo\Tests\IpTraceable\Fixture\Comment;
|
21 | 21 | use Gedmo\Tests\IpTraceable\Fixture\Type;
|
| 22 | +use Gedmo\Tests\TestIpAddressProvider; |
22 | 23 | use Gedmo\Tests\Tool\BaseTestCaseORM;
|
23 | 24 |
|
24 | 25 | /**
|
|
29 | 30 | final class IpTraceableTest extends BaseTestCaseORM
|
30 | 31 | {
|
31 | 32 | private const TEST_IP = '34.234.1.10';
|
| 33 | + private const TEST_PROVIDER_IP = '34.234.2.10'; |
| 34 | + |
| 35 | + private IpTraceableListener $listener; |
32 | 36 |
|
33 | 37 | protected function setUp(): void
|
34 | 38 | {
|
35 | 39 | parent::setUp();
|
36 | 40 |
|
37 |
| - $listener = new IpTraceableListener(); |
38 |
| - $listener->setIpValue(self::TEST_IP); |
| 41 | + $this->listener = new IpTraceableListener(); |
| 42 | + $this->listener->setIpValue(self::TEST_IP); |
39 | 43 |
|
40 | 44 | $evm = new EventManager();
|
41 |
| - $evm->addEventSubscriber($listener); |
| 45 | + $evm->addEventSubscriber($this->listener); |
42 | 46 |
|
43 | 47 | $this->getDefaultMockSqliteEntityManager($evm);
|
44 | 48 | }
|
@@ -116,6 +120,50 @@ public function testIpTraceable(): void
|
116 | 120 | static::assertSame(self::TEST_IP, $sport->getPublished());
|
117 | 121 | }
|
118 | 122 |
|
| 123 | + public function testIpTraceableWithProvider(): void |
| 124 | + { |
| 125 | + $this->listener->setIpAddressProvider(new TestIpAddressProvider(self::TEST_PROVIDER_IP)); |
| 126 | + |
| 127 | + $sport = new Article(); |
| 128 | + $sport->setTitle('Sport'); |
| 129 | + |
| 130 | + $sportComment = new Comment(); |
| 131 | + $sportComment->setMessage('hello'); |
| 132 | + $sportComment->setArticle($sport); |
| 133 | + $sportComment->setStatus(0); |
| 134 | + |
| 135 | + $this->em->persist($sport); |
| 136 | + $this->em->persist($sportComment); |
| 137 | + $this->em->flush(); |
| 138 | + $this->em->clear(); |
| 139 | + |
| 140 | + $sport = $this->em->getRepository(Article::class)->findOneBy(['title' => 'Sport']); |
| 141 | + static::assertSame(self::TEST_PROVIDER_IP, $sport->getCreated()); |
| 142 | + static::assertSame(self::TEST_PROVIDER_IP, $sport->getUpdated()); |
| 143 | + static::assertNull($sport->getPublished()); |
| 144 | + |
| 145 | + $sportComment = $this->em->getRepository(Comment::class)->findOneBy(['message' => 'hello']); |
| 146 | + static::assertSame(self::TEST_PROVIDER_IP, $sportComment->getModified()); |
| 147 | + static::assertNull($sportComment->getClosed()); |
| 148 | + |
| 149 | + $sportComment->setStatus(1); |
| 150 | + $published = new Type(); |
| 151 | + $published->setTitle('Published'); |
| 152 | + |
| 153 | + $sport->setTitle('Updated'); |
| 154 | + $sport->setType($published); |
| 155 | + $this->em->persist($sport); |
| 156 | + $this->em->persist($published); |
| 157 | + $this->em->persist($sportComment); |
| 158 | + $this->em->flush(); |
| 159 | + $this->em->clear(); |
| 160 | + |
| 161 | + $sportComment = $this->em->getRepository(Comment::class)->findOneBy(['message' => 'hello']); |
| 162 | + static::assertSame(self::TEST_PROVIDER_IP, $sportComment->getClosed()); |
| 163 | + |
| 164 | + static::assertSame(self::TEST_PROVIDER_IP, $sport->getPublished()); |
| 165 | + } |
| 166 | + |
119 | 167 | public function testForcedValues(): void
|
120 | 168 | {
|
121 | 169 | $sport = new Article();
|
|
0 commit comments