summaryrefslogtreecommitdiff
path: root/tests/unit/Web/THttpCookieCollectionTest.php
blob: 4ddc4da32a1dd89742944e8ab8c48912ed6c2ff1 (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
51
52
53
<?php

use Prado\Exceptions\TInvalidDataTypeException;
use Prado\Exceptions\TInvalidDataValueException;
use Prado\Web\THttpCookie;
use Prado\Web\THttpCookieCollection;


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

  public function testConstruct() {
    $coll=new THttpCookieCollection();
    self::assertInstanceOf('Prado\\Web\\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'));
  }
}