summaryrefslogtreecommitdiff
path: root/tests/unit/Web/THttpCookieCollectionTest.php
blob: 68ea877709fa3a02e1b68be3f29fd48c6068dbc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

Prado::using('System.Web.THttpRequest');

/**
 * @package System.Web
 */
class THttpCookieCollectionTest extends PHPUnit_Framework_TestCase {

  public function testConstruct() {
    $coll=new THttpCookieCollection();
    self::assertInstanceOf('THttpCookieCollection', $coll);
  }

  public function testInsertAt() {
    $coll=new THttpCookieCollection();
    $coll->insertAt(0, new THttpCookie('name','value'));
    self::assertEquals('value',$coll->itemAt(0)->getValue());
    try {
    	$coll->insertAt(1, "bad parameter");
    	self::fail ('Invalid data type exception not raised');
    } catch (TInvalidDataTypeException $e) {}
  }

  public function testRemoveAt() {
    $coll=new THttpCookieCollection();
    try {
    	$coll->removeAt(0);
    	self::fail('Invalid Value exception not raised');
    } catch (TInvalidDataValueException $e) {}
    
    $coll->insertAt(0, new THttpCookie('name','value'));
    self::assertEquals('value',$coll->removeAt(0)->getValue());
  }

  public function testItemAt() {
    $coll=new THttpCookieCollection();
    $coll->insertAt(0, new THttpCookie('name','value'));
    self::assertEquals('value',$coll->itemAt(0)->getValue());
    self::assertEquals('value',$coll->itemAt('name')->getValue());
  }

  public function testFindCookieByName() {
    $coll=new THttpCookieCollection();
    $coll->insertAt(0, new THttpCookie('name','value'));
    self::assertEquals ('value', $coll->findCookieByName('name')->getValue());
    self::assertNull ($coll->findCookieByName('invalid'));
  }
}
?>