} class sfWebDebugPanelPropelTestDifferentGlue extends sfWebDebugPanelPropel { protected function getPropelConfiguration() { $config = new PropelConfiguration(array()); $config->setParameter('debugpdo.logging.outerglue', 'xx'); $config->setParameter('debugpdo.logging.innerglue', '/ '); $config->setParameter('debugpdo.logging.details.slow.enabled', true); $config->setParameter('debugpdo.logging.details.slow.threshold', 5); return $config; } } // ->getPanelContent() $t->diag('->getPanelContent()'); $dispatcher = new sfEventDispatcher(); $logger = new sfVarLogger($dispatcher); $logger->log('{sfPropelLogger} SELECT * FROM foo WHERE bar<1'); $logger->log('{sfPropelLogger} time: 3.42 sec | mem: 2.8 MB | SELECT * FROM foo WHERE aText like \' | foo\''); $panel = new sfWebDebugPanelPropelTest(new sfWebDebug($dispatcher, $logger)); $content = $panel->getPanelContent(); $t->like($content, '/bar<1/', '->getPanelContent() returns escaped queries'); $t->like($content, '/aText like ' | foo'/', '->getPanelContent() works with glue string in SQL'); $t->like($content, '/sfWebDebugWarning/', '->getPanelContent() contains a slow query warning'); $logger = new sfVarLogger($dispatcher); $logger->log('{sfPropelLogger} time/ 3.42 secxxmem/ 2.8 MBxxSELECT * FROM foo WHERE bar == 42'); $panel = new sfWebDebugPanelPropelTestDifferentGlue(new sfWebDebug($dispatcher, $logger)); $content = $panel->getPanelContent(); $t->like($content, '/time\\/ 3.42 sec, mem\\/ 2.8 MB/', '->getPanelContent() works with strange glue strings'); $t->unlike($content, '/sfWebDebugWarning/', '->getPanelContent() should not contain a slow warning');
/*************************/ $t->diag('Simple DELETE request'); $t->like($b->delete($dump_headers_url)->getResponseText(), '/\\[REQUEST_METHOD\\] => DELETE/', 'delete() performs a DELETE request'); /*********************/ /* Arbitrary request */ /*********************/ $t->diag('Arbitrary request'); $t->like($b->call($dump_headers_url, 'MICHEL')->getResponseText(), '/\\[REQUEST_METHOD\\] => MICHEL/', 'call() supports any HTTP methods'); /****************************/ /* Response formats methods */ /****************************/ $t->diag('Response formats methods'); $b = $sc->reload('web_browser'); $b->get($example_site_url); $t->like($b->getResponseText(), '/<body .*>/', 'getResponseText() returns the response text'); $t->unlike($b->getResponseBody(), '/<body>/', 'getResponseBody() returns the response body'); $t->isa_ok($b->getResponseDom(), 'DOMDocument', 'getResponseDom() returns the response Dom'); $t->isa_ok($b->getResponseDomCssSelector(), 'sfDomCssSelector', 'getResponseDomCssSelector() returns a CSS selector on the response Dom'); $b->get('http://rss.cnn.com/rss/cnn_topstories.rss'); $t->isa_ok($b->getResponseXml(), 'SimpleXMLElement', 'getResponseXml() returns the response as a SimpleXML Element'); $b->get('http://www.w3.org/StyleSheets/home.css'); try { $b->getResponseXml(); $t->fail('Incorrect XML throws an exception'); } catch (Exception $e) { $t->pass('Incorrect XML throws an exception'); } try { /******************************/ /* Absolute and relative URls */ /******************************/
$t->is(checkbox_tag('name', 'foo'), '<input type="checkbox" name="name" id="name" value="foo" />', 'checkbox_tag() takes a value as its second argument'); $t->is(checkbox_tag('name', null, true), '<input type="checkbox" name="name" id="name" value="" checked="checked" />', 'checkbox_tag() takes a boolean as its third argument'); // options $t->is(checkbox_tag('name', null, false, array('class' => 'foo')), '<input type="checkbox" name="name" id="name" value="" class="foo" />', 'checkbox_tag() takes an array of attribute options as its fourth argument'); $t->is(checkbox_tag('name', null, false, array('id' => 'foo')), '<input type="checkbox" name="name" id="foo" value="" />', 'checkbox_tag() can override the "id" attribute'); // radiobutton_tag() $t->diag('radiobutton_tag()'); $t->is(radiobutton_tag('name', 1), '<input type="radio" name="name" id="name_1" value="1" />', 'radiobutton_tag() takes a name as its first argument'); $t->is(radiobutton_tag('name', 2), '<input type="radio" name="name" id="name_2" value="2" />', 'radiobutton_tag() takes a value as its second argument'); $t->is(radiobutton_tag('name', null, true), '<input type="radio" name="name" id="name" value="" checked="checked" />', 'radiobutton_tag() takes a boolean as its third argument'); // options $t->is(radiobutton_tag('name', null, false, array('class' => 'foo')), '<input type="radio" name="name" id="name" value="" class="foo" />', 'radiobutton_tag() takes an array of attribute options as its fourth argument'); $t->is(radiobutton_tag('name', null, false, array('id' => 'foo')), '<input type="radio" name="name" id="foo" value="" />', 'radiobutton_tag() can override the "id" attribute'); // input_date_range_tag() $t->diag('input_date_range_tag()'); $t->unlike(input_date_range_tag('date', array('from' => time(), 'to' => time()), array('after' => 'foo')), '/after/', 'input_date_range_tag() output date fields for a date range'); // input_date_tag() $t->diag('input_date_tag()'); $t->todo('input_date_tag()'); // submit_tag() $t->diag('submit_tag()'); $t->is(submit_tag(), '<input type="submit" name="commit" value="Save changes" />', 'submit_tag() default value is "Save changes"'); $t->is(submit_tag("save"), '<input type="submit" name="commit" value="save" />', 'submit_tag() takes a value as its first argument'); // options $t->is(submit_tag('save', array('class' => 'foo')), '<input type="submit" name="commit" value="save" class="foo" />', 'submit_tag() takes an array of attribute options as its second argument'); $t->is(submit_tag('save', array('name' => 'foo')), '<input type="submit" name="foo" value="save" />', 'submit_tag() can override the "name" attribute'); // reset_tag() $t->diag('reset_tag()'); $t->is(reset_tag(), '<input type="reset" name="reset" value="Reset" />', 'reset_tag() default value is "Reset"'); $t->is(reset_tag("save"), '<input type="reset" name="reset" value="save" />', 'reset_tag() takes a value as its first argument'); // options
<option value="selected" selected="selected">selected</option> <option value="last">last</option> </select> </form> </body> </html> EOF; $xml = $f->fillInXml($xml, 'form', null, array('foo' => 'bar')); $t->like($xml, '#<input type="text" name="foo" value="bar"\\s*/>#', '->fillInXml() outputs valid XML'); $t->like($xml, '#<option value="selected" selected="selected">#', '->fillInXml() outputs valid XML'); $t->like($xml, '#<\\?xml version="1.0"\\?>#', '->fillInXml() outputs XML prolog'); // ->fillInXhtml() $xml = $f->fillInXhtml($xml, 'form', null, array('foo' => 'bar')); $t->like($xml, '#<input type="text" name="foo" value="bar"\\s*/>#', '->fillInXhml() outputs valid XML'); $t->like($xml, '#<option value="selected" selected="selected">#', '->fillInXhml() outputs valid XML'); $t->unlike($xml, '#<\\?xml version="1.0"\\?>#', '->fillInXhtml() does not output XML prolog'); // ->fillInHtml() $t->diag('->fillInHtml()'); $f = new sfFillInForm(); $xml = <<<EOF <html> <body> <form action="#" method="post" name="form"> <input type="text" name="foo"> <select name="select"> <option value="first">first</option> <option value="selected" selected="selected">selected</option> <option value="last">last</option> </select> </form> </body>
class sfWebDebugTest extends sfWebDebug { public function __construct() { $this->options['image_root_path'] = ''; $this->options['request_parameters'] = array(); } } $debug = new sfWebDebugTest(); // ->injectToolbar() $t->diag('->injectToolbar()'); $before = '<html><head></head><body></body></html>'; $after = $debug->injectToolbar($before); $t->like($after, '/<style type="text\\/css">/', '->injectToolbar() adds styles'); $t->like($after, '/<div id="sfWebDebug">/', '->injectToolbar() adds the toolbar'); $before = ''; $after = $debug->injectToolbar($before); $t->unlike($after, '/<style type="text\\/css">/', '->injectToolbar() does not add styles if there is no head'); $t->like($after, '/<div id="sfWebDebug">/', '->injectToolbar() adds the toolbar if there is no body'); $before = <<<HTML <html> <head></head> <body> <textarea><html><head></head><body></body></html></textarea> </body> </html> HTML; $after = $debug->injectToolbar($before); $t->is(substr_count($after, '<style type="text/css">'), 1, '->injectToolbar() adds styles once'); $t->is(substr_count($after, '<div id="sfWebDebug">'), 1, '->injectToolbar() adds styles once'); $t->isa_ok(strpos($after, '<textarea><html><head></head><body></body></html></textarea>'), 'integer', '->injectToolbar() leaves inner pages untouched');
$t->fail(sprintf('filters.yml must have a filter of type "%s"', $key)); } catch (sfParseException $e) { $t->like($e->getMessage(), sprintf('/must register a filter of type "%s"/', $key), sprintf('filters.yml must have a filter of type "%s"', $key)); } } // filter inheritance $t->diag('filter inheritance'); $files = array($dir . 'default_filters.yml', $dir . 'not_disabled.yml'); try { $data = $handler->execute($files); $t->fail('filters.yml must keep all filters when inheriting from a master filters configuration file'); } catch (sfConfigurationException $e) { $t->like($e->getMessage(), '/but not present/', 'filters.yml must keep all filters when inheriting from a master filters configuration file'); } // disabling a filter $t->diag('disabling a filter'); $files = array($dir . 'disable.yml'); $t->unlike($handler->execute($files), '/defaultFilterClass/', 'you can disable a filter by settings "enabled" to false'); // condition support $t->diag('condition support'); $files = array($dir . 'condition.yml'); sfConfig::set('default_test', true); $t->like($handler->execute($files), '/defaultFilterClass/', 'you can add a "condition" key to the filter parameters'); sfConfig::set('default_test', false); $t->unlike($handler->execute($files), '/defaultFilterClass/', 'you can add a "condition" key to the filter parameters'); // usual configuration $t->diag('usual configuration'); $files = array($dir . 'default_filters.yml', $dir . 'filters.yml'); $data = $handler->execute($files); $data = preg_replace('#date\\: \\d+/\\d+/\\d+ \\d+\\:\\d+\\:\\d+\\n#', '', $data); $t->is($data, str_replace("\r\n", "\n", file_get_contents($dir . 'result.php')), 'core filters.yml can be overriden');
{ $this->options['image_root_path'] = ''; $this->options['request_parameters'] = array(); } } $debug = new sfWebDebugTest(); // ->injectToolbar() $t->diag('->injectToolbar()'); $before = '<html><head></head><body></body></html>'; $after = $debug->injectToolbar($before); $t->like($after, '/<style type="text\\/css">/', '->injectToolbar() adds styles'); $t->like($after, '/<script type="text\\/javascript">/', '->injectToolbar() adds javascript'); $t->like($after, '/<div id="sfWebDebug">/', '->injectToolbar() adds the toolbar'); $before = ''; $after = $debug->injectToolbar($before); $t->unlike($after, '/<style type="text\\/css">/', '->injectToolbar() does not add styles if there is no head'); $t->unlike($after, '/<script type="text\\/javascript">/', '->injectToolbar() does not add javascripts if there is no body'); $t->like($after, '/<div id="sfWebDebug">/', '->injectToolbar() adds the toolbar if there is no body'); $before = <<<HTML <html> <head></head> <body> <textarea><html><head></head><body></body></html></textarea> </body> </html> HTML; $after = $debug->injectToolbar($before); $t->is(substr_count($after, '<style type="text/css">'), 1, '->injectToolbar() adds styles once'); $t->is(substr_count($after, '<script type="text/javascript">'), 1, '->injectToolbar() adds javascripts once'); $t->is(substr_count($after, '<div id="sfWebDebug">'), 1, '->injectToolbar() adds styles once'); $t->isa_ok(strpos($after, '<textarea><html><head></head><body></body></html></textarea>'), 'integer', '->injectToolbar() leaves inner pages untouched');
require_once dirname(__FILE__) . '/../bootstrap/task.php'; # load fixtures of this plugin $propelData->loadData(sfConfig::get('sf_plugins_dir') . '/sfNewsletterPlugin/data/fixtures'); $limeTest = new lime_test(6, new lime_output_color()); sfConfig::set('sf_newsletterplugin_from', ''); $task = new SendScheduledNewsletterTask($dispatcher, $formatter); try { $task->run(array(), array()); $limeTest->fail('InvalidArgumentException not thrown.'); } catch (InvalidArgumentException $e) { $limeTest->is($e->getMessage(), sfNewsletterPluginConfiguration::EXCEPTION_NO_SENDER, 'Caught correct Exception.'); } sfConfig::set('sf_newsletterplugin_from', 'invalid-email'); try { $task->run(array(), array()); $limeTest->fail('InvalidArgumentException not thrown.'); } catch (InvalidArgumentException $e) { $limeTest->like($e->getMessage(), '/' . sfNewsletterPluginConfiguration::EXCEPTION_INVALID_SENDER . '/', 'Caught correct Exception.'); } sfConfig::set('sf_newsletterplugin_from', '*****@*****.**'); $task->run(array(), array()); $logs = $logger->getLogEntries(); $limeTest->like($logs[2], '/There are no newsletters on schedule./', 'Task exits while no newsletter are given.'); $newsletter = NewsletterPeer::retrieveByName('first newsletter'); $limeTest->ok($newsletter->setScheduledAt(new DateTime('-7 hours'))->save(), 'Scheduled Newsletter.'); $limeTest->is(count(NewsletterPeer::retrieveScheduled(new DateTime('-6 hours'))), 1, 'Found scheduled Newsletter.'); $task->run(array(), array('schedule="-6 hours"')); $logs = $logger->getLogEntries(); $limeTest->unlike($logs[3], '/' . sfNewsletterPluginConfiguration::EXCEPTION_SWIFT_ERROR . '/', 'Email sent successfully.'); // @todo Add test checking POP3 to verify the email really got there!