handle types and categories in a single select input

This commit is contained in:
2021-10-12 15:52:06 +02:00
parent 9eec15873e
commit 88d073b9a9
10 changed files with 323 additions and 78 deletions

View File

@@ -0,0 +1,92 @@
<?php
namespace Chill\ThirdParty\Tests\Entity;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use PHPUnit\Framework\TestCase;
class ThirdPartyTest extends TestCase
{
public function testAddingRemovingActivityTypes()
{
$tp = new ThirdParty();
$cat1 = new ThirdPartyCategory();
$cat2 = new ThirdPartyCategory();
$tp->addTypesAndCategories('type');
$tp->addTypesAndCategories($cat1);
$tp->addTypesAndCategories($cat2);
$this->assertTrue($tp->getCategories()->contains($cat1));
$this->assertTrue($tp->getCategories()->contains($cat2));
$this->assertCount(2, $tp->getCategories());
$this->assertCount(1, $tp->getTypes());
$this->assertContains('type', $tp->getTypes());
$this->assertCount(3, $tp->getTypesAndCategories());
$this->assertContains($cat1, $tp->getTypesAndCategories());
$this->assertContains($cat2, $tp->getTypesAndCategories());
$this->assertContains('type', $tp->getTypesAndCategories());
// remove type
$tp->removeTypesAndCategories('type');
$tp->removeTypesAndCategories($cat2);
$this->assertTrue($tp->getCategories()->contains($cat1),
"test that cat1 is still present");
$this->assertFalse($tp->getCategories()->contains($cat2));
$this->assertCount(1, $tp->getCategories());
$this->assertCount(0, $tp->getTypes());
$this->assertNotContains('type', $tp->getTypes());
$this->assertCount(1, $tp->getTypesAndCategories());
$this->assertContains($cat1, $tp->getTypesAndCategories());
$this->assertNotContains($cat2, $tp->getTypesAndCategories());
$this->assertNotContains('type', $tp->getTypesAndCategories());
}
public function testSyncingActivityTypes()
{
$tp = new ThirdParty();
$tp->setTypesAndCategories([
'type1',
'type2',
$cat1 = new ThirdPartyCategory(),
$cat2 = new ThirdPartyCategory()
]);
$this->assertTrue($tp->getCategories()->contains($cat1));
$this->assertTrue($tp->getCategories()->contains($cat2));
$this->assertCount(2, $tp->getCategories());
$this->assertCount(2, $tp->getTypes());
$this->assertContains('type1', $tp->getTypes());
$this->assertContains('type2', $tp->getTypes());
$this->assertCount(4, $tp->getTypesAndCategories());
$this->assertContains($cat1, $tp->getTypesAndCategories());
$this->assertContains($cat2, $tp->getTypesAndCategories());
$this->assertContains('type1', $tp->getTypesAndCategories());
$this->assertContains('type2', $tp->getTypesAndCategories());
$tp->setTypesAndCategories([$cat1, 'type1']);
$this->assertTrue($tp->getCategories()->contains($cat1));
$this->assertFalse($tp->getCategories()->contains($cat2));
$this->assertCount(1, $tp->getCategories());
$this->assertCount(1, $tp->getTypes());
$this->assertContains('type1', $tp->getTypes());
$this->assertNotContains('type2', $tp->getTypes());
$this->assertCount(2, $tp->getTypesAndCategories());
$this->assertContains($cat1, $tp->getTypesAndCategories());
$this->assertNotContains($cat2, $tp->getTypesAndCategories());
$this->assertContains('type1', $tp->getTypesAndCategories());
$this->assertNotContains('type2', $tp->getTypesAndCategories());
}
}