/** * 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'); } } }
/** * * @param lime_test $t * @return PHPGit_Repository the git repo */ function _createTmpGitRepo(lime_test $t, array $options = array()) { $repoDir = sys_get_temp_dir() . '/php-git-repo/' . uniqid(); $t->ok(!is_dir($repoDir . '/.git'), $repoDir . ' is not a Git repo'); try { new PHPGit_Repository($repoDir, true, $options); $t->fail($repoDir . ' is not a valid git repository'); } catch (InvalidArgumentException $e) { $t->pass($repoDir . ' is not a valid git repository'); } $t->comment('Create Git repo'); exec('git init ' . escapeshellarg($repoDir)); $t->ok(is_dir($repoDir . '/.git'), $repoDir . ' is a Git repo'); $repo = new PHPGit_Repository($repoDir, true, $options); $t->isa_ok($repo, 'PHPGit_Repository', $repoDir . ' is a valid git repo'); $originalRepoDir = dirname(__FILE__) . '/repo'; foreach (array('README.markdown', 'index.php') as $file) { copy($originalRepoDir . '/' . $file, $repoDir . '/' . $file); } return $repo; }
function php_html_writer_run_tests(lime_test $t, array $tests, $callable) { foreach ($tests as $test) { $parameters = $test['params']; $expectedResult = isset($test['result']) ? $test['result'] : null; try { $result = call_user_func_array($callable, $parameters); if (isset($test['throws'])) { $t->fail($parameters[0] . ' throws a ' . $test['throws']); } else { $t->is_deeply($result, $expectedResult, '"' . str_replace('"', '\'', $parameters[0]) . '" ' . str_replace("\n", '', var_export($expectedResult, true))); } } catch (Exception $exception) { $exceptionClass = get_class($exception); $message = sprintf('"%s" throws a %s: %s', isset($parameters[0]) ? str_replace('"', '\'', (string) $parameters[0]) : 'NULL', $exceptionClass, $exception->getMessage()); if (isset($test['throws']) && $test['throws'] == $exceptionClass) { $t->pass($message); } else { $t->fail($message); } } } }
<?php require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot('front'); clearstatcache(true); $isSqlite = Doctrine_Manager::getInstance()->getConnection('doctrine') instanceof Doctrine_Connection_Sqlite; $t = new lime_test(16 + ($isSqlite ? 0 : 1) + 3 * count($helper->get('i18n')->getCultures())); $user = $helper->get('user'); try { $index = $helper->get('search_index'); $t->fail('Can\'t create index without dir'); } catch (dmSearchIndexException $e) { $t->pass('Can\'t create index without dir'); } $engine = $helper->get('search_engine'); $t->isa_ok($engine, 'dmSearchEngine', 'Got a dmSearchEngine instance'); $expected = dmProject::rootify(dmArray::get($helper->get('service_container')->getParameter('search_engine.options'), 'dir')); $t->is($engine->getFullPath(), $expected, 'Current engine full path is ' . $expected); $t->ok(!file_exists(dmProject::rootify('segments.gen')), 'There is no segments.gen in project root dir'); $engine->setDir('cache/testIndex'); foreach ($helper->get('i18n')->getCultures() as $culture) { $user->setCulture($culture); $currentIndex = $engine->getCurrentIndex(); $t->is($currentIndex->getName(), 'dm_page_' . $culture, 'Current index name is ' . $currentIndex->getName()); $t->is($currentIndex->getCulture(), $culture, 'Current index culture is ' . $culture); $t->is($currentIndex->getFullPath(), dmProject::rootify('cache/testIndex/' . $currentIndex->getName()), 'Current index full path is ' . $currentIndex->getFullPath()); } $user->setCulture(sfConfig::get('sf_default_culture')); $currentIndex = $engine->getCurrentIndex(); $t->isa_ok($currentIndex->getLuceneIndex(), 'Zend_Search_Lucene_Proxy', 'The current index is instanceof Zend_Search_Lucene_Proxy');
$v1 = new sfValidatorString(array('max_length' => 3)); $v2 = new sfValidatorString(array('min_length' => 3)); $v = new sfValidatorOr(array($v1, $v2)); // __construct() $t->diag('__construct()'); $v = new sfValidatorOr(); $t->is($v->getValidators(), array(), '->__construct() can take no argument'); $v = new sfValidatorOr($v1); $t->is($v->getValidators(), array($v1), '->__construct() can take a validator as its first argument'); $v = new sfValidatorOr(array($v1, $v2)); $t->is($v->getValidators(), array($v1, $v2), '->__construct() can take an array of validators as its first argument'); try { $v = new sfValidatorOr('string'); $t->fail('_construct() throws an exception when passing a non supported first argument'); } catch (InvalidArgumentException $e) { $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);
*/ require_once dirname(__FILE__) . '/../lib/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); require_once dirname(__FILE__) . '/../lib/yaml/sfYaml.php'; $t = new lime_test(4); $dir = dirname(__FILE__) . '/fixtures/yaml'; // ->dump() $t->diag('->dump()'); $dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder()); $t->is($dumper->dump(), file_get_contents($dir . '/services1.yml'), '->dump() dumps an empty container as an empty YAML file'); $container = new sfServiceContainerBuilder(); $dumper = new sfServiceContainerDumperYaml($container); // ->addParameters() $t->diag('->addParameters()'); $container = (include dirname(__FILE__) . '/fixtures/containers/container8.php'); $dumper = new sfServiceContainerDumperYaml($container); $t->is($dumper->dump(), file_get_contents($dir . '/services8.yml'), '->dump() dumps parameters'); // ->addService() $t->diag('->addService()'); $container = (include dirname(__FILE__) . '/fixtures/containers/container9.php'); $dumper = new sfServiceContainerDumperYaml($container); $t->is($dumper->dump(), str_replace('%path%', dirname(__FILE__) . '/fixtures/includes', file_get_contents($dir . '/services9.yml')), '->dump() dumps services'); $dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder()); $container->register('foo', 'FooClass')->addArgument(new stdClass()); try { $dumper->dump(); $t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); } catch (RuntimeException $e) { $t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); }
<?php require_once dirname(__FILE__) . '/vendor/lime.php'; require_once dirname(__FILE__) . '/../lib/phpHtmlWriter.php'; require_once dirname(__FILE__) . '/phpHtmlWriterTestHelper.php'; $t = new lime_test(3); $view = new phpHtmlWriter(); $nbTests = 500; $nbTags = 10; $t->is($view->tag('div'), '<div></div>', 'Writer is ready'); $startTime = microtime(true); for ($iterator = 0; $iterator < $nbTests; ++$iterator) { $view->tag('div#my_id' . $iterator, $view->tag('ul.my_class' . $iterator, $view->tag('li.li_class', 'some content ' . $iterator) . $view->tag('li.li_class', $view->tag('input value="my value ' . $iterator . '"')) . $view->tag('li', array('id' => 'my_id'), $view->tag('p', array('lang' => 'fr'), 'du contenu'))) . $view->open('div') . 'some text' . $view->tag('br') . $view->close('div')); } $time = 1000 * (microtime(true) - $startTime); $t->pass(sprintf('Time to render %d nested tags: %0.2f milliseconds', $nbTests * $nbTags, $time)); $t->pass(sprintf('Time per tag: %0.3f milliseconds', $time / ($nbTests * $nbTags)));
require_once dirname(__FILE__) . '/../bootstrap.php'; use Bundle\sfFormBundle\Validator\SchemaFilter; use Bundle\sfFormBundle\Validator\String; use Bundle\sfFormBundle\Validator\Error; use Bundle\sfFormBundle\Validator\ErrorSchema; $t = new lime_test(6); $v1 = new String(array('min_length' => 2, 'trim' => true)); $v = new SchemaFilter('first_name', $v1); // ->clean() $t->diag('->clean()'); $t->is($v->clean(array('first_name' => ' foo ')), array('first_name' => 'foo'), '->clean() executes the embedded validator'); try { $v->clean('string'); $t->fail('->clean() throws a \\InvalidArgumentException if the input value is not an array'); } catch (\InvalidArgumentException $e) { $t->pass('->clean() throws a \\InvalidArgumentException if the input value is not an array'); } try { $v->clean(null); $t->fail('->clean() throws a Error if the embedded validator failed'); $t->skip('', 1); } catch (Error $e) { $t->pass('->clean() throws a Error if the embedded validator failed'); $t->is($e->getCode(), 'first_name [required]', '->clean() throws a Error'); } try { $v->clean(array('first_name' => 'f')); $t->fail('->clean() throws a Error if the embedded validator failed'); $t->skip('', 1); } catch (Error $e) { $t->pass('->clean() throws a Error if the embedded validator failed');
<?php require_once dirname(__FILE__) . '/../../vendor/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/TwitterBot.class.php'; $t = new lime_test(12, new lime_output_color()); // Sample data $xmlTweet = DOMDocument::load(dirname(__FILE__) . '/xml/server/statuses/show/2043091669.xml'); // createFromXml() $t->diag('createFromXML()'); try { $tweet = Tweet::createFromXML($xmlTweet); $t->pass('createFromXml() creates a Tweet instance from an XML element without throwing an exception'); } catch (Exception $e) { $t->fail('createFromXml() creates a Tweet instance from an XML element without throwing an exception'); $t->diag(sprintf(' %s: %s', get_class($e), $e->getMessage())); } $t->isa_ok($tweet, 'Tweet', 'createFromXML() creates a Tweet instance'); $t->is($tweet->created_at, 'Fri Jun 05 14:21:23 +0000 2009', 'createFromXML() can retrieve created_at property'); $t->is($tweet->id, 2043091669, 'createFromXML() can retrieve id property'); $t->is($tweet->text, 'foo', 'createFromXML() can retrieve text property'); $t->is($tweet->source, '<a href="http://www.nambu.com">Nambu</a>', 'createFromXML() can retrieve source property'); $t->is($tweet->truncated, false, 'createFromXML() can retrieve truncated property'); $t->is($tweet->in_reply_to_status_id, 2043033723, 'createFromXML() can retrieve in_reply_to_status_id property'); $t->is($tweet->in_reply_to_user_id, 14587759, 'createFromXML() can retrieve in_reply_to_user_id property'); $t->is($tweet->favorited, false, 'createFromXML() can retrieve favorited property'); $t->is($tweet->in_reply_to_screen_name, 'fvsch', 'createFromXML() can retrieve in_reply_to_screen_name property'); $t->isa_ok($tweet->user, 'TwitterUser', 'createFromXML() imports TwitterUser');
$number = 12; $error = null; $t->ok($v->execute($number, $error), '->execute() returns true if you don\'t define any parameter'); foreach (array('not a number', '0xFE') as $number) { $error = null; $t->ok(!$v->execute($number, $error), '->execute() returns "nan_error" if value is not a number'); $t->is($error, 'Input is not a number', '->execute() changes "$error" with a default message if it returns false'); } foreach (array('any', 'decimal', 'float', 'int', 'integer') as $type) { $t->ok($v->initialize($context, array('type' => $type)), sprintf('->execute() can take "%s" as a type argument', $type)); } try { $v->initialize($context, array('type' => 'another type')); $t->fail('->initialize() throws an sfValidatorException if "type" is invalid'); } catch (sfValidatorException $e) { $t->pass('->initialize() throws an sfValidatorException if "type" is invalid'); } $h = new sfValidatorTestHelper($context, $t); // min $t->diag('->execute() - min parameter'); $h->launchTests($v, 6, true, 'min', null, array('min' => 5)); $h->launchTests($v, 5, true, 'min', null, array('min' => 5)); $h->launchTests($v, 4, false, 'min', 'min_error', array('min' => 5)); // max $t->diag('->execute() - max parameter'); $h->launchTests($v, 4, true, 'max', null, array('max' => 5)); $h->launchTests($v, 5, true, 'max', null, array('max' => 5)); $h->launchTests($v, 6, false, 'max', 'max_error', array('max' => 5)); // type is integer $t->diag('->execute() - type is integer'); $h->launchTests($v, 4, true, 'type', null, array('type' => 'integer'));
$w3->setParent($schema); $t->ok($f->getWidget('name') == $w3, '->setWidget() sets a widget for a field'); // ArrayAccess interface $t->diag('ArrayAccess interface'); $f = new FormTest(); $f->setWidgetSchema(new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInputText(array('default' => 'Fabien')), 'last_name' => new sfWidgetFormInputText(), 'image' => new sfWidgetFormInputFile()))); $f->setValidatorSchema(new sfValidatorSchema(array('first_name' => new sfValidatorPass(), 'last_name' => new sfValidatorPass(), 'image' => new sfValidatorPass()))); $f->setDefaults(array('image' => 'default.gif')); $f->embedForm('embedded', new sfForm()); $t->ok($f['first_name'] instanceof sfFormField, '"sfForm" implements the ArrayAccess interface'); $t->is($f['first_name']->render(), '<input type="text" name="first_name" value="Fabien" id="first_name" />', '"sfForm" implements the ArrayAccess interface'); try { $f['image'] = 'image'; $t->fail('"sfForm" ArrayAccess implementation does not permit to set a form field'); } catch (LogicException $e) { $t->pass('"sfForm" ArrayAccess implementation does not permit to set a form field'); } $t->ok(isset($f['image']), '"sfForm" implements the ArrayAccess interface'); unset($f['image']); $t->ok(!isset($f['image']), '"sfForm" implements the ArrayAccess interface'); $t->ok(!array_key_exists('image', $f->getDefaults()), '"sfForm" ArrayAccess implementation removes form defaults'); $v = $f->getValidatorSchema(); $t->ok(!isset($v['image']), '"sfForm" ArrayAccess implementation removes the widget and the validator'); $w = $f->getWidgetSchema(); $t->ok(!isset($w['image']), '"sfForm" ArrayAccess implementation removes the widget and the validator'); try { $f['nonexistant']; $t->fail('"sfForm" ArrayAccess implementation throws a LogicException if the form field does not exist'); } catch (LogicException $e) { $t->pass('"sfForm" ArrayAccess implementation throws a LogicException if the form field does not exist'); }
/* * 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); // __construct() $t->diag('__construct()'); try { new sfValidatorCSRFToken(); $t->fail('__construct() throws an RuntimeException if you don\'t pass a token option'); } catch (RuntimeException $e) { $t->pass('__construct() throws an RuntimeException if you don\'t pass a token option'); } $v = new sfValidatorCSRFToken(array('token' => 'symfony')); // ->clean() $t->diag('->clean()'); $t->is($v->clean('symfony'), 'symfony', '->clean() checks that the token is valid'); try { $v->clean('another'); $t->fail('->clean() throws an sfValidatorError if the token is not valid'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the token is not valid'); $t->is($e->getCode(), 'csrf_attack', '->clean() throws a sfValidatorError'); } // ->asString() $t->diag('->asString()');
if (isset($test['todo']) && $test['todo']) { $t->todo($test['test']); } else { $expected = var_export(eval('return ' . trim($test['php']) . ';'), true); $t->is(var_export($parser->parse($test['yaml']), true), $expected, $test['test']); } } } // test tabs in YAML $yamls = array("foo:\n\tbar", "foo:\n \tbar", "foo:\n\t bar", "foo:\n \t bar"); foreach ($yamls as $yaml) { try { $content = $parser->parse($yaml); $t->fail('YAML files must not contain tabs'); } catch (InvalidArgumentException $e) { $t->pass('YAML files must not contain tabs'); } } $yaml = <<<EOF --- %YAML:1.0 foo ... EOF; $t->is('foo', $parser->parse($yaml)); // objects $t->diag('Objects support'); class A { public $a = 'foo'; } $a = array('foo' => new A(), 'bar' => 1);
$t->is($option->acceptParameter(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $t->is($option->isParameterRequired(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $t->is($option->isParameterOptional(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode'); $option = new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_REQUIRED); $t->is($option->acceptParameter(), true, '__construct() can take "sfCommandOption::PARAMETER_REQUIRED" as its mode'); $t->is($option->isParameterRequired(), true, '__construct() can take "sfCommandOption::PARAMETER_REQUIRED" as its mode'); $t->is($option->isParameterOptional(), false, '__construct() can take "sfCommandOption::PARAMETER_REQUIRED" as its mode'); $option = new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_OPTIONAL); $t->is($option->acceptParameter(), true, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode'); $t->is($option->isParameterRequired(), false, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode'); $t->is($option->isParameterOptional(), true, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode'); try { $option = new sfCommandOption('foo', 'f', 'ANOTHER_ONE'); $t->fail('__construct() throws an sfCommandException if the mode is not valid'); } catch (sfCommandException $e) { $t->pass('__construct() throws an sfCommandException if the mode is not valid'); } // ->isArray() $t->diag('->isArray()'); $option = new sfCommandOption('foo', null, sfCommandOption::IS_ARRAY); $t->ok($option->isArray(), '->isArray() returns true if the option can be an array'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE | sfCommandOption::IS_ARRAY); $t->ok($option->isArray(), '->isArray() returns true if the option can be an array'); $option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE); $t->ok(!$option->isArray(), '->isArray() returns false if the option can not be an array'); // ->getHelp() $t->diag('->getHelp()'); $option = new sfCommandOption('foo', 'f', null, 'Some help'); $t->is($option->getHelp(), 'Some help', '->getHelp() returns the help message'); // ->getDefault() $t->diag('->getDefault()');
{ public function setup() { $this->enablePlugins(array('sfAutoloadPlugin', 'sfConfigPlugin')); $this->setPluginPath('sfConfigPlugin', $this->rootDir . '/lib/plugins/sfConfigPlugin'); } } $configuration = new ProjectConfiguration(__DIR__ . '/../../functional/fixtures'); // ->setPlugins() ->disablePlugins() ->enablePlugins() ->enableAllPluginsExcept() $t->diag('->setPlugins() ->disablePlugins() ->enablePlugins() ->enableAllPluginsExcept()'); foreach (array('setPlugins', 'disablePlugins', 'enablePlugins', 'enableAllPluginsExcept') as $method) { try { $configuration->{$method}(array()); $t->fail('->' . $method . '() throws an exception if called too late'); } catch (Exception $e) { $t->pass('->' . $method . '() throws an exception if called too late'); } } class ProjectConfiguration2 extends sfProjectConfiguration { public function setup() { $this->enablePlugins('sfAutoloadPlugin', 'sfConfigPlugin'); } } $configuration = new ProjectConfiguration2(__DIR__ . '/../../functional/fixtures'); $t->is_deeply($configuration->getPlugins(), array('sfAutoloadPlugin', 'sfConfigPlugin'), '->enablePlugins() can enable plugins passed as arguments instead of array'); // ->__construct() $t->diag('->__construct()'); class ProjectConfiguration3 extends sfProjectConfiguration {
* (c) 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'; $t = new lime_test(8); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->configure() $t->diag('->configure()'); try { new sfWidgetFormI18nChoiceCountry(array('culture' => 'en', 'countries' => array('EN'))); $t->fail('->configure() throws an InvalidArgumentException if a country does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->configure() throws an InvalidArgumentException if a country does not exist'); } $v = new sfWidgetFormI18nChoiceCountry(array('culture' => 'en', 'countries' => array('FR', 'GB'))); $t->is(array_keys($v->getOption('choices')), array('FR', 'GB'), '->configure() can restrict the number of countries with the countries option'); // ->render() $t->diag('->render()'); $w = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr')); $dom->loadHTML($w->render('country', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#country option[value="FR"]')->getValue(), 'France', '->render() renders all countries as option tags'); $t->is(count($css->matchAll('#country option[value="FR"][selected="selected"]')->getNodes()), 1, '->render() renders all countries as option tags'); // Test for ICU Upgrade and Ticket #7988 // should be 0. Tests will break after ICU Update, which is fine. change count to 0 $t->is(count($css->matchAll('#country option[value="ZZ"]')), 1, '->render() does not contain dummy data'); $t->is(count($css->matchAll('#country option[value="419"]')), 0, '->render() does not contain region data'); // add_empty
$storage->sessionWrite(session_id(), $newSessionData); $t->isnt(session_id(), $session_id, 'regenerate() regenerated the session with a different session id'); // checking if the old session record still exists $result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id)); $data = $result->fetchAll(); $t->is(count($data), 1, 'regenerate() has kept destroyed old session'); // checking if the new session record has been created $result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', session_id())); $data = $result->fetchAll(); $t->is(count($data), 1, 'regenerate() has created a new session record'); $t->is($data[0]['sess_data'], $newSessionData, 'regenerate() has created a new record with correct data'); $session_id = session_id(); // sessionRead() try { $retrieved_data = $storage->sessionRead($session_id); $t->pass('sessionRead() does not throw an exception'); } catch (Exception $e) { $t->fail('sessionRead() does not throw an exception'); } $t->is($retrieved_data, $newSessionData, 'sessionRead() reads session data'); // sessionWrite() $otherSessionData = 'foo:foo:foo'; try { $write = $storage->sessionWrite($session_id, $otherSessionData); $t->pass('sessionWrite() does not throw an exception'); } catch (Exception $e) { $t->fail('sessionWrite() does not throw an exception'); } $t->ok($write, 'sessionWrite() returns true'); $t->is($storage->sessionRead($session_id), $otherSessionData, 'sessionWrite() wrote session data'); // sessionGC()
* 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(13); function choice_callable() { return array(1, 2, 3); } // __construct() $t->diag('__construct()'); try { new sfValidatorChoice(); $t->fail('__construct() throws an RuntimeException if you don\'t pass an expected option'); } catch (RuntimeException $e) { $t->pass('__construct() throws an RuntimeException if you don\'t pass an expected option'); } $v = new sfValidatorChoice(array('choices' => array('foo', 'bar'))); // ->clean() $t->diag('->clean()'); $t->is($v->clean('foo'), 'foo', '->clean() checks that the value is an expected value'); $t->is($v->clean('bar'), 'bar', '->clean() checks that the value is an expected value'); try { $v->clean('foobar'); $t->fail('->clean() throws an sfValidatorError if the value is not an expected value'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the value is not an expected value'); $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); } // ->asString()
} public function hasTemplate($template) { return false; } } $t->diag('::isTaggable'); $t->ok(TaggableToolkit::isTaggable('ValidModel'), 'valid model name'); $t->ok(TaggableToolkit::isTaggable(new ValidModel('ValidModel')), 'valid model object'); $t->ok(!TaggableToolkit::isTaggable('InValidModel'), 'invalid model name'); $t->ok(!TaggableToolkit::isTaggable(new InValidModel('InValidModel')), 'invalid model object'); try { TaggableToolkit::isTaggable('MyClass'); $t->fail('no exception for no doctrine model name'); } catch (Exception $e) { $t->pass('no doctrine model name'); } class MyClass { } try { TaggableToolkit::isTaggable(new MyClass()); $t->fail('no exception for no doctrine model class'); } catch (Exception $e) { $t->pass('no doctrine model class'); } $t->diag('::normalize'); $t->todo('test normalize'); $t->diag('::triplify'); $tags = array('peter', 'wolf'); array_walk($tags, 'TaggableToolkit::triplify', 'namespace:key');
*/ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $validV4Ips = array('0.0.0.0', '10.0.0.0', '123.45.67.178', '172.16.0.0', '192.168.1.0', '224.0.0.1', '255.255.255.255', '127.0.0.0'); $invalidV4Ips = array('0', '0.0', '0.0.0', '256.0.0.0', '0.256.0.0', '0.0.256.0', '0.0.0.256', '-1.0.0.0', 'foobar'); $invalidPrivateV4Ips = array('10.0.0.0', '172.16.0.0', '192.168.1.0'); $invalidReservedV4Ips = array('0.0.0.0', '224.0.0.1', '255.255.255.255'); $validV6Ips = array('2001:0db8:85a3:0000:0000:8a2e:0370:7334', '2001:0DB8:85A3:0000:0000:8A2E:0370:7334', '2001:0Db8:85a3:0000:0000:8A2e:0370:7334', 'fdfe:dcba:9876:ffff:fdc6:c46b:bb8f:7d4c', 'fdc6:c46b:bb8f:7d4c:fdc6:c46b:bb8f:7d4c', 'fdc6:c46b:bb8f:7d4c:0000:8a2e:0370:7334', 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', 'fe80:0:0:0:202:b3ff:fe1e:8329', 'fe80::202:b3ff:fe1e:8329', '0:0:0:0:0:0:0:0', '::', '0::', '::0', '0::0', '2001:0db8:85a3:0000:0000:8a2e:0.0.0.0', '::0.0.0.0', '::255.255.255.255', '::123.45.67.178'); $invalidV6Ips = array('z001:0db8:85a3:0000:0000:8a2e:0370:7334', 'fe80', 'fe80:8329', 'fe80:::202:b3ff:fe1e:8329', 'fe80::202:b3ff::fe1e:8329', '2001:0db8:85a3:0000:0000:8a2e:0370:0.0.0.0', '::0.0', '::0.0.0', '::256.0.0.0', '::0.256.0.0', '::0.0.256.0', '::0.0.0.256'); $invalidPrivateV6Ips = array('fdfe:dcba:9876:ffff:fdc6:c46b:bb8f:7d4c', 'fdc6:c46b:bb8f:7d4c:fdc6:c46b:bb8f:7d4c', 'fdc6:c46b:bb8f:7d4c:0000:8a2e:0370:7334'); $t = new lime_test(180, new lime_output_color()); $t->diag('testing against empty IP'); $v = new sfValidatorIp(array('required' => false)); foreach (array(null, '') as $ip) { try { $v->clean($ip); $t->pass("Empty IP is considered as valid"); } catch (sfValidatorError $e) { $t->fail("Empty IP is considered as valid"); } } $t->diag('testing against valid IP all'); foreach (array_merge($validV4Ips, $validV6Ips) as $ip) { try { $v->clean($ip); $t->pass(sprintf("%s is considered as valid ip", $ip)); } catch (sfValidatorError $e) { $t->fail(sprintf("%s is considered as valid ip", $ip)); } } foreach (array(sfValidatorIp::IP_V4 => $validV4Ips, sfValidatorIp::IP_V6 => $validV6Ips) as $version => $ips) { $t->diag('testing against valid IP V' . $version);
{ return parent::guessFromFileBinary($file); } public function getMimeTypesFromCategory($category) { return parent::getMimeTypesFromCategory($category); } } // ->getMimeTypesFromCategory() $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()
require 'result/xfResultException.class.php'; require 'mock/result/xfMockRetort.class.php'; $t = new lime_test(11, new lime_output_color()); $document = new xfDocument('guid'); $document->addField(new xfFieldValue(new xfField('_service', xfField::STORED), 'foo-service')); $hit = new xfDocumentHit($document, array('score' => 0.2)); $t->diag('->getOption(), ->getOptions(), hasOption(), setOption()'); $t->is($hit->getOption('score'), 0.2, '->getOption() returns the option value'); $t->is($hit->getOption('foobar'), null, '->getOption() returns null for unset options'); $t->is($hit->getOption('foobar', 42), 42, '->getOption() returns the default for unset options'); $t->ok($hit->hasOption('score'), '->hasOption() returns true for options that exist'); $t->ok(!$hit->hasOption('foobar'), '->hasOption() returns false for options that do not exist'); $hit->setOption('foobar', 'baz'); $t->is($hit->getOption('foobar'), 'baz', '->getOption() returns the option value'); $t->is($hit->getOptions(), array('score' => 0.2, 'foobar' => 'baz'), '->getOptions() returns all options'); $t->diag('->getDocument(), ->getServiceName()'); $t->is($hit->getDocument(), $document, '->getDocument() returns the wrapped document'); $t->is($hit->getServiceName(), 'foo-service', '->getServiceName() returns the service name'); $t->diag('->__call()'); $retort = new xfMockRetort(); $retort->can = false; $hit->setRetorts(array($retort)); try { $msg = '->__call() throws exception when a retort is not found'; $hit->getWhatever(); $t->fail($msg); } catch (Exception $e) { $t->pass($msg); } $hit->setRetorts(array(new xfMockRetort())); $t->is($hit->getWhatever(), 42, '->__call() returns the retort response');
<?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 __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(1); class ProjectDumper extends sfServiceContainerDumper { } $builder = new sfServiceContainerBuilder(); $dumper = new ProjectDumper($builder); try { $dumper->dump(); $t->fail('->dump() returns a LogicException if the dump() method has not been overriden by a children class'); } catch (LogicException $e) { $t->pass('->dump() returns a LogicException if the dump() method has not been overriden by a children class'); }
require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(13, new lime_output_color()); $v = new sfValidatorI18nNumber(); // ->clean() - no culture $t->diag('->clean() - standard culture = en'); $v->setOption('culture', 'en'); $t->is($v->clean(12.3), 12.3, '->clean() returns the numbers unmodified'); $t->is($v->clean('12.3'), 12.3, '->clean() converts strings to numbers'); $t->is($v->clean(12.12345678901234), 12.12345678901234, '->clean() returns the numbers unmodified'); $t->is($v->clean('12.12345678901234'), 12.12345678901234, '->clean() converts strings to numbers'); $t->is($v->clean('123,456.78'), 123456.78, '->clean() convert grouped numbers'); try { $v->clean('123,456.789,012'); $t->fail('->clean fails wrong grouped numbers'); } catch (sfValidatorError $e) { $t->pass('->clean throws a sfValidatorError if the value is grouped wrong'); } try { $v->clean('not a float'); $t->fail('->clean() throws a sfValidatorError if the value is not a number'); } catch (sfValidatorError $e) { $t->pass('->clean() throws a sfValidatorError if the value is not a number'); } $t->diag('->clean() - culture = de'); $v->setOption('culture', 'de'); $t->is($v->clean("12,3"), "12.3", '->clean() return the normalized string'); $t->is($v->clean('12,12345678901234'), 12.12345678901234, '->clean() converts strings to normalized numbers'); $t->is($v->clean('123.456,78'), 123456.78, '->clean() convert grouped numbers'); $t->is($v->clean('100.000'), 100000, '->clean() convert grouped numbers'); try { $v->clean('123.456,789.012');
<input type="image" src="myimage.png" alt="image submit" name="submit_image" value="image" /> </span></div> </form> <a href="/myotherlink">test link</a> </body> </html> EOF; $b = new myClickBrowser(); $b->setHtml($html); try { $b->click('nonexistantname'); $t->fail('->click() throws an error if the name does not exist'); } catch (Exception $e) { $t->pass('->click() throws an error if the name does not exist'); } try { list($method, $uri, $parameters) = $b->click('submit5'); $t->pass('->click() clicks on button links'); } catch (Exception $e) { $t->fail('->click() clicks on button links'); } list($method, $uri, $parameters) = $b->click('test link'); $t->is($uri, '/mylink', '->click() clicks on links'); list($method, $uri, $parameters) = $b->click('test link', array(), array('position' => 2)); $t->is($uri, '/myotherlink', '->click() can take a third argument to tell the position of the link to click on'); list($method, $uri, $parameters) = $b->click('image link'); $t->is($uri, '/myimagelink', '->click() clicks on image links'); list($method, $uri, $parameters) = $b->click('submit'); $t->is($method, 'post', '->click() gets the form method');
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(4, new lime_output_color()); $scope = new afVarScope(array('title' => 'hello', 'start' => 5)); $t->is($scope->interpret('Title: {title}, start={start}'), 'Title: hello, start=5'); $t->is($scope->interpret('normal text'), 'normal text'); $t->is($scope->interpret('/a regex[a-Z]{3}/'), '/a regex[a-Z]{3}/'); try { $scope->interpret('other: {other}'); $t->fail(); } catch (XmlParserException $e) { $t->pass(); }
<?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'); } }
$databaseManager = new sfDatabaseManager($configuration); $table = Doctrine_Core::getTable('sfGuardUser'); // ->retrieveByUsername() $t->diag('->retrieveByUsername()'); $table->createQuery()->delete()->where('username = ? OR username = ?', array('inactive_user', 'active_user'))->execute(); $inactiveUser = new sfGuardUser(); $inactiveUser->email_address = '*****@*****.**'; $inactiveUser->username = '******'; $inactiveUser->password = '******'; $inactiveUser->is_active = false; $inactiveUser->save(); $activeUser = new sfGuardUser(); $activeUser->email_address = '*****@*****.**'; $activeUser->username = '******'; $activeUser->password = '******'; $activeUser->is_active = true; $activeUser->save(); $t->is($table->retrieveByUsername('invalid'), null, '->retrieveByUsername() returns "null" if username is invalid'); $t->is($table->retrieveByUsername('inactive_user'), null, '->retrieveByUsername() returns "null" if user is inactive'); $t->isa_ok($table->retrieveByUsername('inactive_user', false), 'sfGuardUser', '->retrieveByUsername() returns an inactive user when second parameter is false'); $t->isa_ok($table->retrieveByUsername('active_user'), 'sfGuardUser', '->retrieveByUsername() returns an active user'); $t->is($table->retrieveByUsername('active_user', false), null, '->retrieveByUsername() returns "null" if user is active and second parameter is false'); $t->isa_ok($table->retrieveByUsername('active_user'), 'sfGuardUser', '->retrieveByUsername() can be called non-statically'); try { $table->retrieveByUsername(null); $t->pass('->retrieveByUsername() does not throw an exception if username is null'); } catch (Exception $e) { $t->diag($e->getMessage()); $t->fail('->retrieveByUsername() does not throw an exception if username is null'); } $t->isa_ok(@PluginsfGuardUserTable::retrieveByUsername('active_user'), 'sfGuardUser', '->retrieveByUsername() can be called statically (BC)');
<?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'; require_once __DIR__ . '/sfCacheDriverTests.class.php'; $t = new lime_test(65); // setup sfConfig::set('sf_logging_enabled', false); $temp = tempnam('/tmp/cache_dir', 'tmp'); unlink($temp); mkdir($temp); // ->initialize() $t->diag('->initialize()'); try { $cache = new sfFileCache(); $t->fail('->initialize() throws an sfInitializationException exception if you don\'t pass a "cache_dir" parameter'); } catch (sfInitializationException $e) { $t->pass('->initialize() throws an sfInitializationException exception if you don\'t pass a "cache_dir" parameter'); } $cache = new sfFileCache(array('cache_dir' => $temp)); sfCacheDriverTests::launch($t, $cache); // teardown sfToolkit::clearDirectory($temp); rmdir($temp);
<?php require_once dirname(__FILE__) . '/../bootstrap/unit.php'; $lime = new lime_test(1); $lime->pass('This test always passes!');