friendica-addons/dav/sabre-vobject/tests/Sabre/VObject/PropertyTest.php

294 lines
7.8 KiB
PHP
Raw Normal View History

2012-06-03 18:19:28 +00:00
<?php
namespace Sabre\VObject;
class PropertyTest extends \PHPUnit_Framework_TestCase {
2012-06-03 18:19:28 +00:00
public function testToString() {
$property = new Property('propname','propvalue');
2012-06-03 18:19:28 +00:00
$this->assertEquals('PROPNAME', $property->name);
$this->assertEquals('propvalue', $property->value);
$this->assertEquals('propvalue', $property->__toString());
$this->assertEquals('propvalue', (string)$property);
}
public function testParameterExists() {
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$this->assertTrue(isset($property['PARAMNAME']));
$this->assertTrue(isset($property['paramname']));
$this->assertFalse(isset($property['foo']));
}
public function testParameterGet() {
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']);
2012-06-03 18:19:28 +00:00
}
public function testParameterNotExists() {
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$this->assertInternalType('null',$property['foo']);
}
public function testParameterMultiple() {
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']);
2012-06-03 18:19:28 +00:00
$this->assertEquals(2,count($property['paramname']));
}
public function testSetParameterAsString() {
$property = new Property('propname','propvalue');
2012-06-03 18:19:28 +00:00
$property['paramname'] = 'paramvalue';
$this->assertEquals(1,count($property->parameters));
$this->assertInstanceOf('Sabre\\VObject\\Parameter', $property->parameters[0]);
2012-06-03 18:19:28 +00:00
$this->assertEquals('PARAMNAME',$property->parameters[0]->name);
$this->assertEquals('paramvalue',$property->parameters[0]->value);
}
/**
* @expectedException InvalidArgumentException
*/
public function testSetParameterAsStringNoKey() {
$property = new Property('propname','propvalue');
2012-06-03 18:19:28 +00:00
$property[] = 'paramvalue';
}
public function testSetParameterObject() {
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$property[] = $param;
$this->assertEquals(1,count($property->parameters));
$this->assertEquals($param, $property->parameters[0]);
}
/**
* @expectedException InvalidArgumentException
*/
public function testSetParameterObjectWithKey() {
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$property['key'] = $param;
}
/**
* @expectedException InvalidArgumentException
*/
public function testSetParameterObjectRandomObject() {
$property = new Property('propname','propvalue');
$property[] = new \StdClass();
2012-06-03 18:19:28 +00:00
}
public function testUnsetParameter() {
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$property->parameters[] = $param;
unset($property['PARAMNAME']);
$this->assertEquals(0,count($property->parameters));
}
public function testParamCount() {
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
2012-06-03 18:19:28 +00:00
$property->parameters[] = $param;
$property->parameters[] = clone $param;
$this->assertEquals(2,count($property->parameters));
}
public function testSerialize() {
$property = new Property('propname','propvalue');
2012-06-03 18:19:28 +00:00
$this->assertEquals("PROPNAME:propvalue\r\n",$property->serialize());
}
public function testSerializeParam() {
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$property->parameters[] = new Parameter('paramname2','paramvalue2');
2012-06-03 18:19:28 +00:00
$this->assertEquals("PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propvalue\r\n",$property->serialize());
}
public function testSerializeNewLine() {
$property = new Property('propname',"line1\nline2");
2012-06-03 18:19:28 +00:00
$this->assertEquals("PROPNAME:line1\\nline2\r\n",$property->serialize());
}
public function testSerializeLongLine() {
$value = str_repeat('!',200);
$property = new Property('propname',$value);
2012-06-03 18:19:28 +00:00
$expected = "PROPNAME:" . str_repeat('!',66) . "\r\n " . str_repeat('!',74) . "\r\n " . str_repeat('!',60) . "\r\n";
$this->assertEquals($expected,$property->serialize());
}
public function testSerializeUTF8LineFold() {
$value = str_repeat('!',65) . "\xc3\xa4bla"; // inserted umlaut-a
$property = new Property('propname', $value);
2012-06-03 18:19:28 +00:00
$expected = "PROPNAME:" . str_repeat('!',65) . "\r\n \xc3\xa4bla\r\n";
$this->assertEquals($expected, $property->serialize());
}
public function testGetIterator() {
$it = new ElementList(array());
$property = new Property('propname','propvalue');
$property->setIterator($it);
2012-06-03 18:19:28 +00:00
$this->assertEquals($it,$property->getIterator());
}
public function testGetIteratorDefault() {
$property = new Property('propname','propvalue');
2012-06-03 18:19:28 +00:00
$it = $property->getIterator();
$this->assertTrue($it instanceof ElementList);
2012-06-03 18:19:28 +00:00
$this->assertEquals(1,count($it));
}
function testAddScalar() {
$property = new Property('EMAIL');
2012-06-03 18:19:28 +00:00
$property->add('myparam','value');
$this->assertEquals(1, count($property->parameters));
$this->assertTrue($property->parameters[0] instanceof Parameter);
2012-06-03 18:19:28 +00:00
$this->assertEquals('MYPARAM',$property->parameters[0]->name);
$this->assertEquals('value',$property->parameters[0]->value);
}
function testAddParameter() {
$prop = new Property('EMAIL');
2012-06-03 18:19:28 +00:00
$prop->add(new Parameter('MYPARAM','value'));
2012-06-03 18:19:28 +00:00
$this->assertEquals(1, count($prop->parameters));
$this->assertEquals('MYPARAM',$prop['myparam']->name);
}
function testAddParameterTwice() {
$prop = new Property('EMAIL');
2012-06-03 18:19:28 +00:00
$prop->add(new Parameter('MYPARAM', 'value1'));
$prop->add(new Parameter('MYPARAM', 'value2'));
2012-06-03 18:19:28 +00:00
$this->assertEquals(2, count($prop->parameters));
$this->assertEquals('MYPARAM',$prop['MYPARAM']->name);
}
/**
* @expectedException InvalidArgumentException
*/
function testAddArgFail() {
$prop = new Property('EMAIL');
$prop->add(new Parameter('MPARAM'),'hello');
2012-06-03 18:19:28 +00:00
}
/**
* @expectedException InvalidArgumentException
*/
function testAddArgFail2() {
$property = new Property('EMAIL','value');
2012-06-03 18:19:28 +00:00
$property->add(array());
}
/**
* @expectedException InvalidArgumentException
*/
function testAddArgFail3() {
$property = new Property('EMAIL','value');
2012-06-03 18:19:28 +00:00
$property->add('hello',array());
}
function testClone() {
$property = new Property('EMAIL','value');
2012-06-03 18:19:28 +00:00
$property['FOO'] = 'BAR';
$property2 = clone $property;
$property['FOO'] = 'BAZ';
$this->assertEquals('BAR', (string)$property2['FOO']);
}
function testCreateParams() {
$property = Property::create('X-PROP', 'value', array(
'param1' => 'value1',
'param2' => array('value2', 'value3')
));
$this->assertEquals(1, count($property['PARAM1']));
$this->assertEquals(2, count($property['PARAM2']));
}
2012-06-03 18:19:28 +00:00
}