Example #1
0
    {
    }
}
class fakeResponse
{
}
$t = new lime_test(7, new lime_output_color());
$dispatcher = new sfEventDispatcher();
// ->initialize()
$t->diag('->initialize()');
$response = new myResponse($dispatcher, array('foo' => 'bar'));
$options = $response->getOptions();
$t->is($options['foo'], 'bar', '->initialize() takes an array of options as its second argument');
// ->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');
// ->serialize() ->unserialize()
$t->diag('->serialize() ->unserialize()');
$t->ok(new myResponse($dispatcher) instanceof Serializable, 'sfResponse implements the Serializable interface');
// new methods via sfEventDispatcher
require_once $_test_dir . '/unit/sfEventDispatcherTest.class.php';
$dispatcherTest = new sfEventDispatcherTest($t);
$dispatcherTest->launchTests($dispatcher, $response, 'response');
Example #2
0
    {
    }
}
$context = sfContext::getInstance(array('routing' => 'sfNoRouting', 'request' => 'sfWebRequest'));
// ->initialize()
$t->diag('->initialize()');
$component = new myComponent($context, 'module', 'action');
$t->is($component->getContext(), $context, '->initialize() takes a sfContext object as its first argument');
$component->initialize($context, 'module', 'action');
$t->is($component->getContext(), $context, '->initialize() takes a sfContext object as its first argument');
// ->getContext()
$t->diag('->getContext()');
$component->initialize($context, 'module', 'action');
$t->is($component->getContext(), $context, '->getContext() returns the current context');
// ->getRequest()
$t->diag('->getRequest()');
$component->initialize($context, 'module', 'action');
$t->is($component->getRequest(), $context->getRequest(), '->getRequest() returns the current request');
// ->getResponse()
$t->diag('->getResponse()');
$component->initialize($context, 'module', 'action');
$t->is($component->getResponse(), $context->getResponse(), '->getResponse() returns the current response');
// __set()
$t->diag('__set()');
$component->foo = array();
$component->foo[] = 'bar';
$t->is($component->foo, array('bar'), '__set() populates component variables');
// new methods via sfEventDispatcher
require_once $_test_dir . '/unit/sfEventDispatcherTest.class.php';
$dispatcherTest = new sfEventDispatcherTest($t);
$dispatcherTest->launchTests($context->getEventDispatcher(), $component, 'component');
Example #3
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);
Example #4
0
// 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');
Example #5
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;
}
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please controller the LICENSE
 * file that was distributed with this source code.
 */

require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
require_once($_test_dir.'/unit/sfContextMock.class.php');

$t = new lime_test(2);

class myController extends sfController
{
  function execute () {}
}

$context = sfContext::getInstance();

$controller = new myController($context);

// new methods via sfEventDispatcher
require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php');
$dispatcherTest = new sfEventDispatcherTest($t);
$dispatcherTest->launchTests($context->getEventDispatcher(), $controller, 'controller');