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); } } } }
<?php $app = 'frontend'; $fixtures = 'fixtures/fixtures.yml'; include dirname(__FILE__) . '/../../bootstrap/functional.php'; $t = new lime_test(4); // ->getChoices() $t->diag('->getChoices()'); $validator = new sfWidgetFormDoctrineChoice(array('model' => 'Author')); $author = Doctrine_Core::getTable('Author')->createQuery()->limit(1)->fetchOne(); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage', 2 => 'Fabien POTENCIER'), '->getChoices() returns choices'); $validator->setOption('order_by', array('name', 'asc')); $t->cmp_ok($validator->getChoices(), '===', array(2 => 'Fabien POTENCIER', 1 => 'Jonathan H. Wage'), '->getChoices() returns ordered choices'); $validator->setOption('table_method', 'testTableMethod'); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage', 2 => 'Fabien POTENCIER'), '->getChoices() returns choices for given "table_method" option'); $validator = new sfWidgetFormDoctrineChoice(array('model' => 'Author', 'query' => Doctrine_Core::getTable('Author')->createQuery()->limit(1))); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage'), '->getChoices() returns choices for given "query" option');
ArticlePeer::doDeleteAll(); $title = sfPropelFinder::from('Article')->select('Title')->findOne(); $t->isa_ok($title, 'NULL', 'findOne() called after select(string) returns null when no record is found'); /*******************************/ /* sfPropelFinder::select('*') */ /*******************************/ $t->diag('sfPropelFinder::select(\'*\')'); $finder = sfPropelFinder::from('Category')->select('*'); $category = $finder->findOne(); $t->is($finder->getLatestQuery(), propel_sql('SELECT [P12category.ID, ]category.ID AS "Category.Id", category.NAME AS "Category.Name" FROM category LIMIT 1'), 'select(\'*\') selects all the columns from the main object'); $t->isa_ok($category, 'array', 'findOne() called after select(\'*\') returns an array'); $t->is_deeply(array_keys($category), array('Category.Id', 'Category.Name'), 'select(\'*\') returns all the columns from the main object, in complete form'); /*************************************************************/ /* sfPropelFinder::select(array, sfModelFinder::ASSOCIATIVE) */ /*************************************************************/ $t->diag('sfPropelFinder::select(array, sfModelFinder::ASSOCIATIVE)'); ArticlePeer::doDeleteAll(); CategoryPeer::doDeleteAll(); $finder = sfPropelFinder::from('Category')-> select(array('Id','Name'), sfModelFinder::ASSOCIATIVE); $categories = $finder->find(); $t->is($finder->getLatestQuery(), propel_sql('SELECT [P12category.ID, ]category.ID AS Id, category.NAME AS Name FROM category'), 'find() called after select(array) selects several columns'); $t->isa_ok($categories, 'array', 'find() called after select(array) returns an array');
$v = $f->getValidatorSchema(); $t->ok(isset($v['_token_']), '::setCSRFFieldName() changes the CSRF token field name'); $t->is(sfForm::getCSRFFieldName(), '_token_', '::getCSRFFieldName() returns the CSRF token field name'); // ->isMultipart() $t->diag('->isMultipart()'); $f = new FormTest(); $t->ok(!$f->isMultipart(), '->isMultipart() returns false if the form does not need a multipart form'); $f->setWidgetSchema(new sfWidgetFormSchema(array('image' => new sfWidgetFormInputFile()))); $t->ok($f->isMultipart(), '->isMultipart() returns true if the form needs a multipart form'); // ->setValidators() ->setValidatorSchema() ->getValidatorSchema() ->setValidator() ->getValidator() $t->diag('->setValidators() ->setValidatorSchema() ->getValidatorSchema() ->setValidator() ->getValidator()'); $f = new FormTest(); $validators = array('first_name' => new sfValidatorPass(), 'last_name' => new sfValidatorPass()); $validatorSchema = new sfValidatorSchema($validators); $f->setValidatorSchema($validatorSchema); $t->is_deeply($f->getValidatorSchema(), $validatorSchema, '->setValidatorSchema() sets the current validator schema'); $f->setValidators($validators); $schema = $f->getValidatorSchema(); $t->ok($schema['first_name'] == $validators['first_name'], '->setValidators() sets field validators'); $t->ok($schema['last_name'] == $validators['last_name'], '->setValidators() sets field validators'); $f->setValidator('name', $v3 = new sfValidatorPass()); $t->ok($f->getValidator('name') == $v3, '->setValidator() sets a validator for a field'); // ->setWidgets() ->setWidgetSchema() ->getWidgetSchema() ->getWidget() ->setWidget() $t->diag('->setWidgets() ->setWidgetSchema() ->getWidgetSchema()'); $f = new FormTest(); $widgets = array('first_name' => new sfWidgetFormInput(), 'last_name' => new sfWidgetFormInput()); $widgetSchema = new sfWidgetFormSchema($widgets); $f->setWidgetSchema($widgetSchema); $t->ok($f->getWidgetSchema() == $widgetSchema, '->setWidgetSchema() sets the current widget schema'); $f->setWidgets($widgets); $schema = $f->getWidgetSchema();
$this->lastArguments = $arguments; $this->lastOptions = $options; } } // ->run() $t->diag('->run()'); class ArgumentsTest1Task extends BaseTestTask { protected function configure() { $this->addArguments(array(new sfCommandArgument('foo', sfCommandArgument::REQUIRED), new sfCommandArgument('bar', sfCommandArgument::OPTIONAL))); } } $task = new ArgumentsTest1Task(); $task->run(array('FOO')); $t->is_deeply($task->lastArguments, array('foo' => 'FOO', 'bar' => null), '->run() accepts an indexed array of arguments'); $task->run(array('foo' => 'FOO')); $t->is_deeply($task->lastArguments, array('foo' => 'FOO', 'bar' => null), '->run() accepts an associative array of arguments'); $task->run(array('bar' => 'BAR', 'foo' => 'FOO')); $t->is_deeply($task->lastArguments, array('foo' => 'FOO', 'bar' => 'BAR'), '->run() accepts an unordered associative array of arguments'); $task->run('FOO BAR'); $t->is_deeply($task->lastArguments, array('foo' => 'FOO', 'bar' => 'BAR'), '->run() accepts a string of arguments'); $task->run(array('foo' => 'FOO', 'bar' => null)); $t->is_deeply($task->lastArguments, array('foo' => 'FOO', 'bar' => null), '->run() accepts an associative array of arguments when optional arguments are passed as null'); $task->run(array('bar' => null, 'foo' => 'FOO')); $t->is_deeply($task->lastArguments, array('foo' => 'FOO', 'bar' => null), '->run() accepts an unordered associative array of arguments when optional arguments are passed as null'); class ArgumentsTest2Task extends BaseTestTask { protected function configure() { $this->addArguments(array(new sfCommandArgument('foo', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY)));
/* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../../bootstrap/unit.php'; sfYaml::setSpecVersion('1.1'); $t = new lime_test(124); // ::load() $t->diag('::load()'); $testsForLoad = array('' => '', 'null' => null, 'false' => false, 'true' => true, '12' => 12, '"quoted string"' => 'quoted string', "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '0x4D2' => 0x4d2, '02333' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '123456789123456789000' => '123456789123456789000', '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', '2007-10-30' => mktime(0, 0, 0, 10, 30, 2007), '2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007), '2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007), '"a \\"string\\" with \'quoted strings inside\'"' => 'a "string" with \'quoted strings inside\'', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, http://urls.are/no/mappings, false, null, 12]' => array('foo', 'http://urls.are/no/mappings', false, null, 12), '[ foo , bar , false , null , 12 ]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{foo:bar,bar:foo,false:false,null:null,integer:12}' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo : bar, bar : foo, false : false, null : null, integer : 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{foo: \'bar\', bar: \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\'\'\': \'bar\', "bar\\"": \'foo: bar\'}' => array('foo\'' => 'bar', "bar\"" => 'foo: bar'), '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => array('foo: ' => 'bar', "bar: " => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, {bar: foo}]' => array('foo', array('bar' => 'foo')), '{ foo: {bar: foo} }' => array('foo' => array('bar' => 'foo')), '{ foo: [bar, foo] }' => array('foo' => array('bar', 'foo')), '[ foo, [ bar, foo ] ]' => array('foo', array('bar', 'foo')), '[{ foo: {bar: foo} }]' => array(array('foo' => array('bar' => 'foo'))), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))), '[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar')))); foreach ($testsForLoad as $yaml => $value) { $t->is_deeply(sfYamlInline::load($yaml), $value, sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml)); } $testsForDump = array('null' => null, 'false' => false, 'true' => true, '12' => 12, "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '1234' => 0x4d2, '1243' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo: bar, bar: \'foo: bar\' }' => array('foo' => 'bar', 'bar' => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '{ foo: { bar: foo } }' => array('foo' => array('bar' => 'foo')), '[foo, { bar: foo }]' => array('foo', array('bar' => 'foo')), '[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo')))); // ::dump() $t->diag('::dump()'); foreach ($testsForDump as $yaml => $value) { $t->is(sfYamlInline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml)); } foreach ($testsForLoad as $yaml => $value) { if ($value == 1230) { continue; } $t->is_deeply(sfYamlInline::load(sfYamlInline::dump($value)), $value, 'check consistency'); } foreach ($testsForDump as $yaml => $value) { if ($value == 1230) {
<?php require_once __DIR__ . '/../../bootstrap.php'; use greebo\essence\Container; $t = new lime_test(8); $container = new Container(); $container->foo = 'foo'; $container->bar = function ($c) { return new stdClass(); }; $t->pass('setter works properly'); $t->is_deeply($container->foo, 'foo', 'getter returns simple values properly'); $t->is_deeply($container->invalid, null, 'getter returns null on invalid keys'); $bar1 = $container->bar; $bar2 = $container->bar; $t->ok($bar1 instanceof stdClass, 'getter returns lazy loaded instance properly'); $t->ok($bar1 !== $bar2, 'getter returns distinct instances by default'); $container->baz = $container->shared(function ($c) { return new stdClass(); }); $baz1 = $container->baz; $baz2 = $container->baz; $t->ok($baz1 instanceof stdClass, 'getter returns lazy loaded instance properly as shared'); $t->ok($baz1 === $baz2, 'getter returns distinct instances when shared'); $t->ok(isset($container->bar) && !isset($container->invalid), 'property check works properly');
<?php require dirname(__FILE__) . '/../bootstrap/unit.php'; require $ga_lib_dir . '/transaction/sfGoogleAnalyticsTransaction.class.php'; require $ga_lib_dir . '/transaction/sfGoogleAnalyticsItem.class.php'; $t = new lime_test(12, new lime_output_color()); $t->diag('sfGoogleAnalyticsTransaction'); $trans = new sfGoogleAnalyticsTransaction(); $t->isa_ok($trans, 'sfGoogleAnalyticsTransaction', 'transaction instantiated ok'); $t->is_deeply($trans->getValues(), array_fill(0, 8, null), 'getValues empty'); $trans->setOrderId('orderid'); $trans->setStoreName('storename'); $trans->setTotal(100); $trans->setTax(1.25); $trans->setShipping(4.99); $trans->setCity('new york'); $trans->setState('ny'); $trans->setCountry('usa'); $item1 = new sfGoogleAnalyticsItem(); $item2 = new sfGoogleAnalyticsItem(); $trans->addItem($item1); $trans->addItem($item2); $t->is($trans->getOrderId(), 'orderid', 'order id ok'); $t->is($trans->getStoreName(), 'storename', 'store name ok'); $t->is($trans->getTotal(), 100, 'total ok'); $t->is($trans->getTax(), 1.25, 'tax ok'); $t->is($trans->getShipping(), 4.99, 'shipping ok'); $t->is($trans->getCity(), 'new york', 'city ok'); $t->is($trans->getState(), 'ny', 'state ok'); $t->is($trans->getCountry(), 'usa', 'country ok'); $t->is_deeply($trans->getItems(), array($item1, $item2), 'items ok');
$t->diag('->getNumberFormat()'); $c = sfCultureInfo::getInstance(); $t->isa_ok($c->getNumberFormat(), 'sfNumberFormatInfo', '->getNumberFormat() returns a sfNumberFormatInfo instance'); // ->setNumberFormat() $t->diag('->setNumberFormat()'); $d = $c->getNumberFormat(); $c->setNumberFormat('.'); $t->is($c->getNumberFormat(), '.', '->setNumberFormat() sets the sfNumberFormatInfo instance'); $c->NumberFormat = '#'; $t->is($c->getNumberFormat(), '#', '->setNumberFormat() is equivalent to ->NumberFormat = '); // ->simplify() $t->diag('->simplify()'); class myCultureInfo extends sfCultureInfo { public function __construct($culture = 'en') { parent::__construct($culture); } public static function simplify($array) { return parent::simplify($array); } } $array1 = array(0 => 'hello', 1 => 'world'); $array2 = array(0 => array('hello'), 1 => 'world'); $array3 = array(0 => array('hello', 'hi'), 1 => 'world'); $ci = new myCultureInfo(); $t->isa_ok($ci->simplify($array1), 'array', '::simplify() returns an array'); $t->is_deeply($ci->simplify($array1), $array1, '::simplify() leaves 1D-arrays unchanged'); $t->is_deeply($ci->simplify($array2), $array1, '::simplify() simplifies arrays'); $t->is_deeply($ci->simplify($array3), $array3, '::simplify() leaves not-simplifiable arrays unchanged');
<?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');
$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'); $t->is($form->getDefault('text'), array(), 'The form default link is correct'); $t->comment('Submit form without additional data'); $form->bind(array(), array()); $t->is($form->isValid(), true, 'The form is valid'); if (!$form->isValid()) { $t->comment($form->getErrorSchema()->getMessage()); } $t->comment('Add an item'); $form->bind(array('link' => array('page:1'), 'text' => array('Home'), 'depth' => 0, 'cssClass' => 'test css_class'), array()); $t->is($form->isValid(), true, 'The form is valid'); if (!$form->isValid()) {
<?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(1); class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins('sfPropelORMPlugin'); sfConfig::set('sf_plugins_dir', sfConfig::get('sf_root_dir') . '/../../../'); } } new ProjectConfiguration(); // ->__construct() $t->diag('->__construct()'); $configuration = array('propel' => array('datasources' => array('propel' => array('adapter' => 'mysql', 'connection' => array('dsn' => 'mysql:dbname=testdb;host=localhost', 'user' => 'foo', 'password' => 'bar', 'classname' => 'PropelPDO', 'options' => array('ATTR_PERSISTENT' => true, 'ATTR_AUTOCOMMIT' => false), 'settings' => array('charset' => array('value' => 'utf8'), 'queries' => array())), 'slaves' => array()), 'default' => 'propel'))); $parametersTests = array('dsn' => 'mysql:dbname=testdb;host=localhost', 'username' => 'foo', 'password' => 'bar', 'encoding' => 'utf8', 'persistent' => true, 'options' => array('ATTR_AUTOCOMMIT' => false)); $p = new sfPropelDatabase($parametersTests); $t->is_deeply($p->getConfiguration(), $configuration, '->__construct() creates a valid propel configuration from parameters');
$t->diag('Initialization'); $b = $sc->reload('web_browser'); $t->is($b->getUserAgent(), 'Project (?) Diem/' . DIEM_VERSION . ' (http://diem-project.org)', 'a new browser has a default user agent: ' . $b->getUserAgent()); $t->is($b->getResponseText(), '', 'a new browser has an empty response'); $t->is($b->getResponseCode(), '', 'a new browser has an empty response code'); $t->is($b->getResponseHeaders(), array(), 'a new browser has empty reponse headers'); /*******************/ /* Utility methods */ /*******************/ $t->diag('Utility methods'); $b = $sc->reload('web_browser'); $t->is($b->setUserAgent('foo bar')->getUserAgent(), 'foo bar', 'setUserAgent() sets the user agent'); $t->is($b->setResponseText('foo bar')->getResponseText(), 'foo bar', 'setResponseText() extracts the response'); $t->is($b->setResponseCode('foo 123 bar')->getResponseCode(), '123', 'setResponseCode() extracts the three-digits code'); $t->is($b->setResponseCode('foo 12 bar')->getResponseCode(), '', 'setResponseCode() fails silently when response status is incorrect'); $t->is_deeply($b->setResponseHeaders(array('HTTP1.1 200 OK', 'foo: bar', 'bar: baz'))->getResponseHeaders(), array('Foo' => 'bar', 'Bar' => 'baz'), 'setResponseHeaders() extracts the headers array'); $t->is_deeply($b->setResponseHeaders(array('ETag: "535a8-9fb-44ff4a13"', 'WWW-Authenticate: Basic realm="Myself"'))->getResponseHeaders(), array('ETag' => '"535a8-9fb-44ff4a13"', 'WWW-Authenticate' => 'Basic realm="Myself"'), 'setResponseHeaders() extracts the headers array and accepts response headers with several uppercase characters'); $t->is_deeply($b->setResponseHeaders(array('HTTP1.1 200 OK', 'foo: bar', 'bar:baz', 'baz:bar'))->getResponseHeaders(), array('Foo' => 'bar'), 'setResponseHeaders() ignores malformed headers'); /**************/ /* Exceptions */ /**************/ $t->diag('Exceptions'); $b = $sc->reload('web_browser'); try { $b->get('htp://askeet'); $t->fail('get() throws an exception when passed an uri which is neither http nor https'); } catch (Exception $e) { $t->pass('get() throws an exception when passed an uri which is neither http nor https'); } /**********************/ /* Simple GET request */
$output = <<<EOF <link rel="stylesheet" type="text/css" media="all" href="/path/to/a/foo.css" /> <link rel="stylesheet" type="text/css" media="print" href="/path/to/a/bar.css" /> EOF; $t->is(get_stylesheets_for_form($form), fix_linebreaks($output), 'get_stylesheets_for_form() returns link tags'); // use_javascripts_for_form() use_stylesheets_for_form() $t->diag('use_javascripts_for_form() use_stylesheets_for_form()'); $response = sfContext::getInstance()->getResponse(); $form = new MyForm(); $response->resetAssets(); use_stylesheets_for_form($form); $t->is_deeply($response->getStylesheets(), array('/path/to/a/foo.css' => array('media' => 'all'), '/path/to/a/bar.css' => array('media' => 'print')), 'use_stylesheets_for_form() adds stylesheets to the response'); $response->resetAssets(); use_javascripts_for_form($form); $t->is_deeply($response->getJavaScripts(), array('/path/to/a/foo.js' => array(), '/path/to/a/bar.js' => array()), 'use_javascripts_for_form() adds javascripts to the response'); // custom web paths $t->diag('Custom asset path handling'); sfConfig::set('sf_web_js_dir_name', 'static/js'); $t->is(javascript_path('xmlhr'), '/static/js/xmlhr.js', 'javascript_path() decorates a relative filename with js dir name and extension with custom js dir'); $t->is(javascript_include_tag('xmlhr'), '<script type="text/javascript" src="/static/js/xmlhr.js"></script>'."\n", 'javascript_include_tag() takes a javascript name as its first argument'); sfConfig::set('sf_web_css_dir_name', 'static/css');
<?php require_once realpath(dirname(__FILE__) . '/../../..') . '/unit/helper/dmModuleUnitTestHelper.php'; $helper = new dmModuleUnitTestHelper(); $helper->boot(); $t = new lime_test(10); $models = dmProject::getModels(); $dmModels = dmProject::getDmModels(); $allModels = dmProject::getAllModels(); $t->is_deeply($models, $expected = array('DmTestCateg', 'DmTestComment', 'DmTestDomainCateg', 'DmTestDomain', 'DmTestFruit', 'DmTestPost', 'DmTestPostTag', 'DmTestTag', 'DmTestUser', 'DmContact', 'DmTag'), 'dmProject::getModels() -> ' . implode(', ', $expected)); $t->is_deeply(array_intersect($models, $allModels), $models, 'dmProject::getAllModels() contain all project models'); $t->is_deeply(array_intersect($dmModels, $allModels), $dmModels, 'dmProject::getAllModels() contain all Diem models'); $t->is_deeply(array_intersect($models, $dmModels), array(), 'dmProject::getDmModels() contain no project models'); $t->is_deeply(array_intersect($dmModels, $models), array(), 'dmProject::getModels() contain no Diem models'); $t->is(count($dmModels), $expected = 17, 'Diem has ' . $expected . ' models'); $t->is(dmProject::getKey(), 'project', 'project key is "project"'); $t->ok(dmProject::appExists('front'), 'project has a front app'); $t->ok(dmProject::appExists('admin'), 'project has a admin app'); $t->ok(!dmProject::appExists('bluk'), 'project has no bluk app');
<?php require_once __DIR__ . '/../../bootstrap.php'; use greebo\conveniences\Container; $t = new lime_test(13); $container = new Container(); $t->diag('defaults'); $t->is_deeply($container->vendor, 'greebo', 'default vendor'); $t->is_deeply($container->app, 'conveniences', 'default app'); $t->is_deeply($container->charset, 'utf-8', 'default character set'); $t->is_deeply($container->debug, false, 'default debug mode'); $t->isa_ok($container->event, 'greebo\\essence\\Event', 'default event instance'); $t->isa_ok($container->request, 'greebo\\conveniences\\Request', 'default request instance'); $t->isa_ok($container->response, 'greebo\\conveniences\\Response', 'default response instance'); $t->is_deeply($container->action_name, 'index', 'default action name'); $t->diag('context related instances'); $_GET['action'] = 'assignments'; $container = new Container(); $container->app = 'test'; $t->is_deeply($container->action_name, 'assignments', 'correct action name'); $t->isa_ok($container->action, 'greebo\\test\\ActionSet', 'correct action set instance'); try { $container->template; $t->fail('template getter throws exception if template class not exists'); } catch (\greebo\conveniences\ContainerException $e) { $t->pass('template getter throws exception if template class not exists'); } try { $container->action_name = 'index'; $template = $container->template; $t->isa_ok($template, 'greebo\\test\\Template\\index', 'correct template instance');
{ $this->processedFields[] = $field; } public function getFields() { return array_merge(parent::getFields(), array('body' => 'Invalid', 'nomethod_bc' => 'Text')); } } $t->diag('->getQuery()'); $filter = new ArticleFormFilter(); $filter->bind(array()); $t->isa_ok($filter->getQuery(), 'Doctrine_Query', '->getQuery() returns a Doctrine_Query object'); $query = Doctrine_Query::create()->select('title, body'); $filter = new ArticleFormFilter(array(), array('query' => $query)); $filter->bind(array()); $t->is_deeply($filter->getQuery()->getDqlPart('select'), array('title, body'), '->getQuery() uses the query option'); $t->ok($filter->getQuery() !== $query, '->getQuery() clones the query option'); // BC with symfony 1.2 $filter = new TestFormFilter(); $filter->bind(array('nomethod_bc' => 'nomethod_bc')); try { $filter->getQuery(); $t->fail('->getQuery() throws an exception if a field that is not a real column is specified in getFields() but a column method does not exist'); } catch (Exception $e) { $t->pass('->getQuery() throws an exception if a field that is not a real column is specified in getFields() but a column method does not exist'); } // BC with symfony 1.2 $filter = new TestFormFilter(); $filter->bind(array('body' => 'body')); try { $filter->getQuery();
list($method, $uri, $parameters) = $b->click('image submit'); $t->is($uri, '/myform4?submit_image=image', '->click() can click on image button in forms'); list($method, $uri, $parameters) = $b->click('submit', array('text_default_value' => 'myvalue', 'text' => 'myothervalue', 'textarea' => 'mycontent', 'select' => 'last', 'select_multiple' => array('first', 'selected', 'last'), 'article' => array('title' => 'mytitle', 'category' => array(1, 2, 3), 'or' => array('much' => array('longer' => 'long'))))); $t->is($parameters['text_default_value'], 'myvalue', '->click() takes an array of parameters as its second argument'); $t->is($parameters['text'], 'myothervalue', '->click() can override input fields'); $t->is($parameters['textarea'], 'mycontent', '->click() can override textarea fields'); $t->is($parameters['select'], 'last', '->click() can override select fields'); $t->is($parameters['select_multiple'], array('first', 'selected', 'last'), '->click() can override select (multiple) fields'); $t->is($parameters['article']['title'], 'mytitle', '->click() can override array fields'); $t->is($parameters['article']['category'], array(1, 2, 3), '->click() can override array fields'); $t->is($parameters['article']['or']['much']['longer'], 'long', '->click() recognizes array names'); $t->is(isset($parameters['i_am_disabled']), false, '->click() ignores disabled fields'); list($method, $uri, $parameters) = $b->click('#clickable-link'); $t->is($method, 'get', '->click() accepts a CSS selector'); $t->is($uri, '/mylink', '->click() accepts a CSS selector'); $t->is_deeply($parameters, array(), '->click() accepts a CSS selector'); list($method, $uri, $parameters) = $b->click('.one-of-many-clickable-links', array(), array('position' => 2)); $t->is($method, 'get', '->click() accepts a CSS selector and position option'); $t->is($uri, '/myimagelink', '->click() accepts a CSS selector and position option'); $t->is_deeply($parameters, array(), '->click() accepts a CSS selector and position option'); list($method, $uri, $parameters) = $b->click('#clickable-input-submit'); $t->is($method, 'post', '->click() accepts a CSS selector for a submit input'); $t->is($uri, '/myform', '->click() accepts a CSS selector for a submit input'); try { $b->click('#orphaned-input-submit'); $t->fail('->click() throws an error if a submit is clicked outside a form'); } catch (Exception $e) { $t->pass('->click() throws an error if a submit is clicked outside a form'); } // ->setField() $t->diag('->setField()');
require_once TEST_BASE_DIR . '/../src/SimpleMail/Template/YamlLoader.php'; $template_file = TEST_BASE_DIR . '/fixtures/templates.yml'; $template_dir = TEST_BASE_DIR . '/fixtures/templates'; $t = new lime_test(11); try { $loader = new SimpleMail_Template_YamlLoader(TEST_BASE_DIR . '/fixtures/no-templates.yml'); $t->fail('->__construct() have to throw exception on invalid template file'); } catch (Exception $e) { $t->pass('->__construct() throw exception on invalid template file'); } $t->diag('Fetching templates from one file'); $loader = new SimpleMail_Template_YamlLoader($template_file); try { $foo = $loader->fetch('foo_template'); $t->pass('->fetch() load valid template properly from template file'); $t->is_deeply($foo['subject'], 'foo', '->fetch() load the correct template'); $t->is($loader->modifiedAt('foo_template'), filemtime($template_file), '->modifiedAt() returns correct timestamp'); $foo = $loader->fetch('foo_template'); $t->is_deeply($foo['subject'], 'foo', '->fetch() second time load the correct template from cache'); } catch (Exception $e) { $t->fail('->fetch() have to load valid template properly from template file'); $t->fail('->fetch() have to load the correct template'); $t->fail('->modifiedAt() have to return correct timestamp'); $t->fail('->fetch() have to load second time the correct template from cache'); } try { $foo = $loader->fetch('invalid_template'); $t->fail('->fetch() have to throw exception on invalid template'); } catch (Exception $e) { $t->pass('->fetch() throw exception on invalid template'); }
$request->resetPathInfoArray(); $request->setOption('https_port', '8043'); $_SERVER['HTTP_HOST'] = 'symfony-project.org'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'; $t->is($request->getUriPrefix(), 'https://symfony-project.org:8043', '->getUriPrefix() uses the configured port on secure requests forwarded as non-secure requests'); $request->resetPathInfoArray(); // ->getRemoteAddress() $t->diag('->getRemoteAddress()'); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $t->is($request->getRemoteAddress(), '127.0.0.1', '->getRemoteAddress() returns the remote address'); // ->getForwardedFor() $t->diag('->getForwardedFor()'); $t->is($request->getForwardedFor(), null, '->getForwardedFor() returns null if the request was not forwarded.'); $_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.2'; $t->is_deeply($request->getForwardedFor(), array('10.0.0.1', '10.0.0.2'), '->getForwardedFor() returns the value from HTTP_X_FORWARDED_FOR'); // ->getMethod() $t->diag('->getMethod()'); $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['sf_method'] = 'PUT'; $request = new myRequest($dispatcher); $t->is($request->getMethod(), 'PUT', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST'); $_SERVER['REQUEST_METHOD'] = 'GET'; $_POST['sf_method'] = 'PUT'; $request = new myRequest($dispatcher); $t->is($request->getMethod(), 'GET', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST'); $_SERVER['REQUEST_METHOD'] = 'POST'; unset($_POST['sf_method']); $request = new myRequest($dispatcher); $t->is($request->getMethod(), 'POST', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST'); // ->getScriptName()
<?php require dirname(__FILE__) . '/../bootstrap/unit.php'; require $ga_lib_dir . '/transaction/sfGoogleAnalyticsItem.class.php'; $t = new lime_test(9, new lime_output_color()); $t->diag('sfGoogleAnalyticsItem'); $item = new sfGoogleAnalyticsItem(); $t->isa_ok($item, 'sfGoogleAnalyticsItem', 'item instantiated ok'); $t->is_deeply($item->getValues(), array_fill(0, 6, null), 'getValues empty'); $item->setOrderId('orderid'); $item->setSku('mysku'); $item->setProductName('a product'); $item->setCategory('socks'); $item->setUnitPrice(4.99); $item->setQuantity(5); $t->is($item->getOrderId(), 'orderid', 'order id ok'); $t->is($item->getSku(), 'mysku', 'sku ok'); $t->is($item->getProductName(), 'a product', 'product name ok'); $t->is($item->getCategory(), 'socks', 'category ok'); $t->is($item->getUnitPrice(), 4.99, 'unit price ok'); $t->is($item->getQuantity(), 5, 'quantity ok'); $t->is_deeply($item->getValues(), array('orderid', 'mysku', 'a product', 'socks', 4.99, 5), 'getValues ok');
try { $configuration->{$method}(array()); $t->fail('->' . $method . '() throws an exception if called too late'); } catch (Exception $e) { $t->pass('->' . $method . '() throws an exception if called too late'); } } class ProjectConfiguration2 extends sfProjectConfiguration { public function setup() { $this->enablePlugins('sfAutoloadPlugin', 'sfConfigPlugin'); } } $configuration = new ProjectConfiguration2(__DIR__ . '/../../functional/fixtures'); $t->is_deeply($configuration->getPlugins(), array('sfAutoloadPlugin', 'sfConfigPlugin'), '->enablePlugins() can enable plugins passed as arguments instead of array'); // ->__construct() $t->diag('->__construct()'); class ProjectConfiguration3 extends sfProjectConfiguration { public function setup() { $this->enablePlugins('NonExistantPlugin'); } } try { $configuration = new ProjectConfiguration3(__DIR__ . '/../../functional/fixtures'); $t->fail('->__construct() throws an exception if a non-existant plugin is enabled'); } catch (Exception $e) { $t->pass('->__construct() throws an exception if a non-existant plugin is enabled'); }
$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'); // Non-empty string $t->diag(' ::retrieveOptFromString() non-empty string'); $string = 'x=y'; $opt = array('aa' => 'bb'); dmString::retrieveOptFromString($string, $opt); $t->is_deeply($opt, array('aa' => 'bb', 'x' => 'y'), '::retrieveOptFromString() merges the options'); $t->is_deeply($string, '', '::retrieveOptFromString() sets the string parameter to an empty string'); // string overwrites opt $t->diag(' ::retrieveOptFromString() overwriting'); $string = 'x=string'; $opt = array('x' => 'opt'); dmString::retrieveOptFromString($string, $opt); $t->is_deeply($opt, array('x' => 'string'), '::retrieveOptFromString() string has the precedence over opt');
$f = new FormTest(array(), array(), 'secret'); $v = $f->getValidatorSchema(); $t->ok($f->isCSRFProtected(), '__construct() takes a CSRF secret as its second argument'); $t->is($v[sfForm::getCSRFFieldName()]->getOption('token'), '*secret*', '__construct() takes a CSRF secret as its second argument'); sfForm::enableCSRFProtection(); $f = new FormTest(array(), array(), false); $t->ok(!$f->isCSRFProtected(), '__construct() can disable the CSRF protection by passing false as the second argument'); $f = new FormTest(); $t->ok($f->isCSRFProtected(), '__construct() uses CSRF protection if null is passed as the second argument and it\'s enabled globally'); // ->getOption() ->setOption() ->getOptions() $t->diag('->getOption() ->setOption()'); $f = new FormTest(array(), array('foo' => 'bar')); $t->is($f->getOption('foo'), 'bar', '__construct takes an option array as its second argument'); $f->setOption('bar', 'foo'); $t->is($f->getOption('bar'), 'foo', '->setOption() changes the value of an option'); $t->is_deeply($f->getOptions(), array('foo' => 'bar', 'bar' => 'foo'), '->getOptions() returns all options'); sfForm::disableCSRFProtection(); // ->setDefault() ->getDefault() ->hasDefault() ->setDefaults() ->getDefaults() $t->diag('->setDefault() ->getDefault() ->hasDefault() ->setDefaults() ->getDefaults()'); $f = new FormTest(); $f->setDefaults(array('first_name' => 'Fabien')); $t->is($f->getDefaults(), array('first_name' => 'Fabien'), 'setDefaults() sets the form default values'); $f->setDefault('last_name', 'Potencier'); $t->is($f->getDefaults(), array('first_name' => 'Fabien', 'last_name' => 'Potencier'), 'setDefault() sets a default value'); $t->is($f->hasDefault('first_name'), true, 'hasDefault() returns true if the form has a default value for the given field'); $t->is($f->hasDefault('name'), false, 'hasDefault() returns false if the form does not have a default value for the given field'); $t->is($f->getDefault('first_name'), 'Fabien', 'getDefault() returns a default value for a given field'); $t->is($f->getDefault('name'), null, 'getDefault() returns null if the form does not have a default value for a given field'); sfForm::enableCSRFProtection('*mygreatsecret*'); $f = new FormTest(); $f->setDefaults(array('first_name' => 'Fabien'));
{ $t->pass('->redirect() throw an InvalidArgumentException when the url argument is null'); } catch(Exception $e) { $t->fail('->redirect() throw an InvalidArgumentException when the url argument is null. '.get_class($e).' was received'); } // Test empty string url argument for ->redirect() try { $controller->redirect(''); $t->fail('->redirect() throw an InvalidArgumentException when the url argument is an empty string'); } catch (InvalidArgumentException $iae) { $t->pass('->redirect() throw an InvalidArgumentException when the url argument is an empty string'); } catch(Exception $e) { $t->fail('->redirect() throw an InvalidArgumentException when the url argument is an empty string. '.get_class($e).' was received'); } // ->genUrl() $t->diag('->genUrl()'); $t->is($controller->genUrl('module/action?id=4'), $controller->genUrl(array('action' => 'action', 'module' => 'module', 'id' => 4)), '->genUrl() accepts a string or an array as its first argument'); $lastError = error_get_last(); $controller->genUrl(''); $t->is_deeply(error_get_last(), $lastError, '->genUrl() accepts an empty string');
$t = new lime_test(19); $browser = $helper->get('browser'); $namorokaUbuntu = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2pre) Gecko/20100116 Ubuntu/9.10 (karmic) Namoroka/3.6pre'; $namorokaMac = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100105 Firefox/3.6'; $chromeMac = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.49 Safari/532.5'; $safariMac = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; fr-fr) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10'; $opera9Windows = 'Opera/9.61 (Windows NT 6.0; U; en) Presto/2.1.1'; $opera10Windows = 'Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.10'; $googleBot = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'; $msnBot = 'msnbot/2.0b (+http://search.msn.com/msnbot.htm)'; $firefoxLinux = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.17) Gecko/2010010604 Linux Mint/7 (Gloria) Firefox/3.0.17'; $firefoxWindows = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6 (.NET CLR 3.5.30729)'; $firefoxOsx = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8'; //$firefoxWindowsSp2 = 'Gecko 2009122116Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.0.17) Gecko/2009122116 Firefox[xSP_2:077784879bbf239604c69a247f6786a0_220] 967907703 (.NET CLR 3.5.30729)'; $chromeLinux = 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.43 Safari/532.5'; $speedySpider = 'Speedy Spider (http://www.entireweb.com/about/search_tech/speedy_spider/)'; $minefieldMac = 'Gecko 20100113Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.3a1pre) Gecko/20100113 Minefield/3.7a1pre'; $ie7Windows = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; GTB6; SLCC1; .NET CLR 2.0.50727; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.5.30729; InfoPath.2; .NET CLR 3.0.30729; MSOffice 12)'; $ie6Windows = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; DigExt)'; $feedFetcherGoogle = 'Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; 2 subscribers; feed-id=6924676383167400434)'; $iphone = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; de-de) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7D11'; $yahooBot = 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'; $tests = array($namorokaUbuntu => array('browser_name' => 'firefox', 'browser_version' => '3.6', 'is_unknown' => false), $namorokaMac => array('browser_name' => 'firefox', 'browser_version' => '3.6', 'is_unknown' => false), $chromeMac => array('browser_name' => 'chrome', 'browser_version' => '4.0', 'is_unknown' => false), $safariMac => array('browser_name' => 'safari', 'browser_version' => '4.0', 'is_unknown' => false), $googleBot => array('browser_name' => 'googlebot', 'browser_version' => '2.1', 'is_unknown' => false), $msnBot => array('browser_name' => 'msnbot', 'browser_version' => '2.0', 'is_unknown' => false), $yahooBot => array('browser_name' => 'yahoobot', 'browser_version' => null, 'is_unknown' => false), $opera9Windows => array('browser_name' => 'opera', 'browser_version' => '9.61', 'is_unknown' => false), $opera10Windows => array('browser_name' => 'opera', 'browser_version' => '10.10', 'is_unknown' => false), $firefoxLinux => array('browser_name' => 'firefox', 'browser_version' => '3.0', 'is_unknown' => false), $firefoxWindows => array('browser_name' => 'firefox', 'browser_version' => '3.5', 'is_unknown' => false), $firefoxOsx => array('browser_name' => 'firefox', 'browser_version' => '3.5', 'is_unknown' => false), $chromeLinux => array('browser_name' => 'chrome', 'browser_version' => '4.0', 'is_unknown' => false), $speedySpider => array('browser_name' => null, 'browser_version' => null, 'is_unknown' => true), $minefieldMac => array('browser_name' => 'firefox', 'browser_version' => '3.7', 'is_unknown' => false), $ie7Windows => array('browser_name' => 'msie', 'browser_version' => '7.0', 'is_unknown' => false), $ie6Windows => array('browser_name' => 'msie', 'browser_version' => '6.0', 'is_unknown' => false), $feedFetcherGoogle => array('browser_name' => null, 'browser_version' => null, 'is_unknown' => true), $iphone => array('browser_name' => 'applewebkit', 'browser_version' => '528.18', 'is_unknown' => false)); $parser = $helper->get('user_agent_parser'); foreach ($tests as $userAgent => $description) { $browser->configureFromUserAgentString($userAgent, $parser); $result = $browser->toArray(); $result['is_unknown'] = $browser->isUnknown(); unset($result['operating_system']); $t->is_deeply($result, $description, $userAgent . ' -> ' . implode(', ', $description)); }
$menu->addChild('Home', '@homepage')->end()->addChild('Sites')->ulClass('my_ul_class')->addChild('Diem', 'http://diem-project.org')->showId(true)->end()->addChild('Symfony', 'http://symfony-project.org')->end(); $html = _tag('ul', _tag('li.first', _link('@homepage')->text($helper->get('i18n')->__('Home'))) . _tag('li.last', 'Sites' . _tag('ul.my_ul_class', _tag('li#my-menu-diem.first', _link('http://diem-project.org')->text('Diem')) . _tag('li.last', _link('http://symfony-project.org')->text('Symfony'))))); $t->is($menu->render(), $html, $html); $t->comment('Test getRoot'); $t->is($menu['Home']->getRoot(), $menu, 'Home root is $menu'); $t->is($menu['Sites']['Diem']->getRoot(), $menu, 'Diem root is menu'); $sitemap = $helper->get('sitemap_menu')->build(); $t->isa_ok($sitemap, 'dmSitemapMenu', 'Got a dmSitemapMenu'); $t->is($sitemap->getFirstChild()->renderLink(), (string) _link(), 'Sitemap first child is Home'); $t->like((string) $sitemap, '|^' . preg_quote('<ul><li class="first last"><a class="link" href="', '|') . '.*|', 'Sitemap html is valid'); $t->comment('Test current page'); $homePage = dmDb::table('DmPage')->getTree()->fetchRoot(); $helper->getContext()->setPage($homePage); $menu = $helper->get('menu')->addChild('Home', '@homepage')->end(); $html = _tag('ul', _tag('li.first.last.dm_current', _link()->text($helper->get('i18n')->__('Home')))); $t->is($menu->render(), $html, 'Current li has the dm_current class'); $helper->getContext()->setPage(dmDb::table('DmPage')->findOneByModuleAndAction('main', 'signin')); $menu = $helper->get('menu')->addChild('Home', '@homepage')->end(); $html = _tag('ul', _tag('li.first.last.dm_parent', _link()->text($helper->get('i18n')->__('Home')))); $t->is($menu->render(), $html, 'Parent li has the dm_parent class'); $menu = $helper->get('menu')->addChild('Home')->end()->addChild('Sites')->addChild('Diem')->end()->addChild('Symfony')->end()->end(); $html = _tag('ul', _tag('li.first', 'Home') . _tag('li.last', 'Sites' . _tag('ul', _tag('li.first', 'Diem') . _tag('li.last', 'Symfony')))); $t->is($menu->render(), $html, $html); $t->comment('->getSiblings()'); $t->is_deeply($menu['Home']->getSiblings(), array('Sites' => $menu['Sites']), '->getSiblings() works'); $t->is_deeply($menu['Home']->getSiblings(true), array('Home' => $menu['Home'], 'Sites' => $menu['Sites']), '->getSiblings(true) works'); $t->comment('Move menus'); $menu['Home']->moveToLast(); $menu['Sites']['Symfony']->moveToFirst(); $html = _tag('ul', _tag('li.first', 'Sites' . _tag('ul', _tag('li.first', 'Symfony') . _tag('li.last', 'Diem'))) . _tag('li.last', 'Home')); $t->is($menu->render(), $html, $html);
$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'; $size = 10; $shortTypeSize = "{$type}({$size})"; $column = new sfDoctrineColumnSchema($colName, array('type' => $shortTypeSize)); $t->is($column->getProperty('size'), $size, 'short array syntax for size'); $t->is($column->getProperty('type'), $type, 'short array syntax for type'); $column = new sfDoctrineColumnSchema($colName, $shortTypeSize); $t->is($column->getProperty('size'), $size, 'short string syntax for size'); $t->is($column->getProperty('type'), $type, 'short string syntax for type'); $column = new sfDoctrineColumnSchema($column, 'boolean'); $t->is($column->getProperty('type'), 'boolean', 'short string syntax without size'); $t->diag('PHP output'); $type = 'integer'; $size = 456; $constraint = 'primary'; $colSetup = array('type' => $type, 'size' => $size, 'columnName' => 'test_column', $constraint => true); $column = new sfDoctrineColumnSchema($colName, $colSetup); $t->is($column->asPhp(), "\$this->hasColumn('test_column as {$colName}', '{$type}', {$size}, array ( '{$constraint}' => true,));", 'php output'); $t->diag('Doctrine YML output'); $t->is_deeply($column->asDoctrineYml(), $colSetup, 'Doctrine array output'); $colEnum = new sfDoctrineColumnSchema($colName, array('type' => array('a a', 'b'))); #$t->like($colEnum->asPhp(), "|this->setEnumValues\('TestColumn', .*0=>'a',.*1=>'b'.*\);|", 'enum types are declared');
<?php $app = 'frontend'; $fixtures = 'fixtures/fixtures.yml'; include dirname(__FILE__) . '/../../bootstrap/functional.php'; $t = new lime_test(2); // ->getChoices() $t->diag('->getChoices()'); $validator = new sfWidgetFormDoctrineArrayChoice(array('model' => 'Author', 'table_method' => 'getChoices')); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage', 2 => 'Fabien POTENCIER'), '->getChoices() returns choices'); $validator->setOption('table_method_params', array(1)); $t->is_deeply($validator->getChoices(), array(1 => 'Jonathan H. Wage'), '->getChoices() returns limited choices');