mirror of
https://github.com/jbcr/SyliusGDPRPlugin.git
synced 2026-03-24 17:02:19 +01:00
66 lines
2.6 KiB
PHP
66 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Synolia\SyliusGDPRPlugin\PHPUnit\Provider;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
use Synolia\SyliusGDPRPlugin\Provider\Anonymizer;
|
|
use Tests\Synolia\SyliusGDPRPlugin\PHPUnit\Fixtures\Foo;
|
|
use Tests\Synolia\SyliusGDPRPlugin\PHPUnit\Fixtures\YamlFoo;
|
|
|
|
final class AnonymizerTest extends KernelTestCase
|
|
{
|
|
private ?Anonymizer $anonymizer = null;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
self::bootKernel();
|
|
$this->anonymizer = static::getContainer()->get(Anonymizer::class);
|
|
}
|
|
|
|
public function testAnonymizeWithAnnotationAndYamlProperties(): void
|
|
{
|
|
$foo = new Foo();
|
|
$foo->email = 'contact@synolia.com';
|
|
$foo->bar = 'coucou';
|
|
|
|
$this->anonymizer->anonymize($foo, false, 10000);
|
|
|
|
$this->assertSame($foo->bar, 'coucou');
|
|
$this->assertSame('test-annonation-value', $foo->value);
|
|
$this->assertSame('test-annonation-value-without-property', $foo->valueWithoutProperty);
|
|
$this->assertStringContainsString('test-annotation-prefix-', $foo->prefix);
|
|
$this->assertStringContainsString('@', $foo->prefix);
|
|
$this->assertSame('test-annotation-prefix-value-value', $foo->prefixValue);
|
|
$this->assertNotSame('contact@synolia.com', $foo->email);
|
|
$this->assertNotSame('annotation', $foo->mergeYamlAnnotationConfiguration);
|
|
$this->assertStringContainsString('@', $foo->mergeYamlAnnotationConfiguration);
|
|
$this->assertStringContainsString('@', $foo->email);
|
|
$this->assertIsInt($foo->integer);
|
|
$this->assertIsArray($foo->arrayValue);
|
|
$this->assertCount(2, $foo->arrayValue);
|
|
$this->assertSame(15_421_542, $foo->integer);
|
|
}
|
|
|
|
public function testYamlConfig(): void
|
|
{
|
|
$foo = new YamlFoo();
|
|
$foo->email = 'contact@synolia.com';
|
|
$foo->bar = 'coucou';
|
|
$foo->setId((new \DateTime())->getTimestamp());
|
|
|
|
$this->anonymizer->anonymize($foo, false, 10000);
|
|
|
|
$this->assertStringContainsString('@', $foo->bar);
|
|
$this->assertSame('test-yaml-value', $foo->value);
|
|
$this->assertStringContainsString('test-yaml-prefix-', $foo->prefix);
|
|
$this->assertStringContainsString('@', $foo->prefix);
|
|
$this->assertSame('test-yaml-prefix-value', $foo->prefixValue);
|
|
$this->assertSame('anonymize@synolia.com', $foo->email);
|
|
$this->assertStringContainsString('@', $foo->email);
|
|
$this->assertNull($foo->nullValue);
|
|
$this->assertSame('anonymized-' . $foo->getId() . '@domain+1.xyz', $foo->dynamicValue);
|
|
}
|
|
}
|