Skip to content

Instantly share code, notes, and snippets.

@pumatertion
Created March 8, 2014 14:37
Show Gist options
  • Save pumatertion/9431429 to your computer and use it in GitHub Desktop.
Save pumatertion/9431429 to your computer and use it in GitHub Desktop.
<?php
/* *
* This script belongs to the TYPO3 Flow package "BLEICKER.ArtManager.Structure". *
* *
* */
namespace BLEICKER\ArtManager\Structure\Tests\Functional\Domain\Model;
use BLEICKER\ArtManager\Structure\Domain\Model\Artist;
use BLEICKER\ArtManager\Structure\Domain\Model\Company;
use BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection;
use BLEICKER\ArtManager\Structure\Domain\Repository\PartyCollectionRepository;
use BLEICKER\ArtManager\Structure\Domain\Repository\PartyRepository;
/**
* Testcase for PartyCollection
*
* @group large
*/
class PartyCollectionTest extends \TYPO3\Flow\Tests\FunctionalTestCase {
static protected $testablePersistenceEnabled = TRUE;
/**
* @var PartyCollectionRepository
*/
protected $partyCollectionRepository;
/**
* @var PartyRepository
*/
protected $partyRepository;
/**
* Sets up test requirements depending on the enabled tests.
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->partyCollectionRepository = $this->objectManager->get('BLEICKER\ArtManager\Structure\Domain\Repository\PartyCollectionRepository');
$this->partyRepository = $this->objectManager->get('BLEICKER\ArtManager\Structure\Domain\Repository\PartyRepository');
}
/**
* @test
*/
public function simplePartyCollectionWorks() {
$partyCollection = new PartyCollection();
$partyCollection->setAlias('PartyCollection')->setWorkspace('Acme.Foo')->setId('1');
$this->persistenceManager->add($partyCollection);
$this->persistenceManager->persistAll();
$persistedPartyCollection = $this->persistenceManager->getObjectByIdentifier(array('id' => '1', 'workspace' => 'Acme.Foo'), 'BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection');
$this->assertInstanceOf('BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection', $persistedPartyCollection);
}
/**
* @test
*/
public function partyCollectionWithI18nWorks() {
$partyCollectionI18n = new \BLEICKER\ArtManager\Structure\Domain\Model\I18n\PartyCollection();
$partyCollectionI18n->setAlias('PartyCollection EN')->setLocale('de_DE');
$partyCollection = new PartyCollection();
$partyCollection->setAlias('PartyCollection')->setWorkspace('Acme.Foo')->setId('1')->attachI18n($partyCollectionI18n);
$this->persistenceManager->add($partyCollection);
$this->persistenceManager->persistAll();
/** @var PartyCollection $persistedPartyCollection */
$persistedPartyCollection = $this->persistenceManager->getObjectByIdentifier(array('id' => '1', 'workspace' => 'Acme.Foo'), 'BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection');
$this->assertEquals(1, $persistedPartyCollection->getI18ns()->count());
$this->assertInstanceOf('BLEICKER\ArtManager\Structure\Domain\Model\I18n\PartyCollection', $persistedPartyCollection->getI18ns()->first());
}
/**
* @test
*/
public function partyCollectionCanHoldManyDifferentKindOfParties() {
$artist = new Artist();
$artist->setAlias('Artist 1')->setWorkspace('Acme.Foo')->setId('1');
$company = new Company();
$company->setAlias('Company 1')->setWorkspace('Acme.Foo')->setId('2');
$partyCollection = new PartyCollection();
$partyCollection->setAlias('PartyCollection')->setWorkspace('Acme.Foo')->setId('3')->attachParty($artist)->attachParty($company);
$this->persistenceManager->add($partyCollection);
$this->persistenceManager->persistAll();
/** @var PartyCollection $persistedPartyCollection */
$persistedPartyCollection = $this->persistenceManager->getObjectByIdentifier(array('id' => '3', 'workspace' => 'Acme.Foo'), 'BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection');
$this->assertEquals(2, $persistedPartyCollection->getParties()->count());
$this->assertInstanceOf('BLEICKER\ArtManager\Structure\Domain\Model\AbstractParty', $persistedPartyCollection->getParties()->first());
$this->assertInstanceOf('BLEICKER\ArtManager\Structure\Domain\Model\AbstractParty', $persistedPartyCollection->getParties()->next());
}
/**
* @test
*/
public function partyCollectionWithDifferentKindOfPartiesAndDifferentKindOfI18nsWorks() {
$artist = new Artist();
$artist->setAlias('Artist 1')->setWorkspace('Acme.Foo')->setId('1');
$artistI18n = $artist->newI18n();
$artistI18n->setAlias('Artist 1 DE')->setLocale('de_DE');
$artistI18n = $artist->newI18n();
$artistI18n->setAlias('Artist 1 US')->setLocale('en_US');
$company = new Company();
$company->setAlias('Company 1')->setWorkspace('Acme.Foo')->setId('2');
$companyI18n = $company->newI18n();
$companyI18n->setAlias('Company 1 DE')->setLocale('de_DE');
$companyI18n = $company->newI18n();
$companyI18n->setAlias('Company 1 US')->setLocale('en_US');
$partyCollection = new PartyCollection();
$partyCollection->setAlias('PartyCollection')->setWorkspace('Acme.Foo')->setId('3')->attachParty($artist)->attachParty($company);
$partyCollectionI18n = $partyCollection->newI18n();
$partyCollectionI18n->setAlias('PartyCollection 1 DE')->setLocale('de_DE');
$partyCollectionI18n = $partyCollection->newI18n();
$partyCollectionI18n->setAlias('PartyCollection 1 US')->setLocale('en_US');
$this->persistenceManager->add($partyCollection);
$this->persistenceManager->persistAll();
/** @var PartyCollection $persistedPartyCollection */
$persistedPartyCollection = $this->persistenceManager->getObjectByIdentifier(array('id' => '3', 'workspace' => 'Acme.Foo'), 'BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection');
$this->assertEquals(2, $persistedPartyCollection->getI18ns()->count());
$this->assertEquals(2, $persistedPartyCollection->getParties()->count());
$this->assertEquals(2, $persistedPartyCollection->getParties()->first()->getI18ns()->count());
$this->assertEquals(2, $persistedPartyCollection->getParties()->next()->getI18ns()->count());
}
/**
* @test
*/
public function partyCollectionWithSameForeignIdentitiesCanExistIfWorkspaceIsDifferent() {
$partyCollection1 = new PartyCollection();
$partyCollection1->setWorkspace('Acme.Foo')
->setAlias('Collection 1')
->setId('1');
$partyCollection2 = new PartyCollection();
$partyCollection2->setWorkspace('Acme.Bar')
->setAlias('Collection 2')
->setId('1');
$this->persistenceManager->add($partyCollection1);
$this->persistenceManager->add($partyCollection2);
$this->persistenceManager->persistAll();
$persistedPartyCollection1 = $this->persistenceManager->getObjectByIdentifier(array('id' => '1', 'workspace' => 'Acme.Foo'), 'BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection');
$persistedPartyCollection2 = $this->persistenceManager->getObjectByIdentifier(array('id' => '1', 'workspace' => 'Acme.Bar'), 'BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection');
$this->assertInstanceOf('BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection', $persistedPartyCollection1);
$this->assertInstanceOf('BLEICKER\ArtManager\Structure\Domain\Model\PartyCollection', $persistedPartyCollection2);
$this->assertEquals(2, $this->partyRepository->countAll());
$this->assertEquals(2, $this->partyCollectionRepository->countAll());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment