Permalink
Browse files

regeneration flags added to collection/resource. test added for resource

  • Loading branch information...
fideloper committed Mar 29, 2013
1 parent 383c1ae commit c00a148d771d35234e9e1a4d6727f74c19ba6964
@@ -2,7 +2,7 @@
interface CollectionInterface {
public function getEtags();
public function getEtags($regen=false);
public function setCollectionName($name);
@@ -12,13 +12,13 @@ class Collection extends BaseCollection implements CollectionInterface {
*
* @return string md5 of all ETags
*/
public function getEtags()
public function getEtags($regen=false)
{
$etag = '';
foreach ( $this as $resource )
{
$etag .= $resource->getEtag();
$etag .= $resource->getEtag($regen);
}
return md5($etag);
@@ -2,7 +2,7 @@
interface ResourceInterface {
public function getEtag();
public function getEtag($regen=false);
public function setResourceName($name);
@@ -40,14 +40,58 @@ public function testGetEtag()
$id = $this->_randString(2);
$model->setAttribute($model->getKeyName(), $id);
// Get eTag when not generated
// Get eTag when not already generated
$expectedEtag = md5($table . $id . $datetime->format('Y-m-d H:i:s'));
$this->assertEquals( $expectedEtag , $model->getEtag() );
// Get eTag when is generated
$this->assertEquals( $expectedEtag, $model->getEtag() );
}
public function testRegenerateEtag()
{
$this->_mockConnectionAndStuff();
$model = new Resource;
// Of course you do...
$model->exists = true;
// Timestamps on in this case
$model->timestamps = true;
// Set updated_at to now
$datetime = new DateTime;
$model->updated_at = $datetime;
// Set table name
$table = $this->_randString();
$model->setTable($table);
// Set primary key
$id = $this->_randString(2);
$model->setAttribute($model->getKeyName(), $id);
// Get eTag when not already generated
$expectedEtag = md5($table . $id . $datetime->format('Y-m-d H:i:s'));
$this->assertEquals( $expectedEtag , $model->getEtag() , 'Original Etag still Generated Correctly' );
// Change updated_at date
$updateDatetime = new DateTime('@'.strtotime('+1 hour')); // Now, plus one hour ( the future! )
$model->updated_at = $updateDatetime;
// eTag should not have changed yet
$this->assertEquals( $expectedEtag , $model->getEtag() , 'eTag should remain the same until regenerated' );
// What the eTag should be now:
$newExpectedEtag = md5($table . $id . $updateDatetime->format('Y-m-d H:i:s'));
// eTag now should have change only after regeneration flag
$this->assertNotEquals( $newExpectedEtag , $model->getEtag() , 'eTag should still remain the same until regenerated' ); // Without regeneration
$this->assertEquals( $newExpectedEtag , $model->getEtag(true) , 'eTag recreated when regenerate flag used' ); // With regeneration
}
public function testCreateNewCollection()
{
$model = new Resource;

0 comments on commit c00a148

Please sign in to comment.