Development

Changeset 7443

You must first sign up to be able to contribute.

Changeset 7443

Show
Ignore:
Timestamp:
02/09/08 22:12:13 (10 months ago)
Author:
francois
Message:

sfPropelVersionableBehaviorPlugin Fixed two bugs (and added unit tests for them)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelVersionableBehaviorPlugin/trunk/README

    r7406 r7443  
    304304== Changelog == 
    305305 
    306 === 2008-02-08 | Trunk === 
     306=== 2008-02-09 | Trunk === 
    307307 
    308308 * francois: Added `getCurrentResourceVersion`, `setResourceCreatedBy`, `getResourceCreatedBy`, `setResourceComment` and `getResourceComment` methods to the public API 
  • plugins/sfPropelVersionableBehaviorPlugin/trunk/lib/sfPropelVersionableBehavior.class.php

    r7406 r7443  
    173173    } 
    174174    self::incrementVersion($resource); 
     175    if(!$createdBy && isset($resource->versionCreatedBy) && $resource->versionCreatedBy != '') 
     176    { 
     177      $createdBy = $resource->versionCreatedBy; 
     178      $resource->versionCreatedBy = ''; 
     179    } 
     180    if(!$comment && isset($resource->versionComment) && $resource->versionComment != '') 
     181    { 
     182      $comment = $resource->versionComment; 
     183      $resource->versionComment = ''; 
     184    } 
    175185    self::createResourceVersion($resource, $createdBy, $comment); 
    176186  } 
     
    222232  public function getVersionComment(BaseObject $resource) 
    223233  { 
    224     if(isset($resource->versionComment)
     234    if(isset($resource->versionComment) && $resource->versionComment
    225235    { 
    226236      return $resource->versionComment; 
     
    253263  public function getVersionCreatedBy(BaseObject $resource) 
    254264  { 
    255     if(isset($resource->versionCreatedBy)
     265    if(isset($resource->versionCreatedBy) && $resource->versionCreatedBy
    256266    { 
    257267      return $resource->versionCreatedBy; 
     
    300310    if (self::versionConditionMet($resource)) 
    301311    { 
    302       self::createResourceVersion($resource, isset($resource->versionCreatedBy) ? $resource->versionCreatedBy : '', isset($resource->versionComment) ? $resource->versionComment : ''); 
     312      $createdBy = ''; 
     313      $comment = ''; 
     314      if(isset($resource->versionCreatedBy) && $resource->versionCreatedBy != '') 
     315      { 
     316        $createdBy = $resource->versionCreatedBy; 
     317        $resource->versionCreatedBy = ''; 
     318      } 
     319      if(isset($resource->versionComment) && $resource->versionComment != '') 
     320      { 
     321        $comment = $resource->versionComment; 
     322        $resource->versionComment = ''; 
     323      } 
     324      self::createResourceVersion($resource, $createdBy, $comment); 
    303325    } 
    304326    if(isset($resource->resourceVersion) && $resource->resourceVersion instanceOf ResourceVersion) 
  • plugins/sfPropelVersionableBehaviorPlugin/trunk/test/unit/PropelVersionableBehaviorTest.php

    r7406 r7443  
    7878)))); 
    7979 
    80 $t = new lime_test(43, new lime_output_color()); 
     80$t = new lime_test(49, new lime_output_color()); 
    8181 
    8282// save() 
     
    125125$t->is($r2->getVersionCreatedBy(), 'foo', 'getVersionCreatedBy() returns the creation date of the revision'); 
    126126$t->is($r3->getVersionCreatedBy(), 'foo', 'getVersionCreatedBy() is a proxy method for getCurrentResourceVersion()->getCreatedBy()'); 
    127 $t->is($r2->getLastResourceVersion()->getComment(), 'bar', 'setVersionComment() defines the comment to be saved in the ResourceVersion object'); 
     127$t->is($r2->getCurrentResourceVersion()->getComment(), 'bar', 'setVersionComment() defines the comment to be saved in the ResourceVersion object'); 
    128128$t->is($r2->getVersionComment(), 'bar', 'getVersionComment() is a proxy method for getCurrentResourceVersion()->getComment()'); 
    129129$t->is($r3->getVersionComment(), 'bar', 'getVersionComment() is a proxy method for getCurrentResourceVersion()->getComment()'); 
     130$r2->setByName($test_class_title_column, 'v0', BasePeer::TYPE_FIELDNAME); 
     131$r2->save(); 
     132$resourceVersion = $r2->getCurrentResourceVersion(); 
     133$t->is($resourceVersion->getCreatedBy(), '', 'setVersionCreatedBy() only affects the next version saved'); 
     134$t->is($resourceVersion->getComment(), '', 'setVersionComment() only affects the next version saved'); 
    130135 
    131136// conditional versioning 
     
    153158{ 
    154159  $r2->setByName($test_class_title_column, 'v0', BasePeer::TYPE_FIELDNAME); 
    155   $r2->addVersion('author1'); 
     160  $r2->addVersion(); 
    156161  $r2->save(); 
    157162  $t->pass('calling addVersion() on an unsaved object does not throw an exception'); 
     
    160165} 
    161166$t->is($r2->getLastResourceVersion()->getNumber(), 1, 'addVersion() creates a version object even on unsaved objects'); 
     167 
     168$r2->setByName($test_class_title_column, 'v1', BasePeer::TYPE_FIELDNAME); 
     169$r2->setVersionCreatedBy('author2'); 
     170$r2->setVersionComment('baz'); 
     171$r2->addVersion(); 
     172$r2->save(); 
     173$resourceVersion = $r2->getCurrentResourceVersion(); 
     174$t->is($resourceVersion->getCreatedBy(), 'author2', 'addVersion() allows for use of setVersionCreatedBy()'); 
     175$t->is($resourceVersion->getComment(), 'baz', 'addVersion() allows for use of setVersionComment()'); 
     176 
     177$r2->setByName($test_class_title_column, 'v2', BasePeer::TYPE_FIELDNAME); 
     178$r2->addVersion('author3', 'bazz'); 
     179$r2->save(); 
     180$resourceVersion = $r2->getCurrentResourceVersion(); 
     181$t->is($resourceVersion->getCreatedBy(), 'author3', 'addVersion() accepts a version author name as first parameter'); 
     182$t->is($resourceVersion->getComment(), 'bazz', 'addVersion() accepts a version comment as second parameter'); 
    162183 
    163184