public function loremizeModule($module, $nb = 10, lime_test $t = null) { if ($t) { $t->comment('Loremizing module ' . $module . ' with ' . $nb . ' records'); } $this->get('table_loremizer')->execute($this->getModule($module)->getTable(), $nb); }
/** * * @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 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 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 require_once realpath(dirname(__FILE__) . '/../../..') . '/unit/helper/dmModuleUnitTestHelper.php'; $helper = new dmModuleUnitTestHelper(); $helper->boot(); $t = new lime_test(); $table = dmDb::table('DmPage'); $page1 = $table->create(array('name' => 'name1', 'slug' => 'slug1', 'module' => 'test', 'action' => 'test1')); $page1->Node->insertAsFirstChildOf($table->getTree()->fetchRoot()); $t->ok($page1->exists(), 'Created a page'); $t->is('slug1', $page1->slug, 'Page slug is slug1'); $t->comment('Saving page with existing slug'); $page2 = $table->create(array('name' => 'name2', 'slug' => 'slug1', 'module' => 'test', 'action' => 'test2')); $page2->Node->insertAsFirstChildOf($table->getTree()->fetchRoot()); $t->ok($page2->exists(), 'Created a page'); $t->is($page2->slug, 'slug1-' . $page2->id, 'Page2 slug is slug1-' . $page2->id); $page1->slug = 'slug1-' . $page2->id; $page1->save(); $t->is($page1->slug, 'slug1-' . $page2->id . '-' . $page1->id, 'Page1 slug is now slug1-' . $page2->id . '-' . $page1->id); $page2->slug = 'slug1'; $page2->save(); $t->is($page2->slug, 'slug1', 'Page2 slug is now slug1'); $page2->slug = ''; $page2->save(); $t->is($page2->slug, '/' . $page2->id, 'Page2 slug is now /' . $page2->id); $page1->Node->moveAsFirstChildOf($page2); $page2->refresh(); $page1->slug = $page2->slug; $page1->save(); $t->is($page1->slug, $page2->slug . '/' . $page1->id, 'Page1 slug is now ' . $page2->slug . '/' . $page1->id); //$helper->get('page_tree_watcher')->connect();
<?php require_once dirname(__FILE__) . '/../bootstrap/unit.php'; require_once dirname(__FILE__) . '/../../lib/sfDynamics.class.php'; $testCount = 1; class ManagerMock extends sfDynamicsManager { } $t = new lime_test($testCount, new lime_output_color()); $t->comment('::getManager()'); if (!sfContext::hasInstance()) { require_once $_SERVER['SYMFONY'] . '/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register(); require_once dirname(__FILE__) . '/../fixtures/project/config/ProjectConfiguration.class.php'; sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration('frontend', 'test', isset($debug) ? $debug : true)); if (!sfContext::hasInstance()) { $t->error('A context instance is required'); die; } $t->info('A frontend context has been initialized for tests'); } sfConfig::set('app_sfDynamicsPlugin_manager', 'ManagerMock'); $t->isa_ok(sfDynamics::getManager(), 'ManagerMock', '::getManager() the manager class can be customized in app.yml');
$dirTransferConfig = $configDir . '/filesystem-dir-transfer.yml'; function isPluginEnabled($beeConfig, $plugin) { if (!file_exists($beeConfig)) { throw new Exception('bee config file not found'); } $parser = sfYaml::load($beeConfig); $plugins = isset($parser['project']['bee']['enabled_plugins']) ? $parser['project']['bee']['enabled_plugins'] : array(); return in_array($plugin, $plugins); } $t = new lime_test(12); $cmd = new nbGenerateProjectCommand(); $t->ok($cmd->run(new nbCommandLineParser(), $projectDir), 'Command nbGenerateProjectCommand called successfully'); $t->ok(file_exists($beeConfig), 'bee.yml added to the destination dir :' . $beeConfig); $t->ok(file_exists($config), 'config.yml added to the destination dir :' . $config); $t->comment('enabling nbDummyPlugin'); $plugin = 'nbDummyPlugin'; $t->ok(!isPluginEnabled($beeConfig, $plugin), $plugin . ' not found'); $cmd = new nbEnablePluginCommand(); $t->ok($cmd->run(new nbCommandLineParser(), $plugin . ' ' . $projectDir), 'Plugin enabled successfully'); $t->ok(isPluginEnabled($beeConfig, $plugin), $plugin . ' found'); $t->comment('enabling a fake plugin'); $cmd = new nbEnablePluginCommand(); try { $cmd->run(new nbCommandLineParser(), 'nbNonExistentPlugin' . ' ' . $projectDir); $t->fail('plugin nbNonExistentPlugin exists ?'); } catch (Exception $e) { $t->pass('plugin nbNonExistentPlugin not exists'); } $t->comment('enabling nbFileSystemPlugin'); $secondPlugin = 'nbFileSystemPlugin';
* */ /** * advanced rtShopVoucher Testing * * @package rtShopPlugin * @author Piers Warmers <*****@*****.**> * @author Konny Zurcher <*****@*****.**> */ include dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new lime_test(16, new lime_output_color()); $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true); $configuration->loadHelpers('Number'); sfContext::createInstance($configuration); new sfDatabaseManager($configuration); $t->comment('/////////////////////////////////////////////////////////////////////////////'); $t->comment('/// rtShopVoucher: Test range'); $t->comment('/////////////////////////////////////////////////////////////////////////////'); $numberFormat = new sfNumberFormat(sfContext::getInstance()->getUser()->getCulture()); // Tools $tools = new rtShopVoucherRangeTestTools(); // Tax and shipping configurations sfConfig::set('app_rt_shop_tax_rate', 10); sfConfig::set('app_rt_shop_tax_mode', 'exclusive'); sfConfig::set('app_rt_shop_shipping_charges', array('default' => 20, 'AU' => 10, 'NZ' => 10)); // Add some data to play with... $tools->clean(); // Products try { $prod1 = new rtShopProduct(); $prod1->setTitle('Product A');
<?php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(0); $t->comment('nbNumberCompare - Test compare');
<?php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(40); $fooArgument = new nbArgument('foo'); $barOption = new nbOption('bar'); $command1 = new DummyCommand("foo"); $command2 = new DummyCommand("ns:bar", new nbArgumentSet(array($fooArgument))); $command3 = new DummyCommand("ns2:bas", null, new nbOptionSet(array($barOption))); $t->comment('nbCommandTest - Test constructor'); try { new DummyCommand(''); $t->fail('command name can\'t be empty'); } catch (InvalidArgumentException $e) { $t->pass('command name can\'t be empty'); } try { new DummyCommand('ns:'); $t->fail('command name can\'t be empty'); } catch (InvalidArgumentException $e) { $t->pass('command name can\'t be empty'); } $command = new DummyCommand('foo'); $t->is($command->getArguments()->count(), 0, '->__construct() returns a command with no arguments'); $t->is($command->getOptions()->count(), 0, '->__construct() returns a command with no options'); $t->comment('nbCommandTest - Test name'); $t->is($command1->getName(), "foo", '->getName() returns a command with name "foo"'); $t->is($command2->getName(), "bar", '->getName() returns a command with name "bar"'); $t->comment('nbCommandTest - Test namespace'); $t->is($command1->getNamespace(), "", '->getNamespace() returns an empty namespace'); $t->is($command2->getNamespace(), "ns", '->getNamespace() returns a namespace "ns"');
<?php require_once dirname(__FILE__) . '/../../vendor/lime.php'; require_once dirname(__FILE__) . '/../../lib/phpGitHubApi.php'; $t = new lime_test(3); $api = new phpGitHubApi(true); $t->comment('Test ->listIssues'); $issues = $api->listIssues('ornicar', 'php-github-api', 'closed'); $t->is($issues[0]['state'], 'closed', 'Found closed issues'); $t->comment('Test ->searchIssues'); $issues = $api->searchIssues('ornicar', 'php-github-api', 'closed', 'documentation'); $t->is($issues[0]['state'], 'closed', 'Found closed issues matching "documentation"'); $issue = $api->showIssue('ornicar', 'php-github-api', 1); $t->is($issue['title'], 'Provide documentation', 'Found issue #1');
$t->diag('Countable interface'); $t->is(count($pager), 20, 'Pager has 20 results'); // Iterator interface $t->diag('Iterator interface'); $pager->init(); $normal = 0; $iterated = 0; foreach ($pager->getResults() as $object) { $normal++; } foreach ($pager as $object) { $iterated++; } $t->is($iterated, $normal, '"Iterator" interface loops over objects in the current pager'); $t->is($pager->getCurrent(), $query->fetchOne(), 'Found the first post'); $t->comment('Render navigation top'); $pattern = '<div class="pager"><ul class="clearfix"><li class="page current"><span class="link">1</span></li><li class="page">.+</li></ul></div>'; $t->like($navigation = $pager->renderNavigationTop(), '|^' . $pattern . '$|', 'navigation top: ' . $navigation); $t->comment('Pass custom classes with array'); $pager->setOption('class', 'custom_class1 class2'); $pattern = '<div class="pager custom_class1 class2"><ul class="clearfix"><li class="page current"><span class="link">1</span></li><li class="page">.+</li></ul></div>'; $t->like($navigation = $pager->renderNavigationTop(), '|^' . $pattern . '$|', 'navigation top: ' . $navigation); $t->comment('Pass custom classes with CSS expression'); $pager->setOption('class', null); $pattern = '<div class="pager custom_class1 class2"><ul class="clearfix"><li class="page current"><span class="link">1</span></li><li class="page">.+</li></ul></div>'; $t->like($navigation = $pager->renderNavigationTop('.custom_class1.class2'), '|^' . $pattern . '$|', 'navigation top: ' . $navigation); $t->comment('Disable navigation top'); $pager->setOption('class', null)->setOption('navigation_top', false); $t->is($navigation = $pager->renderNavigationTop(), '', 'navigation top: ' . $navigation); $t->comment('Pass custom separator'); $pager->setOption('navigation_top', true)->setOption('separator', '-');
/* * With some old version of sqlite, like on continuous integration server * This test will not work as expected */ if (strpos(getcwd(), 'hudson')) { return; } $t->ok($page = $domain->getDmPage(), 'Domain has a page'); $t->is(dmDb::table('DmPage')->count(), $nbPage + 1, 'One new page'); $t->is($page->isActive, false, 'The page is not active'); $t->is($page->Record, $domain, 'The page record is the domain'); $domain = dmDb::table('DmTestDomain')->create(array('title' => dmString::random(), 'is_active' => true))->saveGet(); $t->ok($domain->exists(), 'Record has been saved'); $t->ok($domain->isActive, 'Record is active'); $t->is(dmDb::table('DmPage')->count(), $nbPage + 1, 'No new page'); $t->ok($page = $domain->getDmPage(), 'Domain has a page'); $t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'One new page'); $t->is($page->isActive, true, 'The page is active'); $t->is($page->Record, $domain, 'The page record is the domain'); $categ = dmDb::table('DmTestCateg')->create(array('name' => dmString::random(), 'is_active' => false))->saveGet(); $t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'No new page'); $t->ok(!$categ->getDmPage(), 'Categ has a NO page'); $t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'No new page'); $t->comment('link the categ to a domain'); $categ->Domains->add($domain); $categ->save(); $t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'No new page'); $t->ok($page = $categ->getDmPage(), 'Categ has a page'); $t->is(dmDb::table('DmPage')->count(), $nbPage + 3, 'One new page'); $t->is($page->isActive, false, 'The page is not active'); $t->is($page->Record, $categ, 'The page record is the categ');
<?php require dirname(__FILE__) . '/../bootstrap/unit.php'; require dirname(__FILE__) . '/../../lib/model/sfAssetsManagerPackage.class.php'; $t = new lime_test(7, new lime_output_color()); $t->comment('Accessors'); $package = new sfAssetsManagerPackage('test'); $t->is($package->get('css'), array(), '->get() method returns an empty array by default'); $package->set('css', 'script.css'); $t->is($package->get('css'), array('script.css'), '->set() and ->get() write and read property'); $package->add('import', 'reference1'); $package->add('import', 'reference2'); $t->is($package->get('import'), array('reference1', 'reference2'), '->add() adds reference packages retrieved by ->get()'); $t->comment('Configuration from array'); $package = new sfAssetsManagerPackage('test2'); $package->fromArray(array('import' => 'reference', 'js' => 'script.js', 'css' => array('style1.css', 'style2.css'))); $t->is($package->get('import'), array('reference'), '->fromArray() inject imports property'); $t->is($package->get('js'), array('script.js'), '->fromArray() inject javascripts property'); $t->is($package->get('css'), array('style1.css', 'style2.css'), '->fromArray() inject stylesheets property'); $t->is_deeply($package->toArray(), array('import' => array('reference'), 'js' => array('script.js'), 'css' => array('style1.css', 'style2.css')), '->toArray() exports values into an array');
<?php require_once realpath(dirname(__FILE__) . '/../../..') . '/unit/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot('front'); $t = new lime_test(39); $wtm = $helper->get('widget_type_manager'); $widgetType = $wtm->getWidgetType('dmWidgetNavigation', 'menu'); $formClass = $widgetType->getOption('form_class'); $page1 = dmDb::table('DmPage')->findOneByModuleAndAction('main', 'page1'); $t->comment('Create a menu widget'); $widget = dmDb::create('DmWidget', array('module' => $widgetType->getModule(), 'action' => $widgetType->getAction(), 'value' => '[]', 'dm_zone_id' => $page1->PageView->Area->Zones[0])); $t->comment('Create a ' . $formClass . ' instance'); $form = new $formClass($widget); $form->removeCsrfProtection(); $html = $form->render(); $t->like($html, '_^<form\\s(.|\\n)*</form>$_', 'Successfully obtained and rendered a ' . $formClass . ' instance'); $t->is(count($form->getStylesheets()), 2, 'This widget form requires 2 additional stylesheets'); $t->is(count($form->getJavascripts()), 3, 'This widget form requires 3 additional javascripts'); $t->comment('Submit an empty form'); $form->bind(array(), array()); $t->is($form->isValid(), true, 'The form is valid'); $t->comment('Save the widget'); $form->updateWidget()->save(); $t->ok($widget->exists(), 'Widget has been saved'); $expected = array('ulClass' => '', 'liClass' => '', 'items' => array()); $t->is_deeply($widget->values, $expected, 'Widget values are correct'); $t->comment('Recreate the form from the saved widget'); $form = new $formClass($widget); $form->removeCsrfProtection(); $t->is($form->getDefault('link'), array(), 'The form default text is correct');
<?php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; class testShellCommand extends nbShellExecuteCommand { public function getAlias($command) { return parent::getAlias($command); } } $shellCommand = new testShellCommand(); $t = new lime_test(); $t->is($shellCommand->getAlias('command'), null, '->getAlias() returns null if param isn\'t an alias'); nbConfig::set('project_shell_aliases_command', 'realCommand'); nbConfig::set('project_shell_aliases_anotheralias', 'another real command'); $t->is($shellCommand->getAlias('command'), 'realCommand', '->getAlias() returns real command if param is an alias'); $t->is($shellCommand->getAlias('anotheralias'), 'another real command', '->getAlias() returns real command if param is an alias'); $t->comment('nbShellExecuteCommandTest - pass args value to command line'); ob_start(); $t->ok(!$shellCommand->run(new nbCommandLineParser(array(), array()), 'dir --args="-Doption=true"')); $contents = ob_get_contents(); ob_end_clean(); ob_start(); $t->ok($shellCommand->run(new nbCommandLineParser(array(), array()), 'dir')); $contents = ob_get_contents(); ob_end_clean();
<?php include dirname(__FILE__) . '/../../bootstrap/Propel.php'; $t = new lime_test(3); $t->comment('->getCompanySlug()'); $job = JobeetJobPeer::doSelectOne(new Criteria()); $t->is($job->getCompanySlug(), Jobeet::slugify($job->getCompany()), '->getCompanySlug() return the slug for the company'); $t->comment('->save()'); $job = create_job(); $job->save(); $expiresAt = date('Y-m-d', time() + 86400 * sfConfig::get('app_active_days')); $t->is($job->getExpiresAt('Y-m-d'), $expiresAt, '->save() updates expires_at if not set'); $job = create_job(array('expires_at' => '2008-08-08')); $job->save(); $t->is($job->getExpiresAt('Y-m-d'), '2008-08-08', '->save() does not update expires_at if set'); function create_job($defaults = array()) { static $category = null; if (is_null($category)) { $category = JobeetCategoryPeer::doSelectOne(new Criteria()); } $job = new JobeetJob(); $job->fromArray(array_merge(array('category_id' => $category->getId(), 'company' => 'Sensio Labs', 'position' => 'Senior Tester', 'location' => 'Paris, France', 'description' => 'Testing is fun', 'how_to_apply' => 'Send e-Mail', 'email' => '*****@*****.**', 'token' => rand(1111, 9999), 'is_activated' => true), $defaults), BasePeer::TYPE_FIELDNAME); return $job; }
<?php require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot(); $t = new lime_test(59); $t->comment('iconv available : ' . function_exists('iconv')); $t->is(dmString::slugify(" phrâse avèc dés accënts "), $expected = "phrase-avec-des-accents", $expected); $t->is(dmString::slugify("fonctionnalité"), $expected = "fonctionnalite", $expected); $t->is(dmString::urlize(" phrâse avèc dés accënts "), $expected = "phrase-avec-des-accents", $expected); $t->is(dmString::urlize("fonctionnalité"), $expected = "fonctionnalite", $expected); $t->is(dmString::slugify("an-url.htm"), $expected = "an-url-htm", $expected); $t->is(dmString::slugify("an-url.html"), $expected = "an-url-html", $expected); $t->is(dmString::urlize("an-url.htm"), $expected = "an-url.htm", $expected); $t->is(dmString::urlize("an-url.html"), $expected = "an-url.html", $expected); $hexTests = array(array('ffffff', 'FFFFFF'), array('#ffffff', 'FFFFFF'), array('#0Cd4fe', '0CD4FE'), array('aaa', null), array('fffff', null), array('fffxff', null)); foreach ($hexTests as $hexTest) { $t->is(dmString::hexColor($hexTest[0]), $hexTest[1], 'dmString::hexColor(' . $hexTest[0] . ') = ' . (null === $hexTest[1] ? 'NULL' : $hexTest[1])); } $t->is(dmString::lcfirst('TEST'), 'tEST', 'lcfirst test'); $t->is(dmString::lcfirst('another test'), 'another test', 'lcfirst test'); // ::retrieveOptFromString() $t->diag('::retrieveOptFromString()'); // Empty string $t->diag(' ::retrieveOptFromString() empty string'); $string = ''; $opt = array('aa' => 'bb'); $originalOpt = $opt; $t->is_deeply(dmString::retrieveOptFromString($string, $opt), null, '::retrieveOptFromString() with an empty string returns null'); $t->is_deeply($opt, $originalOpt, '::retrieveOptFromString() with an empty string does not modify opt'); $t->is_deeply($string, '', '::retrieveOptFromString() with an empty string does not modify string');
<?php include dirname(__FILE__) . '/../bootstrap/unit.php'; include dirname(__FILE__) . '/../../apps/client/lib/StreemeItunesPlaylistParser.class.php'; // Initialize the test object $t = new lime_test(7, new lime_output_color()); $t->comment('->construct()'); try { $missing_file = new StreemeItunesPlaylistParser(dirname(__FILE__) . '/../files/nonexistent xml file.xml'); $t->fail('This should halt execution until the user fixes the file'); } catch (Exception $e) { if ($e->getMessage() === 'Could not open iTunes File') { $t->pass('File Does not Exist Exception thrown properly'); } else { $t->fail('Unexpected exception thrown...'); } } $parser = new StreemeItunesPlaylistParser(dirname(__FILE__) . '/../files/iTunes Music Library.xml'); $playlist_name = $itunes_playlist_id = null; $playlist_songs = array(); $parser->getPlaylist($playlist_name, $itunes_playlist_id, $playlist_songs); $t->is($playlist_name, 'Library', 'Correct name for first library entry'); $t->is($itunes_playlist_id, 'E913B5CC1E293488', 'Correct playlist permanent id'); $t->is($playlist_songs, array(0 => array('filename' => 'file://localhost/E:/music/TheKingOfLimbs-MP3/The%20King%20Of%20Limbs/01%20Bloom.MP3'), 1 => array('filename' => 'file://localhost/E:/music/03%20Hoppipolla.mp3'), 2 => array('filename' => 'file://localhost/E:/music/1Xtra%20D&B%20Show%20%5B2010-08-04%5D%20%E2%80%93%20Bailey%20&%20DJ%20Fresh/1Xtra%20D&B%20Show%20%5B2010-08-04%5D%20%E2%80%93%20Bailey%20&%20DJ%20Fresh.mp3')), 'playlist songs are correct'); $playlist_name = $itunes_playlist_id = null; $playlist_songs = array(); $parser->getPlaylist($playlist_name, $itunes_playlist_id, $playlist_songs); $t->is($playlist_name, '90\'s Rock', 'Correct name for first library entry'); $t->is($itunes_playlist_id, 'B16E9C5DFFC4695D', 'Correct playlist permanent id'); $t->is($playlist_songs, array(0 => array('filename' => 'file://localhost/E:/music/TheKingOfLimbs-MP3/The%20King%20Of%20Limbs/01%20Bloom.MP3'), 1 => array('filename' => 'file://localhost/E:/music/03%20Hoppipolla.mp3')), 'playlist songs are correct'); $parser->free();
<?php include dirname(__FILE__) . '/../bootstrap/doctrine.php'; // Initialize the test object $t = new lime_test(6, new lime_output_color()); $genre_table = Doctrine_Core::getTable('Genre'); $t->comment('->addGenre'); $first_insert_id = $genre_table->addGenre('Electronic'); $t->is($first_insert_id, '53', 'Successfully selected an existing genre.'); $second_insert_id = $genre_table->addGenre('Electronic'); $t->is($first_insert_id, $second_insert_id, 'Got the same genre fixture.'); $third_insert_id = $genre_table->addGenre('Some Awesome Custom Genre! Woo!'); $t->like($third_insert_id, '/\\d+/', 'Successfully added a new genre entry.'); $fourth_insert_id = $genre_table->addGenre(' Some Awesome Custom Genre! Woo! '); $t->is($third_insert_id, $fourth_insert_id, 'Selected retargeted the second genre entry.'); $fifth_insert_id = $genre_table->addGenre('Русский'); $t->like($fifth_insert_id, '/\\d+/', 'Successfully added a new UTF-8 entry'); $t->comment('->finalizeScan'); $genre_table->addGenre('This should be deleted on next finalize'); $t->is($genre_table->finalizeScan(), 3, 'finalized scan successfully');
require_once dirname(__FILE__) . '/../bootstrap/unit.php'; $logDir = $symfonyRootDir . '/log'; $cacheDir = $symfonyRootDir . '/cache'; $dbName = 'nbSymfonyPlugintest_dev'; $adminUsername = nbConfig::get('mysql_admin-username'); $adminPassword = nbConfig::get('mysql_admin-password'); $fileSystem->mkdir(nbConfig::get('archive_archive-dir_destination-dir')); $t = new lime_test(2); //Setup try { $cmd = new nbMysqlDropCommand(); $commandLine = sprintf('%s %s %s', $dbName, $adminUsername, $adminPassword); $cmd->run(new nbCommandLineParser(), $commandLine); } catch (Exception $e) { $t->comment('Drop database: ' . $e->getMessage()); } try { $cmd = new nbMysqlCreateCommand(); $commandLine = sprintf('%s %s %s', $dbName, $adminUsername, $adminPassword); $cmd->run(new nbCommandLineParser(), $commandLine); } catch (Exception $e) { $t->comment('Create database: ' . $e->getMessage()); } $cmd = new nbSymfonyDeployCommand(); $parser = new nbCommandLineParser(); $parser->setDefaultConfigurationDirs(array(dirname(__FILE__) . '/../data/config')); $t->comment('Symfony Deploy dry run'); $commandLine = '--config-file '; $t->ok($cmd->run($parser, $commandLine), 'Symfony project deployed successfully'); $cmd = new nbSymfonyDeployCommand();
<?php require_once dirname(__FILE__) . '/../bootstrap/unit.php'; require_once sfConfig::get("sf_plugins_dir") . '/sfPaymentPlugin/lib/sfPaymentMockGatewayInterface.php'; $t = new lime_test(8, new lime_output_color()); $gateway = new sfPaymentMockGatewayInterface(); $transaction = new sfPaymentTransaction($gateway); $t->comment('sfPaymentGatewayInterface.'); $t->is($transaction->getVendor(), "", "vendor not set yet"); $transaction->setVendor("test"); $t->is($transaction->getVendor(), "test", "::setVendor"); $t->is($transaction->getCurrency(), "", "currency not set yet"); $transaction->setCurrency("USD"); $t->is($transaction->getCurrency(), "USD", "::setCurrency"); $t->is($transaction->getAmount(), "", "amount not set yet"); $transaction->setAmount(100); $t->is($transaction->getAmount(), 100, "::setAmount"); $t->is($transaction->getProductName(), "", "product name not set yet"); $transaction->setProductName("Symfony Book"); $t->is($transaction->getProductName(), "Symfony Book", "::setProductName");
//$adminUrl = 'http://symfony/admin.php'; //$t->is(£link('app:admin')->getHref(), $adminUrl, $adminUrl); // //$adminUrl2 = 'http://symfony/admin.php/main/test'; //$t->is(£link('app:admin/main/test')->getHref(), $adminUrl2, $adminUrl2); // //$adminUrl3 = 'http://symfony/admin.php?var1=val2'; //$t->is(£link('app:admin?var1=val2')->getHref(), $adminUrl3, $adminUrl3); $t->diag('blank'); $blankLink = sprintf('<a class="link" href="%s" target="%s">%s</a>', 'http://diem-project.org', '_blank', 'http://diem-project.org'); $t->is((string) £link('http://diem-project.org')->target('blank'), $blankLink, 'blank link is ' . $blankLink); $blankLink = sprintf('<a class="link" href="%s">%s</a>', 'http://diem-project.org', 'http://diem-project.org'); $t->is((string) £link('http://diem-project.org')->target('blank')->target(false), $blankLink, 'canceled blank link is ' . $blankLink); $t->diag('media links'); dmDb::table('DmMediaFolder')->checkRoot(); $t->comment('Create a test image media'); $mediaFileName = 'test_image_' . dmString::random() . '.jpg'; copy(dmOs::join(sfConfig::get('dm_core_dir'), 'data/image/defaultMedia.jpg'), dmOs::join(sfConfig::get('sf_upload_dir'), $mediaFileName)); $media = dmDb::create('DmMedia', array('file' => $mediaFileName, 'dm_media_folder_id' => dmDb::table('DmMediaFolder')->checkRoot()->id))->saveGet(); $t->ok($media->exists(), 'A test media has been created'); $mediaLink = sprintf('<a class="link" href="%s">%s</a>', $helper->get('request')->getAbsoluteUrlRoot() . '/' . $media->webPath, $media->file); $t->is((string) £link($media), $mediaLink, '$media -> ' . $mediaLink); $t->is((string) £link('media:' . $media->id), $mediaLink, 'media:' . $media->id . ' -> ' . $mediaLink); $t->is((string) £link('/' . $media->webPath)->text($media->file), $expected = str_replace($helper->get('request')->getAbsoluteUrlRoot(), '', $mediaLink), $media->webPath . ' -> ' . $expected); sfConfig::set('sf_debug', true); $badSource = dmString::random() . '/' . dmString::random(); $errorText = '[EXCEPTION] ' . $badSource . ' is not a valid link resource'; $expr = '_^<a class="link" href="\\?dm\\_debug=1" title="[^"]+">' . preg_quote($errorText, '_') . '</a>$_'; $errorLink = (string) £link($badSource); $t->like($errorLink, $expr, $errorLink); sfConfig::set('sf_debug', false);
<?php // test/unit/fixtures/CustomerTest.php include dirname(__FILE__) . '/../../bootstrap/Doctrine.php'; $t = new lime_test(2); # Check the existence of all available Customers. $t->comment('-> fixture Customer'); $number_of_Customers = Doctrine_Core::getTable('Customer')->createQuery()->count(); $t->is($number_of_Customers, 1, '-> fixture Customer. There is 1 Customer counted via DQL'); # Test or the (Customer)name and sfGuardUser.name proper are added via the fixtures. $q = Doctrine_Query::create()->from('Customer c INDEXBY c.company')->innerJoin('c.GuardUser'); $companies = $q->execute(); $t->is($companies['AuxZambia']->GuardUser->username, 'hansrip', '-> fixture Customer. CompanyName and GuardUserName proper defined.');
<?php require_once dirname(__FILE__) . '/../bootstrap/unit.php'; $mode = '644'; $folder = nbConfig::get('nb_sandbox_dir') . '/folder'; $fs = nbFileSystem::getInstance(); if (php_uname('s') == 'Linux') { $fs->mkdir($folder); $t = new lime_test(1); $cmd = new nbChangeModeCommand(); $commandLine = sprintf('%s %s', $folder, $mode); $t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'Folder mode changed successfully'); $fs->rmdir($folder); } else { $t = new lime_test(0); $t->comment('No tests under Windows'); }
$t->is(get_class($new), get_class($menu), 'Test child is correct class type'); $new2 = $new['Root 3']['Child 1']; $t->is((string) $new, '<ul><li class="first">Child 1<ul><li class="first last">Child 2</li></ul></li><li class="last">Root 3<ul><li class="first last">Child 1</li></ul></li></ul>', 'Test __toString()'); $menu['Test']['With Route']->link('http://www.google.com'); $t->is((string) $menu['Test'], '<ul><li class="first last"><a class="link" href="http://www.google.com">With Route</a></li></ul>', 'Test __toString()'); $menu['Test']['With Route']->getLink()->set('target', '_BLANK'); $t->is((string) $menu['Test'], '<ul><li class="first last"><a class="link" href="http://www.google.com" target="_blank">With Route</a></li></ul>', 'Test __toString()'); $menu['Test']->showId(true); $menu['Test']['With Route']->secure(true)->showId(true); $t->is((string) $menu['Test'], '', 'Test secure()'); $user = $helper->get('user'); $user->setAuthenticated(true); $t->is($user->isAuthenticated(), true, 'Test isAuthenticated()'); $t->is($menu['Test']['With Route']->checkUserAccess($user), true, 'Test checkUserAccess()'); $t->is((string) $menu['Test'], '<ul id="test-menu"><li id="test-menu-with-route" class="first last"><a class="link" href="http://www.google.com" target="_blank">With Route</a></li></ul>', 'Test authentication'); $t->comment('test notAuthenticated'); $menu['Test']['With Route']->secure(false)->notAuthenticated(true); $t->is($menu['Test']['With Route']->checkUserAccess($user), false, 'Test checkUserAccess()'); $user->setAuthenticated(false); $t->is($menu['Test']['With Route']->checkUserAccess($user), true, 'Test checkUserAccess()'); $t->comment('misc tests'); $t->is($menu->getLevel(), -1, 'Test getLevel()'); $t->is($menu['Test']['With Route']->getParent()->getLabel(), $menu['Test']->getLabel(), 'Test getLabel()'); $menu['Root 4']['Test']; $t->is($menu['Root 4']->toArray(), array('name' => 'Root 4', 'level' => 0, 'options' => array('ul_class' => NULL, 'li_class' => NULL, 'show_id' => false, 'show_children' => true, 'translate' => true), 'children' => array('Test' => array('name' => 'Test', 'level' => 1, 'options' => array('ul_class' => NULL, 'li_class' => NULL, 'show_id' => false, 'show_children' => true, 'translate' => true), 'children' => array()))), 'Test toArray()'); $test = $helper->get('menu')->name('Test'); $test->fromArray($menu['Root 4']->toArray()); $t->is($test->toArray(), $menu['Root 4']->toArray(), 'Test fromArray()'); $t->is($menu['Root 4']['Test']->getPathAsString(), 'Test Menu > Root 4 > Test', 'Test getPathAsString()'); $t->is($menu->getFirstChild()->getName(), 'Root 1', 'Test getFirstChild()'); $t->is($menu->getLastChild()->getName(), 'Root 4', 'Test getLastChild()');
<?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');
return '<script type="text/javascript" src="/dynamics/foo.js"></script>'; } } $t = new lime_test(7, new lime_output_color()); if (!sfContext::hasInstance()) { require_once $_SERVER['SYMFONY'] . '/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register(); require_once dirname(__FILE__) . '/../../fixtures/project/config/ProjectConfiguration.class.php'; sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration('frontend', 'test', isset($debug) ? $debug : true)); if (!sfContext::hasInstance()) { $t->error('A context instance is required'); die; } $t->info('A frontend context has been initialized for tests'); } $t->comment('->addSfDynamicsTags()'); sfConfig::set('app_sfDynamicsPlugin_manager', 'ManagerMock'); $manager = sfDynamics::getManager(); $t->info('New placeholder system'); $content = <<<END <html> <head> <!-- Include sfDynamics css tags --> <link rel="stylesheet" type="text/css" media="screen" href="/bar.css" /> </head> <body> <p>Lorem ipsum</p> <!-- Include sfDynamics js tags --> <script type="text/javascript" src="/bar.js"></script> </body>
<?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 require_once dirname(__FILE__) . '/../../vendor/lime.php'; require_once dirname(__FILE__) . '/../../lib/phpGitHubApi.php'; $t = new lime_test(3); $api = new phpGitHubApi(true); $t->comment('Test ->listObjectTree'); $tree = $api->listObjectTree('ornicar', 'php-github-api', '691c2ec7fd0b948042047b515886fec40fe76e2b'); $firstFile = array_pop($tree); $t->cmp_ok($firstFile['sha'], '!=', null, 'Tree returned with SHA listings'); $blob = $api->showObjectBlob('ornicar', 'php-github-api', '691c2ec7fd0b948042047b515886fec40fe76e2b', 'CHANGELOG'); print_r($blob); $t->is($blob['name'], 'CHANGELOG', 'Returned CHANGELOG blob'); $blobs = $api->listObjectBlobs('ornicar', 'php-github-api', '691c2ec7fd0b948042047b515886fec40fe76e2b'); $t->cmp_ok(count($blobs), '>', 0, 'Returned array of blobs');