function check_test_tree(lime_test $t, ioMenuItem $menu) { $t->info('### Running checks on the integrity of the test tree.'); $t->is(count($menu), 2, 'count(rt) returns 2 children'); $t->is(count($menu['Parent 1']), 3, 'count(pt1) returns 3 children'); $t->is(count($menu['Parent 2']), 1, 'count(pt2) returns 1 child'); $t->is(count($menu['Parent 2']['Child 4']), 1, 'count(ch4) returns 1 child'); $t->is_deeply($menu['Parent 2']['Child 4']['Grandchild 1']->getName(), 'Grandchild 1', 'gc1 has the name "Grandchild 1"'); }
/** * 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'); } } }
/** * Test launcher * * @param string $schema Path to schema file */ function launchTests($schema) { $this->t->diag('->load()'); $this->load($schema); $this->t->diag('->getTables()'); $tables = $this->tables; $this->t->is(count($tables), 2, "->getTables() should return 2 table from fixture."); $this->t->ok(in_array('testTable', array_keys($tables)), "->getTables() should return 'testTable' from fixture."); $this->t->diag('->classes'); $this->t->is(count($this->classes), 2, "->classes should have 2 class from fixture"); $this->t->ok($this->getClass('TestTable'), "->classes should have 'TestTable' from fixture."); $this->t->ok($this->getClass('TestTable')->getColumn('dummy_id')->hasRelation(), 'foreign relation is properly imported'); #$this->t->diag('->asDoctrineYml()'); #$yml = $this->asDoctrineYml(); #$this->t->cmp_ok(strlen($yml['source']), '>', 0, "->asDoctrineYml() doctrine YAML shoudl not be empty."); $this->t->diag('->findClassByTableName()'); $this->t->is($this->findClassByTableName('testTable')->getPhpName(), 'TestTable', "->findClassByTableName() returns 'TestTable' class for 'testTable' table."); $yml = $this->asDoctrineYml(); $yml = $yml['source']; $this->t->like($yml, '@cascadeDelete: 1@', 'onDelete is generated'); }
/** * Test launcher * * @param string $schema Path to schema file */ function launchTests($schema) { $this->t->diag('->load()'); $this->load($schema); $this->process(); $yml = $this->asDoctrineYml(); $this->t->diag('->getClasses()'); $classes = $this->getClasses(); $nbClasses = 12; $this->t->is(count($classes), $nbClasses, "->getClasses() should return {$nbClasses} classes from fixture."); $this->t->diag('->getClass()'); $class = $this->getClass('TestClass'); #$this->t->ok($class->isTable(),"->getClass() should return return class instance."); $this->t->diag('->parentTable()'); $table = $this->parentTable($class); $this->t->is(get_class($table), 'sfDoctrineTableSchema', "->parentTable() should return table instance."); $this->t->is($this->getClass('ColAggregation')->getTableName(), 'parent_table', 'inheritance gets the right parent table'); #$this->t->ok($this->getClass('SeparateTable')->isTable(), '"SeparateTable" is a table-class'); $this->t->is($this->getClass('BookI18n')->getColumn('culture')->getProperty('type'), 'string', 'culture field is defined (as a string)'); $rel = $this->getClass('BookI18n')->getRelation('id'); $this->t->is($rel->get('localName'), 'BookI18n', 'i18n relation name is not a plural'); $this->t->is($this->getClass('ColAggregation')->getTable()->getColumn('class_key')->getProperty('type'), 'integer', 'inheritance field is defined (as an integer)'); $c = $this->getClass('SeparateTable'); $SeparateTablePhp = $c->asPhp(); $SeparateTableSource = $SeparateTablePhp[0]['source']; $this->t->like($SeparateTableSource, '/extends Parent/', 'The class "SeparateTable" extends Parent without having any class key field'); $this->t->like($SeparateTableSource, '@setTableName\\(\'separate_table\'\\)@', 'class "SeparateTable" has both a table and inheritance'); $this->t->like($SeparateTableSource, '@parent::setTableDefinition\\(\\);@', 'class "SeparateTable" calls parent::setTableDefinition'); $colAggregationPhp = $this->getClass('ColAggregation')->asPhp(); $this->t->like($colAggregationPhp[0]['source'], "@setInheritanceMap\\(array\\('class_key'=>1\\)\\)@", 'setInheritanceMap is properly set'); $this->t->diag('relationships'); $yangPhp = $this->getClass('Yin')->asPhp(); $this->t->like($yangPhp[0]['source'], "#hasOne\\('Yang as Yang', 'Yin.yang_id', 'id'\\)#", 'one to one relationships is properly declared'); $userPhp = $this->getClass('User')->asPhp(); $this->t->like($userPhp[0]['source'], "#hasMany\\('Book as Books', 'Book.author_id'\\)#", 'hasMany is properly declared'); $this->t->like($userPhp[0]['source'], "#hasMany\\('Group as Groups', 'User2Group.group_id'\\)#", 'has many to many properly declared'); $userGroupPhp = $this->getClass('User2Group')->asPhp(); $this->t->like($userGroupPhp[0]['source'], "#ownsOne\\('User as User', 'User2Group.group_id', 'id'\\)#", 'has many to many with cascade properly defined'); }
$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() $t->diag('->getPluginVersions()'); $t->is($rest->getPluginVersions('sfTestPlugin'), array('1.1.3', '1.0.3', '1.0.0'), '->getPluginVersions() returns an array of stable versions for a plugin'); $t->is($rest->getPluginVersions('sfTestPlugin', 'stable'), array('1.1.3', '1.0.3', '1.0.0'), '->getPluginVersions() accepts stability as a second parameter and returns an array of versions for a plugin based on stability'); $t->is($rest->getPluginVersions('sfTestPlugin', 'beta'), array('1.0.4', '1.1.4', '1.1.3', '1.0.3', '1.0.0'), '->getPluginVersions() accepts stability as a second parameter and returns an array of versions for a plugin based on stability cascade (beta includes stable)'); // ->getPluginDependencies() $t->diag('->getPluginDependencies()'); $dependencies = $rest->getPluginDependencies('sfTestPlugin', '1.1.4'); $t->is($dependencies['required']['package']['min'], '1.1.0', '->getPluginDependencies() returns an array of dependencies'); // ->getPluginDownloadURL() $t->diag('->getPluginDownloadURL()'); $t->is($rest->getPluginDownloadURL('sfTestPlugin', '1.1.3', 'stable'), 'http://pear.example.com/get/sfTestPlugin/sfTestPlugin-1.1.3.tgz', '->getPluginDownloadURL() returns a plugin URL'); // teardown sfToolkit::clearDirectory($temp); rmdir($temp);
<?php require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot('front'); $t = new lime_test(); $pageHelper = $helper->get('page_helper'); $t->is($pageHelper->getOption('widget_css_class_pattern'), dmArray::get($helper->get('service_container')->getParameter('page_helper.options'), 'widget_css_class_pattern'), 'widget_css_class_pattern : ' . $pageHelper->getOption('widget_css_class_pattern')); $widget = array('id' => 9999, 'module' => 'dmWidgetContent', 'action' => 'breadCrumb', 'value' => json_encode(array('text' => 'test title', 'tag' => 'h1')), 'css_class' => 'custom_class'); $pageHelper->setOption('widget_css_class_pattern', ''); $expected = array('dm_widget custom_class', 'dm_widget_inner'); $t->is($pageHelper->getWidgetContainerClasses($widget), $expected, 'widgetContainerClasses for breadCrumb : ' . implode(', ', $expected)); $widget['action'] = 'title'; $expected = array('dm_widget custom_class', 'dm_widget_inner'); $t->is($pageHelper->getWidgetContainerClasses($widget), $expected, 'widgetContainerClasses for title : ' . implode(', ', $expected)); $pageHelper->setOption('widget_css_class_pattern', '%module%_%action%'); $expected = array('dm_widget content_title custom_class', 'dm_widget_inner'); $t->is($pageHelper->getWidgetContainerClasses($widget), $expected, 'widgetContainerClasses for title : ' . implode(', ', $expected)); $pageHelper->setOption('widget_css_class_pattern', 'module_%module% action_%action%'); $expected = array('dm_widget module_content action_title custom_class', 'dm_widget_inner'); $t->is($pageHelper->getWidgetContainerClasses($widget), $expected, 'widgetContainerClasses for title : ' . implode(', ', $expected));
<?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(1, new lime_output_color()); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->configure() $t->diag('->configure()'); $w = new sfWidgetFormI18nDateTime(array('culture' => 'fr')); $t->is($w->getOption('format'), '%date% %time%', '->configure() automatically changes the date format for the given culture');
<?php require_once dirname(__FILE__) . '/../../../../../test/bootstrap/unit.php'; $t = new lime_test(23); $serviceContainer->pluginLoader->loadPlugins(array('nbVisualStudioPlugin')); $t->comment('nbVisualStudioClientTest - Test default compiler line for LIB DEBUG project'); $client = new nbVisualStudioClient('outputFile'); $t->is($client->getCompilerCmdLine(), 'cl /c /nologo /EHsc /Gd /TP /Od /RTC1 /MDd /DUNICODE /D_UNICODE /DWIN32 /D_DEBUG', '->getCompilerCmdLine() has all default flags for LIB + DEBUG configuration'); $t->is($client->getLinkerCmdLine(), 'lib /nologo /OUT:outputFile obj/Debug/*.obj', '->getLinkerCmdLine() has all default flags for LIB + DEBUG configuration'); $t->comment('nbVisualStudioClientTest - Test default compiler line for LIB RELEASE project'); $client = new nbVisualStudioClient('outputFile', nbVisualStudioClient::LIB, nbVisualStudioClient::RELEASE); $t->is($client->getCompilerCmdLine(), 'cl /c /nologo /EHsc /Gd /TP /O2 /Oi /GL /MD /Gy /DUNICODE /D_UNICODE /DWIN32 /DNDEBUG', '->getCompilerCmdLine() has all default flags for LIB + RELEASE configuration'); $t->is($client->getLinkerCmdLine(), 'lib /nologo /OUT:outputFile obj/Release/*.obj', '->getLinkerCmdLine() has all default flags for LIB + RELEASE configuration'); $t->comment('nbVisualStudioClientTest - Test default compiler line for APP DEBUG project'); $client = new nbVisualStudioClient('outputFile', nbVisualStudioClient::APP); $t->is($client->getCompilerCmdLine(), 'cl /c /nologo /EHsc /Gd /TP /Od /RTC1 /MDd /DUNICODE /D_UNICODE /DWIN32 /D_DEBUG', '->getCompilerCmdLine() has all default flags for APP + DEBUG configuration'); $t->is($client->getLinkerCmdLine(), 'link /nologo /OUT:outputFile obj/Debug/*.obj', '->getLinkerCmdLine() has all default flags for APP + DEBUG configuration'); $t->comment('nbVisualStudioClientTest - Test default compiler line for APP RELEASE project'); $client = new nbVisualStudioClient('outputFile', nbVisualStudioClient::APP, nbVisualStudioClient::RELEASE); $t->is($client->getCompilerCmdLine(), 'cl /c /nologo /EHsc /Gd /TP /O2 /Oi /GL /MD /Gy /DUNICODE /D_UNICODE /DWIN32 /DNDEBUG', '->getCompilerCmdLine() has all default flags for APP + RELEASE configuration'); $t->is($client->getLinkerCmdLine(), 'link /nologo /OUT:outputFile obj/Release/*.obj', '->getLinkerCmdLine() has all default flags for APP + RELEASE configuration'); $t->comment('nbVisualStudioClientTest - Test set additional defines to compiler'); $client = new nbVisualStudioClient('outputFile', nbVisualStudioClient::APP); $client->setProjectDefines(array('CUSTOM')); $t->is($client->getCompilerCmdLine(), 'cl /c /nologo /EHsc /Gd /TP /Od /RTC1 /MDd /DUNICODE /D_UNICODE /DWIN32 /D_DEBUG /DCUSTOM', '->setProjectDefines() sets one additional define to compiler command line'); $client->setProjectDefines(array('CUSTOM1', 'CUSTOM2')); $t->is($client->getCompilerCmdLine(), 'cl /c /nologo /EHsc /Gd /TP /Od /RTC1 /MDd /DUNICODE /D_UNICODE /DWIN32 /D_DEBUG /DCUSTOM1 /DCUSTOM2', '->setProjectDefines() sets all additional defines to compiler command line'); $t->comment('nbVisualStudioClientTest - Test set additional includes to compiler'); $client = new nbVisualStudioClient('outputFile'); $client->setProjectIncludes(array('include1')); $t->is($client->getCompilerCmdLine(), 'cl /c /nologo /EHsc /Gd /TP /Od /RTC1 /MDd /DUNICODE /D_UNICODE /DWIN32 /D_DEBUG /I"include1"', '->setProjectIncludes() sets one additional include to compiler command line');
<?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'); } }
} else { $error .= $line; // stderr } } fclose($pipe); } $returnCode = proc_close($process); } // Init lime include_once dirname(__FILE__) . '/../lime/lime.php'; $t = new lime_test(8, new lime_output_color()); $scriptPath = realpath(dirname(__FILE__) . '/../../svn_pre_commit_hook.php'); // Test calling the script in an invalid way execute("php {$scriptPath} repoName trxNum --toto", $output, $error, $returnCode); $t->is($returnCode, 1, "Script fail as two arguments are required"); $t->is($error, "PRE COMMIT HOOK SYSTEM ERROR, PLEASE CONTACT SERVER ADMIN.\n (Invalid option name [\"toto\"])\n", "Valid error message is return"); // First test with a working commit $cmd = "php {$scriptPath} repoName trxNum --test-mode --include=EmptyComment"; execute($cmd, $output, $error, $returnCode); $t->is($returnCode, 0, "On success, return code is 0"); $t->is($output, "All pre commit checks successed", "On success a success message is return"); $t->is($error, "", "On success, no error output on stderr"); // Second test with a fail commit, due to an empty comment $cmd = "php {$scriptPath} emptyComment trxNum --test-mode --include=EmptyComment"; execute($cmd, $output, $error, $returnCode); $t->is($returnCode, 1, "On error, return code is 1"); $t->is($output, "", "On error, no echo on the stdout"); $errorMsg = <<<EOC
<?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'; $t = new lime_test(50); // ->clear() $t->diag('->clear()'); $ph = new sfNamespacedParameterHolder(); $ph->clear(); $t->is($ph->getAll(), null, '->clear() clears all parameters'); $ph->set('foo', 'bar'); $ph->clear(); $t->is($ph->getAll(), null, '->clear() clears all parameters'); // ->get() $t->diag('->get()'); $ph = new sfNamespacedParameterHolder(); $ph->set('foo', 'bar'); $t->is($ph->get('foo'), 'bar', '->get() returns the parameter value for the given key'); $t->is($ph->get('bar'), null, '->get() returns null if the key does not exist'); $ph = new sfNamespacedParameterHolder(); $t->is('default_value', $ph->get('foo1', 'default_value'), '->get() takes the default value as its second argument'); $ph = new sfNamespacedParameterHolder(); $ph->set('myfoo', 'bar', 'symfony/mynamespace'); $t->is('bar', $ph->get('myfoo', null, 'symfony/mynamespace'), '->get() takes an optional namespace as its third argument'); $t->is(null, $ph->get('myfoo'), '->get() can have the same key for several namespaces');
return parent::guessFromMimeContentType($file); } public function guessFromFileBinary($file) { 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');
* (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.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 {
<?php // initializes testing framework $sf_root_dir = realpath(dirname(__FILE__) . '/../../../../'); // initialize database manager require_once $sf_root_dir . '/test/bootstrap/unit.php'; // start tests $t = new lime_test(31); // these tests check for the tags attachement consistency $t->diag('::cleanTagName'); $tag = TaggableToolkit::cleanTagName(''); $t->is($tag, '', 'empty string'); $tag = TaggableToolkit::cleanTagName('test'); $t->is($tag, 'test', 'single tag'); $tag = TaggableToolkit::cleanTagName('test1,test2'); $t->is($tag, 'test1 test2', 'double tag whitespace'); $tag = TaggableToolkit::cleanTagName('test1, test2'); $t->is($tag, 'test1 test2', 'double tag with whitespace'); $t->todo('test optional option parameter'); $t->diag('::explodeTagString'); $tag = TaggableToolkit::explodeTagString(''); $t->is($tag, '', 'empty string'); $tag = TaggableToolkit::explodeTagString('test1'); $t->is($tag, 'test1', 'single tag'); $tag = TaggableToolkit::explodeTagString('test1 test2'); $t->is($tag, 'test1 test2', 'single tag with whitespace'); $tag = TaggableToolkit::explodeTagString('test1,test2'); $t->is($tag, array('test1', 'test2'), 'double tag'); $tag = TaggableToolkit::explodeTagString(' test1 , test2'); $t->is($tag, array('test1', 'test2'), 'double dirty tag'); $tag = TaggableToolkit::explodeTagString(' test1 ,
<?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__) . '/../lib/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/sfTemplateAutoloader.php'; sfTemplateAutoloader::register(); $t = new lime_test(2); $renderer = new sfTemplateRendererPhp(); // ->evaluate() $t->diag('->evaluate()'); $template = new sfTemplateStorageString('<?php echo $foo ?>'); $t->is($renderer->evaluate($template, array('foo' => 'bar')), 'bar', '->evaluate() renders templates that are instances of sfTemplateStorageString'); $template = new sfTemplateStorageFile(dirname(__FILE__) . '/fixtures/templates/foo.php'); $t->is($renderer->evaluate($template, array('foo' => 'bar')), 'bar', '->evaluate() renders templates that are instances of sfTemplateStorageFile');
{ } function unserialize($serialized) { } } class fakeResponse { } $t = new lime_test(7, new lime_output_color()); $dispatcher = new sfEventDispatcher(); // ->initialize() $t->diag('->initialize()'); $response = new myResponse($dispatcher, array('foo' => 'bar')); $options = $response->getOptions(); $t->is($options['foo'], 'bar', '->initialize() takes an array of options as its second argument'); // ->getContent() ->setContent() $t->diag('->getContent() ->setContent()'); $t->is($response->getContent(), null, '->getContent() returns the current response content which is null by default'); $response->setContent('test'); $t->is($response->getContent(), 'test', '->setContent() sets the response content'); // ->sendContent() $t->diag('->sendContent()'); ob_start(); $response->sendContent(); $content = ob_get_clean(); $t->is($content, 'test', '->sendContent() output the current response content'); // ->serialize() ->unserialize() $t->diag('->serialize() ->unserialize()'); $t->ok(new myResponse($dispatcher) instanceof Serializable, 'sfResponse implements the Serializable interface'); // new methods via sfEventDispatcher
/* * 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(18, new lime_output_color()); $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);
require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; require_once $_test_dir . '/../../../../test/unit/sfContextMock.class.php'; $t = new lime_test(28); $context = sfContext::getInstance(); $v = new sfEmailValidator($context); // ->execute() $t->diag('->execute()'); $validEmails = array('*****@*****.**', '*****@*****.**', '*****@*****.**'); $invalidEmails = array('example', 'example@', 'example@localhost', 'example@example.com@example.com'); $validEmailsNotStrict = array('*****@*****.**', '*****@*****.**', '*****@*****.**', 'example@localhost'); $invalidEmailsNotStrict = array('example', 'example@', 'example@example.com@example.com'); $v->initialize($context); foreach ($validEmails as $value) { $error = null; $t->ok($v->execute($value, $error), sprintf('->execute() returns true for a valid email "%s"', $value)); $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true'); } foreach ($invalidEmails as $value) { $error = null; $t->ok(!$v->execute($value, $error), sprintf('->execute() returns false for an invalid email "%s"', $value)); $t->isnt($error, null, '->execute() changes "$error" with a default message if it returns false'); } // strict parameter $t->diag('->execute() - strict parameter'); $v->initialize($context, array('strict' => false)); foreach ($validEmailsNotStrict as $value) { $error = null; $t->ok($v->execute($value, $error), sprintf('->execute() returns true for a valid email "%s"', $value)); $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true'); } foreach ($invalidEmailsNotStrict as $value) {
include dirname(__FILE__) . '/../../bootstrap/functional.php'; $t = new lime_test(13); // ->__construct() $t->diag('->__construct()'); class NumericFieldForm extends ArticleForm { public function configure() { $this->widgetSchema[1] = new sfWidgetFormInputText(); $this->validatorSchema[1] = new sfValidatorPass(); $this->setDefault(1, '==DEFAULT_VALUE=='); } } $form = new NumericFieldForm(); $defaults = $form->getDefaults(); $t->is($defaults[1], '==DEFAULT_VALUE==', '->__construct() allows ->configure() to set defaults on numeric fields'); class DefaultValuesForm extends AuthorForm { public function configure() { $this->setDefault('name', 'John Doe'); } } $author = new Author(); $form = new DefaultValuesForm($author); $t->is($form->getDefault('name'), 'John Doe', '->__construct() uses form defaults for new objects'); $author = new Author(); $author->name = 'Jacques Doe'; $author->save(); $form = new DefaultValuesForm($author); $t->is($form->getDefault('name'), 'Jacques Doe', '->__construct() uses object value as a default for existing objects');
<?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)));
<?php // test/unit/renderer/sympal/mySympalMarkdownRendererTest.php // あらかじめパーサー定数を変更しておく define('MARKDOWN_PARSER_CLASS', 'myMarkdownExtra_Parser'); require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(3); // markdownテスト $t->diag('markdown機能自体をテスト'); $data = "test"; $t->is(mySympalMarkdownRenderer::enhanceHtml(Markdown($data), $data), "<p>test</p>\n", 'markdownレンダリング'); $data = "# test\n## test2"; $t->is(mySympalMarkdownRenderer::enhanceHtml(Markdown($data), $data), "<h1 id=\"" . md5('test') . "\">test</h1>\n\n<h2 id=\"" . md5('test2') . "\">test2</h2>\n", 'markdownレンダリング'); $data = <<<EOT [php] echo "Hello, World!"; EOT; $t->is(mySympalMarkdownRenderer::enhanceHtml(Markdown($data), $data), "<pre class=\"php\"><span class=\"kw3\">echo</span> <span class=\"st0\">"Hello, World!"</span>;\n </pre>\n", 'markdownレンダリング(php)');
/** * @package symfony.plugins * @subpackage sfDoctrine * @author Pavel Kunc * @author Olivier Verdier <*****@*****.**> * @version SVN: $Id: sfDoctrineColumnTest.php 3438 2007-02-10 15:31:31Z chtito $ */ //We need bootStrap require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; //TODO: add planned tests $t = new lime_test(null, new lime_output_color()); $colName = 'TestColumn'; $column = new sfDoctrineColumnSchema($colName); // ->__construct(), special case without variable parameters $t->diag('->__constuct()'); $t->is($column->getName(), $colName, '->__construct() takes first parameter as Column name'); $t->isa_ok($column->getColumnInfo(), 'sfParameterHolder', '->__construct() sets column infor to sfParameterHolder'); //Construct sets default values, nothing passed $props = $column->getProperties(); $t->is($props['type'], 'string', "->__construct() default type is 'string'"); $t->is($props['name'], $colName, "->__construct() sets property name to column name"); $column = new sfDoctrineColumnSchema($colName, array('foreignClass' => 'other')); $props = $column->getProperties(); $t->is($props['type'], 'integer', 'default foreign key type is integer'); $t->diag('constraints'); $column = new sfDoctrineColumnSchema($colName, array('enum' => true, 'noconstraint' => true)); $props = $column->getProperties(); $t->is($props['enum'], true, 'constraints are stored properly'); $t->ok(!isset($props['notaconstraint']), 'false constraints are not stored'); $t->diag('short syntax'); $type = 'string';
<?php require_once dirname(__FILE__) . '/../../../../test/bootstrap/unit.php'; $serviceContainer->pluginLoader->loadPlugins(array('nbAntPlugin')); $t = new lime_test(); $client = new nbAntClient(); $t->comment('nbAntClientTest - Test command without options'); $t->is($client->getCommandLine('mycmd', array(), array()), 'ant mycmd'); $t->comment('nbAntClientTest - Test command with options'); $options = array('option' => 'value'); $t->is($client->getCommandLine('mycmd', array(), $options), 'ant mycmd -Doption=value'); // test command with arguments $args = array('arg' => 'value'); $t->is($client->getCommandLine('mycmd', $args, array()), 'ant mycmd -Darg=value'); // test ANT cmd line options (library path) $client->setLibraryPath("C:\\AntExtensions\\lib"); $t->is($client->getCommandLine('mycmd', $args, $options), 'ant -lib C:\\AntExtensions\\lib mycmd -Darg=value -Doption=value'); // test ANT cmd line options (property file) $client->setPropertyFile("C:\\AntExtensions\\lib\\myfile.properties"); $t->is($client->getCommandLine('mycmd', $args, $options), 'ant -lib C:\\AntExtensions\\lib -propertyfile C:\\AntExtensions\\lib\\myfile.properties mycmd -Darg=value -Doption=value'); // test options with no value // test ANT cmd line options (property file) $options['incremental'] = ''; $t->is($client->getCommandLine('mycmd', $args, $options), 'ant -lib C:\\AntExtensions\\lib -propertyfile C:\\AntExtensions\\lib\\myfile.properties mycmd -Darg=value -Doption=value -Dincremental=true');
<?php /** * This file is part of the sfSearch package. * (c) Carl Vondrick <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require dirname(__FILE__) . '/../../bootstrap/unit.php'; require 'criteria/xfCriterion.interface.php'; require 'criteria/xfCriterionTerm.class.php'; require 'criteria/xfCriterionDecorator.class.php'; require 'criteria/xfCriterionRequired.class.php'; require 'criteria/xfCriterionTranslator.interface.php'; require 'criteria/xfCriterionTranslatorString.class.php'; $t = new lime_test(3, new lime_output_color()); $c = new xfCriterionRequired(new xfCriterionTerm('foo')); $t->is($c->toString(), 'REQUIRED {foo}', '->toString() works'); $trans = new xfCriterionTranslatorString(); $c->translate($trans); $t->is($trans->getString(), '+foo', '->translate() translates the query'); $t->is($c->optimize(), $c, '->optimize() does nothing');
<?php // test/unit/fixtures/TransportLoadTest.php include dirname(__FILE__) . '/../../bootstrap/Doctrine.php'; $t = new lime_test(6); # Check the existence of all available TransportLoads. $t->comment('-> fixture TransportLoad'); $number_of_TransportLoads = Doctrine_Core::getTable('TransportLoad')->createQuery()->count(); $t->is($number_of_TransportLoads, 1, '-> fixture TransportLoad. There is 1 TransportLoad counted via DQL'); # Test or the (company)name and sfGuardUser.name proper are added via the fixtures. $q = Doctrine_Query::create()->select('df.name as df_name, dt.name as dt_name, tg.username as tg_username, cg.username as cg_username, t.sf_guard_user_id as t_guard_user, c.sf_guard_user_id as c_guard_user, tl.bid as bid ')->from('TransportLoad tl')->leftJoin('tl.FromDistrict df')->leftJoin('tl.ToDistrict dt')->leftJoin('tl.Customer c, c.GuardUser cg')->leftJoin('tl.Transporter t, t.GuardUser tg'); $transportLoads = $q->execute(); /* Test purpose */ $t->is($transportLoads->toArray(), 'NULL', '-> fixture TransportLoad. Array checked'); $t->is($transportLoads[0]->tg_username, 'ericsummeling', '-> fixture TransportLoad. Transporter proper defined.'); $t->is($transportLoads[0]->cg_username, 'hansrip', '-> fixture TransportLoad. Customer proper defined.'); $t->is($transportLoads[0]->bid, 'Open', '-> fixture TransportLoad. Bid proper defined.'); $t->is($transportLoads[0]->df_name, 'Lusaka City', '-> fixture TransportLoad. DistrictFrom proper defined'); $t->is($transportLoads[0]->dt_name, 'Lusaka City', '-> fixture TransportLoad. DistrictTo proper defined');
* 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__) . '/../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 {
$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'); $t->ok(!file_exists(dmProject::rootify('segments.gen')), 'There is no segments.gen in project root dir'); dmConfig::set('search_stop_words', 'un le les de,du , da, di ,do ou '); $t->is($currentIndex->getStopWords(), array('un', 'le', 'les', 'de', 'du', 'da', 'di', 'do', 'ou'), 'stop words retrieved from site instance : ' . implode(', ', $currentIndex->getStopWords()));
/** * Unit test for the sfSympalConfiguration class * * @package * @subpackage * @author Ryan Weaver <*****@*****.**> * @since 2010-02-06 * @version svn:$Id$ $Author$ */ $app = 'sympal'; require_once dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new lime_test(24, new lime_output_color()); $sympalPluginConfiguration = sfContext::getInstance()->getConfiguration()->getPluginConfiguration('sfSympalPlugin'); $sympalConfiguration = $sympalPluginConfiguration->getSympalConfiguration(); $themes = $sympalConfiguration->getThemes(); $t->is(isset($themes['default']), true, '->getThemes() includes default theme'); $availableThemes = $sympalConfiguration->getAvailableThemes(); $t->is(isset($themes['admin']), 'admin', '->getAvailableThemes() does not include admin theme'); $contentTemplates = $sympalConfiguration->getContentTemplates('page'); $t->is(isset($contentTemplates['default_view']), true, '->getContentTemplates() returns default_view for page'); $t->is(isset($contentTemplates['register']), true, '->getContentTemplates() returns register for page'); sfContext::getInstance()->getRequest()->setParameter('module', 'sympal_dashboard'); $t->is($sympalConfiguration->isAdminModule(), true, '->isAdminModule() returns true for admin module'); sfContext::getInstance()->getRequest()->setParameter('module', 'sympal_content_renderer'); $t->is($sympalConfiguration->isAdminModule(), false, '->isAdminModule() returns false for non-admin module'); $plugins = $sympalConfiguration->getPlugins(); $t->is(is_array($plugins), true, '->getPlugins() returns array'); $t->is(in_array('sfSympalBlogPlugin', $plugins), true, '->getPlugins() includes sfSympalBlogPlugin'); $pluginPaths = $sympalConfiguration->getPluginPaths(); $t->is(is_array($pluginPaths), true, '->getPluginPaths() returns array'); $t->is(isset($pluginPaths['sfSympalBlogPlugin']), true, '->getPluginPaths() includes sfSympalBlogPlugin');
<?php require dirname(__FILE__) . '/setup.php'; require dirname(__FILE__) . '/db_init.php'; $pdo = new PDO('mysql:host=localhost; dbname=hermit_test', 'root', 'password'); db_init($pdo); $test = new lime_test(); $test->diag(basename(__FILE__)); $dbmeta = new HermitMySQLDatabaseMeta($pdo); $test->diag(basename(__FILE__) . '::parameter[in:out]'); $procedureInfo = $dbmeta->getProcedureInfo('PROC_IN_OUT'); $test->ok($procedureInfo !== null); $parameters = array_map('strtolower', $procedureInfo->getParamNames()); $expect = array('sales', 'tax'); $test->is(count(array_diff($parameters, $expect)), 0); $test->is($procedureInfo->typeofIn('sales'), true); $test->is($procedureInfo->typeofOut('sales'), false); $test->is($procedureInfo->typeofInOut('sales'), false); $test->is($procedureInfo->typeofIn('tax'), false); $test->is($procedureInfo->typeofOut('tax'), true); $test->is($procedureInfo->typeofInOut('tax'), false); $procedureInfo2 = $dbmeta->getProcedureInfo('PROC_IN_OUT'); $test->ok($procedureInfo === $procedureInfo2, 'same instance'); $test->diag(basename(__FILE__) . '::parameter[in:out:out]'); $procedureInfo = $dbmeta->getProcedureInfo('PROC_IN_OUT_OUT'); $parameters = array_map('strtolower', $procedureInfo->getParamNames()); $expect = array('sales', 'tax', 'total'); $test->is(count(array_diff($parameters, $expect)), 0); $test->is($procedureInfo->typeofIn('sales'), true); $test->is($procedureInfo->typeofOut('sales'), false); $test->is($procedureInfo->typeofInOut('sales'), false);
$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'); $t->is($uri, '/myform', '->click() clicks on form submit buttons'); $t->is($parameters['text_default_value'], 'default', '->click() uses default form field values (input)'); $t->is($parameters['text'], '', '->click() uses default form field values (input)'); $t->is($parameters['textarea'], 'content', '->click() uses default form field values (textarea)'); $t->is($parameters['select'], 'selected', '->click() uses default form field values (select)'); $t->is($parameters['select_multiple'], array('selected', 'last'), '->click() uses default form field values (select - multiple)'); $t->is($parameters['article']['title'], 'title', '->click() recognizes array names'); $t->is($parameters['article']['category'], array('2', '3'), '->click() recognizes array names'); $t->is($parameters['article']['or']['much']['longer'], 'very long!', '->click() recognizes array names');