/** * Tests that this input fails * * @param string $input * @param string $message */ public function fail($input, $message = null, $encoding = 'utf-8') { $this->lime->diag($input); try { $this->lexer->tokenize($input, $encoding); $this->lime->fail('exception not thrown'); if ($message) { $this->lime->skip(''); } } catch (Exception $e) { $this->lime->pass('exception caught: ' . $e->getMessage()); if ($message) { $this->lime->is($e->getMessage(), $message, 'exception message matches'); } } }
$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'); // passing a "culture" option to initialize() should set PHP locale if (class_exists('Locale') && ($en = Locale::lookup(array('en-US'), 'en-US', true)) && ($fr = Locale::lookup(array('fr-FR'), 'fr-FR', true))) { $i18n = new sfI18N($configuration, $cache, array('culture' => $fr)); $frLocale = localeconv(); $i18n = new sfI18N($configuration, $cache, array('culture' => $en)); $enLocale = localeconv(); $t->isnt(serialize($frLocale), serialize($enLocale), '->initialize() sets the PHP locale when a "culture" option is provided'); } else { $t->skip('Locale class or English and French locales are not installed'); } // ->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('->__()'); sfConfig::set('sf_charset', 'UTF-8'); $i18n = new sfI18N($configuration, $cache, array('culture' => 'fr')); $t->is($i18n->__('an english sentence'), 'une phrase en français', '->__() translates a string'); class EnglishSentence { public function __toString()
<?php require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot(); $t = new lime_test(33); $v = new dmValidatorCssIdAndClasses(); $t->diag('->clean()'); foreach (array('a', 'a_b', 'a-c', 'qieurgfbqoiuzbfvoqiuzZFZGPSOZDNZKFjflzkh986875OoihzyfvbxoquyfvxqozufyxqzUEFV', '9', '_', ' bla rebla ', '- _ 8', '.class', '.a b.c.d', '#myid.a b.c.d', '#myid class1 class2', 'class1 class2 #myid', '.a b#myid.c.d', '.a b#myid.c.d#myid', '.a b#myid.c.d #myid', '#my_id', '#my-id', ' #my-id ') as $classes) { try { $t->comment('"' . $classes . '" -> "' . $v->clean($classes) . '"'); $t->pass('->clean() checks that the value is a valid css class name + id'); } catch (sfValidatorError $e) { $t->fail('->clean() checks that the value is a valid css class name + id'); } } foreach (array('.zegze$g.zegf', '/', 'a/f', 'a^', 'a # @', 'é', '-{') as $nonClass) { $t->comment($nonClass); try { $v->clean($nonClass); $t->fail('->clean() throws an sfValidatorError if the value is not a valid css class name + id'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the value is not a valid css class name + id'); $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); } }
/* * 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'); $plan = 73; $t = new lime_test($plan); if (!class_exists('Memcache')) { $t->skip('Memcache needed to run these tests', $plan); return; } require_once(dirname(__FILE__).'/sfCacheDriverTests.class.php'); // setup sfConfig::set('sf_logging_enabled', false); // ->initialize() $t->diag('->initialize()'); try { $cache = new sfMemcacheCache(array('storeCacheInfo' => true)); } catch (sfInitializationException $e)
<?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 __DIR__ . '/../../bootstrap/unit.php'; ob_start(); $plan = 14; $t = new lime_test($plan); if (!extension_loaded('SQLite') && !extension_loaded('pdo_SQLite')) { $t->skip('SQLite needed to run these tests', $plan); return; } // initialize the storage $database = new sfPDODatabase(array('dsn' => 'sqlite::memory:')); $connection = $database->getConnection(); $connection->exec('CREATE TABLE session (sess_id, sess_data, sess_time)'); ini_set('session.use_cookies', 0); $session_id = "1"; $storage = new sfPDOSessionStorage(array('db_table' => 'session', 'session_id' => $session_id, 'database' => $database)); $t->ok($storage instanceof sfStorage, 'sfPDOSessionStorage is an instance of sfStorage'); $t->ok($storage instanceof sfDatabaseSessionStorage, 'sfPDOSessionStorage is an instance of sfDatabaseSessionStorage'); // regenerate() $oldSessionData = 'foo:bar'; $storage->sessionWrite($session_id, $oldSessionData); $storage->regenerate(false); $newSessionData = 'foo:bar:baz';
$t->is(truncate_text($text), $truncated, 'text_truncate() adds ... to truncated text'); $text = str_repeat('A', 35); $truncated = str_repeat('A', 22) . '...'; $t->is(truncate_text($text, 25), $truncated, 'text_truncate() takes the max length as its second argument'); $text = str_repeat('A', 35); $truncated = str_repeat('A', 21) . 'BBBB'; $t->is(truncate_text($text, 25, 'BBBB'), $truncated, 'text_truncate() takes the ... text as its third argument'); $text = str_repeat('A', 10) . str_repeat(' ', 10) . str_repeat('A', 10); $truncated_true = str_repeat('A', 10) . '...'; $truncated_false = str_repeat('A', 10) . str_repeat(' ', 2) . '...'; $t->is(truncate_text($text, 15, '...', false), $truncated_false, 'text_truncate() accepts a truncate lastspace boolean as its fourth argument'); $t->is(truncate_text($text, 15, '...', true), $truncated_true, 'text_truncate() accepts a truncate lastspace boolean as its fourth argument'); if (extension_loaded('mbstring')) { $t->is(truncate_text('P?�li? ?lu?ou?k? k?? �p?l ?�belsk� �dy!', 11), 'P?�li? ?...', 'text_truncate() handles unicode characters using mbstring if available'); } else { $t->skip('mbstring extension is not enabled'); } // highlight_text() $t->diag('highlight_text()'); $t->is(highlight_text("This is a beautiful morning", "beautiful"), "This is a <strong class=\"highlight\">beautiful</strong> morning", 'text_highlighter() highlights a word given as its second argument'); $t->is(highlight_text("This is a beautiful morning, but also a beautiful day", "beautiful"), "This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day", 'text_highlighter() highlights all occurrences of a word given as its second argument'); $t->is(highlight_text("This is a beautiful morning, but also a beautiful day", "beautiful", '<b>\\1</b>'), "This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day", 'text_highlighter() takes a pattern as its third argument'); $t->is(highlight_text('', 'beautiful'), '', 'text_highlighter() returns an empty string if input is empty'); $t->is(highlight_text('', ''), '', 'text_highlighter() returns an empty string if input is empty'); $t->is(highlight_text('foobar', 'beautiful'), 'foobar', 'text_highlighter() does nothing is string to highlight is not present'); $t->is(highlight_text('foobar', ''), 'foobar', 'text_highlighter() returns input if string to highlight is not present'); $t->is(highlight_text("This is a beautiful! morning", "beautiful!"), "This is a <strong class=\"highlight\">beautiful!</strong> morning", 'text_highlighter() escapes search string to be safe in a regex'); $t->is(highlight_text("This is a beautiful! morning", "beautiful! morning"), "This is a <strong class=\"highlight\">beautiful! morning</strong>", 'text_highlighter() escapes search string to be safe in a regex'); $t->is(highlight_text("This is a beautiful? morning", "beautiful? morning"), "This is a <strong class=\"highlight\">beautiful? morning</strong>", 'text_highlighter() escapes search string to be safe in a regex'); $t->is(highlight_text("The http://www.google.com/ website is great", "http://www.google.com/"), "The <strong class=\"highlight\">http://www.google.com/</strong> website is great", 'text_highlighter() escapes search string to be safe in a regex'); // excerpt_text()
* 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'); require_once(dirname(__FILE__).'/sfCacheDriverTests.class.php'); $plan = 129; $t = new lime_test($plan); if (!extension_loaded('SQLite') && !extension_loaded('pdo_SQLite')) { $t->skip('SQLite extension not loaded, skipping tests', $plan); return; } try { new sfSQLiteCache(array('database' => ':memory:')); } catch (sfInitializationException $e) { $t->skip($e->getMessage(), $plan); return; } // ->initialize() $t->diag('->initialize()');
chdir($this->tmp_dir); $symfony = file_exists('symfony') ? 'symfony' : dirname(__FILE__) . '/../../data/bin/symfony'; ob_start(); passthru(sprintf('%s "%s" %s 2>&1', $this->php_cli, $symfony, $cmd), $return); $content = ob_get_clean(); $this->t->cmp_ok($return, '==', $awaited_return, sprintf('"symfony %s" returns awaited value (%d)', $cmd, $awaited_return)); return $content; } public function get_fixture_content($file) { return str_replace("\r\n", "\n", file_get_contents(dirname(__FILE__) . '/fixtures/' . $file)); } } $t = new lime_test(40, new lime_output_color()); if (!extension_loaded('SQLite')) { $t->skip('You need SQLite to run these tests', $t->plan); return; } $c = new sf_test_project(); $c->initialize($t); // generate:* $content = $c->execute_command('generate:project myproject'); $t->ok(file_exists($c->tmp_dir . DS . 'symfony'), '"generate:project" installs the symfony CLI in root project directory'); $content = $c->execute_command('generate:app frontend --escaping-strategy=on'); $t->ok(is_dir($c->tmp_dir . DS . 'apps' . DS . 'frontend'), '"generate:app" creates a "frontend" directory under "apps" directory'); $t->like(file_get_contents($c->tmp_dir . '/apps/frontend/config/settings.yml'), '/escaping_strategy: +true/', '"generate:app" switches escaping_strategy "on"'); $content = $c->execute_command('generate:app backend'); $t->like(file_get_contents($c->tmp_dir . '/apps/backend/config/settings.yml'), '/escaping_strategy: +false/', '"generate:app" switches escaping_strategy "off"'); // failing $content = $c->execute_command('generate:module wrongapp foo', 1); $content = $c->execute_command('generate:module frontend foo');
<?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(5); $v1 = new sfValidatorString(array('min_length' => 3)); // __construct() $t->diag('__construct()'); $v = new sfValidatorSchemaForEach($v1, 3); $t->is($v->getFields(), array($v1, $v1, $v1), '->__construct() takes a sfValidator object as its first argument'); $v = new sfValidatorSchemaForEach($v1, 6); $t->is($v->getFields(), array($v1, $v1, $v1, $v1, $v1, $v1), '->__construct() takes a number of times to duplicate the validator'); // ->clean() $t->diag('->clean()'); try { $v->clean(array('f', 'a', 'b', 'i', 'e', 'n')); $t->fail('->clean() throws an sfValidatorError'); $t->skip('', 2); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError'); $t->is(count($e->getGlobalErrors()), 0, '->clean() does not throw global errors'); $t->is(count($e->getNamedErrors()), 6, '->clean() throws named errors'); }
{ protected function configure($options = array(), $attributes = array()) { $this->addRequiredOption('foo'); } } // __construct() $t->diag('__construct()'); $w = new MyWidget(); $t->is($w->getAttributes(), array(), '->__construct() can take no argument'); $w = new MyWidget(array(), array('class' => 'foo')); $t->is($w->getAttributes(), array('class' => 'foo'), '->__construct() can take an array of default HTML attributes'); try { new MyWidget(array('nonexistant' => false)); $t->fail('__construct() throws an InvalidArgumentException if you pass some non existant options'); $t->skip(); } catch (InvalidArgumentException $e) { $t->pass('__construct() throws an InvalidArgumentException if you pass some non existant options'); $t->like($e->getMessage(), '/ \'nonexistant\'/', 'The exception contains the non existant option names'); } $t->diag('getRequiredOptions'); $w = new MyWidgetWithRequired(array('foo' => 'bar')); $t->is($w->getRequiredOptions(), array('foo'), '->getRequiredOptions() returns an array of required option names'); try { new MyWidgetWithRequired(); $t->fail('__construct() throws an RuntimeException if you don\'t pass a required option'); } catch (RuntimeException $e) { $t->pass('__construct() throws an RuntimeException if you don\'t pass a required option'); } $w = new MyWidget(); // ->getOption() ->setOption() ->setOptions() ->getOptions() ->hasOption()
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * (c) 2008 Dejan Spasic <*****@*****.**> * * 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'; ob_start(); $plan = 12; $t = new lime_test($plan, new lime_output_color()); if (!extension_loaded('mysqli')) { $t->skip('Mysqli extension must be loaded', $plan); return; } // Configure your database with the settings below in order to run the test $mysqli_config = array('host' => 'localhost', 'username' => 'root', 'password' => ''); if (!isset($mysqli_config)) { $t->skip('Mysql credentials needed to run these tests', $plan); return; } try { // Creating mysql database connection $database = new sfMySQLiDatabase($mysqli_config); $connection = $database->getResource(); } catch (sfDatabaseException $e) { $t->diag($e->getMessage()); $t->skip('Unable to connect to MySQL database, skipping', $plan);
$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'); // passing a "culture" option to initialize() should set PHP locale if (version_compare(PHP_VERSION, '5.3', '<') && class_exists('Locale') && ($en = Locale::lookup(array('en-US'), 'en-US', true)) && ($fr = Locale::lookup(array('fr-FR'), 'fr-FR', true))) { $i18n = new sfI18N($configuration, $cache, array('culture' => $fr)); $frLocale = localeconv(); $i18n = new sfI18N($configuration, $cache, array('culture' => $en)); $enLocale = localeconv(); $t->isnt(serialize($frLocale), serialize($enLocale), '->initialize() sets the PHP locale when a "culture" option is provided'); } else { $t->skip('PHP version > 5.2 or Locale class or English and French locales are not installed'); } // ->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('->__()'); sfConfig::set('sf_charset', 'UTF-8'); $i18n = new sfI18N($configuration, $cache, array('culture' => 'fr')); $t->is($i18n->__('an english sentence'), 'une phrase en français', '->__() translates a string'); class EnglishSentence { public function __toString()
<?php require_once dirname(__FILE__).'/../bootstrap/unit.php'; $t = new lime_test(9); $t->is(Swingmachine::slugify('LindyHop'), 'lindyhop', '::slugify() converts all characters to lower case'); $t->is(Swingmachine::slugify('lindy hop'), 'lindy-hop', '::slugify() replaces a white space by a -'); $t->is(Swingmachine::slugify('lindy hop'), 'lindy-hop', '::slugify() replaces several white spaces by a single -'); $t->is(Swingmachine::slugify('lindy,balboa'), 'lindy-balboa', '::slugify() removes - at the beginning of a string'); $t->is(Swingmachine::slugify(' lindy'), 'lindy', '::slugify() removes - at the end of a string'); $t->is(Swingmachine::slugify('lindy '), 'lindy', '::slugify() replaces non-ASCII characters by a -'); $t->is(Swingmachine::slugify(''), 'n-a', '::slugify() converts the empty string to n-a'); $t->is(Swingmachine::slugify(' - '), 'n-a', '::slugify() converts a string that only contains non-ASCII characters to n-a'); if (function_exists('iconv')) { $t->is(Swingmachine::slugify('Cours Réguliers'), 'cours-reguliers', '::slugify() removes accents'); } else { $t->skip('::slugify() removes accents - iconv not installed'); }
} } // ->configure() $t->diag('->configure()'); $v = new ValidatorIdentity(); $t->is($v->getOption('foo'), 'bar', '->configure() can add some options'); $v = new ValidatorIdentity(array('foo' => 'foobar')); $t->is($v->getOption('foo'), 'foobar', '->configure() takes an options array as its first argument and values override default option values'); $v = new ValidatorIdentity(); $t->is($v->getMessage('foo'), 'bar', '->configure() can add some message'); $v = new ValidatorIdentity(array(), array('foo' => 'foobar')); $t->is($v->getMessage('foo'), 'foobar', '->configure() takes a messages array as its second argument and values override default message values'); try { new ValidatorIdentity(array('nonexistant' => false, 'foo' => 'foobar', 'anothernonexistant' => 'bar', 'required' => true)); $t->fail('__construct() throws an InvalidArgumentException if you pass some non existant options'); $t->skip(); } catch (InvalidArgumentException $e) { $t->pass('__construct() throws an InvalidArgumentException if you pass some non existant options'); $t->like($e->getMessage(), '/ \'nonexistant\', \'anothernonexistant\'/', 'The exception contains the non existant option names'); } try { new ValidatorIdentity(array(), array('required' => 'This is required.', 'nonexistant' => 'foo', 'anothernonexistant' => false)); $t->fail('__construct() throws an InvalidArgumentException if you pass some non existant error codes'); $t->skip(); } catch (InvalidArgumentException $e) { $t->pass('__construct() throws an InvalidArgumentException if you pass some non existant error codes'); $t->like($e->getMessage(), '/ \'nonexistant\', \'anothernonexistant\'/', 'The exception contains the non existant error codes'); } // ->getRequiredOptions() $t->diag('getRequiredOptions'); $v = new ValidatorIdentityWithRequired(array('foo' => 'bar'));
$id1 = DbFinder::from('DArticle')->where('Title', 'foo')->leftJoin('Category')->withColumn('DCategory.Name')->getUniqueIdentifier(); $id2 = DbFinder::from('DArticle')->where('Title', 'foo')->withColumn('DCategory.Name')->getUniqueIdentifier(); $t->isnt($id1, $id2, 'unique identifier takes joins into account'); $id1 = DbFinder::from('DArticle')->where('Title', 'foo')->where('DCategory.Id', 1)->getUniqueIdentifier(); $id2 = DbFinder::from('DArticle')->where('Title', 'foo')->orWhere('DCategory.Id', 1)->getUniqueIdentifier(); $t->isnt($id1, $id2, 'unique identifier takes logic combinators into account'); $id1 = DbFinder::from('DArticle')->where('Title', 'foo')->where('Id', '=', 1, 'temp')->getUniqueIdentifier(); $id2 = DbFinder::from('DArticle')->where('Title', 'foo')->getUniqueIdentifier(); $t->is($id1, $id2, 'unique identifier does not take uncombined conditions into account'); if (Doctrine::VERSION == '0.11.0') { $t->skip('Query cache does not work with Doctrine 0.11', 13); die(); } $cache = new Doctrine_Cache_Apc(); $t->diag('useCache()'); // Simple queries apc_clear_cache('user'); $finder = DbFinder::from('DArticle')->where('Title', 'foo')->useCache($cache, 10); $finder->findOne(); $SQL1 = $finder->getLatestQuery(); // SELECT * FROM article WHERE article.title = 'foo' LIMIT 1 $finder = DbFinder::from('DArticle')->where('Title', 'bar')->useCache($cache, 10);
$app = 'frontend'; require_once(dirname(__FILE__).'/../../bootstrap/functional.php'); $_test_dir = realpath(dirname(__FILE__).'/../../'); require_once($_test_dir.'/../lib/vendor/lime/lime.php'); sfConfig::set('sf_symfony_lib_dir', realpath($_test_dir.'/../lib')); $plan = 8; $t = new lime_test($plan); if (!ini_get('apc.enable_cli')) { $t->skip('APC must be enable on CLI to run these tests', $plan); return; } // initialize the storage try { $storage = new sfCacheSessionStorage(); $t->fail('->__construct() does not throw an exception when not provided a cache option'); } catch (InvalidArgumentException $e) { $t->pass('->__construct() throws an exception when not provided a cache option'); }
} // ->clean() $t->diag('->clean()'); $validator = new TestValidator(); $activeUser = new MockUser(); $activeUser->active = true; $inactiveUser = new MockUser(); $inactiveUser->active = false; MockTable::$user = $activeUser; try { $values = $validator->clean(array('username' => 'mock', 'password' => 'correct')); $t->pass('->clean() does not throw an error if an active user is found'); $t->isa_ok($values['user'], 'MockUser', '->clean() adds the user object to the cleaned values'); } catch (sfValidatorErrorSchema $error) { $t->fail('->clean() does not throw an error if an active user is found'); $t->skip(); } try { $values = $validator->clean(array('username' => '*****@*****.**', 'password' => 'correct')); $t->pass('->clean() does not throw an error if an active user is found'); $t->isa_ok($values['user'], 'MockUser', '->clean() adds the user object to the cleaned values'); } catch (sfValidatorErrorSchema $error) { $t->fail('->clean() does not throw an error if an active user is found'); $t->skip(); } try { $validator->clean(array('username' => 'mock', 'password' => 'incorrect')); $t->fail('->clean() throws an error if password is incorrect'); } catch (sfValidatorErrorSchema $error) { $t->pass('->clean() throws an error if password is incorrect'); }
$pager = sfDoctrineFinder::from('DArticle')-> where('Title', 'like', 'tt%')-> paginate(1, 2); $t->is($pager->getNbResults(), 4, 'sfDoctrineFinder::paginate() sfDoctrineFinder::paginate() uses the internal conditions'); $t->is($pager->getLastPage(), 2, 'sfDoctrineFinder::paginate() sfDoctrineFinder::paginate() uses the internal conditions'); $t->is($pager->getFirstIndice(), 1, 'sfDoctrineFinder::paginate() sfDoctrineFinder::paginate() uses the internal conditions'); $t->diag('sfDoctrineFinderPager issues with GroupBy'); $finder = sfDoctrineFinder::from('DArticle')->groupBy('Title'); $pager = new sfDoctrineFinderPager('DArticle', 2); $pager->setFinder($finder); $pager->init(); //$t->is($finder->getLatestQuery(), 'SELECT COUNT(DISTINCT d.id) AS num_results FROM d_article d', 'sfDoctrineFinderPager::init() removes groupBy clauses and issues a count()'); $t->skip('sfDoctrineFinderPager::init() removes groupBy clauses and issues a count() (bug in sfDoctrinePager)'); $pager->getResults(); $t->is($finder->getLatestQuery(), 'SELECT d.id AS d__id, d.title AS d__title, d.category_id AS d__category_id FROM d_article d GROUP BY d.title LIMIT 2', 'sfDoctrineFinderPager::getResults() does not remove groupBy clauses and issues a select()'); $t->diag('sfDoctrineFinderPager issues with object finders classes'); class DArticleFinder extends sfDoctrineFinder { protected $class = 'DArticle'; } $finder = new DArticleFinder(); try { $pager = $finder->paginate(); $t->pass('Children of sfDoctrineFinder can use paginate()'); } catch(sfException $e)
Doctrine::getTable('DArticle')->clear(); Doctrine::getTable('DComment')->clear(); $finder = sfDoctrineFinder::from('DComment')-> join('DArticle')-> withColumn('DArticle.Title'); $comment = $finder->findOne(); $t->is($comment['Article']['DArticle.Title'], 'bbbbb', 'Additional columns added with withColumn() are stored in the object and can be retrieved as properties of the related object'); try { $t->is($comment->getColumn('DArticle.Title'), 'bbbbb', 'Additional columns added with withColumn() are stored in the object and can be retrieved with getColumn()'); } catch(Doctrine_Record_Exception $e) { $t->skip('getColumn() is not available with Doctrine 0.11'); } $t->is($finder->getLatestQuery(), 'SELECT d.id AS d__id, d.content AS d__content, d.article_id AS d__article_id, d.author_id AS d__author_id, d2.title AS d2__0 FROM d_comment d INNER JOIN d_article d2 ON d.article_id = d2.id LIMIT 1', 'Columns added with withColumn() can contain a dot'); Doctrine::getTable('DArticle')->clear(); Doctrine::getTable('DComment')->clear(); $finder = sfDoctrineFinder::from('DComment')-> withColumn('DArticle.Title'); $comment = $finder->findOne(); try { $t->is($comment->getColumn('DArticle.Title'), 'bbbbb', 'If withColumn() is called on a related object column with no join on this class, the finder adds the join automatically'); } catch(Doctrine_Record_Exception $e) {
require dirname(__FILE__) . '/../../bootstrap/unit.php'; require 'util/xfException.class.php'; require 'document/xfField.class.php'; require 'document/xfDocumentException.class.php'; $t = new lime_test(17, new lime_output_color()); $t->diag('->__construct()'); $validTypes = array(xfField::STORED, xfField::INDEXED, xfField::TOKENIZED, xfField::KEYWORD, xfField::TEXT, xfField::UNSTORED, xfField::UNINDEXED, xfField::BINARY); $invalidTypes = array(0, '42', 'foobar'); foreach ($validTypes as $type) { $msg = '->__construct() accepts the valid type ' . $type; try { $field = new xfField('foobar', $type); $t->pass($msg); } catch (Exception $e) { $t->fail($constructorMsg); $t->skip($msg); } } foreach ($invalidTypes as $type) { $msg = '->__construct() rejects the invalid type ' . $type; try { $field = new xfField('foobar', $type); $t->fail($msg); } catch (Exception $e) { $t->pass($msg); } } $t->diag('->getName(), ->getType()'); $field = new xfField('foobar', xfField::KEYWORD); $t->is($field->getName(), 'foobar', '->getName() returns the name'); $t->is($field->getType(), xfField::KEYWORD, '->getType() returns the type');
} } $object = new OutputEscaperTest(); $escaped = sfOutputEscaper::escape('esc_entities', $object); $t->is($escaped->getTitle(), '<strong>escaped!</strong>', 'The escaped object behaves like the real object'); $array = $escaped->getTitles(); $t->is($array[2], '<strong>escaped!</strong>', 'The escaped object behaves like the real object'); // __toString() $t->diag('__toString()'); $t->is($escaped->__toString(), '<strong>escaped!</strong>', 'The escaped object behaves like the real object'); if (class_exists('SimpleXMLElement')) { $element = new SimpleXMLElement('<foo>bar</foo>'); $escaped = sfOutputEscaper::escape('esc_entities', $element); $t->is((string) $escaped, (string) $element, '->__toString() is compatible with SimpleXMLElement'); } else { $t->skip('->__toString() is compatible with SimpleXMLElement'); } class Foo { } class FooCountable implements Countable { public function count() { return 2; } } // implements Countable $t->diag('implements Countable'); $foo = sfOutputEscaper::escape('esc_entities', new Foo()); $fooc = sfOutputEscaper::escape('esc_entities', new FooCountable());
// ->clean() $t->diag('->clean()'); $v = new sfValidatorSchema(); $t->is($v->clean(null), array(), '->clean() converts null to empty array before validation'); $v = new sfValidatorSchema(array('s1' => $v1, 's2' => $v2)); try { $v->clean('foo'); $t->fail('->clean() throws an InvalidArgumentException exception if the first argument is not an array of value'); } catch (InvalidArgumentException $e) { $t->pass('->clean() throws an InvalidArgumentException exception if the first argument is not an array of value'); } $t->is($v->clean(array('s1' => 'foo', 's2' => 'bar')), array('s1' => 'foo', 's2' => 'bar'), '->clean() returns the string unmodified'); try { $v->clean(array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar')); $t->fail('->clean() throws an sfValidatorErrorSchema exception if a you give a non existant field'); $t->skip('', 2); } catch (sfValidatorErrorSchema $e) { $t->pass('->clean() throws an sfValidatorErrorSchema exception if a you give a non existant field'); $t->is(count($e), 1, '->clean() throws an exception with all error messages'); $t->is($e[0]->getCode(), 'extra_fields', '->clean() throws an exception with all error messages'); } $t->diag('required fields'); try { $v->clean(array('s1' => 'foo')); $t->fail('->clean() throws an sfValidatorErrorSchema exception if a required field is not provided'); $t->skip('', 2); } catch (sfValidatorErrorSchema $e) { $t->pass('->clean() throws an sfValidatorErrorSchema exception if a required field is not provided'); $t->is(count($e), 1, '->clean() throws an exception with all error messages'); $t->is($e['s2']->getCode(), 'required', '->clean() throws an exception with all error messages'); }
$cache->clear(); $DbFinderCache = new sfPropelFinderCache($cache, 10); $finder = DbFinder::from('Article')->useCache($DbFinderCache, 10); $finder->where('Title', 'foo')->findOne(); $t->is($DbFinderCache->justUsedCache(), false, 'justUsedCache() returns false when the query has been executed'); $finder->where('Title', 'foo')->findOne(); $t->is($DbFinderCache->justUsedCache(), true, 'justUsedCache() returns true when the query has not been executed'); $finder->where('Title', 'bar')->findOne(); $t->is($DbFinderCache->justUsedCache(), false, 'justUsedCache() returns false when the query has been executed'); $t->diag('Cache lifetime'); // Cannot test because of PHP bug // See http://pecl.php.net/bugs/bug.php?id=13331 $t->skip('The same query asked after the lifetime does not use the cache', 2); /* $cache->clear(); $finder = DbFinder::from('Article')->useCache($cache, 1); $finder->where('Title', 'foo')->findOne(); // write cache 1 $finder->where('Title', 'bar')->findOne(); // write cache 2 $SQL1 = $finder->getLatestQuery(); $finder->where('Title', 'foo')->findOne(); // read cache 1 $SQL2 = $finder->getLatestQuery(); $t->is($SQL1, $SQL2, 'The same query asked within the lifetime uses the cache'); sleep(2); $finder->where('Title', 'foo')->findOne(); // re-write cache 1 $SQL3 = $finder->getLatestQuery(); $t->isnt($SQL1, $SQL3, 'The same query asked after the lifetime does not use the cache'); */
$date = '2010-05-01'; $account->addEntry($date, $qty, $ref_class, $ref_id); $account->addEntry($date, $qty, $ref_class, $ref_id); $date = '2010-06-01'; $account->addEntry($date, $qty, $ref_class, $ref_id); $account->addEntry($date, $qty, $ref_class, $ref_id); $date = '2010-07-01'; $account->addEntry($date, $qty, $ref_class, $ref_id); $account->addEntry($date, $qty, $ref_class, $ref_id); $t->is($resultok = $account->testEntries(), true, 'maintainance phase completed successfully'); //end maintainance $accountentries = $account->getaccountentries(); $t->diag('getAccountEntries()'); $t->is(get_class($accountentries), "Doctrine_Collection", 'getaccountentries() fetches a Doctrine_Collection of Accountentry objects'); if (count($accountentries) == 0) { $t->skip('getaccountentries() fetches an array of Accountentry objects'); } else { $t->is(get_class($accountentries[0]), "Accountentry", 'getaccountentries() fetches a Doctrine_Collection of Accountentry objects'); } //test getFirstEntry() $t->diag('getFirstEntry()'); $first = $account->getFirstEntry(); $t->is($first->getId(), $accountentries[0]->getId(), 'getFirstEntry() fetches the first entry'); //test getLastEntry() $t->diag('getLastEntry()'); $last = $account->getLastEntry(); $t->is($last->getId(), $accountentries[count($accountentries) - 1]->getId(), 'getLastEntry() fetches the last entry'); //----------------------------------------------- //this should fix balances of entries, even after being messed up $t->diag('calcFromAccountentry()'); //calcfromaccountentry should set balance of first record to qty, if it is null
$t->diag('->getMimeTypesFromCategory()'); $v = new testValidatorFile(); try { $t->is($v->getMimeTypesFromCategory('non_existant_category'), ''); $t->fail('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } $categories = $v->getOption('mime_categories'); $t->is($v->getMimeTypesFromCategory('web_images'), $categories['web_images'], '->getMimeTypesFromCategory() returns an array of mime types for a given category'); $v->setOption('mime_categories', array_merge($v->getOption('mime_categories'), array('text' => array('text/plain')))); $t->is($v->getMimeTypesFromCategory('text'), array('text/plain'), '->getMimeTypesFromCategory() returns an array of mime types for a given category'); // ->guessFromFileinfo() $t->diag('->guessFromFileinfo()'); if (!function_exists('finfo_open')) { $t->skip('finfo_open is not available', 2); } else { $v = new testValidatorFile(); $t->is($v->guessFromFileinfo($tmpDir . '/test.txt'), 'text/plain', '->guessFromFileinfo() guesses the type of a given file'); $t->is($v->guessFromFileinfo($tmpDir . '/foo.txt'), null, '->guessFromFileinfo() returns null if the file type is not guessable'); } // ->guessFromMimeContentType() $t->diag('->guessFromMimeContentType()'); if (!function_exists('mime_content_type')) { $t->skip('mime_content_type is not available', 2); } else { $v = new testValidatorFile(); $t->is($v->guessFromMimeContentType($tmpDir . '/test.txt'), 'text/plain', '->guessFromMimeContentType() guesses the type of a given file'); $t->is($v->guessFromMimeContentType($tmpDir . '/foo.txt'), null, '->guessFromMimeContentType() returns null if the file type is not guessable'); } // ->guessFromFileBinary()
$t->diag('->getMimeTypesFromCategory()'); $v = new testValidatorFile(); try { $t->is($v->getMimeTypesFromCategory('non_existant_category'), ''); $t->fail('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } $categories = $v->getOption('mime_categories'); $t->is($v->getMimeTypesFromCategory('web_images'), $categories['web_images'], '->getMimeTypesFromCategory() returns an array of mime types for a given category'); $v->setOption('mime_categories', array_merge($v->getOption('mime_categories'), array('text' => array('text/plain')))); $t->is($v->getMimeTypesFromCategory('text'), array('text/plain'), '->getMimeTypesFromCategory() returns an array of mime types for a given category'); // ->guessFromFileinfo() $t->diag('->guessFromFileinfo()'); if (!function_exists('finfo_open')) { $t->skip('finfo_open is not available', 2); } else { $v = new testValidatorFile(); $t->is($v->guessFromFileinfo($tmpDir . '/test.txt'), 'text/plain', '->guessFromFileinfo() guesses the type of a given file'); $t->is($v->guessFromFileinfo($tmpDir . '/foo.txt'), null, '->guessFromFileinfo() returns null if the file type is not guessable'); } // ->guessFromMimeContentType() $t->diag('->guessFromMimeContentType()'); if (!function_exists('mime_content_type')) { $t->skip('mime_content_type is not available', 2); } else { $v = new testValidatorFile(); $mimeType = $v->guessFromMimeContentType($tmpDir . '/test.txt'); if (version_compare(PHP_VERSION, '5.3', '<') && false === $mimeType) { $t->skip('mime_content_type has some issue with php 5.2', 1); } else {
$t->pass('_construct() throws an exception when passing a non supported first argument'); } // ->addValidator() $t->diag('->addValidator()'); $v = new sfValidatorOr(); $v->addValidator($v1); $v->addValidator($v2); $t->is($v->getValidators(), array($v1, $v2), '->addValidator() adds a validator'); // ->clean() $t->diag('->clean()'); $t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified'); try { $v->setOption('required', true); $v->clean(null); $t->fail('->clean() throws an sfValidatorError exception if the input value is required'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError exception if the input value is required'); $t->is($e->getCode(), 'required', '->clean() throws a sfValidatorError'); } $v1->setOption('max_length', 1); $v2->setOption('min_length', 5); try { $v->clean('foo'); $t->fail('->clean() throws an sfValidatorError exception if all the validators fails'); $t->skip('', 3); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError exception if all the validators fails'); $t->is(count($e), 2, '->clean() throws an exception with all error messages'); $t->is($e[0]->getCode(), 'max_length', '->clean() throws a sfValidatorSchemaError'); $t->is($e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorSchemaError');
*/ require_once __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(12); $v = new sfValidatorString(); // ->clean() $t->diag('->clean()'); $t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified'); $v->setOption('required', false); $t->ok($v->clean(null) === '', '->clean() converts the value to a string'); $t->ok($v->clean(1) === '1', '->clean() converts the value to a string'); $v->setOption('max_length', 2); $t->is($v->clean('fo'), 'fo', '->clean() checks the maximum length allowed'); try { $v->clean('foo'); $t->fail('"max_length" option set the maximum length of the string'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('"max_length" option set the maximum length of the string'); $t->is($e->getCode(), 'max_length', '->clean() throws a sfValidatorError'); } $v->setMessage('max_length', 'Too long'); try { $v->clean('foo'); $t->fail('"max_length" error message customization'); } catch (sfValidatorError $e) { $t->is($e->getMessage(), 'Too long', '"max_length" error message customization'); } $v->setOption('max_length', null); $v->setOption('min_length', 3); $t->is($v->clean('foo'), 'foo', '->clean() checks the minimum length allowed'); try {
<?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. */ error_reporting(error_reporting() & ~E_STRICT); require_once __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(5); @(include_once 'PEAR.php'); if (!class_exists('PEAR')) { $t->skip('PEAR must be installed', 5); return; } require_once __DIR__ . '/sfPearDownloaderTest.class.php'; require_once __DIR__ . '/sfPearRestTest.class.php'; require_once __DIR__ . '/sfPluginTestHelper.class.php'; // setup $temp = tempnam('/tmp/sf_plugin_test', 'tmp'); unlink($temp); mkdir($temp, 0777, true); define('SF_PLUGIN_TEST_DIR', $temp); $options = array('plugin_dir' => $temp . '/plugins', 'cache_dir' => $temp . '/cache', 'preferred_state' => 'stable', 'rest_base_class' => 'sfPearRestTest', 'downloader_base_class' => 'sfPearDownloaderTest'); $dispatcher = new sfEventDispatcher(); $environment = new sfPearEnvironment($dispatcher, $options); $environment->registerChannel('pear.example.com', true); $rest = $environment->getRest(); // ->getPluginVersions()
<link rel="stylesheet" type="text/css" media="screen" href="/dynamics/foo.css" /> <link rel="stylesheet" type="text/css" media="screen" href="/bar.css" /> </head> <body> <p>Lorem ipsum</p> <script type="text/javascript" src="/dynamics/foo.js"></script> <script type="text/javascript" src="/bar.js"></script> </body> </html> END; $t->is($manager->filterContent(new sfEvent('lorem', 'event.name'), $content), $waited, '->addSfDynamicsTags() replaces placeholder by sfDynamics tags'); $t->info('Backward compatibility tests: content has no placeholder'); if ('append' !== sfDynamicsConfig::getAssetsPositionInHead()) { $t->error('We can’t test append inclusion'); $t->skip('skip 1 tests', 1); } else { $content = <<<END <html> <head> <link rel="stylesheet" type="text/css" media="screen" href="/bar.css" /> <script type="text/javascript" src="/bar.js"></script> </head> <body> <p>Lorem ipsum</p> </body> </html> END; $waited = <<<END <html> <head>