Example #1
0
 /**
  * Autoloads symfony
  * Note: This is not compatible with ->bootstrap()
  * Code adopted from command/sfSymfonyCommandApplication.class.php
  */
 public function autoload()
 {
     if ($this->autoload) {
         return;
     }
     $this->autoload = 'simple';
     require_once $this->sf_lib_dir . '/util/sfCore.class.php';
     require_once $this->sf_lib_dir . '/config/sfConfig.class.php';
     require_once $this->sf_lib_dir . '/util/sfSimpleAutoload.class.php';
     require_once $this->sf_lib_dir . '/util/sfToolkit.class.php';
     require_once $this->sf_lib_dir . '/util/sfFinder.class.php';
     sfConfig::add(array('sf_symfony_lib_dir' => $this->sf_lib_dir, 'sf_symfony_data_dir' => $this->sf_lib_dir));
     // directory layout
     sfCore::initDirectoryLayout($this->sf_lib_dir);
     // include path
     set_include_path(sfConfig::get('sf_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_app_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_model_dir') . PATH_SEPARATOR . get_include_path());
     $cache = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . sprintf('limeade_autoload_%s.data', md5(__FILE__));
     $autoloader = sfSimpleAutoload::getInstance($cache);
     $autoloader->register();
     $finder = sfFinder::type('file')->ignore_version_control()->prune('test')->prune('vendor')->name('*.php');
     $autoloader->addFiles($finder->in(sfConfig::get('sf_symfony_lib_dir')));
     $autoloader->addFiles($finder->in($this->project_root));
     $autoloader->addDirectory(sfConfig::get('sf_root_dir') . '/plugins');
     return $this;
 }
 public function initialize($t)
 {
     $this->t = $t;
     $this->tmp_dir = sfToolkit::getTmpDir() . DS . 'sf_test_project';
     if (is_dir($this->tmp_dir)) {
         $this->clearTmpDir();
         rmdir($this->tmp_dir);
     }
     mkdir($this->tmp_dir, 0777);
     $this->current_dir = getcwd();
     chdir($this->tmp_dir);
     $this->php_cli = sfToolkit::getPhpCli();
 }
Example #3
0
 public static function getInstance($factories = array(), $force = false)
 {
     if (!isset(self::$instance) || $force) {
         self::$instance = new sfContext();
         self::$instance->sessionPath = sfToolkit::getTmpDir() . '/sessions_' . rand(11111, 99999);
         self::$instance->storage = new sfSessionTestStorage(array('session_path' => self::$instance->sessionPath));
         self::$instance->dispatcher = new sfEventDispatcher();
         foreach ($factories as $type => $class) {
             self::$instance->inject($type, $class);
         }
     }
     return self::$instance;
 }
Example #4
0
 public function initialize($t)
 {
     $this->t = $t;
     $this->tmp_dir = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . 'symfony_cmd';
     if (is_dir($this->tmp_dir)) {
         $this->clearTmpDir();
         rmdir($this->tmp_dir);
     }
     mkdir($this->tmp_dir, 0777);
     $this->current_dir = getcwd();
     chdir($this->tmp_dir);
     $this->php_cli = sfToolkit::getPhpCli();
 }
Example #5
0
File: unit.php Project: habtom/uas
function sf_unit_test_shutdown()
{
    $sf_root_dir = sfToolkit::getTmpDir() . '/sf_test_project';
    if (is_dir($sf_root_dir)) {
        sfToolkit::clearDirectory($sf_root_dir);
        @rmdir($sf_root_dir);
    }
    $sessions = glob(sfToolkit::getTmpDir() . '/sessions*');
    $tmp_files = glob(sfToolkit::getTmpDir() . '/sf*');
    $files = array_merge(empty($sessions) ? array() : $sessions, empty($tmp_files) ? array() : $tmp_files);
    foreach ($files as $file) {
        if (is_dir($file)) {
            sfToolkit::clearDirectory($file);
            @rmdir($file);
        } else {
            @unlink($file);
        }
    }
}
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     if (!$options['no-confirmation'] && !$this->askConfirmation(array('This command will remove all data in your database.', 'Are you sure you want to proceed? (y/N)'), null, false)) {
         $this->logSection('propel', 'Task aborted.');
         return 1;
     }
     $this->schemaToXML(self::DO_NOT_CHECK_SCHEMA, 'generated-');
     $this->copyXmlSchemaFromPlugins('generated-');
     $databaseManager = new sfDatabaseManager($this->configuration);
     $properties = $this->getProperties(sfConfig::get('sf_data_dir') . '/sql/sqldb.map');
     $sqls = array();
     foreach ($properties as $file => $connection) {
         if (!is_null($options['connection']) && $options['connection'] != $connection) {
             continue;
         }
         if (!isset($sqls[$connection])) {
             $sqls[$connection] = array();
         }
         $sqls[$connection][] = $file;
     }
     $this->tmpDir = sfToolkit::getTmpDir() . '/propel_insert_sql_' . rand(11111, 99999);
     register_shutdown_function(array($this, 'removeTmpDir'));
     mkdir($this->tmpDir, 0777, true);
     foreach ($sqls as $connection => $files) {
         $dir = $this->tmpDir . '/' . $connection;
         mkdir($dir, 0777, true);
         $content = '';
         foreach ($files as $file) {
             $content .= "{$file}={$connection}\n";
             copy(sfConfig::get('sf_data_dir') . '/sql/' . $file, $dir . '/' . $file);
         }
         file_put_contents($dir . '/sqldb.map', $content);
         $properties = $this->getPhingPropertiesForConnection($databaseManager, $connection);
         $properties['propel.sql.dir'] = $dir;
         $ret = $this->callPhing('insert-sql', self::CHECK_SCHEMA, $properties);
     }
     $this->removeTmpDir();
     $this->cleanup();
     return !$ret;
 }
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(47, new lime_output_color());
class MySessionStorage extends sfSessionTestStorage
{
    public function regenerate($destroy = false)
    {
        $this->sessionId = rand(1, 9999);
        return true;
    }
}
$dispatcher = new sfEventDispatcher();
$sessionPath = sfToolkit::getTmpDir() . '/sessions_' . rand(11111, 99999);
$storage = new MySessionStorage(array('session_path' => $sessionPath));
$user = new sfBasicSecurityUser($dispatcher, $storage);
// ->initialize()
$t->diag('->initialize()');
$t->todo('->initialize() times out the user if no request made for a long time');
// ->listCredentials()
$t->diag('->listCredentials()');
$user->clearCredentials();
$user->addCredential('user');
$t->is($user->listCredentials(), array('user'), '->listCredentials() returns user credentials as an array');
// ->setAuthenticated() ->isAuthenticated()
$t->diag('->setAuthenticated() ->isAuthenticated()');
$t->is($user->isAuthenticated(), false, '->isAuthenticated() returns false by default');
$user->setAuthenticated(true);
$t->is($user->isAuthenticated(), true, '->isAuthenticated() returns true if the user is authenticated');
Example #8
0
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/unit.php';
require_once sfConfig::get('sf_symfony_lib_dir') . '/command/sfCommandApplication.class.php';
require_once sfConfig::get('sf_symfony_lib_dir') . '/command/sfSymfonyCommandApplication.class.php';
$tmpDir = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . 'sf_' . rand(11111, 99999);
mkdir($tmpDir, 0777, true);
chdir($tmpDir);
$application = new sfSymfonyCommandApplication(new sfEventDispatcher(), new sfFormatter(), array('symfony_lib_dir' => sfConfig::get('sf_symfony_lib_dir')));
register_shutdown_function('sf_shutdown_task_test');
function sf_shutdown_task_test()
{
    global $tmpDir;
    sfToolkit::clearDirectory($tmpDir);
    rmdir($tmpDir);
}
Example #9
0
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(29, new lime_output_color());
class ProjectConfiguration extends sfProjectConfiguration
{
}
class TestConfiguration extends sfApplicationConfiguration
{
    public function getI18NGlobalDirs()
    {
        return array(dirname(__FILE__) . '/fixtures');
    }
}
$configuration = new TestConfiguration('test', true, sfConfig::get('sf_test_cache_dir', sfToolkit::getTmpDir()));
$dispatcher = $configuration->getEventDispatcher();
$cache = new sfNoCache();
// ->initialize()
$t->diag('->initialize()');
$i18n = new sfI18N($configuration, $cache);
$dispatcher->notify(new sfEvent(null, 'user.change_culture', array('culture' => 'fr')));
$t->is($i18n->getCulture(), 'fr', '->initialize() connects to the user.change_culture event');
// ->getCulture() ->setCulture()
$t->diag('->getCulture() ->setCulture()');
$i18n = new sfI18N($configuration, $cache);
$t->is($i18n->getCulture(), 'en', '->getCulture() returns the current culture');
$i18n->setCulture('fr');
$t->is($i18n->getCulture(), 'fr', '->setCulture() sets the current culture');
// ->__()
$t->diag('->__()');
Example #10
0
$t->is(sfToolkit::stripslashesDeep(array(array('foo' => addslashes("foo's bar")), addslashes("foo's bar"))), array(array('foo' => "foo's bar"), "foo's bar"), '::stripslashesDeep() strip slashes on deep arrays');
// ::clearDirectory()
$t->diag('::clearDirectory()');
$tmp_dir = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . 'symfony_tests_' . rand(1, 999);
mkdir($tmp_dir);
file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'test', 'ok');
mkdir($tmp_dir . DIRECTORY_SEPARATOR . 'foo');
file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'bar', 'ok');
sfToolkit::clearDirectory($tmp_dir);
$t->ok(!is_dir($tmp_dir . DIRECTORY_SEPARATOR . 'foo'), '::clearDirectory() removes all directories from the directory parameter');
$t->ok(!is_file($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'bar'), '::clearDirectory() removes all directories from the directory parameter');
$t->ok(!is_file($tmp_dir . DIRECTORY_SEPARATOR . 'test'), '::clearDirectory() removes all directories from the directory parameter');
rmdir($tmp_dir);
// ::clearGlob()
$t->diag('::clearGlob()');
$tmp_dir = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . 'symfony_tests_' . rand(1, 999);
mkdir($tmp_dir);
mkdir($tmp_dir . DIRECTORY_SEPARATOR . 'foo');
mkdir($tmp_dir . DIRECTORY_SEPARATOR . 'bar');
file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'bar', 'ok');
file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'foo', 'ok');
file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'bar', 'ok');
sfToolkit::clearGlob($tmp_dir . '/*/bar');
$t->ok(!is_file($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'bar'), '::clearGlob() removes all files and directories matching the pattern parameter');
$t->ok(!is_file($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'bar'), '::clearGlob() removes all files and directories matching the pattern parameter');
$t->ok(is_file($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'foo'), '::clearGlob() removes all files and directories matching the pattern parameter');
sfToolkit::clearDirectory($tmp_dir);
rmdir($tmp_dir);
// ::arrayDeepMerge()
$t->diag('::arrayDeepMerge()');
$t->is(sfToolkit::arrayDeepMerge(array('d' => 'due', 't' => 'tre'), array('d' => 'bis', 'q' => 'quattro')), array('d' => 'bis', 't' => 'tre', 'q' => 'quattro'), '::arrayDeepMerge() merges linear arrays preserving literal keys');
Example #11
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../../../../test/bootstrap/unit.php';
require_once dirname(__FILE__) . '/../../../../autoload/sfSimpleAutoload.class.php';
$autoload = sfSimpleAutoload::getInstance(sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . sprintf('sf_autoload_unit_propel_%s.data', md5(__FILE__)));
$autoload->addDirectory(realpath(dirname(__FILE__) . '/../../lib'));
$autoload->register();
$_test_dir = realpath(dirname(__FILE__) . '/..');
    public function getRequest()
    {
        return $this->request;
    }
    public function getUser()
    {
        return $this->user;
    }
    public function getStorage()
    {
        return $this->storage;
    }
}
$t = new lime_test(33, new lime_output_color());
$_SERVER['session_id'] = 'test';
sfConfig::set('sf_test_cache_dir', sfToolkit::getTmpDir());
$context = new sfContext();
$request = new sfWebRequest();
$request->initialize($context);
$context->request = $request;
$storage = sfStorage::newInstance('sfSessionTestStorage');
$storage->initialize($context);
$storage->clear();
$context->storage = $storage;
$user = new sfUser();
$user->initialize($context);
$context->user = $user;
// ->initialize()
$t->diag('->initialize()');
$t->is($user->getCulture(), 'en', '->initialize() sets the culture to "en" by default');
sfConfig::set('sf_i18n_default_culture', 'de');
 public static function removeCache()
 {
     unlink(sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . 'sf_autoload_paths.php');
 }
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(69, new lime_output_color());
$tmpDir = sfToolkit::getTmpDir();
$content = 'This is an ASCII file.';
file_put_contents($tmpDir . '/test.txt', $content);
class testValidatorFile extends sfValidatorFile
{
    public function getMimeType($file, $fallback)
    {
        return parent::getMimeType($file, $fallback);
    }
    public function guessFromNothing($file)
    {
        return 'nothing/plain';
    }
    public function guessFromFileinfo($file)
    {
        return parent::guessFromFileinfo($file);
    }
    public function guessFromMimeContentType($file)
    {
        return parent::guessFromMimeContentType($file);
Example #15
0
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../lib/vendor/lime/lime.php';
class lime_symfony extends lime_harness
{
    protected function get_relative_file($file)
    {
        $file = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(array(realpath($this->base_dir) . DIRECTORY_SEPARATOR, realpath($this->base_dir . '/../lib/plugins') . DIRECTORY_SEPARATOR, $this->extension), '', $file));
        return preg_replace('#^(.*?)Plugin/test/(unit|functional)/#', '[$1] $2/', $file);
    }
}
require_once dirname(__FILE__) . '/../../lib/util/sfToolkit.class.php';
if ($files = glob(sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . '/sf_autoload_unit_*')) {
    foreach ($files as $file) {
        unlink($file);
    }
}
// update sfCoreAutoload
require_once dirname(__FILE__) . '/../../lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::make();
$h = new lime_symfony(new lime_output_color());
$h->base_dir = realpath(dirname(__FILE__) . '/..');
$h->register(sfFinder::type('file')->prune('fixtures')->name('*Test.php')->in(array_merge(array($h->base_dir . '/unit'), glob($h->base_dir . '/../lib/plugins/*/test/unit'), array($h->base_dir . '/functional'), glob($h->base_dir . '/../lib/plugins/*/test/functional'), array($h->base_dir . '/other'))));
exit($h->run() ? 0 : 1);
Example #16
0
        $filterChain->execute();
        // sfCommmonFilter has executed all its code
    }
}
class ProjectConfiguration extends sfProjectConfiguration
{
}
class TestConfiguration extends sfApplicationConfiguration
{
    public function getI18NGlobalDirs()
    {
        return array(dirname(__FILE__) . '/fixtures');
    }
}
$context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'sfWebResponse'));
$context->configuration = new TestConfiguration('test', true, sfToolkit::getTmpDir() . '/sf_test_project');
$response = $context->response;
$selector = execute_filter_chain($context, $t);
check_javascripts_included($t, $selector);
check_stylesheets_included($t, $selector);
// test disabling javascript and stylesheet automatic inclusion
sfConfig::set('symfony.asset.javascripts_included', true);
sfConfig::set('symfony.asset.stylesheets_included', true);
$selector = execute_filter_chain($context, $t);
$t->is($selector->getElements('head script'), array(), '->execute() does not add javascripts if you used get_javascripts() helper');
$t->is($selector->getElements('head link'), array(), '->execute() does not add stylesheets if you used get_stylesheets() helper');
sfConfig::set('symfony.asset.javascripts_included', false);
sfConfig::set('symfony.asset.stylesheets_included', true);
$selector = execute_filter_chain($context, $t);
check_javascripts_included($t, $selector);
$t->is($selector->getElements('head link'), array(), '->execute() does not add javascripts if you used get_javascripts() helper');
Example #17
0
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(7, new lime_output_color());
require_once dirname(__FILE__) . '/../../../lib/util/sfToolkit.class.php';
$file = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . 'sf_log_file.txt';
if (file_exists($file)) {
    unlink($file);
}
$dispatcher = new sfEventDispatcher();
// ->initialize()
$t->diag('->initialize()');
try {
    $logger = new sfFileLogger($dispatcher);
    $t->fail('->initialize() parameters must contains a "file" parameter');
} catch (sfConfigurationException $e) {
    $t->pass('->initialize() parameters must contains a "file" parameter');
}
// ->log()
$t->diag('->log()');
$logger = new sfFileLogger($dispatcher, array('file' => $file));
$logger->log('foo');
$lines = explode("\n", file_get_contents($file));
$t->like($lines[0], '/foo/', '->log() logs a message to the file');