Ejemplo n.º 1
0
$keys['find'] = myQuery::$lastQueryCacheHash;
Doctrine::getTable('AdminUser')->findAll();
$keys['find_all'] = myQuery::$lastQueryCacheHash;
Doctrine::getTable('AdminUser')->findById(1);
$keys['find_by_id'] = myQuery::$lastQueryCacheHash;
Doctrine::getTable('AdminUser')->findOneById(1);
$keys['find_one_by_id'] = myQuery::$lastQueryCacheHash;
Doctrine::getTable('AdminUser')->findByIdAndUsername(1, 'admin');
$keys['find_by_id_and_username'] = myQuery::$lastQueryCacheHash;
Doctrine::getTable('AdminUser')->findOneByIdAndUsername(1, 'admin');
$keys['find_one_by_id_and_username'] = myQuery::$lastQueryCacheHash;
Doctrine::getTable('AdminUser')->findByUsernameAndPassword('admin', 'password');
$keys['find_by_username_and_password'] = myQuery::$lastQueryCacheHash;
Doctrine::getTable('AdminUser')->findOneByUsernameAndPassword('admin', 'password');
$keys['find_one_by_username_and_password'] = myQuery::$lastQueryCacheHash;
$t->isnt($keys['find'], $keys['find_all'], '->find() and ->findAll() generates different query cache keys');
$t->isnt($keys['find'], $keys['find_by_id'], '->find() and ->findById() generates different query cache keys');
$t->is($keys['find'], $keys['find_one_by_id'], '->find() and ->findOneById() generates same query cache keys');
$t->isnt($keys['find'], $keys['find_by_id_and_username'], '->find() and ->findByIdAndUsername() generates different query cache keys');
$t->isnt($keys['find'], $keys['find_one_by_id_and_username'], '->find() and ->findOneByIdAndUsername() generates different query cache keys');
$t->isnt($keys['find'], $keys['find_by_username_and_password'], '->find() and ->findByUsernameAndPassword() generates different query cache keys');
$t->isnt($keys['find'], $keys['find_one_by_username_and_password'], '->find() and ->findOneByUsernameAndPassword() generates different query cache keys');
$t->isnt($keys['find_all'], $keys['find_by_id'], '->findAll() and ->findById() generates different query cache keys');
$t->isnt($keys['find_all'], $keys['find_one_by_id'], '->findAll() and ->findOneById() generates different query cache keys');
$t->isnt($keys['find_all'], $keys['find_by_id_and_username'], '->findAll() and ->findByIdAndUsername() generates different query cache keys');
$t->isnt($keys['find_all'], $keys['find_one_by_id_and_username'], '->findAll() and ->findOneByIdAndUsername() generates different query cache keys');
$t->isnt($keys['find_all'], $keys['find_by_username_and_password'], '->findAll() and ->findByUsernameAndPassword() generates different query cache keys');
$t->isnt($keys['find_all'], $keys['find_one_by_username_and_password'], '->findAll() and ->findOneByUsernameAndPassword() generates different query cache keys');
$t->isnt($keys['find_by_id'], $keys['find_one_by_id'], '->findById() and ->findOneById() generates different query cache keys');
$t->isnt($keys['find_by_id'], $keys['find_by_id_and_username'], '->findById() and ->findByIdAndUsername() generates different query cache keys');
$t->isnt($keys['find_by_id'], $keys['find_one_by_id_and_username'], '->findById() and ->findOneById() generates different query cache keys');
Beware that the tables for these models will be emptied by the tests, so use a test database connection.
*/

include dirname(__FILE__).'/../../bootstrap.php';

$t = new lime_test(34, new lime_output_color());

$t->diag('getUniqueIdentifier()');

$id1 = DbFinder::from('Article')->where('Title', 'foo')->getUniqueIdentifier();
$id2 = DbFinder::from('Article')->where('Title', 'foo')->getUniqueIdentifier();
$t->is($id1, $id2, 'Similar queries get the same unique identifier');

$id1 = DbFinder::from('Article')->where('Title', 'foo')->getUniqueIdentifier();
$id2 = DbFinder::from('Article')->where('Title', 'bar')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'Different queries get a different unique identifier');

$id1 = DbFinder::from('Article')->getUniqueIdentifier();
$id2 = DbFinder::from('Comment')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'unique identifier takes main model class into account');

$id1 = DbFinder::from('Article')->where('Title', 'foo')->with('Category')->getUniqueIdentifier();
$id2 = DbFinder::from('Article')->where('Title', 'foo')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'unique identifier takes with classes into account');

$id1 = DbFinder::from('Article')->where('Title', 'foo')->withColumn('Category.Name')->getUniqueIdentifier();
$id2 = DbFinder::from('Article')->where('Title', 'foo')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'unique identifier takes with columns into account');

$id1 = DbFinder::from('Article')->where('Title', 'foo')->leftJoin('Category')->withColumn('Category.Name')->getUniqueIdentifier();
$id2 = DbFinder::from('Article')->where('Title', 'foo')->withColumn('Category.Name')->getUniqueIdentifier();
Ejemplo n.º 3
0
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(14, new lime_output_color());
$taxs = Doctrine::getTable('Taxonomy')->findOneByName('Falco Peregrinus eliticus');
$t->info('findWithParents($id)');
$taxa = Doctrine::getTable('Taxonomy')->findWithParents($taxs->getId());
$t->isnt($taxa, null, 'we got a taxa');
$t->is($taxa->count(), 9, 'we got all parent of the taxa');
$t->is($taxa[7]->getId(), $taxs->getParentRef(), 'Parent is correct');
$t->is($taxa[1]->Level->__toString(), 'kingdom', 'get Level');
$t->is($taxs->getNameWithFormat(), '<i>Falco Peregrinus eliticus</i>', 'get Name without extinct');
$taxs->setExtinct('true');
$t->is($taxs->getNameWithFormat(), '<i>Falco Peregrinus eliticus</i> †', 'get Name without extinct');
$t->is(DarwinTable::getFilterForTable('classification_syonymies'), "ClassificationSyonymiesFormFilter", 'Filter Form name');
$t->is(DarwinTable::getFormForTable('classification_syonymies'), "ClassificationSyonymiesForm", 'Form Name');
$t->is(DarwinTable::getModelForTable('classification_syonymies'), "ClassificationSyonymies", 'Model Name');
$t->is(Doctrine::getTable('Taxonomy')->find(4)->toArray(), true, 'We got the record with find');
$t->is(Doctrine::getTable('Taxonomy')->find(-1)->toArray(), true, 'Record bellow 0 are found  with find');
$keywords = Doctrine::getTable('ClassificationKeywords')->findForTable('taxonomy', 4);
$t->is(count($keywords), 0, 'No KW per default');
$kw_full = ClassificationKeywords::getTags('taxonomy');
$avail_kw = array_keys($kw_full);
$kw = new ClassificationKeywords();
$kw->setReferencedRelation('taxonomy');
$kw->setRecordId(4);
$kw->setKeywordType($avail_kw[1]);
$kw->setKeyword('Falco Peregrinus');
$kw->save();
$keywords = Doctrine::getTable('ClassificationKeywords')->findForTable('taxonomy', 4);
$t->is(count($keywords), 1, 'The new Keyword');
Ejemplo n.º 4
0
<?php

$app = 'sympal';
require_once dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new lime_test(5);
$t->info('1 - Test that the delete recurses on the application level to the sfSympalContent records');
$site = Doctrine_Core::getTable('sfSympalSite')->findOneBySlug('sympal');
$pages = Doctrine_Core::getTable('sfSympalPage')->createQuery()->execute();
$t->isnt(count($site->Content), 0, 'Sanity check: the sfSympalSite record has at least one Content record');
$t->isnt(count($pages), 0, 'Sanity check: We begin with more than 0 sfSympalPage objects');
$site->delete();
$site->refreshRelated('Content');
$pages = Doctrine_Core::getTable('sfSympalPage')->createQuery()->execute();
$t->is(count($site->Content), 0, 'The site now has no content. This would happen with or without the application-level delete recursion');
$t->is(count($pages), 0, 'All of the sfSympalPage records are gone due to the application-level delete recursion onto sfSympalContent');
$t->info('2 - Quick check on ->deleteApplication');
$site->deleteApplication();
$t->is(file_exists(sfConfig::get('sf_app_dir')), false, 'The application directory no longer exists');
$category1 = new DCategory();
$category1->setName('cat1');
$category1->save();
$article1 = new DArticle();
$article1->setTitle('aaaaa');
$article1->setCategory($category1);
$article1->save();
// Identity Map is there... No query will be issued to fetch an article Category, unless we clear the map
Doctrine::getTable('DCategory')->clear();
Doctrine::getTable('DArticle')->clear();
$finder = sfDoctrineFinder::from('DArticle');
$article = $finder->findOne();
$sql = $finder->getLatestQuery();
$article->getCategory()->getName();
$t->isnt($finder->getLatestQuery(), $sql, 'Calling a getter on a related object issues a new query');

Doctrine::getTable('DCategory')->clear();
Doctrine::getTable('DArticle')->clear();
$finder = sfDoctrineFinder::from('DArticle')->join('DCategory')->with('DCategory');
$article = $finder->findOne();
$sql = $finder->getLatestQuery();
$expectedSQL = 'SELECT d.id AS d__id, d.title AS d__title, d.category_id AS d__category_id, d2.id AS d2__id, d2.name AS d2__name FROM d_article d INNER JOIN d_category d2 ON d.category_id = d2.id LIMIT 1';
$t->is($sql, $expectedSQL, 'with() hydrates the related classes and avoids subsequent queries');
$article->getCategory()->getName();
$t->is($finder->getLatestQuery(), $sql, 'with() hydrates the related classes and avoids subsequent queries');

$t->is($article->getTitle(), 'aaaaa', 'fetching objects with a with() returns the correct main object');
$t->is($article->getCategory()->getName(), 'cat1', 'fetching objects with a with() returns the correct related object');

$finder = sfDoctrineFinder::from('DArticle')->with('DCategory');
Ejemplo n.º 6
0
<?php

include 'lime.php';
$t = new lime_test(4, new lime_output_color());
Mapnik\DataSourceCache::registerDataSources('..\\mapnik-0.7.1\\plugins');
$data_sources = Mapnik\DatasourceCache::getPluginNames();
$t->is(is_array($data_sources), true, 'getPluginNames returns an array');
$t->is(count($data_sources), 1, 'One plugin found');
$t->is($data_sources[0], 'shape', 'Shape plugin found');
$p = new Mapnik\Parameters();
$p->set('type', 'shape');
$p->set('file', '../mapnik-0.7.1/demo/data/boundaries');
$datasource = Mapnik\DataSourceCache::createDatasource($p);
$t->isnt($datasource, null, 'Shape datasource created.');
Ejemplo n.º 7
0
$t->diag('->listCredentials()');
$user->clearCredentials();
$user->addCredential('user');
$t->is($user->listCredentials(), array('user'), '->listCredentials() returns user credentials as an array');
// ->setAuthenticated() ->isAuthenticated()
$t->diag('->setAuthenticated() ->isAuthenticated()');
$t->is($user->isAuthenticated(), false, '->isAuthenticated() returns false by default');
$user->setAuthenticated(true);
$t->is($user->isAuthenticated(), true, '->isAuthenticated() returns true if the user is authenticated');
$user->setAuthenticated(false);
$t->is($user->isAuthenticated(), false, '->setAuthenticated() accepts a boolean as its first parameter');
// session id regeneration
$user->setAuthenticated(false);
$id = $storage->getSessionId();
$user->setAuthenticated(true);
$t->isnt($id, $id = $storage->getSessionId(), '->setAuthenticated() regenerates the session id if the authentication changes');
$user->setAuthenticated(true);
$t->is($storage->getSessionId(), $id, '->setAuthenticated() does not regenerate the session id if the authentication does not change');
$user->addCredential('foo');
$t->isnt($id, $id = $storage->getSessionId(), '->addCredential() regenerates the session id if a new credential is added');
$t->is($id, $storage->getSessionId(), '->addCredential() does not regenerate the session id if the credential already exists');
$user->removeCredential('foo');
$t->isnt($id, $id = $storage->getSessionId(), '->removeCredential() regenerates the session id if a credential is removed');
$t->is($id, $storage->getSessionId(), '->removeCredential() does not regenerate the session id if the credential does not exist');
// ->setTimedOut() ->getTimedOut()
$user = new sfBasicSecurityUser($dispatcher, $storage);
$t->diag('->setTimedOut() ->isTimedOut()');
$t->is($user->isTimedOut(), false, '->isTimedOut() returns false if the session is not timed out');
$user->setTimedOut();
$t->is($user->isTimedOut(), true, '->isTimedOut() returns true if the session is timed out');
// ->hasCredential()
$msg1->save();
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$t->is($topic->getNbPosts(), 3, 'Updating a message doesn\'t change the topic post count');
$t->is($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the topic\'s last update date');
$t->is($topic->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the topic\'s latest reply');
$forum = sfSimpleForumForumPeer::retrieveByPk($forum->getId());
$t->is($forum->getNbPosts(), 3, 'Updating a message doesn\'t change the forum\'s post count');
$t->is($forum->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the forum\'s last update date');
$t->is($forum->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the forum\'s last reply');
$t->diag('Updating the topic');
sleep(1);
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$topic->setTitle('this is another test');
$topic->save();
$t->is($topic->getNbPosts(), 3, 'Updating a topic doesn\'t change the topic number of replies');
$t->isnt($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a topic changes the topic\'s latest update date');
$t->is($topic->getLatestPost()->getId(), $msg3->getId(), 'Updating a topic doesn\'t change the topic\'s latest reply');
$forum = sfSimpleForumForumPeer::retrieveByPk($forum->getId());
$t->is($forum->getLatestPost()->getCreatedAt('U'), $msg3->getCreatedAt('U'), 'Updating the topic doesn\'t change the forum\'s last update date');
$t->is($forum->getLatestPost()->getAuthorName(), $user3->getUsername(), 'Updating the topic doesn\'t change the forum\'s last reply author name');
$t->diag('Deleting a message from the end');
$msg3->delete();
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$t->is($topic->getNbPosts(), 2, 'Deleting a message decrements the topic number of replies');
$t->is($topic->getUpdatedAt('U'), $msg2->getCreatedAt('U'), 'Deleting a message changes the topic\'s latest update date to the latest message creation date');
$t->is($topic->getLatestPost()->getId(), $msg2->getId(), 'Deleting a message changes the topic\'s latest reply');
$forum = sfSimpleForumForumPeer::retrieveByPk($forum->getId());
$t->is($forum->getUpdatedAt('U'), $msg2->getCreatedAt('U'), 'Deleting a message changes the forums\'s latest update date to the latest message creation date');
$t->is($forum->getLatestPost()->getId(), $msg2->getId(), 'Deleting a message changes the forums\'s latest reply');
$t->diag('Deleting a message from the middle');
$msg1->delete();
// ::getInstance()
$t->diag('::getInstance()');
$t->isa_ok(sfNumberFormatInfo::getInstance(), 'sfNumberFormatInfo', '::getInstance() returns an sfNumberFormatInfo instance');
$c = new sfCultureInfo();
$t->is(sfNumberFormatInfo::getInstance($c), $c->getNumberFormat(), '::getInstance() can take a sfCultureInfo instance as its first argument');
$t->isa_ok(sfNumberFormatInfo::getInstance('fr'), 'sfNumberFormatInfo', '::getInstance() can take a culture as its first argument');
$n = sfNumberFormatInfo::getInstance();
$n->setPattern(sfNumberFormatInfo::PERCENTAGE);
$t->is(sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::PERCENTAGE)->getPattern(), $n->getPattern(), '::getInstance() can take a formatting type as its second argument');
// ->getPattern() ->setPattern()
$t->diag('->getPattern() ->setPattern()');
$n = sfNumberFormatInfo::getInstance();
$n1 = sfNumberFormatInfo::getInstance();
$n->setPattern(sfNumberFormatInfo::CURRENCY);
$n1->setPattern(sfNumberFormatInfo::PERCENTAGE);
$t->isnt($n->getPattern(), $n1->getPattern(), '->getPattern() ->setPattern() changes the current pattern');
$n = sfNumberFormatInfo::getInstance();
$n1 = sfNumberFormatInfo::getInstance();
$n->Pattern = sfNumberFormatInfo::CURRENCY;
$n1->setPattern(sfNumberFormatInfo::CURRENCY);
$t->is($n->getPattern(), $n1->getPattern(), '->setPattern() is equivalent to ->Pattern = ');
$t->is($n->getPattern(), $n->Pattern, '->getPattern() is equivalent to ->Pattern');
// ::getCurrencyInstance()
$t->diag('::getCurrencyInstance()');
$t->is(sfNumberFormatInfo::getCurrencyInstance()->getPattern(), sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::CURRENCY)->getPattern(), '::getCurrencyInstance() is a shortcut for ::getInstance() and type sfNumberFormatInfo::CURRENCY');
// ::getPercentageInstance()
$t->diag('::getPercentageInstance()');
$t->is(sfNumberFormatInfo::getPercentageInstance()->getPattern(), sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::PERCENTAGE)->getPattern(), '::getPercentageInstance() is a shortcut for ::getInstance() and type sfNumberFormatInfo::PERCENTAGE');
// ::getScientificInstance()
$t->diag('::getScientificInstance()');
$t->is(sfNumberFormatInfo::getScientificInstance()->getPattern(), sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::SCIENTIFIC)->getPattern(), '::getScientificInstance() is a shortcut for ::getInstance() and type sfNumberFormatInfo::SCIENTIFIC');
Beware that the tables for these models will be emptied by the tests, so use a test database connection.
*/

include dirname(__FILE__).'/../../bootstrap.php';

$t = new lime_test(21, new lime_output_color());

$t->diag('getUniqueIdentifier()');

$id1 = DbFinder::from('DArticle')->where('Title', 'foo')->getUniqueIdentifier();
$id2 = DbFinder::from('DArticle')->where('Title', 'foo')->getUniqueIdentifier();
$t->is($id1, $id2, 'Similar queries get the same unique identifier');

$id1 = DbFinder::from('DArticle')->where('Title', 'foo')->getUniqueIdentifier();
$id2 = DbFinder::from('DArticle')->where('Title', 'bar')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'Different queries get a different unique identifier');

$id1 = DbFinder::from('DArticle')->getUniqueIdentifier();
$id2 = DbFinder::from('DComment')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'unique identifier takes main model class into account');

$id1 = DbFinder::from('DArticle')->where('Title', 'foo')->with('DCategory')->getUniqueIdentifier();
$id2 = DbFinder::from('DArticle')->where('Title', 'foo')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'unique identifier takes with classes into account');

$id1 = DbFinder::from('DArticle')->where('Title', 'foo')->withColumn('DCategory.Name')->getUniqueIdentifier();
$id2 = DbFinder::from('DArticle')->where('Title', 'foo')->getUniqueIdentifier();
$t->isnt($id1, $id2, 'unique identifier takes with columns into account');

$id1 = DbFinder::from('DArticle')->where('Title', 'foo')->leftJoin('Category')->withColumn('DCategory.Name')->getUniqueIdentifier();
$id2 = DbFinder::from('DArticle')->where('Title', 'foo')->withColumn('DCategory.Name')->getUniqueIdentifier();
Ejemplo n.º 11
0
$t->diag('->getOptions() ->setOptions()');
$v->setOptions(array('required' => true, 'trim' => false));
$t->is($v->getOptions(), array('required' => true, 'trim' => false, 'empty_value' => null), '->setOptions() changes all options');
// ->getMessages()
$t->diag('->getMessages()');
$t->is($v->getMessages(), array('required' => 'Required.', 'invalid' => 'Invalid.', 'foo' => 'bar'), '->getMessages() returns an array of all error messages');
// ->getMessage()
$t->diag('->getMessage()');
$t->is($v->getMessage('required'), 'Required.', '->getMessage() returns an error message string');
$t->is($v->getMessage('nonexistant'), '', '->getMessage() returns an empty string if the message does not exist');
// ->setMessage()
$t->diag('->setMessage()');
$v->setMessage('required', 'The field is required.');
try {
    $v->clean('');
    $t->isnt($e->getMessage(), 'The field is required.', '->setMessage() changes the default error message string');
} catch (sfValidatorError $e) {
    $t->is($e->getMessage(), 'The field is required.', '->setMessage() changes the default error message string');
}
try {
    $v->setMessage('foobar', 'foo');
    $t->fail('->setMessage() throws an InvalidArgumentException if the message is not registered');
} catch (InvalidArgumentException $e) {
    $t->pass('->setMessage() throws an InvalidArgumentException if the message is not registered');
}
// ->setMessages()
$t->diag('->setMessages()');
$v->setMessages(array('required' => 'This is required!'));
$t->is($v->getMessages(), array('invalid' => 'Invalid.', 'required' => 'This is required!'), '->setMessages() changes all error messages');
// ->addMessage()
$t->diag('->addMessage()');
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(4, new lime_output_color());
$t->diag('getDistinctSubType');
$p = Doctrine::getTable('Institutions')->getDistinctSubType();
$t->is($p[0]->getType(), 'Federal institution', 'Get Institutions types');
$t->diag('Find Institution');
$people = Doctrine::getTable('People')->findByFamilyName('Duchesne');
$r = Doctrine::getTable('Institutions')->findInstitution($people[0]->getId());
$t->is($r, null, 'we did not find the P');
$ugmmm = Doctrine::getTable('People')->findByFamilyName('UGMM');
$r = Doctrine::getTable('Institutions')->findInstitution($ugmmm[0]->getId());
$t->isnt($r, null, 'But ugmm is an Institutions');
$t->is($r->__toString(), 'UGMM', 'get The toString of this institution');
Ejemplo n.º 13
0
<?php

include 'lime.php';
$t = new lime_test(5, new lime_output_color());
$p = new Mapnik\Parameters();
$t->isnt($p, null, 'Created parameters object');
$p->set('string_test', 'hello');
$t->is($p->get('string_test'), 'hello', 'Setter/getter with string key');
$p->set('integer_test', 5);
$t->is($p->get('integer_test'), 5, 'Setter/getter with integer key');
$p->set('double_test', 3.14);
$t->is($p->get('double_test'), 3.14, 'Setter/getter with double key');
$t->is($p->get('doesnt_exist'), null, 'Getter for unknown key returns null');
Ejemplo n.º 14
0
<?php

include 'lime.php';
$t = new lime_test(1, new lime_output_color());
$feature_style = new Mapnik\FeatureStyle();
$t->isnt($feature_style, null, 'FeatureStyle created OK');
$rule = new Mapnik\Rule();
$feature_style->addRule($rule);
// @todo
// PHP_ME(FeatureStyle, getRules,		NULL,	ZEND_ACC_PUBLIC)
Ejemplo n.º 15
0
<?php

include 'lime.php';
$t = new lime_test(5, new lime_output_color());
// Default constructors
$l = new Mapnik\Layer('test layer');
$t->isnt($l, null, 'Layer constructor with one argument');
$t->isa_ok($l, 'Mapnik\\Layer', 'Layer constructor with one argument returned right type');
$l = new Mapnik\Layer('test layer');
$t->isnt($l, null, 'Layer constructor with two arguments', '+proj=latlong +datum=WGS84');
$t->isa_ok($l, 'Mapnik\\Layer', 'Layer constructor with two arguments returned right type');
try {
    $l = new Mapnik\Layer();
    $t->fail('No arguments passed to Layer constructor but no exception thrown');
} catch (Exception $e) {
    $t->pass('No arguments passed to Layer constructor, exception thrown');
}
Ejemplo n.º 16
0
}
$configuration = new TestConfiguration('test', true, sfConfig::get('sf_test_cache_dir', sys_get_temp_dir()));
$dispatcher = $configuration->getEventDispatcher();
$cache = new sfNoCache();
// ->initialize()
$t->diag('->initialize()');
$i18n = new sfI18N($configuration, $cache);
$dispatcher->notify(new sfEvent(null, 'user.change_culture', array('culture' => 'fr')));
$t->is($i18n->getCulture(), 'fr', '->initialize() connects to the user.change_culture event');
// passing a "culture" option to initialize() should set PHP locale
if (version_compare(PHP_VERSION, '5.3', '<') && class_exists('Locale') && ($en = Locale::lookup(array('en-US'), 'en-US', true)) && ($fr = Locale::lookup(array('fr-FR'), 'fr-FR', true))) {
    $i18n = new sfI18N($configuration, $cache, array('culture' => $fr));
    $frLocale = localeconv();
    $i18n = new sfI18N($configuration, $cache, array('culture' => $en));
    $enLocale = localeconv();
    $t->isnt(serialize($frLocale), serialize($enLocale), '->initialize() sets the PHP locale when a "culture" option is provided');
} else {
    $t->skip('PHP version > 5.2 or Locale class or English and French locales are not installed');
}
// ->getCulture() ->setCulture()
$t->diag('->getCulture() ->setCulture()');
$i18n = new sfI18N($configuration, $cache);
$t->is($i18n->getCulture(), 'en', '->getCulture() returns the current culture');
$i18n->setCulture('fr');
$t->is($i18n->getCulture(), 'fr', '->setCulture() sets the current culture');
// ->__()
$t->diag('->__()');
sfConfig::set('sf_charset', 'UTF-8');
$i18n = new sfI18N($configuration, $cache, array('culture' => 'fr'));
$t->is($i18n->__('an english sentence'), 'une phrase en français', '->__() translates a string');
class EnglishSentence
Ejemplo n.º 17
0
$t->is(link_to_if(false, 'test', '@homepage'), '<span>test</span>', 'link_to_if() returns an HTML "span" tag by default if the condition is false');
$t->is(link_to_if(false, 'test', '@homepage', array('tag' => 'div')), '<div>test</div>', 'link_to_if() takes a "tag" option');
$t->is(link_to_if(true, 'test', '@homepage', 'tag=div'), '<a href="module/action">test</a>', 'link_to_if() removes "tag" option (given as string) in true case');
$t->is(link_to_if(true, 'test', '@homepage', array('tag' => 'div')), '<a href="module/action">test</a>', 'link_to_if() removes "tag" option (given as array) in true case');
$t->is(link_to_if(false, 'test', '@homepage', array('query_string' => 'foo=bar', 'absolute' => true, 'absolute_url' => 'http://www.google.com/')), '<span>test</span>', 'link_to_if() returns an HTML "span" tag by default if the condition is false');
$t->is(link_to_if(true, 'test', 'homepage', array(), array('class' => 'test')), '<a class="test" href="homepage">test</a>', 'link_to_if() accepts link_to2 compatible usage');
$t->is(link_to_if(false, 'test', 'homepage', array(), array('class' => 'test')), '<span class="test">test</span>', 'link_to_if() accepts link_to2 compatible usage');
// link_to_unless()
$t->diag('link_to_unless()');
$t->is(link_to_unless(false, 'test', '@homepage'), '<a href="module/action">test</a>', 'link_to_unless() returns an HTML "a" tag if the condition is false');
$t->is(link_to_unless(true, 'test', '@homepage'), '<span>test</span>', 'link_to_unless() returns an HTML "span" tag by default if the condition is true');
$t->is(link_to_unless(true, 'test', 'homepage', array(), array('class' => 'test')), '<span class="test">test</span>', 'link_to_unless() accepts link_to2 compatible usage');
$t->is(link_to_unless(false, 'test', 'homepage', array(), array('class' => 'test')), '<a class="test" href="homepage">test</a>', 'link_to_unless() accepts link_to2 compatible usage');
// public_path()
$t->diag('public_path()');
$t->is(public_path('pdf/download.pdf'), '/public/pdf/download.pdf', 'public_path() returns the public path');
$t->is(public_path('/pdf/download.pdf'), '/public/pdf/download.pdf', 'public_path() returns the public path if starting with slash');
$t->is(public_path('pdf/download.pdf', true), 'https://example.org/public/pdf/download.pdf', 'public_path() returns the public path');
// mail_to()
$t->diag('mail_to()');
$t->is(mail_to('*****@*****.**'), '<a href="mailto:fabien.potencier@symfony-project.com">fabien.potencier@symfony-project.com</a>', 'mail_to() creates a mailto a tag');
$t->is(mail_to('*****@*****.**', 'fabien'), '<a href="mailto:fabien.potencier@symfony-project.com">fabien</a>', 'mail_to() creates a mailto a tag');
preg_match('/href="(.+?)"/', mail_to('*****@*****.**', 'fabien', array('encode' => true)), $matches);
$t->is(html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8'), 'mailto:fabien.potencier@symfony-project.com', 'mail_to() can encode the email address');
$t->diag('mail_to test');
$t->is(mail_to('*****@*****.**'), '<a href="mailto:webmaster@example.com">webmaster@example.com</a>', 'mail_to with only given email works');
$t->is(mail_to('*****@*****.**', 'send us an email'), '<a href="mailto:webmaster@example.com">send us an email</a>', 'mail_to with given email and title works');
$t->isnt(mail_to('*****@*****.**', 'encoded', array('encode' => true)), '<a href="mailto:webmaster@example.com">encoded</a>', 'mail_to with encoding works');
$t->is(mail_to('*****@*****.**', '', array(), array('subject' => 'test subject', 'body' => 'test body')), '<a href="mailto:webmaster@example.com?subject=test+subject&amp;body=test+body">webmaster@example.com</a>', 'mail_to() works with given default values in array form');
$t->is(mail_to('*****@*****.**', '', array(), 'subject=test subject body=test body'), '<a href="mailto:webmaster@example.com?subject=test+subject&amp;body=test+body">webmaster@example.com</a>', 'mail_to() works with given default values in string form');
$t->is(mail_to('*****@*****.**', '', array(), 'subject=Hello World and more'), '<a href="mailto:webmaster@example.com?subject=Hello+World+and+more">webmaster@example.com</a>', 'mail_to() works with given default value with spaces');
Ejemplo n.º 18
0
    $t->skip('Unable to connect to MySQL database, skipping', $plan);
    return;
}
// Creates test database
mysqli_query($connection, 'DROP DATABASE IF EXISTS sf_mysqli_storage_unit_test');
mysqli_query($connection, 'CREATE DATABASE sf_mysqli_storage_unit_test') or $t->fail('Cannot create database sf_mysqli_storage_unit_test');
mysqli_select_db($connection, 'sf_mysqli_storage_unit_test');
mysqli_query($connection, "CREATE TABLE `session` (\n  `sess_id` varchar(40) NOT NULL PRIMARY KEY,\n  `sess_time` int(10) unsigned NOT NULL default '0',\n  `sess_data` text collate utf8_unicode_ci\n) ENGINE=MyISAM") or $t->fail('Can not create table session');
ini_set('session.use_cookies', 0);
$session_id = "1";
$storage = new sfMySQLiSessionStorage(array('db_table' => 'session', 'session_id' => $session_id, 'database' => $database));
$t->ok($storage instanceof sfStorage, 'sfMySQLSessionStorage is an instance of sfStorage');
$t->ok($storage instanceof sfDatabaseSessionStorage, 'sfMySQLSessionStorage is an instance of sfDatabaseSessionStorage');
// regenerate()
$storage->regenerate(false);
$t->isnt(session_id(), $session_id, 'regenerate() regenerated the session id');
$session_id = session_id();
// do some session operations
$_SESSION['foo'] = 'bar';
$_SESSION['bar'] = 'foo';
unset($_SESSION['foo']);
$session_data = session_encode();
// end of session
session_write_close();
// check session data in the database
$result = mysqli_query($connection, sprintf('SELECT sess_data FROM session WHERE sess_id = "%s"', $session_id));
list($thisSessData) = mysqli_fetch_row($result);
$t->is(mysqli_num_rows($result), 1, 'session is stored in the database');
$t->is($thisSessData, $session_data, 'session variables are stored in the database');
mysqli_free_result($result);
unset($thisSessData, $result);
  $t->pass('->__construct() throws an exception when not provided a cache option');
}


$storage = new sfCacheSessionStorage(array('cache' => array('class' => 'sfAPCCache', 'param' => array())));
$t->ok($storage instanceof sfStorage, '->__construct() is an instance of sfStorage');

$storage->write('test', 123);

$t->is($storage->read('test'), 123, '->read() can read data that has been written to storage');

// regenerate()
$oldSessionData = 'foo:bar';
$key = md5($oldSessionData);

$storage->write($key, $oldSessionData);
$session_id = session_id();
$storage->regenerate(false);
$t->is($storage->read($key), $oldSessionData, '->regenerate() regenerated the session with a different session id');
$t->isnt(session_id(), $session_id, '->regenerate() regenerated the session with a different session id');

$storage->regenerate(true);
$t->isnt($storage->read($key), $oldSessionData, '->regenerate() regenerated the session with a different session id and destroyed data');
$t->isnt(session_id(), $session_id, '->regenerate() regenerated the session with a different session id');

$storage->remove($key);
$t->is($storage->read($key), null, '->remove() removes data from the storage');

// shutdown the storage
$storage->shutdown();
Ejemplo n.º 20
0
$t->is((string) $feedXml->channel[0]->item[0]->category[1], $itemParams['categories'][1], '<item><category> contains the item category');
$generatedEnclosure = array('url' => (string) $feedXml->channel[0]->item[0]->enclosure['url'], 'length' => (string) $feedXml->channel[0]->item[0]->enclosure['length'], 'mimeType' => (string) $feedXml->channel[0]->item[0]->enclosure['type']);
$t->is_deeply($generatedEnclosure, $enclosureParams, '<entry><enclosure> contains the proper item enclosure');
$t->diag('asXML() - generated feed');
$feedString = $feed->asXml();
$t->is(sfContext::getInstance()->getResponse()->getContentType(), 'application/rss+xml; charset=UTF-16', 'The reponse comes with the correct Content-Type');
$t->diag('fromXML() - generated feed');
$generatedFeed = new sfRssFeed();
$generatedFeed->fromXml($feedString);
$t->is($generatedFeed->getTitle(), $feed->getTitle(), 'The title property is properly set');
$t->is($generatedFeed->getLink(), $feed->getLink(), 'The link property is properly set');
$t->is($generatedFeed->getDescription(), $feed->getDescription(), 'The description property is properly set');
$t->is($generatedFeed->getLanguage(), $feed->getLanguage(), 'The language property is properly set');
$t->is($generatedFeed->getAuthorEmail(), $feed->getAuthorEmail(), 'The author email property is properly set');
$t->is($generatedFeed->getAuthorName(), $feed->getAuthorName(), 'The author name property is properly set');
$t->isnt($generatedFeed->getAuthorLink(), $feed->getAuthorLink(), 'The author link property cannot be set from a RSS feed');
$t->isnt($generatedFeed->getSubtitle(), $feed->getSubtitle(), 'The subtitle property cannot be set from a RSS feed');
$t->is($generatedFeed->getCategories(), $feed->getCategories(), 'The categories property is properly set');
$t->isnt($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property cannot be set from a RSS feed');
$t->is($generatedFeed->getEncoding(), $feed->getEncoding(), 'The encoding property is properly set');
$t->is($generatedFeed->getImage()->getImage(), $feed->getImage()->getImage(), 'The feed image url is correctly set');
$t->is($generatedFeed->getImage()->getImageX(), $feed->getImage()->getImageX(), 'The feed image x is correctly set');
$t->is($generatedFeed->getImage()->getImageY(), $feed->getImage()->getImageY(), 'The feed image y is correctly set');
$t->is($generatedFeed->getImage()->getLink(), $feed->getImage()->getLink(), 'The feed image link is correctly set');
$t->is($generatedFeed->getImage()->getTitle(), $feed->getImage()->getTitle(), 'The feed image title is correctly set');
$t->diag('fromXML() - generated feed items');
$items = $generatedFeed->getItems();
$generatedItem = $items[0];
$t->is($generatedItem->getTitle(), $feedItem->getTitle(), 'The title property is properly set');
$t->is($generatedItem->getLink(), $feedItem->getLink(), 'The link property is properly set');
$t->is($generatedItem->getDescription(), $feedItem->getDescription(), 'The description property is properly set');
Ejemplo n.º 21
0
ob_start();
$_test_dir = realpath(dirname(__FILE__) . '/../../');
require_once $_test_dir . '/../lib/vendor/lime/lime.php';
sfConfig::set('sf_symfony_lib_dir', realpath($_test_dir . '/../lib'));
$t = new lime_test(8, new lime_output_color());
// initialize the storage
try {
    $storage = new sfSessionStorage();
    $t->pass('->__construct() does not throw an exception when not provided with options');
} catch (InvalidArgumentException $e) {
    $t->fail('->__construct() Startup failure');
}
$storage = new sfSessionStorage();
$t->ok($storage instanceof sfStorage, '->__construct() is an instance of sfStorage');
$storage->write('test', 123);
$t->is($storage->read('test'), 123, '->read() can read data that has been written to storage');
// regenerate()
$oldSessionData = 'foo:bar';
$key = md5($oldSessionData);
$storage->write($key, $oldSessionData);
$session_id = session_id();
$storage->regenerate(false);
$t->is($storage->read($key), $oldSessionData, '->regenerate(false) regenerated the session with a different session id - this class by default doesn\'t regen the id');
$t->isnt(session_id(), $session_id, '->regenerate(false) regenerated the session with a different session id');
$storage->regenerate(true);
$t->is($storage->read($key), $oldSessionData, '->regenerate(true) regenerated the session with a different session id and destroyed data');
$t->isnt(session_id(), $session_id, '->regenerate(true) regenerated the session with a different session id');
$storage->remove($key);
$t->is($storage->read($key), null, '->remove() removes data from the storage');
// shutdown the storage
$storage->shutdown();
Ejemplo n.º 22
0
$t->isa_ok(sfNumberFormatInfo::getInstance(), 'sfNumberFormatInfo', '::getInstance() returns an sfNumberFormatInfo instance');
$c = sfCultureInfo::getInstance();
$t->is(sfNumberFormatInfo::getInstance($c), $c->getNumberFormat(), '::getInstance() can take a sfCultureInfo instance as its first argument');
$t->isa_ok(sfNumberFormatInfo::getInstance('fr'), 'sfNumberFormatInfo', '::getInstance() can take a culture as its first argument');
$n = sfNumberFormatInfo::getInstance();
$n->setPattern(sfNumberFormatInfo::PERCENTAGE);
$t->is(sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::PERCENTAGE)->getPattern(), $n->getPattern(), '::getInstance() can take a formatting type as its second argument');
// ->getPattern() ->setPattern()
$t->diag('->getPattern() ->setPattern()');
$n = sfNumberFormatInfo::getInstance();
$n1 = sfNumberFormatInfo::getInstance();
$n->setPattern(sfNumberFormatInfo::CURRENCY);
$pattern = $n->getPattern();
$n1->setPattern(sfNumberFormatInfo::PERCENTAGE);
$pattern1 = $n1->getPattern();
$t->isnt($pattern, $pattern1, '->getPattern() ->setPattern() changes the current pattern');
$n = sfNumberFormatInfo::getInstance();
$n1 = sfNumberFormatInfo::getInstance();
$n->Pattern = sfNumberFormatInfo::CURRENCY;
$n1->setPattern(sfNumberFormatInfo::CURRENCY);
$t->is($n->getPattern(), $n1->getPattern(), '->setPattern() is equivalent to ->Pattern = ');
$t->is($n->getPattern(), $n->Pattern, '->getPattern() is equivalent to ->Pattern');
// ::getCurrencyInstance()
$t->diag('::getCurrencyInstance()');
$t->is(sfNumberFormatInfo::getCurrencyInstance()->getPattern(), sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::CURRENCY)->getPattern(), '::getCurrencyInstance() is a shortcut for ::getInstance() and type sfNumberFormatInfo::CURRENCY');
// ::getPercentageInstance()
$t->diag('::getPercentageInstance()');
$t->is(sfNumberFormatInfo::getPercentageInstance()->getPattern(), sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::PERCENTAGE)->getPattern(), '::getPercentageInstance() is a shortcut for ::getInstance() and type sfNumberFormatInfo::PERCENTAGE');
// ::getScientificInstance()
$t->diag('::getScientificInstance()');
$t->is(sfNumberFormatInfo::getScientificInstance()->getPattern(), sfNumberFormatInfo::getInstance(null, sfNumberFormatInfo::SCIENTIFIC)->getPattern(), '::getScientificInstance() is a shortcut for ::getInstance() and type sfNumberFormatInfo::SCIENTIFIC');
Ejemplo n.º 23
0
$r->clearRoutes();
$r->connect('test', new sfRoute('/:module/:action', array('module' => 'default')));
$params = array('module' => 'default', 'action' => 'index');
$url = '/default/index';
$t->is($r->generate('', $params), $url, '->generate() creates URL even if there is no default value');
$t->is($r->parse($url), $params, '->parse() finds route even when route has no default value');
// combined examples
$r->clearRoutes();
$r->connect('test', new sfRoute('/:module/:action/:test/:id', array('module' => 'default', 'action' => 'index', 'id' => 'toto')));
$params = array('module' => 'default', 'action' => 'index', 'test' => 'foo', 'id' => 'bar');
$url = '/default/index/foo/bar';
$t->is($r->generate('', $params), $url, '->generate() routes have default parameters value that can be overriden');
$t->is($r->parse($url), $params, '->parse() routes have default parameters value that can be overriden');
$params = array('module' => 'default', 'action' => 'index', 'test' => 'foo', 'id' => 'toto');
$url = '/default/index/foo';
$t->isnt($r->generate('', $params), $url, '->generate() does not remove the last parameter if the parameter is default value');
$t->is($r->parse($url), $params, '->parse() removes the last parameter if the parameter is default value');
$r->clearRoutes();
$r->connect('test', new sfRoute('/:module/:action/:test/:id', array('module' => 'default', 'action' => 'index', 'test' => 'foo', 'id' => 'bar')));
$params = array('module' => 'default', 'action' => 'index', 'test' => 'foo', 'id' => 'bar');
$url = '/default/index';
$t->isnt($r->generate('', $params), $url, '->generate() does not remove last parameters if they have default values');
$t->is($r->parse($url), $params, '->parse() removes last parameters if they have default values');
// routing defaults parameters
$r->setDefaultParameter('foo', 'bar');
$r->clearRoutes();
$r->connect('test', new sfRoute('/test/:foo/:id', array('module' => 'default', 'action' => 'index')));
$params = array('module' => 'default', 'action' => 'index', 'id' => 12);
$url = '/test/bar/12';
$t->is($r->generate('', $params), $url, '->generate() merges parameters with defaults from "sf_routing_defaults"');
$r->setDefaultParameters(array());
Ejemplo n.º 24
0
$helper->boot('front');
$t = new lime_test(14);
$user = $helper->get('user');
$t->ok($helper->get('i18n')->cultureExists($user->getCulture()), 'The user\'s culture exists');
$browser = $user->getBrowser();
$t->is($browser->isUnknown(), true, 'Cli browser is unknown');
$t->is($user->isAuthenticated(), false, 'User is not authenticated');
$t->is($user->can('admin'), false, 'User can not admin');
$randomCredential = dmString::random();
$t->is($user->can($randomCredential), false, 'User can not ' . $randomCredential);
$t->diag('grant ' . $randomCredential . ' credential');
$user->addCredential($randomCredential);
$t->is($user->can($randomCredential), false, 'User can still not ' . $randomCredential . ' because it\'s not authenticated');
$userRecord = dmDb::table('DmUser')->findOne();
$user->signin($userRecord);
$t->is($user->isAuthenticated(), true, 'User is authenticated');
$t->diag('grant ' . $randomCredential . ' credential');
$user->addCredential($randomCredential);
$t->is($user->can($randomCredential), true, 'Now user can ' . $randomCredential);
$user->signout();
$t->is($user->isAuthenticated(), false, 'User is no more authenticated');
$t->is($user->can($randomCredential), false, 'user can no more ' . $randomCredential);
// Testing DmUser records
$username = dmString::random(8);
$t->diag('Create user ' . $username);
$userRecord = dmDb::create('DmUser', array('username' => $username, 'password' => 'changeme', 'email' => $username . '@diem-project.org'))->saveGet();
$t->ok($userRecord->exists(), 'User has been created');
$t->isa_ok($userRecord, 'DmUser', 'User is a DmUser');
$t->isnt($userRecord->password, 'changeme', 'Password has been encrypted');
$userRecord->delete();
$t->ok(!$userRecord->exists(), 'User has been deleted');
Ejemplo n.º 25
0
<?php

include 'lime.php';
// (Fairly) minimal example
// Renders just the cities from the rundemo sample.
$t = new lime_test(23, new lime_output_color());
// Set up the environment
Mapnik\DatasourceCache::registerDatasources("..\\mapnik-0.7.1\\plugins");
$t->is(in_array('shape', Mapnik\DatasourceCache::getPluginNames()), true, 'Shape data source available');
$result = Mapnik\FreetypeEngine::registerFont("..\\mapnik-0.7.1\\fonts\\DejaVuSans.ttf");
$t->is($result, true, 'Registered DejaVuSans.ttf font');
// Set up the map
$m = new Mapnik\Map(800, 600);
$t->isnt($result, null, 'Created Map of 800x600 pixels');
$m->setBackgroundColor(new Mapnik\Color(255, 255, 255));
$t->is($m->getBackgroundColor()->toHexString(), '#ffffff', 'Set background to 0xffffff (white)');
// Set the map data
$popplaces_style = new Mapnik\FeatureStyle();
$t->isnt($popplaces_style, null, 'Created new feature style');
$popplaces_rule = new Mapnik\Rule();
$t->isnt($popplaces_rule, null, 'Created new rule');
$popplaces_text_symbolizer = new Mapnik\TextSymbolizer('GEONAME', 'DejaVu Sans Book', 10, new Mapnik\Color(0, 0, 0));
$t->isnt($popplaces_text_symbolizer, null, 'Created text symbolizer');
// @todo
//$t->is($popplaces_text_symbolizer->getName(), 'GEONAME', 'Text symbolizer name is GEONAME');
//$t->is($popplaces_text_symbolizer->getFontFace(), '', 'Text symbolizer font face is DejaVu Sans Book');
//$t->is($popplaces_text_symbolizer->getTextSize(), 10, 'Text symbolizer text size is 10');
//$t->is($popplaces_text_symbolizer->getColor(), '', 'Text symbolizer text color is black');
$popplaces_text_symbolizer->setHaloFill(new Mapnik\Color(255, 255, 200));
$t->isa_ok($popplaces_text_symbolizer->getHaloFill(), 'Mapnik\\Color', 'halo_fill set to a Color');
$t->is($popplaces_text_symbolizer->getHaloFill()->toHexString(), '#ffffc8', 'halo_fill returns the right color');
<?php

include 'lime.php';
$t = new lime_test(4, new lime_output_color());
$symbolizer = new Mapnik\TextSymbolizer('GEONAME', 'DejaVu Sans Book', 10, new Mapnik\Color(0, 255, 0));
$t->isnt($symbolizer, null, 'Constructor with 4 arguments');
$symbolizer = new Mapnik\TextSymbolizer('GEONAME', 10, new Mapnik\Color(0, 255, 0));
$t->isnt($symbolizer, null, 'Constructor with 3 arguments');
$symbolizer->setHaloFill(new Mapnik\Color(0, 0, 255));
$control_color = new Mapnik\Color(0, 0, 255);
$t->is($symbolizer->getHaloFill()->toHexString(), $control_color->toHexString(), 'halo fill getter/setter');
$symbolizer->setHaloRadius(5);
$t->is($symbolizer->getHaloRadius(), 5, 'halo radius getter/setter');
// @todo all the rest
Ejemplo n.º 27
0
// initialize the storage
$database = new sfPDODatabase(array('dsn' => 'sqlite::memory:'));
$connection = $database->getConnection();
$connection->exec('CREATE TABLE session (sess_id, sess_data, sess_time)');
ini_set('session.use_cookies', 0);
$session_id = "1";
$storage = new sfPDOSessionStorage(array('db_table' => 'session', 'session_id' => $session_id, 'database' => $database));
$t->ok($storage instanceof sfStorage, 'sfPDOSessionStorage is an instance of sfStorage');
$t->ok($storage instanceof sfDatabaseSessionStorage, 'sfPDOSessionStorage is an instance of sfDatabaseSessionStorage');
// regenerate()
$oldSessionData = 'foo:bar';
$storage->sessionWrite($session_id, $oldSessionData);
$storage->regenerate(false);
$newSessionData = 'foo:bar:baz';
$storage->sessionWrite(session_id(), $newSessionData);
$t->isnt(session_id(), $session_id, 'regenerate() regenerated the session with a different session id');
// checking if the old session record still exists
$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id));
$data = $result->fetchAll();
$t->is(count($data), 1, 'regenerate() has kept destroyed old session');
// checking if the new session record has been created
$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', session_id()));
$data = $result->fetchAll();
$t->is(count($data), 1, 'regenerate() has created a new session record');
$t->is($data[0]['sess_data'], $newSessionData, 'regenerate() has created a new record with correct data');
$session_id = session_id();
// sessionRead()
try {
    $retrieved_data = $storage->sessionRead($session_id);
    $t->pass('sessionRead() does not throw an exception');
} catch (Exception $e) {
Ejemplo n.º 28
0
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(6, new lime_output_color());
$mineralo = Doctrine::getTable('Mineralogy')->findOneByName('Alkali carbonates');
$t->info('findWithParents($id)');
$unit = Doctrine::getTable('Mineralogy')->findWithParents($mineralo->getId());
$t->isnt($unit, null, 'we got a unit');
$t->is($unit->count(), 3, 'we got all parent of the unit');
$t->is($unit[1]->getId(), $mineralo->getParentRef(), 'Parent is correct');
$t->is($unit[1]->Level->__toString(), 'sub_class', 'get Level');
$t->is($mineralo->getNameWithFormat(), 'Alkali carbonates', 'get Name');
$t->is($mineralo->getCode(), '5.AA', 'Corect code');
$v = new sfEmailValidator($context);
// ->execute()
$t->diag('->execute()');
$validEmails = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
$invalidEmails = array('example', 'example@', 'example@localhost', 'example@example.com@example.com');
$validEmailsNotStrict = array('*****@*****.**', '*****@*****.**', '*****@*****.**', 'example@localhost');
$invalidEmailsNotStrict = array('example', 'example@', 'example@example.com@example.com');
$v->initialize($context);
foreach ($validEmails as $value) {
    $error = null;
    $t->ok($v->execute($value, $error), sprintf('->execute() returns true for a valid email "%s"', $value));
    $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true');
}
foreach ($invalidEmails as $value) {
    $error = null;
    $t->ok(!$v->execute($value, $error), sprintf('->execute() returns false for an invalid email "%s"', $value));
    $t->isnt($error, null, '->execute() changes "$error" with a default message if it returns false');
}
// strict parameter
$t->diag('->execute() - strict parameter');
$v->initialize($context, array('strict' => false));
foreach ($validEmailsNotStrict as $value) {
    $error = null;
    $t->ok($v->execute($value, $error), sprintf('->execute() returns true for a valid email "%s"', $value));
    $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true');
}
foreach ($invalidEmailsNotStrict as $value) {
    $error = null;
    $t->ok(!$v->execute($value, $error), sprintf('->execute() returns false for an invalid email "%s"', $value));
    $t->isnt($error, null, '->execute() changes "$error" with a default message if it returns false');
}
Ejemplo n.º 30
0
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(15, new lime_output_color());
$t->info('distinct SubGroup()');
$sgroups = Doctrine::getTable('TagGroups')->getDistinctSubGroups('administrative area');
$t->is(count($sgroups), 3, 'Get all administrative sub groups');
$t->is($sgroups['country'], 'country', 'Country is set');
$sgroups = Doctrine::getTable('TagGroups')->getDistinctSubGroups('brol');
$t->is(count($sgroups), 1, 'Get administrative sub groups for this unused');
$t->is($sgroups[''], '', 'thre is only the empty');
$t->info('getPropositions');
$props = Doctrine::getTable('TagGroups')->getPropositions('brussels');
$t->is(count($props), 4, 'We got 4 props');
$props = Doctrine::getTable('TagGroups')->getPropositions('Bruselo');
$t->is(count($props), 2, 'Got 2 prop');
$t->is($props[0]['tag'], 'Brussels', 'Brussels is showed');
$props = Doctrine::getTable('TagGroups')->getPropositions('brussels', 'administrative area', 'city');
$t->is(count($props), 3, 'We got 3 props');
$t->isnt($props[0]['tag'], 'Big White Mountain', 'Purpose from only 1 group');
$t->info('fetchTag');
$gtu = Doctrine::getTable('Gtu')->findOneByCode('irsnb');
$tags = Doctrine::getTable('TagGroups')->fetchTag(array($gtu->getId()));
$t->is(count($tags), 1, 'We got 1 gtu');
$t->is(count($tags[$gtu->getId()]), 2, 'We got 2 group');
$t->is($tags[$gtu->getId()][0]->getGroupName(), 'administrative area', 'administrative is the  group');
$t->is($tags[$gtu->getId()][0]->getSubGroupName(), 'country', 'country is the sub group');
$t->is(count($tags[$gtu->getId()][0]->Tags), 4, 'We got 4 tags');
$t->is(TagGroups::getGroup('populated'), 'Populated Places', 'Get a Tag group');