/**
  * Test launcher
  *
  * @param string $schema Path to schema file
  */
 function launchTests($schema)
 {
     $this->t->diag('->load()');
     $this->load($schema);
     $this->t->diag('->getTables()');
     $tables = $this->tables;
     $this->t->is(count($tables), 2, "->getTables() should return 2 table from fixture.");
     $this->t->ok(in_array('testTable', array_keys($tables)), "->getTables() should return 'testTable' from fixture.");
     $this->t->diag('->classes');
     $this->t->is(count($this->classes), 2, "->classes should have 2 class from fixture");
     $this->t->ok($this->getClass('TestTable'), "->classes should have 'TestTable' from fixture.");
     $this->t->ok($this->getClass('TestTable')->getColumn('dummy_id')->hasRelation(), 'foreign relation is properly imported');
     #$this->t->diag('->asDoctrineYml()');
     #$yml = $this->asDoctrineYml();
     #$this->t->cmp_ok(strlen($yml['source']), '>', 0, "->asDoctrineYml() doctrine YAML shoudl not be empty.");
     $this->t->diag('->findClassByTableName()');
     $this->t->is($this->findClassByTableName('testTable')->getPhpName(), 'TestTable', "->findClassByTableName() returns 'TestTable' class for 'testTable' table.");
     $yml = $this->asDoctrineYml();
     $yml = $yml['source'];
     $this->t->like($yml, '@cascadeDelete: 1@', 'onDelete is generated');
 }
 /**
  * Test launcher
  *
  * @param string $schema Path to schema file
  */
 function launchTests($schema)
 {
     $this->t->diag('->load()');
     $this->load($schema);
     $this->process();
     $yml = $this->asDoctrineYml();
     $this->t->diag('->getClasses()');
     $classes = $this->getClasses();
     $nbClasses = 12;
     $this->t->is(count($classes), $nbClasses, "->getClasses() should return {$nbClasses} classes from fixture.");
     $this->t->diag('->getClass()');
     $class = $this->getClass('TestClass');
     #$this->t->ok($class->isTable(),"->getClass() should return return class instance.");
     $this->t->diag('->parentTable()');
     $table = $this->parentTable($class);
     $this->t->is(get_class($table), 'sfDoctrineTableSchema', "->parentTable() should return table instance.");
     $this->t->is($this->getClass('ColAggregation')->getTableName(), 'parent_table', 'inheritance gets the right parent table');
     #$this->t->ok($this->getClass('SeparateTable')->isTable(), '"SeparateTable" is a table-class');
     $this->t->is($this->getClass('BookI18n')->getColumn('culture')->getProperty('type'), 'string', 'culture field is defined (as a string)');
     $rel = $this->getClass('BookI18n')->getRelation('id');
     $this->t->is($rel->get('localName'), 'BookI18n', 'i18n relation name is not a plural');
     $this->t->is($this->getClass('ColAggregation')->getTable()->getColumn('class_key')->getProperty('type'), 'integer', 'inheritance field is defined (as an integer)');
     $c = $this->getClass('SeparateTable');
     $SeparateTablePhp = $c->asPhp();
     $SeparateTableSource = $SeparateTablePhp[0]['source'];
     $this->t->like($SeparateTableSource, '/extends Parent/', 'The class "SeparateTable" extends Parent without having any class key field');
     $this->t->like($SeparateTableSource, '@setTableName\\(\'separate_table\'\\)@', 'class "SeparateTable" has both a table and inheritance');
     $this->t->like($SeparateTableSource, '@parent::setTableDefinition\\(\\);@', 'class "SeparateTable" calls parent::setTableDefinition');
     $colAggregationPhp = $this->getClass('ColAggregation')->asPhp();
     $this->t->like($colAggregationPhp[0]['source'], "@setInheritanceMap\\(array\\('class_key'=>1\\)\\)@", 'setInheritanceMap is properly set');
     $this->t->diag('relationships');
     $yangPhp = $this->getClass('Yin')->asPhp();
     $this->t->like($yangPhp[0]['source'], "#hasOne\\('Yang as Yang', 'Yin.yang_id', 'id'\\)#", 'one to one relationships is properly declared');
     $userPhp = $this->getClass('User')->asPhp();
     $this->t->like($userPhp[0]['source'], "#hasMany\\('Book as Books', 'Book.author_id'\\)#", 'hasMany is properly declared');
     $this->t->like($userPhp[0]['source'], "#hasMany\\('Group as Groups', 'User2Group.group_id'\\)#", 'has many to many properly declared');
     $userGroupPhp = $this->getClass('User2Group')->asPhp();
     $this->t->like($userGroupPhp[0]['source'], "#ownsOne\\('User as User', 'User2Group.group_id', 'id'\\)#", 'has many to many with cascade properly defined');
 }
Ejemplo n.º 3
0
        return array('/path/to/a/file.js');
    }
    public function getStylesheets()
    {
        return array('/path/to/a/file.css' => 'all');
    }
}
$w->setOption('renderer_class', 'MyWidget');
$t->is(get_class($w->getRenderer()), 'MyWidget', '->getRenderer() uses the renderer_class as the widget class if provided');
$w->setOption('renderer_class', null);
$w->setOption('renderer', new MyWidget(array('choices' => array())));
$t->is(get_class($w->getRenderer()), 'MyWidget', '->getRenderer() uses the renderer as the widget if provided');
// ->render()
$t->diag('->render()');
$w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar')));
$t->like($w->render('foo'), '/<select name="foo" id="foo">/', '->render() renders a select tag by default');
$w->setIdFormat('barID_%s');
$t->like($w->render('foo'), '/<select name="foo" id="barID_foo">/', '->render() uses the id format specified');
$w->setIdFormat('%s');
$w->setOption('multiple', true);
$t->like($w->render('foo'), '/<select name="foo\\[\\]" multiple="multiple" id="foo">/', '->render() adds a multiple attribute for multiple selects');
$w->setOption('expanded', true);
$t->like($w->render('foo'), '/<ul class="checkbox_list">/', '->render() uses a checkbox list when expanded and multiple are true');
$w->setOption('multiple', false);
$t->like($w->render('foo'), '/<ul class="radio_list">/', '->render() uses a checkbox list when expanded is true and multiple is false');
// choices are translated
$t->diag('choices are translated');
$ws = new sfWidgetFormSchema();
$ws->addFormFormatter('stub', new FormFormatterStub());
$ws->setFormFormatterName('stub');
$w = new sfWidgetFormChoice(array('choices' => array('foo' => 'bar', 'foobar' => 'foo')));
    }
}
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&lt;1/', '->getPanelContent() returns escaped queries');
$t->like($content, '/aText like &#039; | foo&#039;/', '->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');
Ejemplo n.º 5
0
EOF;
$t->is($child['name']->renderError(), fix_linebreaks($output), '->renderRow() renders errors as HTML when the widget has a parent');
try {
    $parent->renderError();
    $t->fail('->renderError() throws an LogicException if the form field has no parent');
} catch (LogicException $e) {
    $t->pass('->renderError() throws an LogicException if the form field has no parent');
}
// global errors
$authorErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$authorErrorSchema->addError(new sfValidatorError(new sfValidatorString(), 'name error'), 'name');
$authorErrorSchema->addError(new sfValidatorError(new sfValidatorString(), 'non existent field error'), 'non_existent_field');
$authorErrorSchema->addError(new sfValidatorError(new sfValidatorString(), 'hidden field error'), 'id');
$articleErrorSchema = new sfValidatorErrorSchema(new sfValidatorString());
$articleErrorSchema->addError($titleError = new sfValidatorError(new sfValidatorString(), 'title error'), 'title');
$articleErrorSchema->addError($authorErrorSchema, 'author');
$parent = new sfFormFieldSchema($schema, null, 'article', array('title' => 'symfony', 'author' => array('name' => 'Fabien')), $articleErrorSchema);
$child = $parent['author'];
$output = <<<EOF
  <ul class="error_list">
    <li>non existent field error</li>
    <li>Id: hidden field error</li>
  </ul>

EOF;
$t->is($child->renderError(), fix_linebreaks($output), '->renderError() renders global errors as expected (global errors, hidden field errors, non existent field errors)');
// id format
$schema->setIdFormat('%s_id_format_test');
$parent = new sfFormFieldSchema($schema, null, 'article', array('title' => 'symfony', 'author' => array('name' => 'Fabien')), $articleErrorSchema);
$t->like($parent['author']->render(), '/_id_format_test/', '->render() uses the parent id format');
Ejemplo n.º 6
0
$t->is($last->getNum(), 3, 'Test getNum()');
class dmMyMenu extends dmMenu
{
}
$menu = $helper->get('menu', 'dmMyMenu')->name('My menu');
$t->isa_ok($menu, 'dmMyMenu', 'Got a dmMyMenu instance');
$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');
Ejemplo n.º 7
0
try
{
  $controller->convertUrlStringToParameters('@test?foobar');
  $t->fail('->convertUrlStringToParameters() throw a sfParseException if it cannot parse the query string');
}
catch (sfParseException $e)
{
  $t->pass('->convertUrlStringToParameters() throw a sfParseException if it cannot parse the query string');
}

// ->redirect()
$t->diag('->redirect()');
$controller->redirect('module/action?id=1#photos');
$response = $context->getResponse();
$t->like($response->getContent(), '~http\://localhost/index.php/\?module=module&amp;action=action&amp;id=1#photos~', '->redirect() adds a refresh meta in the content');
$t->like($response->getHttpHeader('Location'), '~http\://localhost/index.php/\?module=module&action=action&id=1#photos~', '->redirect() adds a Location HTTP header');

// Test null url argument for ->redirect()
try
{
  $controller->redirect(null);
  $t->fail('->redirect() throw an InvalidArgumentException when the url argument is null');
}
catch (InvalidArgumentException $iae)
{
  $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');
// ->initialize()
$t->diag('->initialize()');
$logger = new sfAggregateLogger($dispatcher, array('loggers' => $fileLogger));
$t->is($logger->getLoggers(), array($fileLogger), '->initialize() can take a "loggers" parameter');

$logger = new sfAggregateLogger($dispatcher, array('loggers' => array($fileLogger, $streamLogger)));
$t->is($logger->getLoggers(), array($fileLogger, $streamLogger), '->initialize() can take a "loggers" parameter');

// ->log()
$t->diag('->log()');
$logger->log('foo');
rewind($buffer);
$content = stream_get_contents($buffer);
$lines = explode("\n", file_get_contents($file));
$t->like($lines[0], '/foo/', '->log() logs a message to all loggers');
$t->is($content, 'foo'.PHP_EOL, '->log() logs a message to all loggers');

// ->getLoggers() ->addLoggers() ->addLogger()
$logger = new sfAggregateLogger($dispatcher);
$logger->addLogger($fileLogger);
$t->is($logger->getLoggers(), array($fileLogger), '->addLogger() adds a new sfLogger instance');

$logger = new sfAggregateLogger($dispatcher);
$logger->addLoggers(array($fileLogger, $streamLogger));
$t->is($logger->getLoggers(), array($fileLogger, $streamLogger), '->addLoggers() adds an array of sfLogger instances');

// ->shutdown()
$t->diag('->shutdown()');
$logger->shutdown();
function check_attribute(lime_test $t, $result, $attribute, $value)
{
    $str = sprintf('%s="%s"', $attribute, $value);
    $t->like($result, '/' . preg_quote($str) . '/', sprintf('->result contains attribute %s="%s"', $attribute, $value));
}
Ejemplo n.º 10
0
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(null);
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');
Ejemplo n.º 11
0
        return sprintf('translation[%s]', $subject);
    }
}
$t = new lime_test(22);
$dom = new DomDocument('1.0', 'utf-8');
$dom->validateOnParse = true;
// ->render()
$t->diag('->render()');
$w = new sfWidgetFormSelect(array('choices' => array('foo' => 'bar', 'foobar' => 'foo')));
$dom->loadHTML($w->render('foo', 'foobar'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#foo option[value="foobar"][selected="selected"]')->getValue(), 'foo', '->render() renders a select tag with the value selected');
$t->is(count($css->matchAll('#foo option')->getNodes()), 2, '->render() renders all choices as option tags');
// value attribute is always mandatory
$w = new sfWidgetFormSelect(array('choices' => array('' => 'bar')));
$t->like($w->render('foo', 'foobar'), '/<option value="">/', '->render() always generate a value attribute, even for empty keys');
// other attributes are removed is empty
$w = new sfWidgetFormSelect(array('choices' => array('' => 'bar')));
$t->like($w->render('foo', 'foobar', array('class' => '', 'style' => null)), '/<option value="">/', '->render() always generate a value attribute, even for empty keys');
// multiple select
$t->diag('multiple select');
$w = new sfWidgetFormSelect(array('multiple' => true, 'choices' => array('foo' => 'bar', 'foobar' => 'foo')));
$dom->loadHTML($w->render('foo', array('foo', 'foobar')));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('select[multiple="multiple"]')->getNodes()), 1, '->render() automatically adds a multiple HTML attributes if multiple is true');
$t->is(count($css->matchAll('select[name="foo[]"]')->getNodes()), 1, '->render() automatically adds a [] at the end of the name if multiple is true');
$t->is($css->matchSingle('#foo option[value="foobar"][selected="selected"]')->getValue(), 'foo', '->render() renders a select tag with the value selected');
$t->is($css->matchSingle('#foo option[value="foo"][selected="selected"]')->getValue(), 'bar', '->render() renders a select tag with the value selected');
$dom->loadHTML($w->render('foo[]', array('foo', 'foobar')));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('select[name="foo[]"]')->getNodes()), 1, '->render() automatically does not add a [] at the end of the name if multiple is true and the name already has one');
Ejemplo n.º 12
0
 * 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(8);
$handler = new sfFilterConfigHandler();
$handler->initialize();
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'sfFilterConfigHandler' . DIRECTORY_SEPARATOR;
// parse errors
$t->diag('parse errors');
$files = array($dir . 'no_class.yml');
try {
    $data = $handler->execute($files);
    $t->fail('filters.yml must have a "class" section for each filter entry');
} catch (sfParseException $e) {
    $t->like($e->getMessage(), '/with missing class key/', 'filters.yml must have a "class" section for each filter entry');
}
// no execution/rendering filter
foreach (array('execution', 'rendering') as $key) {
    $files = array($dir . sprintf('no_%s.yml', $key));
    try {
        $data = $handler->execute($files);
        $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 {
Ejemplo n.º 13
0
<?php

include dirname(__FILE__) . '/../bootstrap/doctrine.php';
// Initialize the test object
$t = new lime_test(24, new lime_output_color());
$valid_test_song = array('artist_name' => 'Gorillaz', 'album_name' => 'Gorillaz Compilation', 'genre_name' => 'Electronic', 'song_name' => 'Clint Eastwood', 'song_length' => '2:05', 'accurate_length' => '125000', 'filesize' => 3000024, 'bitrate' => 128, 'yearpublished' => 2010, 'tracknumber' => 7, 'label' => 'EMI', 'mtime' => 1293300000, 'atime' => 1293300011, 'filename' => 'file://localhost/home/notroot/music/test.mp3');
$utf8_test_song = array('artist_name' => 'Sigur Rós', 'album_name' => 'með suð í eyrum við spilum endalaust', 'genre_name' => 'Русский', 'song_name' => 'dót widget', 'song_length' => '3:05', 'accurate_length' => 185000, 'filesize' => 3002332, 'bitrate' => 128, 'yearpublished' => 2005, 'tracknumber' => 1, 'label' => 'ンスの映像を世界に先がけて', 'mtime' => 1293300023, 'atime' => 1293300011, 'filename' => 'file://localhost/home/notroot/music/Fließgewässer.mp3');
$media_scan = new MediaScan();
$t->comment('->construct()');
$t->like($media_scan->get_last_scan_id(), '/\\d+/', 'Entered a new scan id successfully.');
$t->comment('->is_scanned()');
$t->is($media_scan->is_scanned('file://localhost/home/notroot/music/test.mp3', '1293300000'), false, 'Song should not exist yet');
$first_insert_id = $media_scan->add_song($valid_test_song);
$t->like($first_insert_id, '/\\d+/', 'Successfully added a song to the database');
$t->comment('->add_song()');
$media_scan = new MediaScan();
$second_insert_id = $media_scan->add_song($utf8_test_song);
$t->like($second_insert_id, '/\\d+/', 'Successfully added a UTF-8 Song entry.');
$t->is($media_scan->is_scanned('file://localhost/home/notroot/music/test.mp3', '1293300000'), true, 'Updated old record to new scan id number');
$media_scan = new MediaScan();
$second_insert_id = $media_scan->add_song($utf8_test_song);
//Test Data Integrity after add
$song_integrity_test = Doctrine_Core::getTable('Song')->find(2);
$artist_integrity_test = Doctrine_Core::getTable('Artist')->find(2);
$album_integrity_test = Doctrine_Core::getTable('Album')->find(2);
$genre_integrity_test = Doctrine_Core::getTable('Genre')->find(127);
$t->is($song_integrity_test->id, 2, 'integrity: primary id');
$t->is($song_integrity_test->scan_id, 2, 'integrity: last_scan_id id');
$t->is($song_integrity_test->artist_id, 2, 'integrity: artist_id');
$t->is($artist_integrity_test->name, 'Sigur Rós', 'integrity: artist_name');
$t->is($song_integrity_test->album_id, 2, 'integrity: album_id');
Ejemplo n.º 14
0
}
$dispatcher = new sfEventDispatcher();
// ->initialize()
$t->diag('->initialize()');
try {
    $logger = new sfFileLogger($dispatcher);
    $t->fail('->initialize() parameters must contains a "file" parameter');
} catch (sfConfigurationException $e) {
    $t->pass('->initialize() parameters must contains a "file" parameter');
}
// ->log()
$t->diag('->log()');
$logger = new sfFileLogger($dispatcher, array('file' => $file));
$logger->log('foo');
$lines = explode("\n", file_get_contents($file));
$t->like($lines[0], '/foo/', '->log() logs a message to the file');
$logger->log('bar');
$lines = explode("\n", file_get_contents($file));
$t->like($lines[1], '/bar/', '->log() logs a message to the file');
class TestLogger extends sfFileLogger
{
    public function getTimeFormat()
    {
        return $this->timeFormat;
    }
    protected function getPriority($priority)
    {
        return '*' . $priority . '*';
    }
}
// option: format
Ejemplo n.º 15
0
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws a sfValidatorError if the date is not valid');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
// validate regex
$t->diag('validate regex');
$v->setOption('date_format', '~(?P<day>\\d{2})/(?P<month>\\d{2})/(?P<year>\\d{4})~');
$t->is($v->clean('18/10/2005'), '2005-10-18', '->clean() accepts a regular expression to match dates');
try {
    $v->clean('2005-10-18');
    $t->fail('->clean() throws a sfValidatorError if the date does not match the regex');
    $t->skip('', 2);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws a sfValidatorError if the date does not match the regex');
    $t->like($e->getMessage(), '/' . preg_quote(htmlspecialchars($v->getOption('date_format'), ENT_QUOTES, 'UTF-8'), '/') . '/', '->clean() returns the expected date format in the error message');
    $t->is($e->getCode(), 'bad_format', '->clean() throws a sfValidatorError');
}
$v->setOption('date_format_error', 'dd/mm/YYYY');
try {
    $v->clean('2005-10-18');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->like($e->getMessage(), '/' . preg_quote('dd/mm/YYYY', '/') . '/', '->clean() returns the expected date format error if provided');
}
$v->setOption('date_format', null);
// option with_time
$t->diag('option with_time');
$v->setOption('with_time', true);
$t->is($v->clean(array('year' => 2005, 'month' => 10, 'day' => 15, 'hour' => 12, 'minute' => 10, 'second' => 15)), '2005-10-15 12:10:15', '->clean() accepts an array as an input');
$t->is($v->clean(array('year' => '2005', 'month' => '10', 'day' => '15', 'hour' => '12', 'minute' => '10', 'second' => '15')), '2005-10-15 12:10:15', '->clean() accepts an array as an input');
Ejemplo n.º 16
0
// 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', '-');
$pattern = '<div class="pager"><ul class="clearfix"><li class="page current"><span class="link">1</span></li><li class="separator">-</li><li class="page">.+</li></ul></div>';
$t->like($navigation = $pager->renderNavigationTop(), '|^' . $pattern . '$|', 'navigation top: ' . $navigation);
Ejemplo n.º 17
0
require_once __DIR__ . '/../../../lib/helper/UrlHelper.php';
require_once __DIR__ . '/../../../lib/helper/TagHelper.php';
// url_for()
$t->diag('url_for()');
$t->is(url_for('@test'), 'module/action', 'url_for() converts an internal URI to a web URI');
$t->is(url_for('@test', true), '/module/action', 'url_for() can take an absolute boolean as its second argument');
$t->is(url_for('@test', false), 'module/action', 'url_for() can take an absolute boolean as its second argument');
// link_to()
$t->diag('link_to()');
$t->is(link_to('test', '@homepage'), '<a href="module/action">test</a>', 'link_to() returns an HTML "a" tag');
$t->is(link_to('test', '@homepage', array('absolute' => true)), '<a href="/module/action">test</a>', 'link_to() can take an "absolute" option');
$t->is(link_to('test', '@homepage', array('absolute' => false)), '<a href="module/action">test</a>', 'link_to() can take an "absolute" option');
$t->is(link_to('test', '@homepage', array('query_string' => 'foo=bar')), '<a href="module/action?foo=bar">test</a>', 'link_to() can take a "query_string" option');
$t->is(link_to('test', '@homepage', array('anchor' => 'bar')), '<a href="module/action#bar">test</a>', 'link_to() can take an "anchor" option');
$t->is(link_to('', '@homepage'), '<a href="module/action">module/action</a>', 'link_to() takes the url as the link name if the first argument is empty');
$t->like(link_to('test', '@homepage', array('method' => 'post')), '/==TOKEN==/', 'link_to() includes CSRF token from BaseForm');
// button_to()
$t->diag('button_to()');
$t->is(button_to('test', '@homepage'), '<input value="test" type="button" onclick="document.location.href=\'module/action\';" />', 'button_to() returns an HTML "input" tag');
$t->is(button_to('test', '@homepage', array('query_string' => 'foo=bar')), '<input value="test" type="button" onclick="document.location.href=\'module/action?foo=bar\';" />', 'button_to() returns an HTML "input" tag');
$t->is(button_to('test', '@homepage', array('anchor' => 'bar')), '<input value="test" type="button" onclick="document.location.href=\'module/action#bar\';" />', 'button_to() returns an HTML "input" tag');
$t->is(button_to('test', '@homepage', array('popup' => 'true', 'query_string' => 'foo=bar')), '<input value="test" type="button" onclick="var w=window.open(\'module/action?foo=bar\');w.focus();return false;" />', 'button_to() returns an HTML "input" tag');
$t->is(button_to('test', '@homepage', 'popup=true'), '<input value="test" type="button" onclick="var w=window.open(\'module/action\');w.focus();return false;" />', 'button_to() accepts options as string');
$t->is(button_to('test', '@homepage', 'confirm=really?'), '<input value="test" type="button" onclick="if (confirm(\'really?\')) { return document.location.href=\'module/action\';} else return false;" />', 'button_to() works with confirm option');
$t->is(button_to('test', '@homepage', 'popup=true confirm=really?'), '<input value="test" type="button" onclick="if (confirm(\'really?\')) { var w=window.open(\'module/action\');w.focus(); };return false;" />', 'button_to() works with confirm and popup option');
$t->like(button_to('test', '@homepage', array('method' => 'post')), '/==TOKEN==/', 'button_to() includes CSRF token from BaseForm');
class testObject
{
}
try {
    $o1 = new testObject();
Ejemplo n.º 18
0
    return $value;
}
// ->fillInXml()
$t->diag('->fillInXml()');
$f = new sfFillInForm();
$xml = <<<EOF
<html>
  <body>
    <form action="#" method="post" name="form">
      <input type="text" name="foo" />
    </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');
$xml = <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <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>
</html>
EOF;
Ejemplo n.º 19
0
<?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');
Ejemplo n.º 20
0
<?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(2, new lime_output_color());
$mail = new sfMail();
$mail->initialize();
$mail->setBody('foo');
$mail->prepare();
$t->like($mail->getRawHeader(), '/^X\\-Mailer\\: PHPMailer/m');
$t->like($mail->getRawBody(), '/^\\s*foo\\s*$/');
Ejemplo n.º 21
0
$t->is(count($css->matchAll('#foo_hour option')->getNodes()), 24, '->render() renders a select tag for the 24 hours around in a day');
$t->is(count($css->matchAll('#foo_minute option')->getNodes()), 60, '->render() renders a select tag for the 60 minutes in an hour');
$t->is(count($css->matchAll('#foo_second option')->getNodes()), 60, '->render() renders a select tag for the 60 seconds in a minute');
$w->setOption('can_be_empty', true);
// empty_values
$t->diag('empty_values option');
$w->setOption('empty_values', array('hour' => 'HOUR', 'minute' => 'MINUTE', 'second' => 'SECOND'));
$dom->loadHTML($w->render('foo', '2005-10-15'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#foo_hour option')->getNode()->nodeValue, 'HOUR', '->configure() can change the empty values');
$t->is($css->matchSingle('#foo_minute option')->getNode()->nodeValue, 'MINUTE', '->configure() can change the empty values');
$t->is($css->matchSingle('#foo_second option')->getNode()->nodeValue, 'SECOND', '->configure() can change the empty values');
$w->setOption('empty_values', array('hour' => '', 'minute' => '', 'second' => ''));
// format option
$t->diag('format option');
$t->like($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '/^:/', '->render() renders 3 selects with a default : as a separator');
$t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, ':', '->render() renders 3 selects with a default : as a separator');
$w->setOption('format', '%hour%#%minute%#%second%');
$dom->loadHTML($w->render('foo', '12:30:35'));
$css = new sfDomCssSelector($dom);
$t->like($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '/^#/', '__construct() can change the default format');
$t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, '#', '__construct() can change the default format');
$w->setOption('format', '%minute%#%hour%#%second%');
$dom->loadHTML($w->render('foo', '12:30:35'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('select')->getNode()->getAttribute('name'), 'foo[minute]', '__construct() can change the default time format');
// hours / minutes / seconds options
$t->diag('hours / minutes / seconds options');
$w->setOption('hours', array(1 => 1, 2 => 2, 3 => 3, 4 => 4));
$w->setOption('minutes', array(1 => 1, 2 => 2));
$w->setOption('seconds', array(15 => 15, 30 => 30, 45 => 45));
Ejemplo n.º 22
0
        $this->addRequiredOption('foo');
    }
}
// __construct()
$t->diag('__construct()');
$w = new MyWidget();
$t->is($w->getAttributes(), array(), '->__construct() can take no argument');
$w = new MyWidget(array(), array('class' => 'foo'));
$t->is($w->getAttributes(), array('class' => 'foo'), '->__construct() can take an array of default HTML attributes');
try {
    new MyWidget(array('nonexistant' => false));
    $t->fail('__construct() throws an InvalidArgumentException if you pass some non existant options');
    $t->skip();
} catch (InvalidArgumentException $e) {
    $t->pass('__construct() throws an InvalidArgumentException if you pass some non existant options');
    $t->like($e->getMessage(), '/ \'nonexistant\'/', 'The exception contains the non existant option names');
}
$t->diag('getRequiredOptions');
$w = new MyWidgetWithRequired(array('foo' => 'bar'));
$t->is($w->getRequiredOptions(), array('foo'), '->getRequiredOptions() returns an array of required option names');
try {
    new MyWidgetWithRequired();
    $t->fail('__construct() throws an RuntimeException if you don\'t pass a required option');
} catch (RuntimeException $e) {
    $t->pass('__construct() throws an RuntimeException if you don\'t pass a required option');
}
$w = new MyWidget();
// ->getOption() ->setOption() ->setOptions() ->getOptions() ->hasOption()
$t->diag('->getOption() ->setOption() ->setOptions() ->getOptions() ->hasOption()');
$w->setOption('foo', 'bar');
$t->is($w->getOption('foo'), 'bar', '->setOption() sets an option value');
$t->is(form_tag('', array('multipart' => true)), '<form method="post" enctype="multipart/form-data" action="module/action">', 'form_tag() takes a "multipart" boolean option');
// select_tag()
$t->diag('select_tag()');
$t->is(select_tag('name'), '<select name="name" id="name"></select>', 'select_tag() takes a name as its first argument');
$option_for_select = options_for_select(array('item1'));
$t->is(select_tag('name', $option_for_select), '<select name="name" id="name">' . $option_for_select . '</select>', 'select_tag() takes an HTML string of options as its second argument');
$t->is(select_tag('name', array('item1')), '<select name="name" id="name">' . $option_for_select . '</select>', 'select_tag() takes an array of options as its second argument');
// options
$t->is(select_tag('name', $option_for_select, array('class' => 'foo')), '<select name="name" id="name" class="foo">' . $option_for_select . '</select>', 'select_tag() takes an array of attribute options as its third argument');
$t->is(select_tag('name', $option_for_select, array('multiple' => true)), '<select name="name[]" id="name" multiple="multiple">' . $option_for_select . '</select>', 'select_tag() takes a "multiple" boolean option');
$t->is(select_tag('name[]', $option_for_select, array('multiple' => true)), '<select name="name[]" id="name" multiple="multiple">' . $option_for_select . '</select>', 'select_tag() takes a "multiple" boolean option');
$t->is(select_tag('name', $option_for_select, array('multiple' => false)), '<select name="name" id="name">' . $option_for_select . '</select>', 'select_tag() takes a "multiple" boolean option');
$t->is(select_tag('name', $option_for_select, array('id' => 'bar')), '<select name="name" id="bar">' . $option_for_select . '</select>', 'select_tag() can take a "id" option');
// select_country_tag()
$t->diag('select_country_tag()');
$t->like(select_country_tag('name'), '/' . preg_quote('<select name="name" id="name">') . '/', 'select_country_tag() takes a name as its first argument');
$t->cmp_ok(preg_match_all('/<option/', select_country_tag('name'), $matches), '>', 200, 'select_country_tag() takes a name as its first argument');
$t->like(select_country_tag('name', 'FR'), '/' . preg_quote('<option value="FR" selected="selected">') . '/', 'select_country_tag() takes an ISO code for the selected country as its second argument');
// options
$t->like(select_country_tag('name', null, array('class' => 'foo')), '/' . preg_quote('<select name="name" id="name" class="foo">') . '/', 'select_country_tag() takes an array of options as its third argument');
$t->is(preg_match_all('/<option/', select_country_tag('name', null, array('countries' => array('FR', 'GB'))), $matches), 2, 'select_country_tag() takes a "countries" option');
// select_language_tag()
$t->diag('select_language_tag()');
$t->like(select_language_tag('name'), '/' . preg_quote('<select name="name" id="name">') . '/', 'select_language_tag() takes a name as its first argument');
$t->cmp_ok(preg_match_all('/<option/', select_language_tag('name'), $matches), '>', 200, 'select_language_tag() takes a name as its first argument');
$t->like(select_language_tag('name', 'fr'), '/' . preg_quote('<option value="fr" selected="selected">') . '/', 'select_language_tag() takes an ISO code for the selected language as its second argument');
// option
$t->like(select_language_tag('name', null, array('class' => 'foo')), '/' . preg_quote('<select name="name" id="name" class="foo">') . '/', 'select_language_tag() takes an array of options as its third argument');
$t->is(preg_match_all('/<option/', select_language_tag('name', null, array('languages' => array('fr', 'en'))), $matches), 2, 'select_language_tag() takes a "languages" option');
// input_tag()
$t->diag('input_tag()');
Ejemplo n.º 24
0
$t->comment('Create a test page');
$testPage = dmDb::create('DmPage', array('module' => dmString::random(), 'action' => dmString::random(), 'name' => dmString::random(), 'slug' => dmString::random()));
$testPage->Node->insertAsFirstChildOf(dmDb::table('DmPage')->getTree()->fetchRoot());
$t->comment('Create a test widget');
$widget = dmDb::create('DmWidget', array('module' => $widgetType->getModule(), 'action' => $widgetType->getAction(), 'value' => '[]', 'dm_zone_id' => $testPage->PageView->Area->Zones[0]));
$t->comment('Create a ' . $formClass . ' instance');
dmDb::table('DmMediaFolder')->checkRoot();
$t->comment('Create a test image media');
$mediaFileName = 'test_' . 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');
$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($form->getStylesheets(), array(), 'This widget form requires no additional stylesheet');
$t->is($form->getJavascripts(), array(), 'This widget form requires no additional javascript');
$t->comment('Submit an empty form');
$form->bind(array(), array());
$t->is($form->isValid(), false, 'The form is not valid');
$t->comment('Use a bad href');
$form->bind(array('href' => 'bad href'), array());
$t->is($form->isValid(), false, 'The form is not valid');
$externalUrl = 'http://symfony-project.org';
$t->comment('Use a good href : ' . $externalUrl);
$form->bind(array('href' => $externalUrl), array());
$t->is($form->isValid(), true, 'The form is valid');
$internalUrl = 'media:' . dmDb::table('DmMedia')->findOne()->id;
$t->comment('Use a good href : ' . $internalUrl);
$form->bind(array('href' => $internalUrl), array());
$dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'sfGeneratorConfigHandler'.DIRECTORY_SEPARATOR;

$t->diag('parse errors');
$files = array(
  $dir.'empty.yml',
  $dir.'no_generator_class.yml',
);

try
{
  $data = $handler->execute($files);
  $t->fail('generator.yml must have a "class" section');
}
catch (sfParseException $e)
{
  $t->like($e->getMessage(), '/must specify a generator class section under the generator section/', 'generator.yml must have a "class" section');
}

$files = array(
  $dir.'empty.yml',
  $dir.'no_generator_section.yml',
);

try
{
  $data = $handler->execute($files);
  $t->fail('generator.yml must have a "generator" section');
}
catch (sfParseException $e)
{
  $t->like($e->getMessage(), '/must specify a generator section/', 'generator.yml must have a "generator" section');
Ejemplo n.º 26
0
/**************/
/* 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 */
/**********************/
$t->diag('Simple GET request');
$t->like($b->get($dump_headers_url)->getResponseText(), '/\\[REQUEST_METHOD\\] => GET/', 'get() performs a GET request');
$t->isa_ok($b, 'dmWebBrowser', 'get() make a web request and returns a browser object');
$t->is($b->getResponseCode(), 200, 'get() fills up the browser status code with the response');
$t->like($b->get($example_site_url)->getResponseHeader('Content-Type'), '/text\\/html/', 'get() populates the header array');
$t->like(strtolower($b->getResponseText()), '/<head>/', 'get() populates the HTML of the response');
/***********************/
/* Simple HEAD request */
/***********************/
$t->diag('Simple HEAD request');
//  $t->like($b->head($dump_headers_url)->getResponseHeader('Content-Type'), '/text\/html/', 'head() populates the header array');
//  $t->is($b->getResponseText(), '', 'HEAD requests do not return a response body');
/***********************/
/* Simple POST request */
/***********************/
$t->diag('Simple POST request');
$t->like($b->post($dump_headers_url)->getResponseText(), '/\\[REQUEST_METHOD\\] => POST/', 'post() performs a POST request');
$t->info('1 - Run some basic functions on the asset');
$t->is($asset->isImage(), false, '->isImage() returns false');
$t->is($asset->getType(), 'text', '->getType() returns "text"');
$t->is($asset->exists(), true, '->exists() returns true as the file does exist');
$t->is($asset->getTypeFromExtension(), 'text', '->getTypeFromExtension() returns text');
$t->is($asset->getIcon(), '/sfSympalAssetsPlugin/images/icons/txt.png', '->getIcon() returns the txt.png icon');
$t->is($asset->getExtension(), 'txt', '->getExtension() returns .txt');
$t->is($asset->getPath(), sfConfig::get('sf_upload_dir') . '/sympal info.txt', '->getPath() returns the correct path');
$t->is($asset->getRelativePath(), '/sympal info.txt', '->getRelativePath() returns the web url for the asset');
$t->is($asset->getRelativePathDirectory(), '', '->getRelativePathDirectory() returns a blank string');
$t->is($asset->getFilePath(), '/sympal info.txt', '->getFilePath() returns /sympal info.txt');
$t->is($asset2->getPath(), sfConfig::get('sf_upload_dir') . '/screens/sympalphp.png', '->getPath() returns the correct path');
$t->is($asset2->getRelativePath(), '/screens/sympalphp.png', '->getRelativePath() returns the web url for the asset');
$t->is($asset2->getRelativePathDirectory(), '/screens', '->getRelativePathDirectory() returns "/screens"');
$t->is($asset2->getFilePath(), '/screens/sympalphp.png', '->getFilePath() returns /sympal info.txt');
$t->like($asset2->getUrl(), '/uploads\\/screens\\/sympalphp\\.png/', '->getFilePath() contains /uploads/screens/sympalphp.png');
$t->like($asset2->getUrl(), '/http\\:\\/\\//', '->getFilePath() contains http://');
$t->is($asset->getName(), 'sympal info.txt', '->getName() return "sympal info.txt"');
$t->is($asset2->getSize(), '275', '->getSize() returns 275 for a 274.7kb file');
$original = $asset->getOriginal();
$t->is($asset->getOriginal()->getPath(), $asset->getPathDirectory() . '/.originals/' . $asset->getName(), 'An original copy of the file exists in the .originals directory');
$doctrineAsset = $asset->getDoctrineAsset();
$t->is($doctrineAsset->name, $asset->getName(), '->getDoctrineAsset() returns the correct asset');
$t->info('2 - Perform a move operation');
$oldPath = $asset2->getPath();
$newPath = sfConfig::get('sf_upload_dir') . '/moved/sympalphp.png';
$asset2->move($newPath);
$t->is($asset2->getPath(), $newPath, '->getPath() now returns the new path');
$t->is($asset2->exists(), true, '->exists returns true');
$t->is(file_exists($oldPath), false, 'The old file path does not exist');
$originalPath = dirname($newPath) . '/.originals/sympalphp.png';
Ejemplo n.º 28
0
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');
$t->is($form->getDefault('text'), array(), 'The form default link is correct');
Ejemplo n.º 29
0
$t = new lime_test(47);
dm::loadHelpers(array('Dm'));
sfConfig::set('sf_no_script_name', false);
dmDb::table('DmPage')->checkBasicPages();
$sc = $helper->get('service_container');
$sc->mergeParameter('link_tag_record.options', array('current_span' => false))->mergeParameter('link_tag_page.options', array('current_span' => false));
$t->diag('link current_span is false');
$home = dmDb::table('DmPage')->getTree()->fetchRoot();
$helper->get('context')->setPage($home);
$t->diag($home->name . ' is the current page');
$testPage = dmDb::create('DmPage', array('module' => 'main', 'action' => 'test' . dmString::random(12), 'name' => 'I am a root child', 'slug' => dmString::random()));
$testPage->Node->insertAsLastChildOf($home);
$scriptName = $helper->get('request')->getScriptName();
$t->diag('Current cli script name = ' . $scriptName);
$t->is((string) _link('http://c2.com/cgi/wiki?DontRepeatYourself')->text('DRY'), $expected = '<a class="link" href="http://c2.com/cgi/wiki?DontRepeatYourself">DRY</a>', $expected);
$t->like(£link()->render(), '|<a class="link dm_current|', '£link() has class dm_current');
$t->like(£link()->set('current_class', 'my_current')->render(), '|<a class="link my_current|', '£link() has class my_current');
$t->is((string) £link($home), (string) £link(), '£link($home) is £link()');
$t->is((string) £link('@homepage'), (string) £link($home), '£link("@homepage") is £link()');
$t->is((string) £link('main/root'), (string) £link($home), '£link("main/root") is £link()');
$t->is(£link()->getHref(), $scriptName, 'root href is ' . $scriptName);
$t->is(£link()->getText(), $home->name, 'root link text is ' . $home->name);
$expected = $helper->get('controller')->genUrl('dmAuth/signin');
$t->is(£link('+/dmAuth/signin')->getHref(), $expected, '+/dmAuth/signin href is ' . $expected);
$rootLink = sprintf('<a class="%s" href="%s">%s</a>', 'link dm_current', $scriptName, $home->name);
$t->is((string) £link(), $rootLink, 'root link is ' . $rootLink);
$rootLink = sprintf('<a class="%s" href="%s">%s</a>', 'link dm_current', $scriptName, $home->name);
$t->is((string) $helper->get('helper')->link(), $rootLink, 'use the helper service : root link is ' . $rootLink);
$hrefWithParam = $scriptName . '?var=val&other=value';
$t->is((string) £link()->param('var', 'val')->param('other', 'value')->getHref(), $hrefWithParam, $hrefWithParam);
$t->is((string) £link()->params(array('var' => 'val', 'other' => 'value'))->getHref(), $hrefWithParam, $hrefWithParam);
{
    public function configure()
    {
        $this->setWidget('body', new sfWidgetFormTextarea());
        $this->setValidator('body', new sfValidatorString(array('min_length' => 12)));
    }
}
$configuration = $configuration->getApplicationConfiguration('frontend', 'test', true, null, $configuration->getEventDispatcher());
sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir'));
$enhancer = new sfFormYamlEnhancerTest($configuration->getConfigCache());
// ->enhance()
$t->diag('->enhance()');
$form = new CommentForm();
$form->bind(array('body' => '+1'));
$enhancer->enhance($form);
$t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() enhances labels');
$t->like($form['body']->render(), '/class="comment"/', '->enhance() enhances widgets');
$t->like($form['body']->renderError(), '/You haven\'t written enough/', '->enhance() enhances error messages');
$form = new CommentForm();
$form->bind();
$enhancer->enhance($form);
$t->like($form['body']->renderError(), '/A base required message/', '->enhance() considers inheritance');
class SpecialCommentForm extends CommentForm
{
}
$form = new SpecialCommentForm();
$form->bind();
$enhancer->enhance($form);
$t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() applies parent config');
$form = new BaseForm();
$form->embedForm('comment', new CommentForm());