diff options
Diffstat (limited to 'tests/UnitTests/framework/Web')
-rw-r--r-- | tests/UnitTests/framework/Web/UI/utControl.php | 416 | ||||
-rw-r--r-- | tests/UnitTests/framework/Web/UI/utJavascriptSerializer.php | 181 | ||||
-rw-r--r-- | tests/UnitTests/framework/Web/utHttpRequest.php | 268 |
3 files changed, 0 insertions, 865 deletions
diff --git a/tests/UnitTests/framework/Web/UI/utControl.php b/tests/UnitTests/framework/Web/UI/utControl.php deleted file mode 100644 index ed2ddd22..00000000 --- a/tests/UnitTests/framework/Web/UI/utControl.php +++ /dev/null @@ -1,416 +0,0 @@ -<?php
-
-require_once(PRADO_DIR.'/Collections/TList.php');
-require_once(PRADO_DIR.'/Collections/TMap.php');
-require_once(PRADO_DIR.'/Web/UI/TControl.php');
-
-class TContext extends TComponent
-{
- public static $_instance=null;
- public function __construct()
- {
- if(self::$_instance)
- throw new Exception('....');
- self::$_instance=$this;
- }
-
- public static function getInstance()
- {
- return self::$_instance;
- }
-}
-
-class ContainerControl extends TControl implements INamingContainer
-{
-}
-
-class PageControl extends TControl implements INamingContainer
-{
- public $eventRaised=false;
- private $_context;
-
- function __construct($context)
- {
- $this->setPage($this);
- $this->_context=$context;
- }
-
- public function getContext()
- {
- return $this->_context;
- }
-
- public function clicked($sender,$param)
- {
- $this->eventRaised=true;
- }
-
- public function getContainsTheme()
- {
- return false;
- }
-
- public function runTo($lifecycle)
- {
- switch($lifecycle)
- {
- case 'init':
- $this->initRecursive(null);
- break;
- case 'load':
- $this->initRecursive(null);
- $this->loadRecursive();
- break;
- case 'prerender':
- $this->initRecursive(null);
- $this->loadRecursive();
- $this->preRenderRecursive();
- break;
- }
- }
-}
-
-class WebControl extends TControl
-{
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- public function setText($value)
- {
- return $this->setViewState('Text',$value,'');
- }
-
- public function getData()
- {
- return $this->getControlState('Data','');
- }
-
- public function setData($value)
- {
- $this->setControlState('Data',$value,'');
- }
-
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-}
-
-class utControl extends UnitTestCase
-{
- private $context;
- private $button1;
- private $button2;
- private $page;
- private $form;
- private $panel;
-
- public function setUp()
- {
- // we mock up a page consisting of a form which encloses a panel.
- // in the panel there are two buttons, button1 and button2
- // The panel is a naming container
- $this->context=new TContext;
- $this->page=new PageControl($this->context);
- $this->form=new WebControl;
- $this->panel=new ContainerControl;
- $this->button1=new WebControl;
- $this->button2=new WebControl;
- $this->form->setTemplateControl($this->page);
- $this->panel->setTemplateControl($this->page);
- $this->button1->setTemplateControl($this->page);
- $this->button2->setTemplateControl($this->page);
- $this->page->getControls()->add($this->form);
- $this->form->getControls()->add($this->panel);
- $this->panel->getControls()->add($this->button1);
- $this->panel->getControls()->add($this->button2);
- $this->button1->setID('button1');
- $this->page->declareObject('button1',$this->button1);
- }
-
- public function tearDown()
- {
- $this->page=null;
- $this->form=null;
- $this->panel=null;
- $this->button1=null;
- $this->button2=null;
- $this->context=null;
- TContext::$_instance=null;
- }
-
- public function testOverload()
- {
- $this->assertEqual($this->page->button1,$this->button1);
- try
- {
- $button=$this->page->button2;
- $this->fail('non exception raised when accessing non-declared control');
- }
- catch(TInvalidOperationException $e)
- {
- $this->pass();
- }
- }
-
- public function testParent()
- {
- $this->assertEqual(null,$this->page->getParent());
- $this->assertEqual($this->page,$this->form->getParent());
- }
-
- public function testNamingContainer()
- {
- $this->assertEqual(null,$this->page->getNamingContainer());
- $this->assertEqual($this->page,$this->panel->getNamingContainer());
- $this->assertEqual($this->panel,$this->button1->getNamingContainer());
- }
-
- public function testPage()
- {
- $this->assertEqual($this->page,$this->page->getPage());
- $this->assertEqual($this->page,$this->panel->getPage());
- $this->assertEqual($this->page,$this->button1->getPage());
- }
-
- public function testTemplateControl()
- {
- $this->assertEqual(null,$this->page->getTemplateControl());
- $this->assertEqual($this->page,$this->panel->getTemplateControl());
- $this->assertEqual($this->page,$this->button1->getTemplateControl());
- }
-
- public function testContext()
- {
- $this->assertEqual($this->context,$this->button1->getContext());
- }
-
- public function testSkinID()
- {
- $this->assertEqual('',$this->button1->getSkinID());
- $this->button1->setSkinID('buttonSkin');
- $this->assertEqual('buttonSkin',$this->button1->getSkinID());
- $this->page->runTo('init');
- try
- {
- $this->button1->setSkinID('buttonSkin2');
- $this->fail('no exception raised when SkinID is set after PreInit');
- }
- catch(TInvalidOperationException $e)
- {
- $this->pass();
- }
- }
-
- public function testID()
- {
- $this->assertEqual('button1',$this->button1->getID());
- $this->assertEqual('',$this->button2->getID());
- $this->assertEqual('ctl1',$this->button2->getID(false));
- $this->button2->setID('button2');
- $this->assertEqual('button2',$this->button2->getID());
- try
- {
- $this->button2->setID('123');
- $this->fail('exception not raised when control is set with an invalid ID');
- }
- catch(TInvalidDataValueException $e)
- {
- $this->pass();
- }
- }
-
- public function testUniqueID()
- {
- $sep=TControl::ID_SEPARATOR;
- $this->assertEqual('ctl0',$this->form->getUniqueID());
- $this->assertEqual('ctl1',$this->panel->getUniqueID());
- $this->assertEqual('ctl1'.$sep.'button1',$this->button1->getUniqueID());
- $this->assertEqual('ctl1'.$sep.'ctl1',$this->button2->getUniqueID());
- $this->button2->setID('button2');
- $this->assertEqual('ctl1'.$sep.'button2',$this->button2->getUniqueID());
- $this->panel->setID('panel');
- $this->assertEqual('panel'.$sep.'button2',$this->button2->getUniqueID());
- }
-
- public function testEnableTheming()
- {
- $this->assertEqual(true,$this->button1->getEnableTheming());
- $this->page->setEnableTheming(false);
- $this->assertEqual(false,$this->button1->getEnableTheming());
- $this->page->setEnableTheming(true);
- $this->assertEqual(true,$this->button1->getEnableTheming());
- $this->button1->setEnableTheming(false);
- $this->assertEqual(false,$this->button1->getEnableTheming());
-
- $this->page->runTo('init');
- try
- {
- $this->button1->setEnableTheming(true);
- $this->fail('no exception raised when EnableTheming is set after PreInit');
- }
- catch(TInvalidOperationException $e)
- {
- $this->pass();
- }
- }
-
- public function testHasControls()
- {
- $this->assertEqual(true,$this->page->getHasControls());
- $this->assertEqual(false,$this->button1->getHasControls());
- }
-
- public function testControls()
- {
- $this->assertEqual(1,$this->page->getControls()->getCount());
- $control=new WebControl;
- $this->panel->getControls()->add($control);
- $this->assertEqual(3,$this->panel->getControls()->getCount());
- $this->panel->getControls()->remove($this->button1);
- $this->assertEqual(2,$this->panel->getControls()->getCount());
- }
-
- public function testVisible()
- {
- $this->assertEqual(true,$this->button1->getVisible());
- $this->page->setVisible(false);
- $this->assertEqual(false,$this->button1->getVisible());
- $this->page->setVisible(true);
- $this->assertEqual(true,$this->button1->getVisible());
- $this->button1->setVisible(false);
- $this->assertEqual(false,$this->button1->getVisible());
- }
-
- public function testEnabled()
- {
- $this->assertEqual(true,$this->button1->getEnabled());
- $this->page->setEnabled(false);
- $this->assertEqual(true,$this->button1->getEnabled());
- $this->assertEqual(false,$this->button1->getEnabled(true));
- $this->page->setEnabled(true);
- $this->assertEqual(true,$this->button1->getEnabled(true));
- $this->button1->setEnabled(false);
- $this->assertEqual(false,$this->button1->getEnabled(true));
- $this->assertEqual(false,$this->button1->getEnabled());
- }
-
- public function testHasAttributes()
- {
- $this->assertEqual(false,$this->button1->getHasAttributes());
- $this->button1->getAttributes()->add('name','value');
- $this->assertEqual(true,$this->button1->getHasAttributes());
- $this->button1->getAttributes()->clear();
- $this->assertEqual(false,$this->button1->getHasAttributes());
- }
-
- public function testAttributes()
- {
- $this->assertEqual(0,$this->button1->getAttributes()->getCount());
- $this->button1->getAttributes()->add('name1','value1');
- $this->button1->getAttributes()->add('name2','value2');
- $this->assertEqual(2,$this->button1->getAttributes()->getCount());
- $this->button1->getAttributes()->remove('name1');
- $this->assertEqual(1,$this->button1->getAttributes()->getCount());
- }
-
- public function testEnableViewState()
- {
- $this->assertEqual(true,$this->button1->getEnableViewState());
- $this->button1->setEnableViewState(false);
- $this->assertEqual(false,$this->button1->getEnableViewState());
-
- }
-
- public function testViewState()
- {
- $this->assertEqual('',$this->button1->getText());
- $this->button1->setText('abc');
- $this->assertEqual('abc',$this->button1->getText());
- }
-
- public function testControlState()
- {
- $this->assertEqual('',$this->button1->getData());
- $this->button1->setData('abc');
- $this->assertEqual('abc',$this->button1->getData());
- }
-
- public function testEventScheme()
- {
- $this->assertEqual(true,$this->button1->hasEvent('OnClick'));
- $this->assertEqual(false,$this->button1->hasEvent('Click'));
- $this->button1->attachEventHandler('OnClick','Page.clicked');
- $this->assertEqual(false,$this->page->eventRaised);
- $this->button1->raiseEvent('OnClick',$this,null);
- $this->assertEqual(true,$this->page->eventRaised);
- $this->button1->getEventHandlers('OnClick')->clear();
- try
- {
- $this->button1->attachEventHandler('OnClick','clicked');
- $this->fail('no exception raised when undefined event is raised');
- }
- catch(TInvalidOperationException $e)
- {
- $this->pass();
- }
- $this->assertEqual(0,$this->button1->getEventHandlers('OnClick')->getCount());
- $this->button1->attachEventHandler('OnClick','Pages.clicked');
- try
- {
- $this->button1->raiseEvent('OnClick',$this,null);
- $this->fail('no exception raised when undefined event handler is invoked');
- }
- catch(TInvalidOperationException $e)
- {
- $this->pass();
- }
- }
-
- public function testDataBindingScheme()
- {
- $this->button1->bindProperty('Text','"abc"."def"');
- $this->button1->dataBind();
- $this->assertEqual('abcdef',$this->button1->getText());
- $this->button2->bindProperty('Text','"abc"."def"');
- $this->button2->unbindProperty('Text');
- $this->button2->dataBind();
- $this->assertEqual('',$this->button2->getText());
- $this->button1->bindProperty('Texts','"abc"."def"');
- try
- {
- $this->button1->dataBind();
- $this->fail('no exception raised for invalid databinding');
- }
- catch(TInvalidOperationException $e)
- {
- $this->pass();
- }
- }
-
- public function testFindControl()
- {
- $this->assertEqual($this->button1,$this->panel->findControl('button1'));
- $this->assertEqual(null,$this->panel->findControl('button2'));
- $this->assertEqual($this->button1,$this->page->findControl($this->panel->getID(false).TControl::ID_SEPARATOR.'button1'));
- $this->button1->setID('button3');
- $this->assertEqual($this->button1,$this->panel->findControl('button3'));
- }
-
- public function testAddRemoveControl()
- {
-
- }
-}
-
-
-if(!defined('RUN_ALL_TESTS'))
-{
- $className=basename(__FILE__,'.php');
- $test = new $className;
- $test->run(new HtmlReporter());
-}
-
-?>
\ No newline at end of file diff --git a/tests/UnitTests/framework/Web/UI/utJavascriptSerializer.php b/tests/UnitTests/framework/Web/UI/utJavascriptSerializer.php deleted file mode 100644 index 89a54820..00000000 --- a/tests/UnitTests/framework/Web/UI/utJavascriptSerializer.php +++ /dev/null @@ -1,181 +0,0 @@ -<?php
-
-require_once(PRADO_DIR.'/Web/Javascripts/TJavascriptSerializer.php');
-
-class testSerializerObject
-{
- public $public = 'public data';
- protected $protected = 'protected data';
- private $private = 'private !';
-}
-
-class testComponentObject extends TComponent
-{
- public $public = 'public data';
- protected $protected = 'protected data';
- private $private = 'private !';
-
- public function getData()
- {
- return "component data";
- }
-}
-
-class utJavascriptSerializer extends UnitTestCase
-{
- function testString()
- {
- $string = "Stan's world!";
- $expect = "'Stan\\'s world!'";
- $js = new TJavascriptSerializer($string);
- $this->assertEqual($expect, $js->toJavascript());
-
- $string = "";
- $expect = "''";
- $js = new TJavascriptSerializer($string);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
- function testInteger()
- {
- $int = 10;
- $expect = "10";
- $js = new TJavascriptSerializer($int);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
- function testFloat()
- {
- $float = 10.2;
- $expect = "10.2";
- $js = new TJavascriptSerializer($float);
- $this->assertEqual($expect, $js->toJavascript());
-
- $float = INF;
- $expect = "Number.POSITIVE_INFINITY";
- $js = new TJavascriptSerializer($float);
- $this->assertEqual($expect, $js->toJavascript());
-
- $expect = "Number.NEGATIVE_INFINITY";
- $js = new TJavascriptSerializer(-$float);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
- function testBoolean()
- {
- $bool = false;
- $expect = "false";
- $js = new TJavascriptSerializer($bool);
- $this->assertEqual($expect, $js->toJavascript());
-
- $expect = "true";
- $js = new TJavascriptSerializer(!$bool);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
- function testNull()
- {
- $null = null;
- $expect = "null";
- $js = new TJavascriptSerializer($null);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
- function testArray()
- {
- $data[0] = 1;
- $data[1] = "hello";
- $data[2] = 1.20;
- $data[3] = true;
- $data[4] = false;
- $data[5] = null;
- $data[6] = array("one");
-
- $expect = "[1,'hello',1.2,true,false,null,['one']]";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toJavascript());
-
- $data = array();
- $expect = "[]";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toJavascript(true));
- }
-
- function testMap()
- {
- $data['hello'] = 'world';
- $data['more'] = array('yes' => 'yah!');
- $expect = "{'hello':'world','more':{'yes':'yah!'}}";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toMap());
- }
-
- function testObject()
- {
- $data = new testSerializerObject;
- $expect = "{'public':'public data'}";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
- //should not serialize components!
- function testComponent()
- {
- $data = new testComponentObject;
- $expect = "{'public':'public data','Data':'component data'}";
- $js = new TJavascriptSerializer($data);
- try
- {
- $js->toJavascript();
- $this->fail();
- }
- catch(TException $e)
- {
- $this->pass();
- }
- }
-
- function testComplexStrings()
- {
- $data[] = "\"It's slash \/ wonderful\"";
- $expect = "['\\\"It\'s slash \\\\/ wonderful\\\"']";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
-
- function testArrayString()
- {
- $data[] = "['hello', 1]";
- $data[] = "{'asd':'asdasd'}";
- $data[] = "[hasdkj}";
- $expect = "[['hello', 1],{'asd':'asdasd'},'[hasdkj}']";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toJavascript());
- }
-
- function testArrayComplex()
- {
- $data = array("hello", 1, 2.12, array("world", null, "", array()));
- $expect = "['hello',1,2.12,['world',null]]";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toJavascript());
-
- $expect = "['hello',1,2.12,['world',null,'',[]]]";
- $this->assertEqual($expect, $js->toJavascript(true));
- }
-
- function testListComplex()
- {
- $data = array("hello"=>"world", 1, 2.12);
- $data["more"] = array("the" => "world", null, "good"=>"", array());
- $expect = "{'hello':'world','0':1,'1':2.12,'more':{'the':'world','0':null}}";
- $js = new TJavascriptSerializer($data);
- $this->assertEqual($expect, $js->toMap());
-
- $expect = "{'hello':'world','0':1,'1':2.12,'more':{'the':'world','0':null,'good':'','1':{}}}";
- $this->assertEqual($expect, $js->toMap(true));
- }
-}
-
-?>
\ No newline at end of file diff --git a/tests/UnitTests/framework/Web/utHttpRequest.php b/tests/UnitTests/framework/Web/utHttpRequest.php deleted file mode 100644 index 3da58a69..00000000 --- a/tests/UnitTests/framework/Web/utHttpRequest.php +++ /dev/null @@ -1,268 +0,0 @@ -<?php - -require_once(dirname(__FILE__).'/../common.php'); - -class utHttpRequest extends ModuleTestCase { - - /** - * @var THttpRequest protected. The THttpRequest object we're using for testing. - */ - protected $request; - - - public function testSetUp() { - $this->request =& new THttpRequest(); - $this->module =& $this->request; // $this->module is used automatically by the underlying class - $this->initModule($this->defaultConfig); - } - - public function tearDown() { - $this->request = null; - parent::tearDown(); - } - - public function testInit($application,$config) { - // Configuration case 1... - $_SERVER = array( - "REQUEST_URI" => "/foo.php?bar", - "SCRIPT_NAME" => "/foo.php", - "QUEST_STRING" => "bar", - "PATH_INFO" => "/foo.php", - "PHP_SELF" => "/foo.php", - ); - $this->mockApplication->expectOnce("setRequest"); - $this->initModule(); - $this->mockApplication->tally(); - $this->assertIsA($this->request->getItems(), "TMap"); - - $this->assertEqual($this->request->getRequestUri(), "/foo.php?bar"); - $this->assertEqual($this->request->getPathInfo(), "/foo.php"); - - $_SERVER = array( - "REQUEST_URI" => "/aaa/bbb/ccc/foo.php?bar", - "SCRIPT_NAME" => "", - "QUEST_STRING" => "", - "PATH_INFO" => "/aaa/bbb/ccc/foo.php", - "PHP_SELF" => "/aaa/bbb/ccc/foo.php", - ); - $this->initModule(); - $this->assertEqual($this->request->getRequestUri(), "/aaa/bbb/ccc/foo.php?bar"); - $this->assertEqual($this->request->getPathInfo(), "/aaa/bbb/ccc/foo.php"); - - $_SERVER = array( - "SCRIPT_NAME" => "/foo.php", - "QUEST_STRING" => "bar", - "PATH_INFO" => "", - "PHP_SELF" => "/foo.php", - ); - $this->initModule(); - $this->assertEqual($this->request->getRequestUri(), "/foo.php?bar"); - $this->assertEqual($this->request->getPathInfo(), "/foo.php"); - - $_SERVER = array( - "REQUEST_URI" => "/foo.php?bar", - "PATH_INFO" => "/foo.php?bar", - ); - $this->initModule(); - $this->assertEqual($this->request->getRequestUri(), "/foo.php?bar"); - $this->assertEqual($this->request->getPathInfo(), "/foo.php"); - } - - /*public function testGetUrl() { - if($this->_url===null) - { - $secure=$this->getIsSecureConnection(); - $url=$secure?'https://':'http://'; - if(empty($_SERVER['HTTP_HOST'])) - { - $url.=$_SERVER['SERVER_NAME']; - $port=$_SERVER['SERVER_PORT']; - if(($port!=80 && !$secure) || ($port!=443 && $secure)) - $url.=':'.$port; - } - else - $url.=$_SERVER['HTTP_HOST']; - $url.=$this->getRequestUri(); - $this->_url=new TUri($url); - } - return $this->_url; - }*/ - - public function testGetRequestType() { - $_SERVER = array("REQUEST_METHOD" => "GET"); - $this->assertEqual($this->request->getRequestType(), "GET"); - } - - public function testGetIsSecureConnection() { - $_SERVER = array("HTTPS" => "true"); - $this->assertTrue($this->request->getIsSecureConnection()); - $_SERVER = array("HTTPS" => ""); - $this->assertFalse($this->request->getIsSecureConnection()); - $_SERVER = array(); - $this->assertFalse($this->request->getIsSecureConnection()); - } - - public function testGetQueryString() { - $_SERVER = array("QUERY_STRING" => "foo=bar"); - $this->assertEqual($this->request->getQueryString(), "foo=bar"); - $_SERVER = array("QUERY_STRING" => ""); - $this->assertEqual($this->request->getQueryString(), ""); - $_SERVER = array(); - $this->assertEqual($this->request->getQueryString(), ""); - } - - public function testGetApplicationPath() { - $_SERVER = array("SCRIPT_NAME" => "/foo/bar.php"); - $this->assertEqual($this->request->getApplicationPath(), "/foo/bar.php"); - } - - public function testGetPhysicalApplicationPath() { - $_SERVER = array("SCRIPT_FILENAME" => "/var/www/foo.php"); - $this->assertEqual($this->request->getPhysicalApplicationPath(), "/var/www/foo.php"); - $_SERVER = array("SCRIPT_FILENAME" => "C:\\web\\foo.php"); - $this->assertEqual($this->request->getPhysicalApplicationPath(), "/web/foo.php"); - } - - public function testGetServerName() { - $_SERVER = array("SERVER_NAME" => "foobar"); - $this->assertEqual($this->request->getApplicationPath(), "foobar"); - } - - public function testGetServerPort() { - $_SERVER = array("SERVER_PORT" => "80"); - $this->assertEqual($this->request->getApplicationPath(), 80); - } - - public function testGetUrlReferrer() { - $_SERVER = array("HTTP_REFERRER" => "http://www.google.com/"); - $this->assertEqual($this->request->getPhysicalApplicationPath(), "http://www.google.com/"); - $_SERVER = array(); - $this->assertNull($this->request->getPhysicalApplicationPath()); - } - - /*public function testGetBrowser() { - return get_browser(); - }*/ - - public function testGetUserAgent() { - $_SERVER = array("HTTP_USER_AGENT" => "foo"); - $this->assertEqual($this->request->getUserAgent(), "foo"); - } - - public function testGetUserHostAddress() { - $_SERVER = array("REMOTE_ADDR" => "121.212.121.212"); - $this->assertEqual($this->request->getUserHostAddress(), "121.212.121.212"); - } - - public function testGetUserHost() { - $_SERVER = array("REMOTE_ADDR" => "foo"); - $this->assertEqual($this->request->getUserHostAddress(), "foo"); - $_SERVER = array(); - $this->assertNull($this->request->getUserHostAddress()); - } - - public function testGetAcceptTypes() { - $_SERVER = array("REMOTE_ADDR" => "foo bar"); - $this->assertEqual($this->request->getAcceptTypes(), "foo bar"); - } - - public function testGetUserLanguages() { - $_SERVER = array("HTTP_ACCEPT_LANGUAGE" => "foo"); - $this->assertEqual($this->request->getUserLanguages(), "foo"); - } - - public function testGetCookies() { - $_COOKIES = array("foo" => "bar", "xxx" => "yyy"); - - // Repeat this twice. The first time tests the parsing logic for $_COOKIES. - // The second time tests the internal caching logic. - for ($i = 0; $i < 2; $i++) { - $cookies = $this->request->getCookies(); - $this->assertIsA($cookies, "THttpCookieCollection"); - $this->asserEqual($cookies->getCount(), 2); - $first = $cookies->itemAt(0); - $this->assertEqual($first->getName(), "foo"); - $this->assertEqual($first->getName(), "bar"); - $second = $cookies->itemAt(0); - $this->assertEqual($second->getName(), "xxx"); - $this->assertEqual($second->getName(), "yyy"); - } - } - - /*public function testGetUploadedFiles() { - if($this->_files===null) - $this->_files=new TMap($_FILES); - return $this->_files; - } - - public function testGetServerVariables() { - if($this->_server===null) - $this->_server=new TMap($_SERVER); - return $this->_server; - } - - public function testGetEnvironmentVariables() { - if($this->_env===null) - $this->_env=new TMap($_ENV); - return $this->_env; - }*/ - - public function testConstructUrl($serviceID,$serviceParam,$getItems=null) { - $_SERVER = array("SCRIPT_NAME" => "/foo/bar.php"); - $sv = THttpRequest::SERVICE_VAR; - - // Note: we can't undefine SID so we can't ensure that the case when SID is not present will be tested. - // Therefore, we define it here so we can be sure that it *is* defined. If it was already defined before - // entering this function then this define() will be ignored. This doesn't matter as immediately after defining - // SID we read it into $sid. - define("SID", "123"); - $sid = SID; - - $this->assertEqual($this->request->constructUrl("page", ""), "/foo/bar.php?$sv=page&$sid"); - $this->assertEqual($this->request->constructUrl("page", null), "/foo/bar.php?$sv=page&$sid"); - $this->assertEqual($this->request->constructUrl("page", "myPage"), "/foo/bar.php?$sv=page.myPage&$sid"); - $this->assertEqual($this->request->constructUrl("page", "myPage", array("aaa"=>"aaa")), "/foo/bar.php?$sv=page.myPage&aaa=aaa&$sid"); - $this->assertEqual($this->request->constructUrl("page", "myPage", array("aaa"=>"aaa","bbb"=>"bbb")), "/foo/bar.php?$sv=page.myPage&aaa=aaa&bbb=bbb&$sid"); - $this->assertEqual($this->request->constructUrl("page", "myPage", new TList(array("aaa"=>"aaa"))), "/foo/bar.php?$sv=page.myPage&aaa=aaa&$sid"); - } - - protected function testResolveRequest() { - $sv = THttpRequest::SERVICE_VAR; - - $_POST = array($sv => "page"); - $this->initModule(); - $this->request->resolveRequest(); - $this->assertEqual($this->request->getServiceID(), "page"); - $this->assertEqual($this->request->getServiceParameter(), ""); - - $_POST = array($sv => "page.xxx"); - $this->initModule(); - $this->request->resolveRequest(); - $this->assertEqual($this->request->getServiceID(), "page"); - $this->assertEqual($this->request->getServiceParameter(), "xxx"); - - $_GET = array($sv => "page.xxx"); - $this->initModule(); - $this->request->resolveRequest(); - $this->assertEqual($this->request->getServiceID(), "page"); - $this->assertEqual($this->request->getServiceParameter(), "xxx"); - - $_POST = array($sv => "page"); - $this->initModule(); - $this->request->resolveRequest(); - $this->assertEqual($this->request->getServiceID(), "page"); - $this->assertEqual($this->request->getServiceParameter(), ""); - } - - public function testGetSetServiceID() { - $this->request->setServiceID("foo"); - $this->assertEqual($this->request->getServiceID(), "foo"); - } - - public function testGetSetServiceParameterD() { - $this->request->setServiceParameter("foo"); - $this->assertEqual($this->request->getServiceParameter(), "foo"); - } -} - -?>
\ No newline at end of file |