Exemple #1
0
$t->is($userBis->hasFlash('foo'), false, '->hasFlash() returns true if the flash variable exists');
// array access for user attributes
$user->setAttribute('foo', 'foo');
$t->diag('Array access for user attributes');
$t->is(isset($user['foo']), true, '->offsetExists() returns true if user attribute exists');
$t->is(isset($user['foo2']), false, '->offsetExists() returns false if user attribute does not exist');
$t->is($user['foo3'], false, '->offsetGet() returns false if attribute does not exist');
$t->is($user['foo'], 'foo', '->offsetGet() returns attribute by name');
$user['foo2'] = 'foo2';
$t->is($user['foo2'], 'foo2', '->offsetSet() sets attribute by name');
unset($user['foo2']);
$t->is(isset($user['foo2']), false, '->offsetUnset() unsets attribute by name');
$user = new sfUser($dispatcher, $storage);
// attribute holder proxy
require_once $_test_dir . '/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($user, 'attribute');
// new methods via sfEventDispatcher
require_once $_test_dir . '/unit/sfEventDispatcherTest.class.php';
$dispatcherTest = new sfEventDispatcherTest($t);
$dispatcherTest->launchTests($dispatcher, $user, 'user');
$storage->clear();
function user_flush($dispatcher, $user, $storage, $options = array())
{
    $user->shutdown();
    $user->initialize($dispatcher, $storage, $options);
    $parameters = $storage->getOptions();
    $storage->shutdown();
    $storage->initialize($parameters);
}
sfToolkit::clearDirectory($sessionPath);
Exemple #2
0
// format
$t->diag('format');
$context = sfContext::getInstance(array('request' => 'sfWebRequest', 'response' => 'sfWebResponse'), true);
$context->getRequest()->setFormat('js', 'application/x-javascript');
$context->getRequest()->setRequestFormat('js');
configuredView::$isDecorated = true;
$view = new configuredView($context, '', '', '');
$t->is($view->isDecorator(), false, '->initialize() uses the format to configure the view');
$t->is($context->getResponse()->getContentType(), 'application/x-javascript', '->initialize() uses the format to configure the view');
$t->is($view->getExtension(), '.js.php', '->initialize() uses the format to configure the view');
$context = sfContext::getInstance(array('request' => 'sfWebRequest', 'response' => 'sfWebResponse'), true);
$context->getEventDispatcher()->connect('view.configure_format', 'configure_format');
$context->getRequest()->setRequestFormat('js');
configuredView::$isDecorated = true;
$view = new configuredView($context, '', '', '');
$t->is($view->isDecorator(), true, '->initialize() uses the format to configure the view');
$t->is($context->getResponse()->getContentType(), 'application/javascript', '->initialize() uses the format to configure the view');
// parameter holder proxy
require_once $_test_dir . '/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($view, 'parameter');
// new methods via sfEventDispatcher
require_once $_test_dir . '/unit/sfEventDispatcherTest.class.php';
$dispatcherTest = new sfEventDispatcherTest($t);
$dispatcherTest->launchTests($context->getEventDispatcher(), $view, 'view');
function configure_format(sfEvent $event)
{
    $event->getSubject()->setDecorator(true);
    $event['response']->setContentType('application/javascript');
    return true;
}
// array access for request parameters
$t->diag('Array access for request parameters');
$t->is(isset($request['foo']), true, '->offsetExists() returns true if request parameter exists');
$t->is(isset($request['foo2']), false, '->offsetExists() returns false if request parameter does not exist');
$t->is($request['foo3'], false, '->offsetGet() returns false if parameter does not exist');
$t->is($request['foo'], 'foo', '->offsetGet() returns parameter by name');

$request['foo2'] = 'foo2';
$t->is($request['foo2'], 'foo2', '->offsetSet() sets parameter by name');

unset($request['foo2']);
$t->is(isset($request['foo2']), false, '->offsetUnset() unsets parameter by name');


$request = new myRequest($dispatcher);

// parameter holder proxy
require_once($_test_dir.'/unit/sfParameterHolderTest.class.php');
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($request, 'parameter');

// attribute holder proxy
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($request, 'attribute');

// new methods via sfEventDispatcher
require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php');
$dispatcherTest = new sfEventDispatcherTest($t);
$dispatcherTest->launchTests($dispatcher, $request, 'request');
Exemple #4
0
class myFilter extends sfFilter
{
    public function isFirstCall()
    {
        return parent::isFirstCall();
    }
}
$context = sfContext::getInstance();
$filter = new myFilter($context);
// ->initialize()
$t->diag('->initialize()');
$filter = new myFilter($context);
$t->is($filter->getContext(), $context, '->initialize() takes a sfContext object as its first argument');
$filter->initialize($context, array('foo' => 'bar'));
$t->is($filter->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument');
// ->getContext()
$t->diag('->getContext()');
$filter->initialize($context);
$t->is($filter->getContext(), $context, '->getContext() returns the current context');
// ->isFirstCall()
$t->diag('->isFirstCall()');
$t->is($filter->isFirstCall('beforeExecution'), true, '->isFirstCall() returns true if this is the first call with this argument');
$t->is($filter->isFirstCall('beforeExecution'), false, '->isFirstCall() returns false if this is not the first call with this argument');
$t->is($filter->isFirstCall('beforeExecution'), false, '->isFirstCall() returns false if this is not the first call with this argument');
$filter = new myFilter($context);
$filter->initialize($context);
$t->is($filter->isFirstCall('beforeExecution'), false, '->isFirstCall() returns false if this is not the first call with this argument');
// parameter holder proxy
require_once $_test_dir . '/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($filter, 'parameter');
Exemple #5
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 __DIR__ . '/../../bootstrap/unit.php';
require_once $_test_dir . '/unit/sfContextMock.class.php';
$t = new lime_test(10);
class myDatabase extends sfDatabase
{
    function connect()
    {
    }
    function shutdown()
    {
    }
}
$context = sfContext::getInstance();
$database = new myDatabase();
$database->initialize($context);
// parameter holder proxy
require_once $_test_dir . '/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($database, 'parameter');
<?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';
require_once $_test_dir . '/../../../../test/unit/sfContextMock.class.php';
$t = new lime_test(11);
class myValidator extends sfValidator
{
    function execute(&$value, &$error)
    {
    }
}
$context = sfContext::getInstance();
$validator = new myValidator($context);
// ->getContext()
$t->diag('->getContext()');
$validator->initialize($context);
$t->is($validator->getContext(), $context, '->getContext() returns the current context');
// parameter holder proxy
require_once $_test_dir . '/../../../../test/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($validator, 'parameter');
$t->is($response->getContext(), null, '->initialize() takes a sfContext object as its first argument');
$response->initialize($context, array('foo' => 'bar'));
$t->is($response->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument');
// ->getContext()
$t->diag('->getContext()');
$response->initialize($context);
$t->is($response->getContext(), $context, '->getContext() returns the current context');
// ->setContext()
$t->diag('->setContext()');
$response->setContext(null);
$t->is($response->getContext(), null, '->setContext() changes the current context');
$response->setContext($context);
// ->getContent() ->setContent()
$t->diag('->getContent() ->setContent()');
$t->is($response->getContent(), null, '->getContent() returns the current response content which is null by default');
$response->setContent('test');
$t->is($response->getContent(), 'test', '->setContent() sets the response content');
// ->sendContent()
$t->diag('->sendContent()');
ob_start();
$response->sendContent();
$content = ob_get_clean();
$t->is($content, 'test', '->sendContent() output the current response content');
// parameter holder proxy
require_once $_test_dir . '/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($response, 'parameter');
// mixins
require_once $_test_dir . '/unit/sfMixerTest.class.php';
$mixert = new sfMixerTest($t);
$mixert->launchTests($response, 'sfResponse');
{
}
$context = new sfContext();
$storage = new myStorage();
$storage->initialize($context);
// ::newInstance()
$t->diag('::newInstance()');
$t->isa_ok(sfStorage::newInstance('myStorage'), 'myStorage', '::newInstance() takes a storage class as its first parameter');
$t->isa_ok(sfStorage::newInstance('myStorage'), 'myStorage', '::newInstance() returns an instance of myStorage');
try {
    sfStorage::newInstance('fakeStorage');
    $t->fail('::newInstance() throws a sfFactoryException if the class does not extends sfStorage');
} catch (sfFactoryException $e) {
    $t->pass('::newInstance() throws a sfFactoryException if the class does not extends sfStorage');
}
// ->initialize()
$t->diag('->initialize()');
$storage = sfStorage::newInstance('myStorage');
$t->is($storage->getContext(), null, '->initialize() takes a sfContext object as its first argument');
$storage->initialize($context, array('foo' => 'bar'));
$t->is($storage->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument');
$storage = new myStorage();
$storage->initialize($context);
// ->getContext()
$t->diag('->getContext()');
$storage->initialize($context);
$t->is($storage->getContext(), $context, '->getContext() returns the current context');
// parameter holder proxy
require_once $_test_dir . '/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($t);
$pht->launchTests($storage, 'parameter');