Author: caefer
Date: 2010-03-23 16:47:15 +0100 (Tue, 23 Mar 2010)
New Revision: 28719

Modified:
   
plugins/sfImageTransformExtraPlugin/trunk/lib/transforms/sfImageTransformManager.class.php
   
plugins/sfImageTransformExtraPlugin/trunk/test/unit/lib/transforms/sfImageTransformManagerTest.php
Log:
some more project independance and greater code coverage achieved

Modified: 
plugins/sfImageTransformExtraPlugin/trunk/lib/transforms/sfImageTransformManager.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/transforms/sfImageTransformManager.class.php
  2010-03-23 15:46:15 UTC (rev 28718)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/transforms/sfImageTransformManager.class.php
  2010-03-23 15:47:15 UTC (rev 28719)
@@ -116,6 +116,29 @@
   }
 
   /**
+   * Returns a adapter class of the specified type
+   * @access protected
+   * @param  string                          $name Name of the transformation 
to instantiate
+   * @return sfImageTransformAdapterAbstract
+   */
+  private function createAdapter($name)
+  {
+    $adapter_class = 'sfImageTransform' . $name . 'Adapter';
+
+    if (class_exists($adapter_class))
+    {
+      $adapter = new $adapter_class();
+    }
+    // Cannot find the adapter class so throw an exception
+    else
+    {
+      throw new sfImageTransformException(sprintf('Unsupported adapter: %s', 
$adapter_class));
+    }
+
+    return $adapter;
+  }
+
+  /**
    * Extends current transformation parameters by a callback
    *
    * This is needed for transformations that need certain objects in their 
parameters,
@@ -149,29 +172,6 @@
   }
 
   /**
-   * Returns a adapter class of the specified type
-   * @access protected
-   * @param  string                          $name Name of the transformation 
to instantiate
-   * @return sfImageTransformAdapterAbstract
-   */
-  private function createAdapter($name)
-  {
-    $adapter_class = 'sfImageTransform' . $name . 'Adapter';
-
-    if (class_exists($adapter_class))
-    {
-      $adapter = new $adapter_class;
-    }
-    // Cannot find the adapter class so throw an exception
-    else
-    {
-      throw new sfImageTransformException(sprintf('Unsupported adapter: %s', 
$adapter_class));
-    }
-
-    return $adapter;
-  }
-
-  /**
    * Callback function to extend/alter parameters as given in your 
thumbnailing.yml.
    *
    * This callback adds the resources path to an overlay image
@@ -205,12 +205,14 @@
         $filename = substr($filename, $pos+1);
       }
 
+      $pluginDirs = ProjectConfiguration::getActive()->getAllPluginPaths();
+      $pluginDir = $pluginDirs['sfImageTransformExtraPlugin'];
       $files = sfFinder::type('file')
         ->name($filename)
         ->maxdepth(1)
         ->in(array(
           sfConfig::get('sf_data_dir') . '/resources/'.$filepath,
-          sfConfig::get('sf_plugins_dir') . 
'/sfImageTransformExtraPlugin/data/example-resources/'.$filepath,
+          $pluginDir . '/data/example-resources/'.$filepath,
         ));
 
       if(0 == count($files))

Modified: 
plugins/sfImageTransformExtraPlugin/trunk/test/unit/lib/transforms/sfImageTransformManagerTest.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/test/unit/lib/transforms/sfImageTransformManagerTest.php
  2010-03-23 15:46:15 UTC (rev 28718)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/test/unit/lib/transforms/sfImageTransformManagerTest.php
  2010-03-23 15:47:15 UTC (rev 28719)
@@ -29,10 +29,34 @@
       'original' => array(
         'quality' => 100,
         'mime_type' => 'image/png',
-        'transformations' => array(),
+        'transformations' => array(
+          0 => array(
+            'adapter' => 'GD',
+            'transformation' => 'alphaMask',
+            'param' => array(
+              'mask' => 'masks/pattern.gif',
+            )
+          ),
+        ),
       )
     );
 
+  private $dummy_failing_formats = array(
+      'original' => array(
+        'quality' => 100,
+        'mime_type' => 'image/png',
+        'transformations' => array(
+          0 => array(
+            'adapter' => 'GD',
+            'transformation' => 'alphaMask',
+            'param' => array(
+              'mask' => 'masks/doesnotexist.gif',
+            )
+          ),
+        ),
+      )
+    );
+
   public function test__constructException()
   {
     try
@@ -51,10 +75,28 @@
     $this->assertType('sfImageTransformManager', $manager);
   }
 
+  /**
+   * @expectedException sfImageTransformExtraPluginConfigurationException
+   */
+  public function testGenerateWrongFormat()
+  {
+    $manager = new sfImageTransformManager($this->dummy_formats);
+    $this->assertType('sfImage', $manager->generate('sfImageSource://mock', 
'doesnotexist'));
+  }
+
+  /**
+   * @expectedException InvalidArgumentException
+   */
+  public function testGenerateIncompleteFormat()
+  {
+    $manager = new sfImageTransformManager($this->dummy_failing_formats);
+    $this->assertType('sfImage', $manager->generate('sfImageSource://mock', 
'original'));
+  }
+
   public function testGenerate()
   {
     $manager = new sfImageTransformManager($this->dummy_formats);
-    $this->assertType('sfImage', 
$manager->generate('sfImageSource://TestFile/file#1', 'original'));
+    $this->assertType('sfImage', $manager->generate('sfImageSource://mock', 
'original'));
   }
 
   protected function setUp()

-- 
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