Author: garak
Date: 2010-09-15 11:37:44 +0200 (Wed, 15 Sep 2010)
New Revision: 30911
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAsset.php
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetFolderPeer.php
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetPeer.php
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/sfAssetsLibraryTools.class.php
plugins/sfAssetsLibraryPlugin/branches/1.3/test/functional/sfAssetActionsTest.php
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderPeerTest.php
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderTest.php
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetPeerTest.php
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetTest.php
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetsLibraryToolsTest.php
Log:
[sfAssetsLibraryPlugin] added more compatibility with Windows. All tests
passing.
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAsset.php
===================================================================
---
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAsset.php
2010-09-14 22:00:06 UTC (rev 30910)
+++
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAsset.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -77,7 +77,7 @@
}
else
{
- $url .= sfAssetsLibraryTools::getThumbnailDir($relative_path) .
$thumbnail_type . '_' . $this->getFilename();
+ $url .= sfAssetsLibraryTools::getThumbnailDir($relative_path, '/') .
$thumbnail_type . '_' . $this->getFilename();
}
if ($pdf)
{
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetFolderPeer.php
===================================================================
---
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetFolderPeer.php
2010-09-14 22:00:06 UTC (rev 30910)
+++
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetFolderPeer.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -17,7 +17,7 @@
*/
public static function createFromPath($path)
{
- $path = self::cleanPath($path);
+ $path = self::cleanPath($path, DIRECTORY_SEPARATOR);
list($parent_path, $name) = sfAssetsLibraryTools::splitPath($path);
if (!$parent_folder = self::retrieveByPath($parent_path))
{
@@ -42,7 +42,7 @@
*/
public static function retrieveByPath($path = '', $separator =
DIRECTORY_SEPARATOR)
{
- $path = self::cleanPath($path);
+ $path = self::cleanPath($path, $separator);
$c = new Criteria();
$c->add(self::RELATIVE_PATH, $path ? $path : null);
@@ -157,12 +157,13 @@
/**
* Sanitize path
*
- * @param string $path
+ * @param string $path
+ * @param string $separator
* @return string
*/
- public static function cleanPath($path)
+ public static function cleanPath($path, $separator = '/')
{
- $path = trim($path, '/');
+ $path = trim($path, $separator);
$root_name = sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media');
if (!$path)
{
@@ -170,7 +171,7 @@
}
elseif (strpos($path, $root_name) !== 0)
{
- $path = $root_name . '/' . $path;
+ $path = $root_name . $separator . $path;
}
return $path;
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetPeer.php
===================================================================
---
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetPeer.php
2010-09-14 22:00:06 UTC (rev 30910)
+++
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/model/plugin/PluginsfAssetPeer.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -31,8 +31,8 @@
*/
public static function retrieveFromUrl($url)
{
- $url = sfAssetFolderPeer::cleanPath($url);
- list($relPath, $filename) = sfAssetsLibraryTools::splitPath($url);
+ $url = sfAssetFolderPeer::cleanPath($url, '/');
+ list($relPath, $filename) = sfAssetsLibraryTools::splitPath($url, '/');
$c = new Criteria();
$c->add(self::FILENAME, $filename);
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/sfAssetsLibraryTools.class.php
===================================================================
---
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/sfAssetsLibraryTools.class.php
2010-09-14 22:00:06 UTC (rev 30910)
+++
plugins/sfAssetsLibraryPlugin/branches/1.3/lib/sfAssetsLibraryTools.class.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -31,7 +31,8 @@
*/
public static function getType($filepath)
{
- $suffix = substr($filepath, strrpos($filepath, '.') - strlen($filepath) +
1);
+ $suffix = pathinfo($filepath, PATHINFO_EXTENSION);
+
if (self::isImage($suffix))
{
return 'image';
@@ -242,7 +243,7 @@
*/
public static function getMediaDir($fileSystem = false)
{
- $upload_dir = rtrim(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'media'), '/').'/';
+ $upload_dir = rtrim(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'media'), '/') . '/';
return $fileSystem ? sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR :
'/';
}
@@ -253,14 +254,15 @@
* @param string $path
* @return string
*/
- public static function getThumbnailDir($path)
+ public static function getThumbnailDir($path, $separator =
DIRECTORY_SEPARATOR)
{
- $thumb_dir = $path . '/' .
sfConfig::get('app_sfAssetsLibrary_thumbnail_dir', 'thumbnail');
+ $thumb_dir = $path . $separator .
sfConfig::get('app_sfAssetsLibrary_thumbnail_dir', 'thumbnail');
- return rtrim($thumb_dir, '/').'/';
+ return rtrim($thumb_dir, $separator) . $separator;
}
/**
+ * Get path of thumbnail
* @param string $path
* @param string $filename
* @param string $thumbnailType
@@ -270,7 +272,7 @@
{
if ($thumbnailType == 'full')
{
- return self::getMediaDir(true) . $path . '/' . $filename;
+ return self::getMediaDir(true) . $path . DIRECTORY_SEPARATOR . $filename;
}
else
{
@@ -389,7 +391,7 @@
return true;
}
-
+
return false;
}
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/test/functional/sfAssetActionsTest.php
===================================================================
---
plugins/sfAssetsLibraryPlugin/branches/1.3/test/functional/sfAssetActionsTest.php
2010-09-14 22:00:06 UTC (rev 30910)
+++
plugins/sfAssetsLibraryPlugin/branches/1.3/test/functional/sfAssetActionsTest.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -2,8 +2,8 @@
include dirname(__FILE__).'/../bootstrap/functional.php';
-$subdir1 = sfAssetFolderPeer::retrieveByPath('TESTsubdir1');
-$subdir2 = sfAssetFolderPeer::retrieveByPath('TESTsubdir2');
+$subdir1 = sfAssetFolderPeer::retrieveByPath('TESTsubdir1', '/');
+$subdir2 = sfAssetFolderPeer::retrieveByPath('TESTsubdir2', '/');
$browser = new sfTestFunctional(new sfBrowser());
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderPeerTest.php
===================================================================
---
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderPeerTest.php
2010-09-14 22:00:06 UTC (rev 30910)
+++
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderPeerTest.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -12,37 +12,37 @@
// prepare test environment
sfAssetFolderPeer::doDeleteAll();
sfAssetPeer::doDeleteAll();
- sfConfig::set('app_sfAssetsLibrary_upload_dir', 'medias');
+ sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST');
$f = new sfAssetFolder();
$f->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
sfAssetFolderPeer::createRoot($f);
$f->save();
// run the test
- $t = new lime_test(13, new lime_output_color());
+ $t = new lime_test(13, array('options' => new lime_output_color(),
'error_reporting' => true));
$t->diag('sfAssetFolderPeer');
- $sfAssetFolder =
sfAssetFolderPeer::retrieveByPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'media'));
+ $sfAssetFolder =
sfAssetFolderPeer::retrieveByPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'mediaTEST'));
$t->ok($sfAssetFolder->isRoot(), 'retrieveByPath() retrieves root from
app_sfAssetsLibrary_upload_dir string');
$sfAssetFolder = sfAssetFolderPeer::retrieveByPath();
$t->ok($sfAssetFolder->isRoot(), 'retrieveByPath() retrieves root from empty
string');
- $sfAssetFolder =
sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'media').'/simple');
+ $sfAssetFolder =
sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'mediaTEST') . DIRECTORY_SEPARATOR . 'simple');
$t->isa_ok($sfAssetFolder, 'sfAssetFolder', 'createFromPath() creates a
sfAssetFolder from simple string');
$t->isa_ok($sfAssetFolder->retrieveParent(), 'sfAssetFolder',
'createFromPath() from simple string has a parent');
$t->ok($sfAssetFolder->retrieveParent()->isRoot(), 'createFromPath() creates
a root child from simple string');
- $sfAssetFolder2 =
sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'media').'/simple/subfolder');
+ $sfAssetFolder2 =
sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'mediaTEST') . DIRECTORY_SEPARATOR . 'simple' . DIRECTORY_SEPARATOR .
'subfolder');
$t->isa_ok($sfAssetFolder2, 'sfAssetFolder', 'createFromPath() creates a
sfAssetFolder from simple string');
$t->is($sfAssetFolder2->retrieveParent()->getId(), $sfAssetFolder->getId(),
'createFromPath() from simple string parent is correct');
- $sfAssetFolder =
sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'media').'/second/subfolder');
+ $sfAssetFolder =
sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir',
'mediaTEST') . DIRECTORY_SEPARATOR . 'second' . DIRECTORY_SEPARATOR .
'subfolder');
$t->ok($sfAssetFolder instanceof sfAssetFolder, 'createFromPath() creates a
sfAssetFolder from simple string');
$t->ok($sfAssetFolder->retrieveParent() instanceof sfAssetFolder,
'createFromPath() from composed string has a parent');
$t->ok($sfAssetFolder->retrieveParent()->retrieveParent()->isRoot(),
'createFromPath() creates a root child from composed string');
- $sfAssetFolder = sfAssetFolderPeer::createFromPath('third/subfolder');
+ $sfAssetFolder = sfAssetFolderPeer::createFromPath('third' .
DIRECTORY_SEPARATOR . 'subfolder');
$t->ok($sfAssetFolder instanceof sfAssetFolder, 'createFromPath() creates a
sfAssetFolder from simple string');
$t->ok($sfAssetFolder->retrieveParent() instanceof sfAssetFolder,
'createFromPath() from composed string has a parent');
$t->ok($sfAssetFolder->retrieveParent()->retrieveParent()->isRoot(),
'createFromPath() creates a root child from composed string');
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderTest.php
===================================================================
--- plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderTest.php
2010-09-14 22:00:06 UTC (rev 30910)
+++ plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetFolderTest.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -12,7 +12,7 @@
// prepare test environment
sfAssetFolderPeer::doDeleteAll();
sfAssetPeer::doDeleteAll();
- sfConfig::set('app_sfAssetsLibrary_upload_dir', 'medias');
+ sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST');
$root = new sfAssetFolder();
$root->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
sfAssetFolderPeer::createRoot($root);
@@ -20,7 +20,7 @@
$rootId = $root->getId();
// run the test
- $t = new lime_test(10, new lime_output_color());
+ $t = new lime_test(10, array('options' => new lime_output_color(),
'error_reporting' => true));
$t->diag('sfAssetFolder::getName()');
@@ -121,4 +121,4 @@
{
echo str_repeat(' ', $folder->getLevel()) , $folder->getName() , ' ',
$folder->getTreeLeft(), '/', $folder->getTreeRight(), "\n";
}
-}
\ No newline at end of file
+}
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetPeerTest.php
===================================================================
--- plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetPeerTest.php
2010-09-14 22:00:06 UTC (rev 30910)
+++ plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetPeerTest.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -12,13 +12,13 @@
// prepare test environment
sfAssetFolderPeer::doDeleteAll();
sfAssetPeer::doDeleteAll();
- sfConfig::set('app_sfAssetsLibrary_upload_dir', 'medias');
+ sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST');
$f = new sfAssetFolder();
$f->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
sfAssetFolderPeer::createRoot($f);
$f->save();
- $t = new lime_test(5, new lime_output_color());
+ $t = new lime_test(5, array('options' => new lime_output_color(),
'error_reporting' => true));
$t->diag('sfAssetPeer');
$t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::retrieveRoot()->getRelativePath()
. '/filename.jpg'), null, 'sfAssetPeer::retrieveFromUrl() returns null when a
URL is not found');
@@ -28,6 +28,7 @@
$sfAsset->setFolder(sfAssetFolderPeer::retrieveRoot());
$sfAsset->setFilename('filename.jpg');
$sfAsset->save($con);
+
$t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::retrieveRoot()->getRelativePath()
. '/filename.jpg')->getId(), $sfAsset->getId(),
'sfAssetPeer::retrieveFromUrl() finds an asset from its URL');
$t->is(sfAssetPeer::retrieveFromUrl($sfAsset->getUrl())->getId(),
$sfAsset->getId(), 'sfAssetPeer::retrieveFromUrl() finds an asset from the
result of `getUrl()`');
$t->is(sfAssetPeer::exists(sfAssetFolderPeer::retrieveRoot()->getId(),
'filename.jpg'), true, 'sfAssetPeer::exists() returns true when an asset is
found');
@@ -38,4 +39,4 @@
}
// reset DB
-$con->rollBack();
\ No newline at end of file
+$con->rollBack();
Modified: plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetTest.php
===================================================================
--- plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetTest.php
2010-09-14 22:00:06 UTC (rev 30910)
+++ plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetTest.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -12,14 +12,14 @@
// prepare test environment
sfAssetFolderPeer::doDeleteAll();
sfAssetPeer::doDeleteAll();
- sfConfig::set('app_sfAssetsLibrary_upload_dir', 'medias');
+ sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST');
$root = new sfAssetFolder();
$root->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
sfAssetFolderPeer::createRoot($root);
$root->save();
// run the tests
- $t = new lime_test(23, new lime_output_color());
+ $t = new lime_test(23, array('options' => new lime_output_color(),
'error_reporting' => true));
$t->diag('sfAsset');
@@ -29,20 +29,20 @@
$sfAsset->setFilename('filename.jpg');
$t->diag('sfAsset::getRelativePath()');
- $t->is($sfAsset->getRelativePath(),
sfConfig::get('app_sfAssetsLibrary_upload_dir') . '/filename.jpg',
'getRelativePath() returns the path relative to the media directory');
+ $t->is($sfAsset->getRelativePath(),
sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR .
'filename.jpg', 'getRelativePath() returns the path relative to the media
directory');
$t->diag('sfAsset::getFullPath()');
- $t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir'). '/' .
sfConfig::get('app_sfAssetsLibrary_upload_dir') . '/filename.jpg',
'getFullPath() returns the complete asset path on the disk');
- $t->is($sfAsset->getFullPath('small'), sfConfig::get('sf_web_dir'). '/' .
sfConfig::get('app_sfAssetsLibrary_upload_dir') .
'/thumbnail/small_filename.jpg', 'getFullPath(\'small\') returns the complete
small thumbnail path on the disk');
- $t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir'). '/' .
sfConfig::get('app_sfAssetsLibrary_upload_dir') .
'/thumbnail/large_filename.jpg', 'getFullPath(\'large\') returns the complete
large thumbnail path on the disk');
+ $t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir').
DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') .
DIRECTORY_SEPARATOR . 'filename.jpg', 'getFullPath() returns the complete asset
path on the disk');
+ $t->is($sfAsset->getFullPath('small'), sfConfig::get('sf_web_dir').
DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') .
DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR . 'small_filename.jpg',
'getFullPath(\'small\') returns the complete small thumbnail path on the disk');
+ $t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir').
DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') .
DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR . 'large_filename.jpg',
'getFullPath(\'large\') returns the complete large thumbnail path on the disk');
$t->diag('sfAsset::getUrl()');
- $t->is($sfAsset->getUrl(), '/' .
sfConfig::get('app_sfAssetsLibrary_upload_dir') . '/filename.jpg', 'getUrl()
returns the asset URL');
+ $t->is($sfAsset->getUrl(), '/' .
sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR .
'filename.jpg', 'getUrl() returns the asset URL');
$t->is($sfAsset->getUrl('small'), '/' .
sfConfig::get('app_sfAssetsLibrary_upload_dir') .
'/thumbnail/small_filename.jpg', 'getUrl(\'small\') returns the small thumbnail
url');
$t->is($sfAsset->getUrl('large'), '/' .
sfConfig::get('app_sfAssetsLibrary_upload_dir') .
'/thumbnail/large_filename.jpg', 'getUrl(\'large\') returns the large thumbnail
url');
$t->diag('sfAsset::create()');
- $assets_path = dirname(__FILE__).'/../assets/';
+ $assets_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
$test_asset = $assets_path . 'raikkonen.jpg';
$folder1 = new sfAssetFolder();
$folder1->insertAsFirstChildOf($root);
Modified:
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetsLibraryToolsTest.php
===================================================================
---
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetsLibraryToolsTest.php
2010-09-14 22:00:06 UTC (rev 30910)
+++
plugins/sfAssetsLibraryPlugin/branches/1.3/test/unit/sfAssetsLibraryToolsTest.php
2010-09-15 09:37:44 UTC (rev 30911)
@@ -8,16 +8,16 @@
include $pluginPaths['sfAssetsLibraryPlugin'] .
'/lib/sfAssetsLibraryTools.class.php';
// run the test
-$t = new lime_test(5, new lime_output_color());
+$t = new lime_test(5, array('options' => new lime_output_color(),
'error_reporting' => true));
$t->diag('assets tools test');
list ($base, $name) = sfAssetsLibraryTools::splitPath('simple');
$t->is($name, 'simple', 'splitPath() gives same name on simple strings');
$t->is($base, '', 'splitPath() gives empty base on simple strings');
-list ($base, $name) = sfAssetsLibraryTools::splitPath('root/file');
+list ($base, $name) = sfAssetsLibraryTools::splitPath('root' .
DIRECTORY_SEPARATOR . 'file');
$t->is($name ,'file', 'splitPath() splits by / gives good name');
$t->is($base ,'root', 'splitPath() splits by / gives good simple base');
-list ($base, $name) =
sfAssetsLibraryTools::splitPath('/Articles/People/Sarkozy');
-$t->is($base ,'/Articles/People', 'splitPath() splits by / gives good composed
base');
\ No newline at end of file
+list ($base, $name) = sfAssetsLibraryTools::splitPath(DIRECTORY_SEPARATOR .
'Articles' . DIRECTORY_SEPARATOR . 'People' . DIRECTORY_SEPARATOR . 'Sarkozy');
+$t->is($base , DIRECTORY_SEPARATOR . 'Articles' . DIRECTORY_SEPARATOR .
'People', 'splitPath() splits by DIRECTORY_SEPARATOR gives good composed base');
--
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.