Author: Kris.Wallsmith
Date: 2010-02-12 14:31:30 +0100 (Fri, 12 Feb 2010)
New Revision: 27940

Added:
   branches/1.3/lib/plugins/sfPropelPlugin/test/unit/validator/
   
branches/1.3/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
   branches/1.4/lib/plugins/sfPropelPlugin/test/unit/validator/
   
branches/1.4/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
Modified:
   
branches/1.3/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
   branches/1.3/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php
   
branches/1.4/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
   branches/1.4/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php
Log:
[1.3, 1.4] fixed field name used when propel unique validator throws a 
non-global error (closes #8108)

Modified: 
branches/1.3/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
===================================================================
--- 
branches/1.3/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
     2010-02-12 12:56:50 UTC (rev 27939)
+++ 
branches/1.3/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
     2010-02-12 13:31:30 UTC (rev 27940)
@@ -42,7 +42,7 @@
    *
    *  * model:              The model class (required)
    *  * column:             The unique column name in Propel field name format 
(required)
-   *                        If the uniquess is for several columns, you can 
pass an array of field names
+   *                        If the uniqueness is for several columns, you can 
pass an array of field names
    *  * field               Field name used by the form, other than the column 
name
    *  * primary_key:        The primary key column name in Propel field name 
format (optional, will be introspected if not provided)
    *                        You can also pass an array if the table has 
several primary keys
@@ -77,6 +77,7 @@
     {
       $this->setOption('column', array($this->getOption('column')));
     }
+    $columns = $this->getOption('column');
 
     if (!is_array($field = $this->getOption('field')))
     {
@@ -85,12 +86,12 @@
     $fields = $this->getOption('field');
 
     $criteria = new Criteria();
-    foreach ($this->getOption('column') as $i => $column)
+    foreach ($columns as $i => $column)
     {
       $name = isset($fields[$i]) ? $fields[$i] : $column;
       if (!array_key_exists($name, $values))
       {
-        // one of the column has be removed from the form
+        // one of the columns has be removed from the form
         return $values;
       }
 
@@ -114,9 +115,7 @@
       throw $error;
     }
 
-    $columns = $this->getOption('column');
-
-    throw new sfValidatorErrorSchema($this, array($columns[0] => $error));
+    throw new sfValidatorErrorSchema($this, array(isset($fields[0]) ? 
$fields[0] : $columns[0] => $error));
   }
 
   /**

Modified: 
branches/1.3/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php
===================================================================
--- branches/1.3/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php 
2010-02-12 12:56:50 UTC (rev 27939)
+++ branches/1.3/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php 
2010-02-12 13:31:30 UTC (rev 27940)
@@ -1,5 +1,13 @@
 <?php
 
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
 $app = 'frontend';
 include dirname(__FILE__).'/../../bootstrap/functional.php';
 include $configuration->getSymfonyLibDir().'/vendor/lime/lime.php';

Added: 
branches/1.3/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
===================================================================
--- 
branches/1.3/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
                         (rev 0)
+++ 
branches/1.3/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
 2010-02-12 13:31:30 UTC (rev 27940)
@@ -0,0 +1,58 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+$app = 'frontend';
+include dirname(__FILE__).'/../../bootstrap/functional.php';
+include $configuration->getSymfonyLibDir().'/vendor/lime/lime.php';
+
+$t = new lime_test(2);
+
+// ->clean()
+$t->diag('->clean()');
+
+$validator = new sfValidatorPropelUnique(array('model' => 'Author', 'column' 
=> 'name'));
+
+$author = new Author();
+$author->setName('==NAME==');
+$author->save();
+
+try
+{
+  $validator->clean(array('name' => '==NAME=='));
+  $t->fail('->clean() throws an error on the column');
+}
+catch (sfValidatorErrorSchema $errors)
+{
+  $t->is(isset($errors['name']), true, '->clean() throws an error on the 
column');
+}
+catch (Exception $e)
+{
+  $t->fail('->clean() throws an error on the column');
+  $t->diag('    '.$e->getMessage());
+}
+
+$validator->setOption('field', 'author_name');
+
+try
+{
+  $validator->clean(array('author_name' => '==NAME=='));
+  $t->fail('->clean() throws an error on the field');
+}
+catch (sfValidatorErrorSchema $errors)
+{
+  $t->is(isset($errors['author_name']), true, '->clean() throws an error on 
the field');
+}
+catch (Exception $e)
+{
+  $t->fail('->clean() throws an error on the field');
+  $t->diag('    '.$e->getMessage());
+}
+
+$author->delete();


Property changes on: 
branches/1.3/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: 
branches/1.4/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
===================================================================
--- 
branches/1.4/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
     2010-02-12 12:56:50 UTC (rev 27939)
+++ 
branches/1.4/lib/plugins/sfPropelPlugin/lib/validator/sfValidatorPropelUnique.class.php
     2010-02-12 13:31:30 UTC (rev 27940)
@@ -42,7 +42,7 @@
    *
    *  * model:              The model class (required)
    *  * column:             The unique column name in Propel field name format 
(required)
-   *                        If the uniquess is for several columns, you can 
pass an array of field names
+   *                        If the uniqueness is for several columns, you can 
pass an array of field names
    *  * field               Field name used by the form, other than the column 
name
    *  * primary_key:        The primary key column name in Propel field name 
format (optional, will be introspected if not provided)
    *                        You can also pass an array if the table has 
several primary keys
@@ -77,6 +77,7 @@
     {
       $this->setOption('column', array($this->getOption('column')));
     }
+    $columns = $this->getOption('column');
 
     if (!is_array($field = $this->getOption('field')))
     {
@@ -85,12 +86,12 @@
     $fields = $this->getOption('field');
 
     $criteria = new Criteria();
-    foreach ($this->getOption('column') as $i => $column)
+    foreach ($columns as $i => $column)
     {
       $name = isset($fields[$i]) ? $fields[$i] : $column;
       if (!array_key_exists($name, $values))
       {
-        // one of the column has be removed from the form
+        // one of the columns has be removed from the form
         return $values;
       }
 
@@ -114,9 +115,7 @@
       throw $error;
     }
 
-    $columns = $this->getOption('column');
-
-    throw new sfValidatorErrorSchema($this, array($columns[0] => $error));
+    throw new sfValidatorErrorSchema($this, array(isset($fields[0]) ? 
$fields[0] : $columns[0] => $error));
   }
 
   /**

Modified: 
branches/1.4/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php
===================================================================
--- branches/1.4/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php 
2010-02-12 12:56:50 UTC (rev 27939)
+++ branches/1.4/lib/plugins/sfPropelPlugin/test/unit/form/sfFormPropelTest.php 
2010-02-12 13:31:30 UTC (rev 27940)
@@ -1,5 +1,13 @@
 <?php
 
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
 $app = 'frontend';
 include dirname(__FILE__).'/../../bootstrap/functional.php';
 include $configuration->getSymfonyLibDir().'/vendor/lime/lime.php';

Added: 
branches/1.4/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
===================================================================
--- 
branches/1.4/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
                         (rev 0)
+++ 
branches/1.4/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
 2010-02-12 13:31:30 UTC (rev 27940)
@@ -0,0 +1,58 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+$app = 'frontend';
+include dirname(__FILE__).'/../../bootstrap/functional.php';
+include $configuration->getSymfonyLibDir().'/vendor/lime/lime.php';
+
+$t = new lime_test(2);
+
+// ->clean()
+$t->diag('->clean()');
+
+$validator = new sfValidatorPropelUnique(array('model' => 'Author', 'column' 
=> 'name'));
+
+$author = new Author();
+$author->setName('==NAME==');
+$author->save();
+
+try
+{
+  $validator->clean(array('name' => '==NAME=='));
+  $t->fail('->clean() throws an error on the column');
+}
+catch (sfValidatorErrorSchema $errors)
+{
+  $t->is(isset($errors['name']), true, '->clean() throws an error on the 
column');
+}
+catch (Exception $e)
+{
+  $t->fail('->clean() throws an error on the column');
+  $t->diag('    '.$e->getMessage());
+}
+
+$validator->setOption('field', 'author_name');
+
+try
+{
+  $validator->clean(array('author_name' => '==NAME=='));
+  $t->fail('->clean() throws an error on the field');
+}
+catch (sfValidatorErrorSchema $errors)
+{
+  $t->is(isset($errors['author_name']), true, '->clean() throws an error on 
the field');
+}
+catch (Exception $e)
+{
+  $t->fail('->clean() throws an error on the field');
+  $t->diag('    '.$e->getMessage());
+}
+
+$author->delete();


Property changes on: 
branches/1.4/lib/plugins/sfPropelPlugin/test/unit/validator/sfValidatorPropelUniqueTest.php
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to