Permalink
Browse files

[Generator] [Versionable] Start fixing the tests

  • Loading branch information...
1 parent 06cb0da commit 64dca71f63ac7edef2d13263bbd997581b5f5524 @willdurand willdurand committed Jan 13, 2013
@@ -17,21 +17,19 @@
* Keeps tracks of all the modifications in an ActiveRecord object
*
* @author Francois Zaninotto
- * @version $Revision$
- * @package propel.generator.behavior.versionable
*/
class VersionableBehavior extends Behavior
{
// default parameters value
protected $parameters = array(
- 'version_column' => 'version',
- 'version_table' => '',
- 'log_created_at' => 'false',
- 'log_created_by' => 'false',
- 'log_comment' => 'false',
+ 'version_column' => 'version',
+ 'version_table' => '',
+ 'log_created_at' => 'false',
+ 'log_created_by' => 'false',
+ 'log_comment' => 'false',
'version_created_at_column' => 'version_created_at',
'version_created_by_column' => 'version_created_by',
- 'version_comment_column' => 'version_comment'
+ 'version_comment_column' => 'version_comment'
);
protected $versionTable;
@@ -264,13 +262,4 @@ public function getQueryBuilderModifier()
return $this->queryBuilderModifier;
}
-
- public function getPeerBuilderModifier()
- {
- if (null === $this->peerBuilderModifier) {
- $this->peerBuilderModifier = new VersionableBehaviorPeerBuilderModifier($this);
- }
-
- return $this->peerBuilderModifier;
- }
}
@@ -25,8 +25,6 @@ class VersionableBehaviorObjectBuilderModifier
protected $objectClassName;
- protected $peerClassName;
-
public function __construct($behavior)
{
$this->behavior = $behavior;
@@ -60,10 +58,9 @@ protected function getActiveRecordClassName()
protected function setBuilder($builder)
{
- $this->builder = $builder;
+ $this->builder = $builder;
$this->objectClassName = $builder->getObjectClassName();
- $this->queryClassName = $builder->getQueryClassName();
- $this->peerClassName = $builder->getPeerClassName();
+ $this->queryClassName = $builder->getQueryClassName();
}
/**
@@ -220,7 +217,8 @@ public function enforceVersioning()
protected function addIsVersioningNecessary(&$script)
{
- $peerClass = $this->builder->getPeerClassName();
+ $queryClassName = $this->builder->getQueryClassName();
+
$script .= "
/**
* Checks whether the current state must be recorded as a version
@@ -237,7 +235,7 @@ public function isVersioningNecessary(\$con = null)
return true;
}
- if ({$peerClass}::isVersioningEnabled() && (\$this->isNew() || \$this->isModified()) || \$this->isDeleted()) {
+ if ({$queryClassName}::isVersioningEnabled() && (\$this->isNew() || \$this->isModified()) || \$this->isDeleted()) {
return true;
}";
foreach ($this->behavior->getVersionableFks() as $fk) {
@@ -272,8 +270,9 @@ public function isVersioningNecessary(\$con = null)
protected function addAddVersion(&$script)
{
- $versionTable = $this->behavior->getVersionTable();
+ $versionTable = $this->behavior->getVersionTable();
$versionARClassName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($versionTable));
+
$script .= "
/**
* Creates a version of the current object and saves it.
@@ -357,11 +356,11 @@ protected function addPopulateFromVersion(&$script)
/**
* Sets the properties of the current object to the value they had at a specific version
*
- * @param {$versionARClassName} \$version The version object to use
- * @param ConnectionInterface \$con the connection to use
- * @param array \$loadedObjects objects thats been loaded in a chain of populateFromVersion calls on referrer or fk objects.
+ * @param {$versionARClassName} \$version The version object to use
+ * @param ConnectionInterface \$con the connection to use
+ * @param array \$loadedObjects objects thats been loaded in a chain of populateFromVersion calls on referrer or fk objects.
*
- * @return {$ARclassName} The current object (for fluent API support)
+ * @return {$ARclassName} The current object (for fluent API support)
*/
public function populateFromVersion(\$version, \$con = null, &\$loadedObjects = array())
{";
@@ -407,18 +406,19 @@ public function populateFromVersion(\$version, \$con = null, &\$loadedObjects =
$fkColumnIds = $this->behavior->getReferrerIdsColumn($fk);
$fkColumnVersions = $this->behavior->getReferrerVersionsColumn($fk);
$relatedVersionQueryClassName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubQueryBuilder($foreignVersionTable));
- $relatedVersionPeerClassName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubPeerBuilder($foreignVersionTable));
+ $relatedVersionTableMapClassName = $this->builder->getTableMapClassName();
$relatedClassName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($foreignTable));
$fkColumn = $fk->getForeignColumn();
$fkVersionColumn = $foreignVersionTable->getColumn($this->behavior->getParameter('version_column'));
+
$script .= "
if (\$fkValues = \$version->get{$fkColumnIds->getPhpName()}()) {
\$this->clear{$fkPhpNames}();
\$fkVersions = \$version->get{$fkColumnVersions->getPhpName()}();
\$query = {$relatedVersionQueryClassName}::create();
foreach (\$fkValues as \$key => \$value) {
- \$c1 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkColumn, $relatedVersionPeerClassName)}, \$value);
- \$c2 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkVersionColumn, $relatedVersionPeerClassName)}, \$fkVersions[\$key]);
+ \$c1 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkColumn, $relatedVersionTableMapClassName)}, \$value);
+ \$c2 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkVersionColumn, $relatedVersionTableMapClassName)}, \$fkVersions[\$key]);
\$c1->addAnd(\$c2);
\$query->addOr(\$c1);
}
@@ -668,7 +668,6 @@ protected function addGetLastVersions(&$script)
$fks = $versionTable->getForeignKeysReferencingTable($this->table->getName());
$relCol = $this->builder->getRefFKPhpNameAffix($fks[0], $plural = true);
$versionGetter = 'get'.$relCol;
- $versionPeer = $this->builder->getNewStubPeerBuilder($versionTable)->getClassName();
$script .= <<<EOF
/**
@@ -680,7 +679,7 @@ protected function addGetLastVersions(&$script)
public function getLastVersions(\$number = 10, \$criteria = null, \$con = null)
{
\$criteria = {$this->getVersionQueryClassName()}::create(null, \$criteria);
- \$criteria->addDescendingOrderByColumn({$versionPeer}::VERSION);
+ \$criteria->addDescendingOrderByColumn({$versionARClassName}::VERSION);
\$criteria->limit(\$number);
return \$this->{$versionGetter}(\$criteria, \$con);
@@ -1,80 +0,0 @@
-<?php
-
-/**
- * This file is part of the Propel package.
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * @license MIT License
- */
-
-namespace Propel\Generator\Behavior\Versionable;
-
-/**
- * Behavior to add versionable columns and abilities
- *
- * @author François Zaninotto
- */
-class VersionableBehaviorPeerBuilderModifier
-{
- public function staticAttributes()
- {
- return "
-/**
- * Whether the versioning is enabled
- */
-static \$isVersioningEnabled = true;
-";
- }
-
- public function staticMethods()
- {
- $script = '';
- $this->addIsVersioningEnabled($script);
- $this->addEnableVersioning($script);
- $this->addDisableVersioning($script);
-
- return $script;
- }
-
- public function addIsVersioningEnabled(&$script)
- {
- $script .= "
-/**
- * Checks whether versioning is enabled
- *
- * @return boolean
- */
-static public function isVersioningEnabled()
-{
- return self::\$isVersioningEnabled;
-}
-";
- }
-
- public function addEnableVersioning(&$script)
- {
- $script .= "
-/**
- * Enables versioning
- */
-static public function enableVersioning()
-{
- self::\$isVersioningEnabled = true;
-}
-";
- }
-
- public function addDisableVersioning(&$script)
- {
- $script .= "
-/**
- * Disables versioning
- */
-static public function disableVersioning()
-{
- self::\$isVersioningEnabled = false;
-}
-";
- }
-}
@@ -18,15 +18,27 @@
class VersionableBehaviorQueryBuilderModifier
{
protected $behavior;
+
protected $table;
+
protected $builder;
+
protected $objectClassName;
- protected $peerClassName;
public function __construct($behavior)
{
$this->behavior = $behavior;
- $this->table = $behavior->getTable();
+ $this->table = $behavior->getTable();
+ }
+
+ public function queryAttributes()
+ {
+ return "
+/**
+ * Whether the versioning is enabled
+ */
+static \$isVersioningEnabled = true;
+";
}
protected function getParameter($key)
@@ -54,7 +66,6 @@ protected function setBuilder($builder)
$this->builder = $builder;
$this->objectClassName = $builder->getObjectClassName();
$this->queryClassName = $builder->getQueryClassName();
- $this->peerClassName = $builder->getPeerClassName();
}
/**
@@ -86,6 +97,11 @@ public function queryMethods($builder)
$this->addOrderByVersion($script);
}
+ $script .= $this->addIsVersioningEnabled();
+ $script .= $this->addEnableVersioning();
+ $script .= $this->addDisableVersioning();
+
+
return $script;
}
@@ -121,4 +137,45 @@ public function orderByVersion(\$order = Criteria::ASC)
}
";
}
+
+ protected function addIsVersioningEnabled()
+ {
+ return "
+/**
+ * Checks whether versioning is enabled
+ *
+ * @return boolean
+ */
+static public function isVersioningEnabled()
+{
+ return self::\$isVersioningEnabled;
+}
+";
+ }
+
+ protected function addEnableVersioning()
+ {
+ return "
+/**
+ * Enables versioning
+ */
+static public function enableVersioning()
+{
+ self::\$isVersioningEnabled = true;
+}
+";
+ }
+
+ protected function addDisableVersioning()
+ {
+ return "
+/**
+ * Disables versioning
+ */
+static public function disableVersioning()
+{
+ self::\$isVersioningEnabled = false;
+}
+";
+ }
}
@@ -1,11 +1,22 @@
<?php
+/**
+ * This file is part of the Propel package.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @license MIT License
+ */
+
namespace Propel\Tests\Generator\Behavior\NestedSet;
use Propel\Generator\Util\QuickBuilder;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Tests\TestCase as BaseTestCase;
+/**
+ * @author William Durand <william.durand1@gmail.com>
+ */
class TestCase extends BaseTestCase
{
protected $con;
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * This file is part of the Propel package.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @license MIT License
+ */
+
+namespace Propel\Tests\Generator\Behavior\Versionable;
+
+use Propel\Tests\TestCase as BaseTestCase;
+
+/**
+ * @author William Durand <william.durand1@gmail.com>
+ */
+class TestCase extends BaseTestCase
+{
+}
Oops, something went wrong.

0 comments on commit 64dca71

Please sign in to comment.