Location: PHPKode > projects > TeamSpeak3-Library > devMX-TeamSpeak3-Library-e93460b/test/src/devmx/Teamspeak3/Query/ResponseTest.php
<?php

namespace devmx\Teamspeak3\Query;


/**
 * Test class for Response.
 * Generated by PHPUnit on 2011-10-29 at 14:49:53.
 */
class ResponseTest extends \PHPUnit_Framework_TestCase
{

    /**
     * @var Response
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
        $this->object = new Response();
        $this->items = Array( Array("cid" => 1, "name"=>"foo") , Array("cid" => 2, "name" => "bar") ) ;
        $this->object->setItems($this->items);
    }
    
    /**
     * tests if items given in constructor are returned right
     */
    public function testGetItems()
    {
        $this->assertEquals($this->items, $this->object->getItems());
    }

    /**
     * tests if item given in constructor is returned right
     */
    public function testGetItem()
    {
        $this->assertEquals($this->items[0], $this->object->getItem(0));
        $this->assertEquals('sthelse', $this->object->getItem(1234,'sthelse'));
    }

    /**
     * tests if a value given in the constructor is returned right
     */
    public function testGetValue()
    {
       $this->assertEquals($this->items[0]['cid'], $this->object->getValue('cid',0));
       $this->assertEquals('sthelse', $this->object->getValue('cdf',1234,'sthelse'));
    }

    /**
     * tests if response is converted into assocative array correctly
     */
    public function testToAssoc()
    {
       $assoc = Array(1 => Array("cid" => 1, "name"=>"foo"), 2 => Array("cid" => 2, "name" => "bar"));
       $this->assertEquals($assoc, $this->object->toAssoc("cid"));

    }
    
    public function testIterator() {
        foreach($this->object as $key=>$value) {
            $this->assertEquals($this->items[$key], $value);
        }
    }
    
    public function testCount() {
        $this->assertEquals(count($this->items), count($this->object));
    }
    
    public function testIneffectiveSet() {
        unset($this->object[1]);
        $this->assertEquals($this->items[1],$this->object[1]);
        $this->object[1] = 'asdf';
        $this->assertEquals($this->items[1],$this->object[1]);
    }
    
    public function testOffsetExists() {
        $this->assertTrue(isset($this->object[1]));
        $this->assertFalse(isset($this->object[123]));
    }
    
    public function test0Shortcut() {
        $this->assertTrue(isset($this->object['cid']));
        $this->assertEquals(1,$this->object['cid']);
    }
    
    public function testRawResponse() {
        $this->object->setRawResponse('foo bar baz');
        $this->assertEquals('foo bar baz', $this->object->getRawResponse());
    }

    
}

?>
Return current item: TeamSpeak3-Library