public function ok($exp, $msg = '') { if (!$this->report_passes && $exp) { ++$this->passed; return true; } return parent::ok($exp, $msg); }
public function __construct() { $this->sfPropelData = new sfPropelData(); $this->testDataDir = SF_ROOT_DIR . '/test/fixtures'; if (!is_readable($this->testDataDir)) { throw new RuntimeException('Could not read directory ' . $this->testDataDir); } parent::__construct(); }
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"'); }
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); } } } }
public function __construct($fixturesFileOrDir = null, $plan = null) { if ($fixturesFileOrDir === null) { $this->testDataDir = SF_ROOT_DIR . '/test/fixtures'; } else { if (file_exists($fixturesFileOrDir)) { $this->testDataDir = $fixturesFileOrDir; } else { throw new RuntimeException($fixturesFileOrDir . ': No such file or directory'); } } if (!is_readable($this->testDataDir)) { throw new RuntimeException($this->testDataDir . ': Could not read file or directory'); } parent::__construct($plan); }
protected function checkEachFolder(lime_test $t) { $errors = 0; if (!($root = $this->folderTable->getTree()->fetchRoot())) { $t->diag('Tree has no root !'); $errors++; } elseif ($root->relPath != '') { $t->diag(sprintf('Root relPath != "" (%s)', $root->relPath)); $errors++; } elseif ($root->getNodeParentId() !== null) { $t->diag(sprintf('Root->getNodeParentId() = %d', $root->getNodeParentId())); $errors++; } $folders = $this->folderTable->findAll(); foreach ($folders as $folder) { $folder->refresh(); if ($folder->getNode()->isRoot()) { continue; } if (!($parent = $folder->getNode()->getParent())) { $t->diag(sprintf('$folder->getNode()->getParent() == NULL (folder : %s)', $folder)); $errors++; } elseif ($parent->id != $folder->getNodeParentId()) { $t->diag(sprintf('$folder->getNode()->getParent()->id != $folder->getNodeParentId() (%d, %d) (folder : %s)', $folder->getNode()->getParent()->id, $folder->getNodeParentId(), $folder)); $errors++; if ($parent->lft >= $folder->lft || $parent->rgt <= $folder->rgt) { $t->diag(sprintf('bad folder / parent lft|rgt (folder %d : %d, %d) (parent %d : %d, %d)', $folder->id, $folder->lft, $folder->rgt, $parent->id, $parent->lft, $parent->rgt)); $errors++; } } if ($folder->lft >= $folder->rgt) { $t->diag(sprintf('$folder->lft >= $folder->rgt (%d, %d) (folder : %s)', $folder->lft, $folder->rgt, $folder)); $errors++; } if (!$folder->lft || !$folder->rgt) { $t->diag(sprintf('!$folder->lft || !$folder->rgt (%d, %d) (folder : %s)', $folder->lft, $folder->rgt, $folder)); $errors++; } } $t->is($errors, 0, "All folders are sane ({$errors} errors)"); }
/** * 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; }
<?php include dirname(__FILE__) . '/../../bootstrap/unit.php'; include dirname(__FILE__) . '/../../bootstrap/database.php'; sfContext::createInstance($configuration); $t = new lime_test(1, new lime_output_color()); $conn = Doctrine::getTable('ApplicationInvite')->getConnection(); $conn->beginTransaction(); $invite = Doctrine::getTable('ApplicationInvite')->find(1); $memberApplication = $invite->accept(); $t->isa_ok($memberApplication, 'MemberApplication', '->accept() returns object of MemberApplication'); $conn->rollback();
<?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()
<?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');
public function to_xml() { return lime_test::to_xml($this->to_array()); }
<?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 $app = 'frontend'; 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';
<?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'); } }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); $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));
<?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)');
<?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/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');
<?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 /** * 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();
<?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');
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(54, new lime_output_color()); // ->click() $t->diag('->click()'); class myClickBrowser extends sfBrowser { public function setHtml($html) { $this->dom = new DomDocument('1.0', 'UTF-8'); $this->dom->validateOnParse = true; $this->dom->loadHTML($html); } public function getFiles() { $f = $this->files; $this->files = array(); return $f; } public function call($uri, $method = 'get', $parameters = array(), $changeStack = true) { $uri = $this->fixUri($uri); $this->fields = array();
<?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');
* file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; class myResponse extends sfResponse { function serialize() { } 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();
<?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);
<?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(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();
<?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);
} if (1 == $key) { $output .= $line; // stdout } 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");