Author: Jonathan.Wage
Date: 2010-02-02 00:53:39 +0100 (Tue, 02 Feb 2010)
New Revision: 27404

Modified:
   plugins/sfSympalPlugin/trunk/config/app.yml
   
plugins/sfSympalPlugin/trunk/lib/doctrine/sfSympalDoctrineCollection.class.php
   
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
   
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentSlot.class.php
   
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAsset.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAssetTable.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/types/sfSympalAssetObject.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetSynchronizer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/modules/sympal_assets/templates/selectSuccess.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/linksSuccess.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
   plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
   plugins/sfSympalPlugin/trunk/test/unit/ContentTest.php
Log:
[1.4][sfSympalPlugin][1.0] Refactoring assets and links to be by slug instead 
of id


Modified: plugins/sfSympalPlugin/trunk/config/app.yml
===================================================================
--- plugins/sfSympalPlugin/trunk/config/app.yml 2010-02-01 23:52:32 UTC (rev 
27403)
+++ plugins/sfSympalPlugin/trunk/config/app.yml 2010-02-01 23:53:39 UTC (rev 
27404)
@@ -274,6 +274,10 @@
       sfSympalContentType:
         fields: [label]
         indexName: content_type_sluggable
+      sfSympalAsset:
+        fields: [path, name]
+        indexName: asset_sluggable
+        builder: [sfSympalAsset, slugBuilder]
 
     # Configure e-mail settings
     default_from_email_address: [email protected]

Modified: 
plugins/sfSympalPlugin/trunk/lib/doctrine/sfSympalDoctrineCollection.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/doctrine/sfSympalDoctrineCollection.class.php  
    2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/doctrine/sfSympalDoctrineCollection.class.php  
    2010-02-01 23:53:39 UTC (rev 27404)
@@ -2,4 +2,18 @@
 
 class sfSympalDoctrineCollection extends Doctrine_Collection
 {
+  public function getAllOfField($field)
+  {
+    $all = array();
+    foreach ($this as $key => $value)
+    {
+      $all[] = $value->get($field);
+    }
+    return $all;
+  }
+
+  public function getSlugs()
+  {
+    return $this->getAllOfField('slug');
+  }
 }
\ No newline at end of file

Modified: 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php 
    2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php 
    2010-02-01 23:53:39 UTC (rev 27404)
@@ -10,8 +10,9 @@
     $_route,
     $_routeObject,
     $_mainMenuItem,
-    $_editableSlotsExistOnPage = false;
-    
+    $_editableSlotsExistOnPage = false,
+    $_slotsByName = null;
+  
   /**
    * Initializes a new sfSympalContent for the given type
    * 
@@ -47,6 +48,19 @@
     return $content;
   }
 
+  public function construct()
+  {
+    foreach ($this->Slots as $slot)
+    {
+      $this->_slotsByName[$slot->name] = $slot;
+    }
+  }
+
+  public function getSlotsByName()
+  {
+    return $this->_slotsByName;
+  }
+
   public function setEditableSlotsExistOnPage($bool)
   {
     $this->_editableSlotsExistOnPage = $bool;
@@ -99,19 +113,19 @@
 
   public function hasSlot($name)
   {
-    return isset($this->Slots[$name]) ? true : false;
+    return isset($this->_slotsByName[$name]) ? true : false;
   }
 
   public function hasSlots()
   {
-    return count($this->Slots) > 0 ? true : false;
+    return count($this->_slotsByName) > 0 ? true : false;
   }
 
   public function getSlot($name)
   {
     if ($this->hasSlot($name))
     {
-      return $this->Slots[$name];
+      return $this->_slotsByName[$name];
     }
     return null;
   }
@@ -516,7 +530,7 @@
     return $this->_routeObject;
   }
 
-  public function getRoute($routeString = null, $path = null)
+  public function getRoute()
   {
     if (!$this->_route)
     {
@@ -530,12 +544,7 @@
         return $this->getRecord()->getRoute();
       }
 
-      if (is_null($routeString))
-      {
-        $routeString = $this->getRouteName();
-      }
-
-      $this->_route = $this->_fillRoute($routeString);
+      $this->_route = $this->_fillRoute($this->getRouteName());
     }
 
     return $this->_route;

Modified: 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentSlot.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentSlot.class.php
 2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentSlot.class.php
 2010-02-01 23:53:39 UTC (rev 27404)
@@ -24,6 +24,14 @@
     $this->_rendered = null;
   }
 
+  public function postUpdate($event)
+  {
+    if ($this->_contentRenderedFor)
+    {
+      $this->_contentRenderedFor->deleteLinkAndAssetReferences();
+    }
+  }
+
   public function getSlotEditFormRenderer()
   {
     $contentSlotTypes = sfSympalConfig::get('content_slot_types');

Modified: 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
        2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
        2010-02-01 23:53:39 UTC (rev 27404)
@@ -150,14 +150,16 @@
     $q = Doctrine_Query::create()
       ->from('sfSympalContent '.$alias)
       ->leftJoin($alias.'.Groups g')
-      ->leftJoin($alias.'.Slots s INDEXBY sl.name')
+      ->leftJoin($alias.'.Slots s')
       ->leftJoin($alias.'.MenuItem m')
       ->leftJoin($alias.'.Links l')
+      ->leftJoin('l.Type lt')
       ->leftJoin($alias.'.Assets a')
       ->leftJoin($alias.'.CreatedBy u')
       ->innerJoin($alias.'.Type t')
       ->innerJoin($alias.'.Site si')
-      ->andWhere('si.slug = ?', $sympalContext->getSiteSlug());
+      ->andWhere('si.slug = ?', $sympalContext->getSiteSlug())
+      ->orderBy('l.slug ASC, a.slug ASC');
 
     $user = sfContext::getInstance()->getUser();
 

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAsset.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAsset.class.php
      2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAsset.class.php
      2010-02-01 23:53:39 UTC (rev 27404)
@@ -50,7 +50,7 @@
 
   public function getEmbedCode()
   {
-    return sprintf('[asset:%s]', $this->getId());
+    return sprintf('[asset:%s]', $this->getSlug());
   }
 
   public function getAssetObject()
@@ -100,6 +100,24 @@
     copy($this->getPath(), $dir.'/'.$this->getName());
   }
 
+  public function fileExists()
+  {
+    return $this->getAssetObject()->exists();
+  }
+
+  public static function slugBuilder($text)
+  {
+    if (strpos($text, '.') !== false)
+    {
+      $e = explode('.', $text);
+      unset($e[count($e) - 1]);
+      $slug = implode('.', $e);
+    } else {
+      $slug = $text;
+    }
+    return Doctrine_Inflector::urlize($slug);
+  }
+
   public function __call($method, $arguments)
   {
     if (method_exists($this->getAssetObject(), $method))

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAssetTable.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAssetTable.class.php
 2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/doctrine/PluginsfSympalAssetTable.class.php
 2010-02-01 23:53:39 UTC (rev 27404)
@@ -7,7 +7,7 @@
   {
     return Doctrine_Core::getTable('sfSympalAsset')
       ->createQuery('a')
-      ->from('sfSympalAsset a INDEXBY a.name')
+      ->from('sfSympalAsset a')
       ->andWhere('a.path = ?', $path)
       ->execute();
   }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/types/sfSympalAssetObject.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/types/sfSympalAssetObject.class.php
 2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/model/types/sfSympalAssetObject.class.php
 2010-02-01 23:53:39 UTC (rev 27404)
@@ -25,7 +25,7 @@
 
   public function exists()
   {
-    return file_exists($this->getPath());
+    return $this->getPath() && file_exists($this->getPath());
   }
 
   public function getTypeFromExtension()

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
     2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
     2010-02-01 23:53:39 UTC (rev 27404)
@@ -3,8 +3,8 @@
 /**
  * Class responsible for actually processing the asset syntaxes:
  * 
- * [asset:1]
- * [asset:1 alt="my cool image"]
+ * [asset:my_file.gif]
+ * [asset:my_file.gif alt="my cool image"]
  * 
  * @package     sfSympalAssetsPlugin
  * @subpackage  replacer
@@ -23,9 +23,9 @@
     $assetObjects = $this->_getAssetObjects(array_keys($replacements));
     $assetObjects = self::_buildObjects($assetObjects);
     
-    foreach ($replacements as $id => $replacement)
+    foreach ($replacements as $slug => $replacement)
     {
-      $assetObject = $assetObjects[$id];
+      $assetObject = $assetObjects[$slug];
       $content = $assetObject->filterContent($content, 
$replacement['replace'], $replacement['options']);
     }
     
@@ -39,14 +39,17 @@
    * we have access to a sfSympalContent object to which we'll want to
    * relate these sfSympalAsset objects
    */
-  protected function _getAssetObjects($ids)
+  protected function _getAssetObjects($slugs)
   {
     if ($this->_replacer instanceof sfSympalContentSlotReplacer)
     {
       $sympalContent = $this->_replacer->getContent();
-      if (array_diff($ids, $sympalContent->Assets->getPrimaryKeys()) || 
array_diff($sympalContent->Assets->getPrimaryKeys(), $ids))
+      $currentSlugs = $sympalContent->Assets->getSlugs();
+      asort($slugs);
+
+      if (array_diff($slugs, $currentSlugs) || array_diff($currentSlugs, 
$slugs))
       {
-        $assetObjects = $this->_getQueryForAssetObjects($ids)->execute();
+        $assetObjects = $this->_getQueryForAssetObjects($slugs)->execute();
         
         foreach ($assetObjects as $assetObject)
         {
@@ -60,7 +63,7 @@
     }
     else
     {
-      return $this->_getQueryForAssetObjects($ids)->execute();
+      return $this->_getQueryForAssetObjects($slugs)->execute();
     }
   }
   
@@ -68,13 +71,14 @@
    * Returns the query that should be used if we need to query out
    * and get a collection of sfSympalContent objects
    */
-  protected function _getQueryForAssetObjects($ids)
+  protected function _getQueryForAssetObjects($slugs)
   {
     $q = Doctrine_Core::getTable('sfSympalAsset')
       ->createQuery()
       ->from('sfSympalAsset a')
-      ->whereIn('a.id', array_unique($ids));
-    
+      ->whereIn('a.slug', array_unique($slugs))
+      ->orderBy('a.slug ASC');
+
     return $q;
   }
 }
\ No newline at end of file

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetSynchronizer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetSynchronizer.class.php
       2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetSynchronizer.class.php
       2010-02-01 23:53:39 UTC (rev 27404)
@@ -37,10 +37,15 @@
     $path = str_replace($this->_path, null, $dir);
 
     $exists = Doctrine_Core::getTable('sfSympalAsset')->findByPath($path);
+    $keys = array();
+    foreach ($exists as $asset)
+    {
+      $keys[$asset->getName()] = $asset;
+    }
 
     foreach ($files as $file)
     {
-      if (!isset($exists[$file]))
+      if (!isset($keys[$file]))
       {
         $assetObject = 
sfSympalAssetToolkit::createAssetObject($path.'/'.$file);
         $doctrineAsset = new sfSympalAsset();
@@ -48,5 +53,14 @@
         $doctrineAsset->save();
       }
     }
+
+    // Remove assets that don't exist anymore on disk
+    foreach ($keys as $name => $asset)
+    {
+      if (!$asset->fileExists())
+      {
+        $asset->delete();
+      }
+    }
   }
 }
\ No newline at end of file

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/modules/sympal_assets/templates/selectSuccess.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/modules/sympal_assets/templates/selectSuccess.php
     2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/modules/sympal_assets/templates/selectSuccess.php
     2010-02-01 23:53:39 UTC (rev 27404)
@@ -46,7 +46,7 @@
     <?php endforeach ?>
 
     <?php foreach($assets as $asset): ?>
-      <li id="<?php echo $asset->getId() ?>" title="<?php echo 
$asset->getName() ?>" class="asset">
+      <li id="<?php echo $asset->getSlug() ?>" title="<?php echo 
$asset->getName() ?>" class="asset">
         <?php echo 
jq_link_to_remote(image_tag('/sfSympalPlugin/images/edit.png'), array(
             'url' => url_for('sympal_assets_edit_asset', $asset),
             'update' => 'sympal_assets_container',

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
   2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
   2010-02-01 23:53:39 UTC (rev 27404)
@@ -55,7 +55,7 @@
     $objects = new Doctrine_Collection($collection->getTable());
     foreach ($collection as $key => $value)
     {
-      $objects[$value->id] = $value;
+      $objects[$value->slug] = $value;
     }
 
     return $objects;

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
  2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
  2010-02-01 23:53:39 UTC (rev 27404)
@@ -98,9 +98,9 @@
         $typeKey = $types[$key];
         
         $e = explode(' ', $body);
-        $id = $e[0];
+        $slug = $e[0];
         
-        $replacements[$typeKey][$id] = array(
+        $replacements[$typeKey][$slug] = array(
           'options' => _parse_attributes(substr($body, strlen($e[0]))),
           'replace' => $matches[0][$key],
         );

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/linksSuccess.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/linksSuccess.php
      2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/linksSuccess.php
      2010-02-01 23:53:39 UTC (rev 27404)
@@ -45,7 +45,7 @@
 
         <?php foreach ($content as $c): ?>
           <?php $menuItem = $c->getMenuItem() ?>
-          <li id="<?php echo $c->getId() ?>"<?php if ($menuItem): ?> 
style="margin-left: <?php echo ($menuItem->getLevel() - ($parentMenuNode ? 
$parentMenuNode->getLevel() : 1)) * 15 ?>px;"<?php endif; ?>>
+          <li id="<?php echo $c->getSlug() ?>"<?php if ($menuItem): ?> 
style="margin-left: <?php echo ($menuItem->getLevel() - ($parentMenuNode ? 
$parentMenuNode->getLevel() : 1)) * 15 ?>px;"<?php endif; ?>>
             <?php if (!$menuItem || $menuItem->getNode()->isLeaf()): ?>
               <?php echo image_tag('/sfSympalPlugin/images/page.png') ?>
             <?php else: ?>

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
   2010-02-01 23:52:32 UTC (rev 27403)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
   2010-02-01 23:53:39 UTC (rev 27404)
@@ -23,9 +23,9 @@
     $contentObjects = $this->_getContentObjects(array_keys($replacements));
     $contentObjects = self::_buildObjects($contentObjects);
     
-    foreach ($replacements as $id => $replacement)
+    foreach ($replacements as $slug => $replacement)
     {
-      $contentObject = $contentObjects[$id];
+      $contentObject = $contentObjects[$slug];
       
       $urlOnly = isset($replacement['options']['url']) ? 
$replacement['options']['url'] : false;
       unset($replacement['options']['url']);
@@ -36,7 +36,7 @@
       }
       else
       {
-        $label = isset($replacement['options']['label']) ? 
$this->_replacer->replace($replacement['options']['label']) : 'Link to content 
id #'.$id;
+        $label = isset($replacement['options']['label']) ? 
$this->_replacer->replace($replacement['options']['label']) : 'Link to content 
'.$slug;
         unset($replacement['options']['label']);
         
         $content = str_replace($replacement['replace'], link_to($label, 
$contentObject->getRoute(), $replacement['options']), $content);
@@ -53,14 +53,17 @@
    * we have access to a sfSympalContent object to which we'll want to
    * relate these sfSympalContent objects
    */
-  protected function _getContentObjects($ids)
+  protected function _getContentObjects($slugs)
   {
     if ($this->_replacer instanceof sfSympalContentSlotReplacer)
     {
       $sympalContent = $this->_replacer->getContent();
-      if (array_diff($ids, $sympalContent->Links->getPrimaryKeys()) || 
array_diff($sympalContent->Links->getPrimaryKeys(), $ids))
+      $currentSlugs = $sympalContent->Links->getSlugs();
+      asort($slugs);
+
+      if (array_diff($slugs, $currentSlugs) || array_diff($currentSlugs, 
$slugs))
       {
-        $contentObjects = $this->_getQueryForContentObjects($ids)->execute();
+        $contentObjects = $this->_getQueryForContentObjects($slugs)->execute();
         
         foreach ($contentObjects as $contentObject)
         {
@@ -74,7 +77,7 @@
     }
     else
     {
-      return $this->_getQueryForContentObjects($ids)->execute();
+      return $this->_getQueryForContentObjects($slugs)->execute();
     }
   }
   
@@ -82,13 +85,17 @@
    * Returns the query that should be used if we need to query out
    * and get a collection of sfSympalContent objects
    */
-  protected function _getQueryForContentObjects($ids)
+  protected function _getQueryForContentObjects($slugs)
   {
     $q = Doctrine_Core::getTable('sfSympalContent')
       ->createQuery('c')
+      ->select('c.*, t.*')
       ->from('sfSympalContent c')
       ->innerJoin('c.Type t')
-      ->whereIn('c.id', array_unique($ids));
+      ->innerJoin('c.Site s')
+      ->whereIn('c.slug', array_unique($slugs))
+      ->andWhere('s.slug = ?', sfConfig::get('sf_app'))
+      ->orderBy('c.slug ASC');
 
     if (sfSympalConfig::isI18nEnabled('sfSympalContent'))
     {

Modified: 
plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
===================================================================
(Binary files differ)

Modified: plugins/sfSympalPlugin/trunk/test/unit/ContentTest.php
===================================================================
--- plugins/sfSympalPlugin/trunk/test/unit/ContentTest.php      2010-02-01 
23:52:32 UTC (rev 27403)
+++ plugins/sfSympalPlugin/trunk/test/unit/ContentTest.php      2010-02-01 
23:53:39 UTC (rev 27404)
@@ -3,8 +3,9 @@
 $app = 'sympal';
 require_once(dirname(__FILE__).'/../bootstrap/unit.php');
 
-$t = new lime_test(38, new lime_output_color());
+$t = new lime_test(17, new lime_output_color());
 
+// Setup sample content record and menu item to test with
 $user = new sfGuardUser();
 $user->first_name = 'test';
 $user->last_name = 'test';
@@ -21,117 +22,63 @@
 $content->title = 'Testing this out';
 $content->save();
 
-$t->is($content->sfSympalPage instanceof sfSympalPage, true);
-$t->is($content->sfSympalPage->title, 'Testing this out');
-
 $menuItem = new sfSympalMenuItem();
 $menuItem->name = 'test';
 $menuItem->RelatedContent = $content;
 $menuItem->Site = 
Doctrine_Core::getTable('sfSympalSite')->findOneBySlug('sympal');
 $menuItem->save();
-
 $content->save();
 
+// Test that $content was setup successfully
+$t->is($content->sfSympalPage instanceof sfSympalPage, true, 'Test that 
content type was instantiated properly');
+$t->is($content->sfSympalPage->title, 'Testing this out', 'Test that content 
type instance title was set from content record');
+
+// Query for new content
 $q = Doctrine_Core::getTable('sfSympalContent')
   ->getFullTypeQuery('sfSympalPage')
   ->andWhere('c.slug = ?', 'testing-this-out');
 
 $content = $q->fetchOne();
+$type = $content->getType();
+$site = $content->getSite();
 
-$t->is(isset($content['Type']), true);
-$t->is($content['Type']['name'], 'sfSympalPage');
-$t->is($content['Type']['label'], 'Page');
-$t->is(isset($content['Site']), true);
-$t->is($content['Site']['title'], 'Sympal');
-$t->is($content['Site']['slug'], 'sympal');
-$t->is(isset($content['sfSympalPage']), true);
-$t->is($content['slug'], 'testing-this-out');
+// Test type
+$t->is($type->getName(), 'sfSympalPage', 'Test content type name');
+$t->is($type->getLabel(), 'Page', 'Test content type label');
 
+// Test site
+$t->is($site->getTitle(), 'Sympal', 'Test site name');
+$t->is($site->getSlug(), 'sympal', 'Test site slug');
+
 $sfUser = sfContext::getInstance()->getUser();
 $sfUser->signIn($user);
 $sfUser->isEditMode(true);
 
-$content = $q->fetchOne();
+// Refresh content
+$content->refresh();
 
 $content->publish();
-$t->is(strtotime($content->date_published) > 0, true);
+$t->is(strtotime($content->date_published) > 0, true, 'Test content is 
published');
 
 $content->unpublish();
-$t->is(strtotime($content->date_published) > 0, false);
+$t->is(strtotime($content->date_published) > 0, false, 'Test content is 
unpublished');
+$t->is(strtotime($menuItem->date_published) > 0, false, 'Test menu item is 
unpublished');
 
-$content->date_published = new Doctrine_Expression('NOW()');
-$content->save();
-$content->free();
+$t->is($content->getTitle(), 'Testing this out', 'Test getting content type 
instance title from content');
+$t->is($content->getTemplateToRenderWith(), 'sympal_page/view', 'Test 
getTemplateToRenderWith()');
+$t->is($content->getHeaderTitle(), 'Testing this out', 'Test 
getHeaderTitle()');
+$t->is($content->getLayout(), null, 'Test getlayout()');
+$t->is($content->getRoute(), '@page?slug=testing-this-out', 'Test getRoute()');
 
-$content = $q->fetchOne();
+// Test getting and adding of slots
+$t->is($content->getSlots()->count(), 0, 'Test we have 0 slots');
 
-$t->is(strtotime($content->date_published) > 0, true);
-
-$menuItem = $content->getMenuItem();
-
-$t->is($menuItem->name, 'test');
-
-$page = $content->getRecord();
-$t->is($page instanceof sfSympalPage, true);
-$t->is($page->title, 'Testing this out');
-
-$template = $content->getTemplateToRenderWith();
-$t->is($template, 'sympal_page/view');
-
-$t->is($content->getTitle(), 'Testing this out');
-$t->is($content->getHeaderTitle(), 'Testing this out');
-
-$t->is($content->getLayout(), null);
-$t->is($content->getRoute(), '@page?slug=testing-this-out');
-
 get_sympal_content_slot($content, 'title', 'Text');
 get_sympal_content_slot($content, 'body', 'Markdown');
 get_sympal_content_slot($content, 'teaser', 'RawHtml');
 
-$content = $q->fetchOne();
+$content->refresh(true);
+$t->is($content->getSlots()->count(), 3, 'Test we have 3 slots');
 
-$slots = $content->getSlots();
-$slots['title']['value'] = 'Title value';
-$slots['body']['value'] = 'Body value';
-$slots['teaser']['value'] = "Body value<br />Testing";
-$slots->save();
-$content->save();
-
-$countBefore = count($slots);
-$slot = $content->getOrCreateSlot('title');
-$t->is($slot->name, 'title');
-$slot = $content->getOrCreateSlot('new');
-$t->is($slot->name, 'new');
-$t->is($slot->type, 'Text');
-
-$content = $q->fetchOne();
-
-$t->is(count($content->getSlots()), $countBefore + 1);
-
-$t->is($content->title, 'Title value');
-$t->is($slots['title']['value'], 'Title value');
-$t->is($slots['title']['type'], 'Text');
-$t->is($slots['title']['is_column'], true);
-$t->is($slots['body']['type'], 'Markdown');
-$t->is($slots['teaser']['type'], 'RawHtml');
-
-$t->is($slots['title']->render(), 'Title value');
-$t->is($slots['body']->render(), '<div class="sympal_markdown"><p>Body 
value</p>
-</div>');
-
-$slots['body']['value'] = "test";
-$t->is($slots['body']->render(), '<div class="sympal_markdown"><p>test</p>
-</div>');
-
-$slots->save();
-
-$slots[2]->type = 'MultiLineText';
-$t->is($slots['teaser']->render(), 'Body value<br />Testing');
-
-$content = sfSympalContent::createNew('sfSympalPage');
-
-$t->is($content->Type->name, 'sfSympalPage');
-$t->is(get_class($content->getRecord()), 'sfSympalPage');
-
-$content->title = 'test';
-$t->is($content->getRecord()->title, 'test');
\ No newline at end of file
+get_sympal_content_slot($content, 'title', 'Text');
+$t->is($content->getSlots()->count(), 3, 'Test we still have 3 slots');
\ No newline at end of file

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