Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/doctrine/phpcr-odm
Browse files Browse the repository at this point in the history
  • Loading branch information
pitpit committed Aug 27, 2012
2 parents f856490 + 11b721d commit 73cd262
Show file tree
Hide file tree
Showing 29 changed files with 488 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -11,9 +11,8 @@ env:
- TRANSPORT=midgard_mysql

before_script:
- wget -nc http://getcomposer.org/composer.phar
- ./tests/travis_${TRANSPORT}.sh
- php composer.phar install --dev
- composer install --dev

script: phpunit -c tests/phpunit_${TRANSPORT}.xml.dist

Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ODM/PHPCR/Document/Resource.php
Expand Up @@ -184,4 +184,14 @@ public function getLastModifiedBy()
{
return $this->lastModifiedBy;
}


/**
* get mime and encoding (RFC2045)
* @return string
*/
public function getMime()
{
return $this->getMimeType() . ($this->getEncoding() ? '; charset=' . $this->getEncoding() : '');
}
}
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/PHPCR/DocumentManager.php
Expand Up @@ -603,6 +603,10 @@ public function move($document, $targetPath)
throw new \InvalidArgumentException(gettype($document));
}

if (strpos($targetPath, '/') !== 0) {
$targetPath = '/'.$targetPath;
}

$this->errorIfClosed();
$this->unitOfWork->scheduleMove($document, $targetPath);
}
Expand Down
12 changes: 1 addition & 11 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
Expand Up @@ -344,7 +344,7 @@ public function setIdentifier($identifier)
/**
* Registers a custom repository class for the document class.
*
* @param string $mapperClassName The class name of the custom mapper.
* @param string $repositoryClassName The class name of the custom repository.
*/
public function setCustomRepositoryClassName($repositoryClassName)
{
Expand Down Expand Up @@ -425,16 +425,6 @@ public function setNodeType($nodeType)
$this->nodeType = $nodeType;
}

/**
* Registers a custom repository class for the document class.
*
* @param string $mapperClassName The class name of the custom mapper.
*/
public function setCustomRepositoryClass($repositoryClassName)
{
$this->customRepositoryClassName = $repositoryClassName;
}

/**
* Gets the ReflectionProperties of the mapped class.
*
Expand Down
31 changes: 24 additions & 7 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php
Expand Up @@ -68,12 +68,16 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$class->setCustomRepositoryClassName((string) $xmlRoot['repository-class']);
}

if (isset($xmlRoot['translator'])) {
$class->setTranslator((string) $xmlRoot['translator']);
}

if (isset($xmlRoot['versionable']) && $xmlRoot['versionable'] !== 'false') {
$class->setVersioned($xmlRoot['versionable']);
$class->setVersioned((string)$xmlRoot['versionable']);
}

if (isset($xmlRoot['referenceable']) && $xmlRoot['referenceable'] !== 'false') {
$class->setReferenceable($xmlRoot['referenceable']);
$class->setReferenceable((bool)$xmlRoot['referenceable']);
}

$class->setNodeType(isset($xmlRoot['nodeType']) ? (string) $xmlRoot['nodeType'] : 'nt:unstructured');
Expand Down Expand Up @@ -145,13 +149,26 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
}

// TODO: referrers, locale
if (isset($xmlRoot->locale)) {
$class->mapLocale(array('fieldName' => (string) $xmlRoot->locale->attributes()->fieldName));
}

if (isset($xmlRoot->versionname)) {
$class->mapVersionName(array('fieldName' => (string) $xmlRoot->versionname->attributes()->name));
if (isset($xmlRoot->referrers)) {
foreach ($xmlRoot->referrers as $referrers) {
$attributes = $referrers->attributes();
$mapping = array('fieldName' => (string) $attributes->fieldName);
$mapping['filter'] = isset($attributes['filter'])
? (string) $attributes->filter : null;
$mapping['referenceType'] = isset($attributes['reference-type'])
? (string) $attributes->{'reference-type'} : null;
$class->mapReferrers($mapping);
}
}
if (isset($xmlRoot->{'version-name'})) {
$class->mapVersionName(array('fieldName' => (string) $xmlRoot->{'version-name'}->attributes()->fieldName));
}
if (isset($xmlRoot->versioncreated)) {
$class->mapVersionCreated(array('fieldName' => (string) $xmlRoot->versionname->attributes()->name));
if (isset($xmlRoot->{'version-created'})) {
$class->mapVersionCreated(array('fieldName' => (string) $xmlRoot->{'version-created'}->attributes()->fieldName));
}

if (isset($xmlRoot->{'lifecycle-callbacks'})) {
Expand Down
22 changes: 21 additions & 1 deletion lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php
Expand Up @@ -68,10 +68,18 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$class->setCustomRepositoryClassName($element['repositoryClass']);
}

if (isset($element['translator'])) {
$class->setTranslator($element['translator']);
}

if (isset($element['versionable']) && $element['versionable']) {
$class->setVersioned($element['versionable']);
}

if (isset($element['referenceable']) && $element['referenceable']) {
$class->setReferenceable($element['referenceable']);
}

$class->setNodeType(isset($element['nodeType']) ? $element['nodeType'] : 'nt:unstructured');
} elseif ($element['type'] === 'mappedSuperclass') {
$class->isMappedSuperclass = true;
Expand Down Expand Up @@ -158,8 +166,20 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
}

// TODO: referrers, locale
if (isset($element['locale'])) {
$class->mapLocale(array('fieldName' => $element['locale']));
}

if (isset($element['referrers'])) {
foreach ($element['referrers'] as $name=>$attributes) {
$mapping = array('fieldName' => $name);
$mapping['filter'] = isset($attributes['filter'])
? $attributes['filter'] : null;
$mapping['referenceType'] = isset($attributes['referenceType'])
? $attributes['referenceType'] : null;
$class->mapReferrers($mapping);
}
}
if (isset($element['versionName'])) {
$class->mapVersionName(array('fieldName' => $element['versionName']));
}
Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Expand Up @@ -1121,6 +1121,13 @@ private function computeReferrerChanges($referrer)
*/
public function persistNew($class, $document, $overrideIdGenerator = null, $parent = null)
{
if (isset($class->lifecycleCallbacks[Event::prePersist])) {
$class->invokeLifecycleCallbacks(Event::prePersist, $document);
}
if ($this->evm->hasListeners(Event::prePersist)) {
$this->evm->dispatchEvent(Event::prePersist, new LifecycleEventArgs($document, $this->dm));
}

$generator = $overrideIdGenerator ? $overrideIdGenerator : $class->idGenerator;

$id = $this->getIdGenerator($generator)->generate($document, $class, $this->dm, $parent);
Expand All @@ -1129,13 +1136,6 @@ public function persistNew($class, $document, $overrideIdGenerator = null, $pare
if ($generator !== ClassMetadata::GENERATOR_TYPE_ASSIGNED) {
$class->setIdentifierValue($document, $id);
}

if (isset($class->lifecycleCallbacks[Event::prePersist])) {
$class->invokeLifecycleCallbacks(Event::prePersist, $document);
}
if ($this->evm->hasListeners(Event::prePersist)) {
$this->evm->dispatchEvent(Event::prePersist, new LifecycleEventArgs($document, $this->dm));
}
}

/**
Expand Down
144 changes: 144 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/Mapping/AbstractMappingDriverTest.php
Expand Up @@ -96,17 +96,29 @@ public function testFieldMappings($class)
{
$this->assertCount(12, $class->fieldMappings);
$this->assertTrue(isset($class->fieldMappings['string']));
$this->assertEquals('string', $class->fieldMappings['string']['type']);
$this->assertTrue(isset($class->fieldMappings['binary']));
$this->assertEquals('binary', $class->fieldMappings['binary']['type']);
$this->assertTrue(isset($class->fieldMappings['long']));
$this->assertEquals('long', $class->fieldMappings['long']['type']);
$this->assertTrue(isset($class->fieldMappings['int']));
$this->assertEquals('long', $class->fieldMappings['int']['type']);
$this->assertTrue(isset($class->fieldMappings['decimal']));
$this->assertEquals('decimal', $class->fieldMappings['decimal']['type']);
$this->assertTrue(isset($class->fieldMappings['double']));
$this->assertEquals('double', $class->fieldMappings['double']['type']);
$this->assertTrue(isset($class->fieldMappings['float']));
$this->assertEquals('double', $class->fieldMappings['float']['type']);
$this->assertTrue(isset($class->fieldMappings['date']));
$this->assertEquals('date', $class->fieldMappings['date']['type']);
$this->assertTrue(isset($class->fieldMappings['boolean']));
$this->assertEquals('boolean', $class->fieldMappings['boolean']['type']);
$this->assertTrue(isset($class->fieldMappings['name']));
$this->assertEquals('name', $class->fieldMappings['name']['type']);
$this->assertTrue(isset($class->fieldMappings['path']));
$this->assertEquals('path', $class->fieldMappings['path']['type']);
$this->assertTrue(isset($class->fieldMappings['uri']));
$this->assertEquals('uri', $class->fieldMappings['uri']['type']);

return $class;
}
Expand Down Expand Up @@ -374,8 +386,26 @@ public function testLoadVersionableMapping()
public function testVersionableMapping($class)
{
$this->assertEquals('simple', $class->versionable);
$this->assertEquals('versionName', $class->versionNameField);
$this->assertEquals('versionCreated', $class->versionCreatedField);
}

public function testLoadReferenceableMapping()
{
$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceableMappingObject';

return $this->loadMetadataForClassname($className);
}

/**
* @depends testLoadReferenceableMapping
* @param ClassMetadata $class
*/
public function testReferenceableMapping($class)
{
$this->assertTrue($class->referenceable);
}

public function testLoadNodeTypeMapping()
{
$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\NodeTypeMappingObject';
Expand Down Expand Up @@ -424,6 +454,39 @@ public function testNodeMapping($class)
$this->assertEquals('node', $class->node);
}

public function testLoadReferenceOneMapping()
{
$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceOneMappingObject';

return $this->loadMetadataForClassname($className);
}

/**
* @depends testLoadReferenceOneMapping
* @param ClassMetadata $class
*/
public function testReferenceOneMapping($class)
{
$this->assertEquals(2, count($class->associationsMappings));
$this->assertTrue(isset($class->associationsMappings['referenceOneWeak']));

$referenceOneWeak = $class->associationsMappings['referenceOneWeak'];
$this->assertEquals('referenceOneWeak', $referenceOneWeak['fieldName']);
$this->assertEquals('Doctrine\Tests\ODM\PHPCR\Mapping\Model\myDocument', $referenceOneWeak['targetDocument']);
$this->assertEquals('weak', $referenceOneWeak['strategy']);
$this->assertEquals('Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceOneMappingObject', $referenceOneWeak['sourceDocument']);
$this->assertEquals(ClassMetadata::MANY_TO_ONE, $referenceOneWeak['type']);

$referenceOneHard = $class->associationsMappings['referenceOneHard'];
$this->assertEquals('referenceOneHard', $referenceOneHard['fieldName']);
$this->assertEquals('Doctrine\Tests\ODM\PHPCR\Mapping\Model\myDocument', $referenceOneHard['targetDocument']);
$this->assertEquals('hard', $referenceOneHard['strategy']);
$this->assertEquals('Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceOneMappingObject', $referenceOneHard['sourceDocument']);
$this->assertEquals(ClassMetadata::MANY_TO_ONE, $referenceOneHard['type']);


}

public function testLoadReferenceManyMapping()
{
$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceManyMappingObject';
Expand Down Expand Up @@ -456,4 +519,85 @@ public function testReferenceManyMapping($class)


}

public function testLoadReferrersMapping()
{
$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferrersMappingObject';

return $this->loadMetadataForClassname($className);
}

/**
* @depends testLoadReferrersMapping
* @param ClassMetadata $class
*/
public function testReferrersMapping($class)
{
$all = $class->referrersMappings['allReferrers'];
$this->assertEquals('allReferrers', $all['fieldName']);
$this->assertEquals('allReferrers', $all['name']);
$this->assertEmpty($all['filter']);
$this->assertNull($all['referenceType']);

$filtered = $class->referrersMappings['filteredReferrers'];
$this->assertEquals('filteredReferrers', $filtered['fieldName']);
$this->assertEquals('filteredReferrers', $filtered['name']);
$this->assertEquals('test_filter', $filtered['filter']);
$this->assertEmpty($filtered['referenceType']);

$hard = $class->referrersMappings['hardReferrers'];
$this->assertEquals('hardReferrers', $hard['fieldName']);
$this->assertEquals('hardReferrers', $hard['name']);
$this->assertEmpty($hard['filter']);
$this->assertEquals('hard', $hard['referenceType']);

$weak = $class->referrersMappings['weakReferrers'];
$this->assertEquals('weakReferrers', $weak['fieldName']);
$this->assertEquals('weakReferrers', $weak['name']);
$this->assertEmpty($weak['filter']);
$this->assertEquals('weak', $weak['referenceType']);
}

public function testLoadTranslatorMapping()
{
$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\TranslatorMappingObject';

return $this->loadMetadataForClassname($className);
}

/**
* @depends testLoadTranslatorMapping
* @param ClassMetadata $class
*/
public function testTranslatorMapping($class)
{
$this->assertEquals('attribute', $class->translator);
$this->assertEquals('doclocale', $class->localeMapping);
$this->assertEquals(2, count($class->translatableFields));
$this->assertContains('topic', $class->translatableFields);
$this->assertContains('image', $class->translatableFields);
}

public function testLoadLifecycleCallbackMapping()
{
$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\LifecycleCallbackMappingObject';

return $this->loadMetadataForClassname($className);
}

/**
* @depends testLoadLifecycleCallbackMapping
* @param ClassMetadata $class
*/
public function testLifecycleCallbackMapping($class)
{
$this->assertEquals(7, count($class->lifecycleCallbacks));
$this->assertEquals('preRemoveFunc', $class->lifecycleCallbacks['preRemove'][0]);
$this->assertEquals('postRemoveFunc', $class->lifecycleCallbacks['postRemove'][0]);
$this->assertEquals('prePersistFunc', $class->lifecycleCallbacks['prePersist'][0]);
$this->assertEquals('postPersistFunc', $class->lifecycleCallbacks['postPersist'][0]);
$this->assertEquals('preUpdateFunc', $class->lifecycleCallbacks['preUpdate'][0]);
$this->assertEquals('postUpdateFunc', $class->lifecycleCallbacks['postUpdate'][0]);
$this->assertEquals('postLoadFunc', $class->lifecycleCallbacks['postLoad'][0]);
}
}

0 comments on commit 73cd262

Please sign in to comment.