From 2c012bfe6caf5f10fe4f05a7a6f7effb17e13ee8 Mon Sep 17 00:00:00 2001 From: Milan Medlik Date: Tue, 16 Jul 2013 15:03:53 +1200 Subject: [PATCH] finaly some test passed --- inc/iCalendar.php | 4 + inc/vCalendar.php | 16 +- inc/vComponent.php | 833 +----------------------------- inc/{myProperty.php => vProperty.php} | 20 +- tests/data/0000-Setup-PUT-collection.test | 148 ++++++ tests/myCalendarTest.php | 32 +- tests/myComponentTest.php | 12 +- tests/myPropertyTest.php | 12 +- 8 files changed, 214 insertions(+), 863 deletions(-) rewrite inc/vComponent.php (100%) mode change 100644 => 120000 rename inc/{myProperty.php => vProperty.php} (94%) create mode 100644 tests/data/0000-Setup-PUT-collection.test diff --git a/inc/iCalendar.php b/inc/iCalendar.php index 9902ffc..a42b4af 100644 --- a/inc/iCalendar.php +++ b/inc/iCalendar.php @@ -804,6 +804,10 @@ class iCalComponent { return $confidential; } + function InternalRender($restricted_properties = null){ + $this->Render($restricted_properties); + } + /** * Renders the component, possibly restricted to only the listed properties diff --git a/inc/vCalendar.php b/inc/vCalendar.php index b3c23d0..ee30425 100644 --- a/inc/vCalendar.php +++ b/inc/vCalendar.php @@ -4,7 +4,7 @@ * * When parsed the underlying structure is roughly as follows: * -* vCalendar( array(vComponent), array(myProperty), array(vTimezone) ) +* vCalendar( array(vComponent), array(vProperty), array(vTimezone) ) * * with the TIMEZONE data still currently included in the component array (likely * to change in the future) and the timezone array only containing vComponent objects @@ -109,7 +109,7 @@ class vCalendar extends vComponent { /** * Get the organizer of this VEVENT/VTODO - * @return myProperty The Organizer property. + * @return vProperty The Organizer property. */ function GetOrganizer() { if ( !isset($this->organizer) ) { @@ -127,7 +127,7 @@ class vCalendar extends vComponent { /** * Get the schedule-agent from the organizer - * @return myProperty The schedule-agent parameter + * @return vProperty The schedule-agent parameter */ function GetScheduleAgent() { if ( !isset($this->schedule_agent) ) $this->GetOrganizer(); @@ -159,9 +159,9 @@ class vCalendar extends vComponent { /** * Update the attendees of this VEVENT/VTODO * @param string $email The e-mail address of the attendee to be updated. - * @param myProperty $statusProperty A replacement property. + * @param vProperty $statusProperty A replacement property. */ - function UpdateAttendeeStatus( $email, myProperty $statusProperty ) { + function UpdateAttendeeStatus( $email, vProperty $statusProperty ) { foreach($this->GetComponents() AS $ck => $v ) { if ($v->GetType() == 'VEVENT' || $v->GetType() == 'VTODO' ) { $new_attendees = array(); @@ -186,9 +186,9 @@ class vCalendar extends vComponent { /** * Update the ORGANIZER of this VEVENT/VTODO - * @param myProperty $statusProperty A replacement property. + * @param vProperty $statusProperty A replacement property. */ - function UpdateOrganizerStatus( myProperty $statusProperty ) { + function UpdateOrganizerStatus( vProperty $statusProperty ) { $this->rendered = null; foreach($this->GetComponents() AS $ck => $v ) { if ($v->GetType() == 'VEVENT' || $v->GetType() == 'VTODO' ) { @@ -408,7 +408,7 @@ class vCalendar extends vComponent { */ function SetUID( $newUid ) { if ( empty($this->primary_component) ) return; - $this->primary_component->SetProperties( array( new myProperty('UID', $newUid) ), 'UID'); + $this->primary_component->SetProperties( array( new vProperty('UID', $newUid) ), 'UID'); } } diff --git a/inc/vComponent.php b/inc/vComponent.php deleted file mode 100644 index 81ce959..0000000 --- a/inc/vComponent.php +++ /dev/null @@ -1,832 +0,0 @@ -type); - - if(isset($propstring) && gettype($propstring) == 'string'){ - $this->initFromText($propstring); - } else if(isset($refData)){ - if(gettype($refData) == 'string'){ - $this->initFromText($refData); - } else if(gettype($refData) == 'object') { - $this->initFromIterator($refData); - } - } else { - $text = ''; - $this->initFromText($text); - } - - -// if(isset($this->iterator)){ -// $this->parseFrom($this->iterator); -// } - - - } - - function initFromIterator(&$iterator, $begin = -1){ - $this->iterator = &$iterator; - - //$this->seekBegin = $this->iterator->key(); - - - - $iterator = $this->iterator; - do { - $line = $iterator->current(); - $seek = $iterator->key(); - - $posStart = strpos($line, vComponent::KEYBEGIN); - if($posStart !== false && $posStart == 0){ - if(!isset($this->type)){ - $this->seekBegin = $seek; - - $this->type = substr($line, vComponent::KEYBEGINLENGTH); - } - } else { - - $posEnd = strpos($line, vComponent::KEYEND); - if($posEnd !== false && $posEnd == 0){ - $thisEnd = substr($line, vComponent::KEYENDLENGTH); - if($thisEnd == $this->type){ - $this->seekEnd = $seek; - //$iterator->next(); - $len = strlen($this->type); - $last = $this->type[$len-1]; - if($last == "\r"){ - $this->type = substr($this->type, 0, $len-1); - } - break; - } - - } else { - //$this->properties[] = new myProperty(null, $iterator, $seek); - } - } - - - - - $iterator->next(); - } while($iterator->valid()); - //$this->parseFrom($iterator); - - } - - public function getIterator(){ - return $this->iterator; - } - - function initFromText(&$plain2){ - $plain2 = &$this->UnwrapComponent($plain2); - - //$file = fopen('data.out.tmp', 'w'); - //$plain3 = preg_replace('{\r?\n}', '\r\n', $plain2 ); - //fwrite($file, $plain2); - //fclose($file); - //$lines = &explode(PHP_EOL, $plain2); -// $arrayData = new ArrayObject($lines); -// $this->iterator = &$arrayData->getIterator(); -// $this->initFromIterator($this->iterator, 0); -// unset($plain); -// unset($iterator); -// unset($arrayData); -// unset($lines); - - $this->iterator = (new ArrayObject(explode(PHP_EOL, $plain2)))->getIterator(); - unset($plain2); - //$this->initFromIterator($this->iterator); - //$this->iterator = new HeapLines($plain); - - //$this->initFromIterator(new HeapLines($plain), 0); - $this->parseFrom($this->iterator); - - } - - function rewind(){ - if(isset($this->iterator) && isset($this->seekBegin)){ - $this->iterator->seek($this->seekBegin); - } - } - - - - - function explode(){ - if((!isset($this->properties) || !isset($this->components)) && $this->isValid()){ - $this->rewind(); - $this->parseFrom($this->iterator); - } - } - - function close(){ - - if(isset($this->components)){ - foreach($this->components as $comp){ - $comp->close(); - } - } - - if($this->isValid()){ - unset($this->properties); - unset($this->components); - } - - - - } - - function parseFrom(&$iterator){ - - - $begin = $iterator->key(); - $typelen = 0; - //$count = $lines->count(); - - do{ - $line = $iterator->current(); - //$line = substr($current, 0, strlen($current) -1); - $end = $iterator->key(); - - $pos = strpos($line, vComponent::KEYBEGIN); - $callnext = true; - if($pos !== false && $pos == 0) { - $type = substr($line, vComponent::KEYBEGINLENGTH); - - if($typelen !== 0 && strncmp($this->type, $type, $typelen) !== 0){ - $this->components[] = new vComponent(null, $iterator); - $callnext = false; - } else { - // in special cases when is "\r" on end remove it - $typelen = strlen($type); - if($type[$typelen-1] == "\r"){ - $typelen--; - $this->type = substr($type, 0, $typelen); - } else { - $this->type = $type; - } - - - //$iterator->offsetUnset($end); - //$iterator->seek($begin); - //$callnext = false; - } - - } else { - $pos = strpos($line, vComponent::KEYEND); - - if($pos !== false && $pos == 0) { - $this->seekBegin = $begin; - $this->seekEnd = $end; - //$iterator->offsetUnset($end); - //$iterator->seek($end-2); - //$line2 = $iterator->current(); - //$this->seekEnd = $iterator->key(); - - //$callnext = false; - //$newheap = $lines->createLineHeapFrom($start, $end); - //$testfistline = $newheap->substr(0); - //echo "end:" . $this->key . "[$start, $end]
"; - //$lines->nextLine(); - //$iterator->offsetUnset($end); - return; - } else { -// $prstart = $lines->getSwheretartLineOnHeap(); -// $prend = -//$this->properties[] = new myProperty("AHOJ"); - $this->properties[] = new myProperty(null, $this->getMaster(), $line, $end); - //echo $this->key . ' property line' . "[$prstart,$prend]
"; - - } - } - -// if($callnext){ -// $iterator->next(); -// } - //if($callnext) - // $iterator->offsetUnset($end); - $iterator->next(); - } while($iterator->valid() && ( !isset($this->seekEnd) || $this->seekEnd > $end) ); - //$lines->getEndLineOnHeap(); - - - } - - - - /** - * count of component - * @return int - */ - public function ComponentCount(){ - $this->explode(); - return isset($this->components) ? count($this->components) : 0; - } - - /** - * count of component - * @return int - */ - public function propertiesCount(){ - $this->explode(); - return isset($this->properties) ? count($this->properties) : 0; - } - - /** - * @param $position - * @return null - whet is position out of range - */ - public function getComponentAt($position){ - $this->explode(); - if($this->ComponentCount() > $position){ - return $this->components[$position]; - } else { - return null; - } - } - - function getPropertyAt($position){ - $this->explode(); - if($this->propertiesCount() > $position){ - return $this->properties[$position]; - } else { - return null; - } - - } - - - /** - * Return the type of component which this is - */ - function GetType() { - return $this->type; - } - - - /** - * Set the type of component which this is - */ - function SetType( $type ) { - if ( $this->isValid() ) { - $this->invalidate(); - }; - $this->type = strtoupper($type); - return $this->type; - } - - - /** - * Collect an array of all parameters of our properties which are the specified type - * Mainly used for collecting the full variety of references TZIDs - */ - function CollectParameterValues( $parameter_name ) { - $this->explode(); - $values = array(); - if(isset($this->components)){ - foreach( $this->components AS $k => $v ) { - $also = $v->CollectParameterValues($parameter_name); - $values = array_merge( $values, $also ); - } - } - if(isset($this->properties)){ - foreach( $this->properties AS $k => $v ) { - $also = $v->GetParameterValue($parameter_name); - if ( isset($also) && $also != "" ) { -// dbg_error_log( 'vComponent', "::CollectParameterValues(%s) : Found '%s'", $parameter_name, $also); - $values[$also] = 1; - } - } - } - - return $values; - } - - - /** - * Return the first instance of a property of this name - */ - function GetProperty( $type ) { - $this->explode(); - foreach( $this->properties AS $k => $v ) { - if ( is_object($v) && $v->Name() == $type ) { - return $v; - } - else if ( !is_object($v) ) { - debug_error_log("ERROR", 'vComponent::GetProperty(): Trying to get %s on %s which is not an object!', $type, $v ); - } - } - /** So we can call methods on the result of this, make sure we always return a vProperty of some kind */ - return null; - } - - /** - * Return the value of the first instance of a property of this name, or null - */ - function GetPValue( $type ) { - $this->explode(); - $p = $this->GetProperty($type); - if ( isset($p) ) return $p->Value(); - return null; - } - - - /** - * Get all properties, or the properties matching a particular type, or matching an - * array associating property names with true values: array( 'PROPERTY' => true, 'PROPERTY2' => true ) - */ - function GetProperties( $type = null ) { - $this->explode(); - $properties = array(); - $testtypes = (gettype($type) == 'string' ? array( $type => true ) : $type ); - foreach( $this->properties AS $k => $v ) { - if ( $type == null || (isset($testtypes[$v->Name()]) && $testtypes[$v->Name()]) ) { - $properties[] = $v; - } - } - return $properties; - } - - /** - * Return an array of properties matching the specified path - * - * @return array An array of vProperty within the tree which match the path given, in the form - * [/]COMPONENT[/...]/PROPERTY in a syntax kind of similar to our poor man's XML queries. We - * also allow COMPONENT and PROPERTY to be !COMPONENT and !PROPERTY for ++fun. - * - * @note At some point post PHP4 this could be re-done with an iterator, which should be more efficient for common use cases. - */ - function GetPropertiesByPath( $path ) { - $properties = array(); - dbg_error_log( 'vComponent', "GetPropertiesByPath: Querying within '%s' for path '%s'", $this->type, $path ); - if ( !preg_match( '#(/?)(!?)([^/]+)(/?.*)$#', $path, $matches ) ) return $properties; - - $anchored = ($matches[1] == '/'); - $inverted = ($matches[2] == '!'); - $ourtest = $matches[3]; - $therest = $matches[4]; - dbg_error_log( 'vComponent', "GetPropertiesByPath: Matches: %s -- %s -- %s -- %s\n", $matches[1], $matches[2], $matches[3], $matches[4] ); - if ( $ourtest == '*' || (($ourtest == $this->type) !== $inverted) && $therest != '' ) { - if ( preg_match( '#^/(!?)([^/]+)$#', $therest, $matches ) ) { - $normmatch = ($matches[1] ==''); - $proptest = $matches[2]; - foreach( $this->properties AS $k => $v ) { - if ( $proptest == '*' || (($v->Name() == $proptest) === $normmatch ) ) { - $properties[] = $v; - } - } - } - else { - /** - * There is more to the path, so we recurse into that sub-part - */ - foreach( $this->components AS $k => $v ) { - $properties = array_merge( $properties, $v->GetPropertiesByPath($therest) ); - } - } - } - - if ( ! $anchored ) { - /** - * Our input $path was not rooted, so we recurse further - */ - foreach( $this->components AS $k => $v ) { - $properties = array_merge( $properties, $v->GetPropertiesByPath($path) ); - } - } - dbg_error_log('vComponent', "GetPropertiesByPath: Found %d within '%s' for path '%s'\n", count($properties), $this->type, $path ); - return $properties; - } - - /** - * Clear all properties, or the properties matching a particular type - * @param string|array $type The type of property - omit for all properties - or an - * array associating property names with true values: array( 'PROPERTY' => true, 'PROPERTY2' => true ) - */ - function ClearProperties( $type = null ) { - $this->explode(); - if($this->isValid()){ - $this->invalidate(); - } - - if ( $type != null ) { - $testtypes = (gettype($type) == 'string' ? array( $type => true ) : $type ); - // First remove all the existing ones of that type - foreach( $this->properties AS $k => $v ) { - if ( isset($testtypes[$v->Name()]) && $testtypes[$v->Name()] ) { - unset($this->properties[$k]); - if ( isset($this->rendered) ) unset($this->rendered); - } - } - $this->properties = array_values($this->properties); - } - else { - - $this->properties = array(); - } - } - - /** - * Set all properties, or the ones matching a particular type - */ - function SetProperties( $new_properties, $type = null ) { - $this->explode(); - $this->ClearProperties($type); - foreach( $new_properties AS $k => $v ) { - $this->properties[] = $v; - } - } - - /** - * Adds a new property - * - * @param vProperty $new_property The new property to append to the set, or a string with the name - * @param string $value The value of the new property (default: param 1 is an vProperty with everything - * @param array $parameters The key/value parameter pairs (default: none, or param 1 is an vProperty with everything) - */ - function AddProperty( $new_property, $value = null, $parameters = null ) { - $this->explode(); - if ( isset($value) && gettype($new_property) == 'string' ) { - $new_prop = new myProperty('', $this->getMaster()); - $new_prop->Name($new_property); - $new_prop->Value($value); - if ( $parameters != null ) { - $new_prop->Parameters($parameters); - } -// dbg_error_log('vComponent'," Adding new property '%s'", $new_prop->Render() ); - $this->properties[] = $new_prop; - } - else if ( $new_property instanceof myProperty ) { - $this->properties[] = $new_property; - $new_property->setMaster($this->getMaster()); - } - - if($this->isValid()){ - $this->invalidate(); - } - } - - /** - * Get all sub-components, or at least get those matching a type, or failling to match, - * should the second parameter be set to false. Component types may be a string or an array - * associating property names with true values: array( 'TYPE' => true, 'TYPE2' => true ) - * - * @param mixed $type The type(s) to match (default: All) - * @param boolean $normal_match Set to false to invert the match (default: true) - * @return array an array of the sub-components - */ - function GetComponents( $type = null, $normal_match = true ) { - $this->explode(); - $components = $this->components; - if ( isset($components) && $type != null ) { - $testtypes = (gettype($type) == 'string' ? array( $type => true ) : $type ); - foreach( $components AS $k => $v ) { -// printf( "Type: %s, %s, %s\n", $v->GetType(), -// ($normal_match && isset($testtypes[$v->GetType()]) && $testtypes[$v->GetType()] ? 'true':'false'), -// ( !$normal_match && (!isset($testtypes[$v->GetType()]) || !$testtypes[$v->GetType()]) ? 'true':'false') -// ); - if ( !($normal_match && isset($testtypes[$v->GetType()]) && $testtypes[$v->GetType()] ) - && !( !$normal_match && (!isset($testtypes[$v->GetType()]) || !$testtypes[$v->GetType()])) ) { - unset($components[$k]); - } - } - $components = array_values($components); - } -// print_r($components); - return $components; - } - - - /** - * Clear all components, or the components matching a particular type - * @param string $type The type of component - omit for all components - */ - function ClearComponents( $type = null ) { - if($this->isValid()){ - $this->explode(); - } - - - if ( $type != null && isset($this->components)) { - $testtypes = (gettype($type) == 'string' ? array( $type => true ) : $type ); - // First remove all the existing ones of that type - foreach( $this->components AS $k => $v ) { - $this->components[$k]->ClearComponents($testtypes); - if ( isset($testtypes[$v->GetType()]) && $testtypes[$v->GetType()] ) { - unset($this->components[$k]); - if ( $this->isValid()) { - $this->invalidate(); - } - } - - } - } - else { - if ( $this->isValid()) { - $this->invalidate(); - } - unset($this->components); - - } - - return $this->isValid(); - } - - /** - * Sets some or all sub-components of the component to the supplied new components - * - * @param array of vComponent $new_components The new components to replace the existing ones - * @param string $type The type of components to be replaced. Defaults to null, which means all components will be replaced. - */ - function SetComponents( $new_component, $type = null ) { - $this->explode(); - if ( $this->isValid()) { - $this->invalidate(); - } - - $this->ClearComponents($type); - foreach( $new_component AS $k => $v ) { - $this->components[] = $v; - $v->setMaster($this->getMaster()); - } - } - - /** - * Adds a new subcomponent - * - * @param vComponent $new_component The new component to append to the set - */ - public function AddComponent( $new_component ) { - $this->explode(); - if ( is_array($new_component) && count($new_component) == 0 ) return; - - if ( $this->isValid()) { - $this->invalidate(); - } - - if ( is_array($new_component) ) { - foreach( $new_component AS $k => $v ) { - $this->components[] = $v; - $v->setMaster($this->getMaster()); - } - } - else { - $this->components[] = $new_component; - foreach( $new_component AS $k => $v ) { - //$v->setMaster($this->getMaster()); - } - } - } - - - /** - * Mask components, removing any that are not of the types in the list - * @param array $keep An array of component types to be kept - * @param boolean $recursive (default true) Whether to recursively MaskComponents on the ones we find - */ - function MaskComponents( $keep, $recursive = true ) { - $this->explode(); - if(!isset($this->components)){ - return ; - } - - foreach( $this->components AS $k => $v ) { - if ( !isset($keep[$v->GetType()]) ) { - unset($this->components[$k]); - if ( $this->isValid()) { - $this->invalidate(); - } - } - else if ( $recursive ) { - $v->MaskComponents($keep); - } - } - } - - /** - * Mask properties, removing any that are not in the list - * @param array $keep An array of property names to be kept - * @param array $component_list An array of component types to check within - */ - function MaskProperties( $keep, $component_list=null ) { - $this->explode(); - if ( !isset($component_list) || isset($component_list[$this->type]) ) { - foreach( $this->properties AS $k => $v ) { - if ( !isset($keep[$v->Name()]) || !$keep[$v->Name()] ) { - unset($this->properties[$k]); - if ( $this->isValid()) { - $this->invalidate(); - } - } - } - } - if(isset($this->components)){ - foreach( $this->components AS $k => $v ) { - $v->MaskProperties($keep, $component_list); - } - } - - } - - /** - * This imposes the (CRLF + linear space) wrapping specified in RFC2445. According - * to RFC2445 we should always end with CRLF but the CalDAV spec says that normalising - * XML parsers often muck with it and may remove the CR. We output RFC2445 compliance. - * - * In order to preserve pre-existing wrapping in the component, we split the incoming - * string on line breaks before running wordwrap over each component of that. - */ - function WrapComponent( $content ) { - $strs = preg_split( "/\r?\n/", $content ); - $wrapped = ""; - foreach ($strs as $str) { - $wrapped .= preg_replace( '/(.{72})/u', '$1'."\r\n ", $str ) ."\r\n"; - } - return $wrapped; - } - - /** - * This unescapes the (CRLF + linear space) wrapping specified in RFC2445. According - * to RFC2445 we should always end with CRLF but the CalDAV spec says that normalising - * XML parsers often muck with it and may remove the CR. We accept either case. - */ - function UnwrapComponent( &$content ) { - return preg_replace('/\r?\n[ \t]/', '', $content ); - } - - - function InternalRender($restricted_properties = null, $force_rendering = false){ - $unroledComponents = isset($this->components); - $rendered = vComponent::KEYBEGIN . $this->type . "\n"; - - - if($this->isValid()){ - $rendered .= $this->InternalRenderUnchanged($unroledComponents); - } else { - $rendered .= $this->InternalRenderChanged(); - } - - if($unroledComponents){ - //$count = 0; - foreach($this->components as $component){ - //$component->explode(); - //$count++; - $rendered .= $component->InternalRender(); - //$component->close(); - - } - } - - return $rendered . vComponent::KEYEND . $this->type . "\n"; - } - - function InternalRenderChanged(){ - $rendered = ''; - if(isset($this->properties)){ - foreach( $this->properties AS $k => $v ) { - if ( method_exists($v, 'Render') ) { - $rendered .= $v->Render(); - } - } - } - - return $rendered; - } - - function InternalRenderUnchanged($unroledComponents){ - $this->rewind(); - $rendered = ''; - $lentype = 0; - if(isset($this->type)){ - $lentype = strlen($this->type); - } - - $iterator = $this->iterator; - $inInnerObject = 0; - do { - $line = $iterator->current() . "\n"; - $seek = $iterator->key(); - - $posStart = strpos($line, vComponent::KEYBEGIN); - if($posStart !== false && $posStart == 0){ - $type = substr($line, vComponent::KEYBEGINLENGTH); - if(!isset($this->type)){ - //$this->seekBegin = $seek; - $this->type = $type; - $lentype = strlen($this->type); - } else if(strncmp($type, $this->type, $lentype) != 0){ - if($unroledComponents){ - $inInnerObject++; - } else { - $rendered .= $line ; - } - } - } else { - - $posEnd = strpos($line, vComponent::KEYEND); - if($posEnd !== false && $posEnd == 0){ - $thisEnd = substr($line, vComponent::KEYENDLENGTH); - if(strncmp($thisEnd, $this->type, $lentype) == 0){ - $this->seekEnd = $seek; - //$iterator->next(); - break; - }else if($unroledComponents){ - $inInnerObject--; - } else { - $rendered .= $line; - } - - } else if($inInnerObject === 0 || !$unroledComponents){ - $rendered .= $line; - } - } - $iterator->next(); - } while($iterator->valid() && ( !isset($this->seekEnd) || $this->seekEnd > $seek)); - - - return $rendered; - - } - - function Render($restricted_properties = null, $force_rendering = false){ - return $this->WrapComponent($this->InternalRender()); - //return $this->InternalRender($restricted_properties, $force_rendering); - } - - /** - * Renders the component, possibly restricted to only the listed properties - */ - function RenderOld( $restricted_properties = null, $force_rendering = false ) { - $this->explode(); - $unrestricted = (!isset($restricted_properties) || count($restricted_properties) == 0); - - if ( !$force_rendering && isset($this->heapLines) && $this->isValid() ){ - $prerendered = $this->heapLines->render(); - return $this->WrapComponent($prerendered); - } - - - $rendered = "BEGIN:$this->type\r\n"; - if(isset($this->properties)){ - foreach( $this->properties AS $k => $v ) { - if ( method_exists($v, 'Render') ) { - if ( $unrestricted || isset($restricted_properties[$v]) ) $rendered .= $v->Render() . "\r\n"; - } - } - } - - if(isset($this->components)){ - foreach( $this->components AS $v ) { - $rendered .= $v->Render( $restricted_properties, $force_rendering ); - } - } - - $rendered .= "END:$this->type\r\n"; - - - $rendered = preg_replace('{(?rendered = $rendered; - - return $rendered; - } - - function isValid(){ - if($this->valid){ - if(isset($this->components)){ - foreach($this->components as $comp){ - if(!$comp->isValid()){ - return false; - } - } - } - - return true; - } - return false; - } - } - -?> \ No newline at end of file diff --git a/inc/vComponent.php b/inc/vComponent.php new file mode 120000 index 0000000..6668c84 --- /dev/null +++ b/inc/vComponent.php @@ -0,0 +1 @@ +/home/milan/projects/awl/inc/vComponent2.php \ No newline at end of file diff --git a/inc/myProperty.php b/inc/vProperty.php similarity index 94% rename from inc/myProperty.php rename to inc/vProperty.php index 842821f..671a9ee 100644 --- a/inc/myProperty.php +++ b/inc/vProperty.php @@ -6,7 +6,7 @@ require_once('XMLElement.php'); * * @package awl */ -class myProperty extends vObject { +class vProperty extends vObject { /**#@+ * @access private */ @@ -179,7 +179,7 @@ class myProperty extends vObject { $this->parameters[$name] = $value; } } -// dbg_error_log('myComponent', " myProperty::ParseFrom found '%s' = '%s' with %d parameters", $this->name, substr($this->content,0,200), count($this->parameters) ); +// dbg_error_log('myComponent', " vProperty::ParseFrom found '%s' = '%s' with %d parameters", $this->name, substr($this->content,0,200), count($this->parameters) ); } @@ -213,7 +213,7 @@ class myProperty extends vObject { if ( $newname != null ) { $this->name = strtoupper($newname); if ( $this->isValid() ) $this->invalidate(); -// dbg_error_log('myComponent', " myProperty::Name(%s)", $this->name ); +// dbg_error_log('myComponent', " vProperty::Name(%s)", $this->name ); } else if(!isset($this->name)){ $this->ParseFromIterator(); } @@ -329,11 +329,11 @@ class myProperty extends vObject { foreach( $this->parameters AS $k => $v ) { if ( is_array($v) ) { foreach( $v AS $vv ) { - $rendered .= sprintf( ';%s=%s', $k, myProperty::escapeParameter($vv) ); + $rendered .= sprintf( ';%s=%s', $k, vProperty::escapeParameter($vv) ); } } else { - $rendered .= sprintf( ';%s=%s', $k, myProperty::escapeParameter($v) ); + $rendered .= sprintf( ';%s=%s', $k, vProperty::escapeParameter($v) ); } } } @@ -414,12 +414,12 @@ class myProperty extends vObject { * * @param array $filter An array of XMLElement defining the filter * - * @return boolean Whether or not this myProperty passes the test + * @return boolean Whether or not this vProperty passes the test */ function TestFilter( $filters ) { foreach( $filters AS $k => $v ) { $tag = $v->GetNSTag(); -// dbg_error_log( 'vCalendar', "myProperty:TestFilter: '%s'='%s' => '%s'", $this->name, $tag, $this->content ); +// dbg_error_log( 'vCalendar', "vProperty:TestFilter: '%s'='%s' => '%s'", $this->name, $tag, $this->content ); switch( $tag ) { case 'urn:ietf:params:xml:ns:caldav:is-defined': case 'urn:ietf:params:xml:ns:carddav:is-defined': @@ -454,7 +454,7 @@ class myProperty extends vObject { break; default: - dbg_error_log( 'myComponent', ' myProperty::TestFilter: unhandled tag "%s"', $tag ); + dbg_error_log( 'myComponent', ' vProperty::TestFilter: unhandled tag "%s"', $tag ); break; } } @@ -468,7 +468,7 @@ class myProperty extends vObject { function TestParamFilter( $filters, $parameter_value ) { foreach( $filters AS $k => $v ) { $subtag = $v->GetNSTag(); -// dbg_error_log( 'vCalendar', "myProperty:TestParamFilter: '%s'='%s' => '%s'", $this->name, $subtag, $parameter_value ); +// dbg_error_log( 'vCalendar', "vProperty:TestParamFilter: '%s'='%s' => '%s'", $this->name, $subtag, $parameter_value ); switch( $subtag ) { case 'urn:ietf:params:xml:ns:caldav:is-defined': case 'urn:ietf:params:xml:ns:carddav:is-defined': @@ -497,7 +497,7 @@ class myProperty extends vObject { break; default: - dbg_error_log( 'myComponent', ' myProperty::TestParamFilter: unhandled tag "%s"', $tag ); + dbg_error_log( 'myComponent', ' vProperty::TestParamFilter: unhandled tag "%s"', $tag ); break; } } diff --git a/tests/data/0000-Setup-PUT-collection.test b/tests/data/0000-Setup-PUT-collection.test new file mode 100644 index 0000000..0cf4994 --- /dev/null +++ b/tests/data/0000-Setup-PUT-collection.test @@ -0,0 +1,148 @@ +BEGIN:VCALENDAR +PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN +X-WR-CALNAME:User 2's Calendar, as uploaded by Admin +VERSION:2.0 + +BEGIN:VTIMEZONE +TZID:Pacific/Auckland +X-LIC-LOCATION:Pacific/Auckland +BEGIN:DAYLIGHT +TZOFFSETFROM:+1200 +TZOFFSETTO:+1300 +TZNAME:NZDT +DTSTART:19700927T020000 +RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=9 +END:DAYLIGHT +BEGIN:STANDARD +TZOFFSETFROM:+1300 +TZOFFSETTO:+1200 +TZNAME:NZST +DTSTART:19700405T030000 +RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=4 +END:STANDARD +END:VTIMEZONE + +BEGIN:VEVENT +CREATED:20081023T054958Z +LAST-MODIFIED:20081023T055044Z +DTSTAMP:20081023T054958Z +UID:33169d69-2969-4a96-a3e1-2e312b7614e6 +SUMMARY:Near Daily Action Meeting +RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,WE,FR +DTSTART;TZID=Pacific/Auckland:20081020T110000 +DTEND;TZID=Pacific/Auckland:20081020T113000 +X-MOZ-GENERATION:2 +END:VEVENT + +BEGIN:VEVENT +CREATED:20081023T054934Z +LAST-MODIFIED:20081023T055059Z +DTSTAMP:20081023T054934Z +UID:047871e3-6b70-4178-9af8-0ceb50f7b092 +SUMMARY:Weekly Project Meeting +RRULE:FREQ=WEEKLY;INTERVAL=1 +DTSTART;TZID=Pacific/Auckland:20081020T090000 +DTEND;TZID=Pacific/Auckland:20081020T100000 +X-MOZ-GENERATION:2 +END:VEVENT + +BEGIN:VEVENT +CREATED:20081023T055115Z +LAST-MODIFIED:20081023T055139Z +DTSTAMP:20081023T055115Z +UID:9429a973-2b13-4b1a-be09-948d75425c45 +SUMMARY:Weekly catch-up +RRULE:FREQ=WEEKLY;INTERVAL=1 +DTSTART;TZID=Pacific/Auckland:20081024T140000 +DTEND;TZID=Pacific/Auckland:20081024T150000 +X-MOZ-GENERATION:2 +END:VEVENT + +BEGIN:VTIMEZONE +TZID:America/Los_Angeles +X-TZINFO:America/Los_Angeles[2007g/Partial@883612800000] +BEGIN:DAYLIGHT +TZOFFSETTO:-0700 +TZOFFSETFROM:-0800 +TZNAME:America/Los_Angeles(DST) +DTSTART:19980405T020000 +RRULE:FREQ=YEARLY;UNTIL=20060403T100000Z;BYMONTH=4;BYDAY=1SU +END:DAYLIGHT +BEGIN:STANDARD +TZOFFSETTO:-0800 +TZOFFSETFROM:-0700 +TZNAME:America/Los_Angeles(STD) +DTSTART:19981025T020000 +RRULE:FREQ=YEARLY;UNTIL=20061030T100000Z;BYMONTH=10;BYDAY=-1SU +END:STANDARD +BEGIN:DAYLIGHT +TZOFFSETTO:-0700 +TZOFFSETFROM:-0800 +TZNAME:America/Los_Angeles(DST) +DTSTART:20070311T020000 +RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU +END:DAYLIGHT +BEGIN:STANDARD +TZOFFSETTO:-0800 +TZOFFSETFROM:-0700 +TZNAME:America/Los_Angeles(STD) +DTSTART:20071104T020000 +RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU +END:STANDARD +END:VTIMEZONE + +BEGIN:VEVENT +LAST-MODIFIED:20080303T015422Z +SEQUENCE:5 +UID:7d729xc0-0895-012d-124e-002421a2359e +SUMMARY:1st Monday, 2nd Tuesday, 3rd Thursday & Last Friday +RRULE:FREQ=MONTHLY;BYDAY=1MO,2TU,3TH,-1FR;INTERVAL=1 +DESCRIPTION:An all day event on various days. +DTSTART;TZID=America/Los_Angeles:20081006T000000 +CREATED:20080303T015329Z +DTSTAMP:20080303T015422Z +DURATION:P1D +END:VEVENT + +BEGIN:VEVENT +LAST-MODIFIED:20081123T210725Z +SEQUENCE:6 +UID:bd262d20-1cdb-012d-1264-002421a2359e +SUMMARY:Afternoon run +DESCRIPTION: +DTSTART;TZID=America/Los_Angeles:20081123T150000 +CREATED:20081123T210644Z +DTSTAMP:20081123T210725Z +DURATION:PT1H +LOCATION: +RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=SU +END:VEVENT + +BEGIN:VEVENT +LAST-MODIFIED:20110101T005414Z +SEQUENCE:12 +URL;VALUE=URI:http://www.oregontrufflefestival.com +UID:56f0e0e0-f742-012d-680c-002421a2359e +SUMMARY:Willamette Valley Vineyards at the Oregon Truffle Festival +DESCRIPTION:The 6th Annual Oregon Truffle Festival will be held in and arou + nd Eugene Oregon over three brisk winter days from January 28-30\, 2011. Cr + eated to celebrate the magnificent Oregon truffles as they reach the peak o + f ripeness in their native soil\, it is the first festival of its kind in N + orth America\, dedicated to sharing the experience of the chefs\, foragers + and fans of Oregon\\'s wild truffles\, from their hidden source in the fore + st to their glory on the table.\n\nThe theme for 2011 is "Slow Food"\, and + Willamette Valley Vineyards will be hosting a gourmet wine luncheon during + the festival. Please visit www.oregontrufflefestival.com for more info and + to purchase tickets.\n\n +DTSTART;TZID=America/Los_Angeles:20110128 +CREATED:20101231T193025Z +DTSTAMP:20110101T005414Z +DURATION:P1D +LOCATION:Eugene Oregon +X-VENUE: +X-EMAIL-RSVP-UPDATES:true +RRULE:FREQ=DAILY;COUNT=3;INTERVAL=1 +END:VEVENT + +END:VCALENDAR \ No newline at end of file diff --git a/tests/myCalendarTest.php b/tests/myCalendarTest.php index 1182692..3b44f4e 100644 --- a/tests/myCalendarTest.php +++ b/tests/myCalendarTest.php @@ -11,10 +11,40 @@ require_once('inc/vCalendar.php'); class myCalendarTest extends PHPUnit_Framework_TestCase { + function getData($filename){ + $file = fopen($filename, 'r'); + $data = fread($file, filesize($filename)); + fclose($file); + return $data; + } + function test1(){ - $mycalendar = new vCalendar(); + $mycalendar = new vCalendar($this->getData('tests/data/0000-Setup-PUT-collection.test')); + $test = $mycalendar->Render(); + + $timezones = $mycalendar->GetComponents('VTIMEZONE',true); + $components = $mycalendar->GetComponents('VTIMEZONE',false); + + + $resources = array(); + foreach($components as $comp){ + + $uid = $comp->GetPValue('UID'); + $resources[$uid][] = $comp; + + + } + + foreach($resources as $key => $res){ + $testcal = new vCalendar(); + $testcal->SetComponents($res); + $t = $testcal->Render(); + $t = $testcal->Render(); + } + + $mycalendar->Render(); } } diff --git a/tests/myComponentTest.php b/tests/myComponentTest.php index 5ebf0bf..07244a4 100644 --- a/tests/myComponentTest.php +++ b/tests/myComponentTest.php @@ -93,7 +93,7 @@ EOSIMPLEDATA1; $property = $component->GetProperty("VERSION"); $this->assertNotNull($property); - $this->assertInstanceOf('myProperty', $property); + $this->assertInstanceOf('vProperty', $property); } function testGetPropertyAndChange(){ @@ -104,7 +104,7 @@ EOSIMPLEDATA1; $property = $component->GetProperty("VERSION"); $this->assertTrue($component->isValid()); $this->assertNotNull($property); - $this->assertInstanceOf('myProperty', $property); + $this->assertInstanceOf('vProperty', $property); $this->assertTrue($component->isValid()); $property->Name("ahoj"); $this->assertFalse($component->isValid()); @@ -211,7 +211,7 @@ EOSIMPLEDATA1; $data = $this->getData('tests/data/inner_valarmdata.test'); $component = new vComponent($data); - $property = new myProperty('HELLO'); + $property = new vProperty('HELLO'); $this->assertEquals(4, $component->propertiesCount()); $component->AddProperty($property); @@ -391,9 +391,9 @@ EOSIMPLEDATA1; //$lines = new HeapLines((new bigtestdata)->testdata2); $component = new vComponent("BEGIN:VCALENDAR\nEND:VCALENDAR"); - $newcomponent = new myProperty("VEVENT"); - $newcomponent2 = new myProperty("MASK"); - $newcomponent3 = new myProperty("VEVENT"); + $newcomponent = new vProperty("VEVENT"); + $newcomponent2 = new vProperty("MASK"); + $newcomponent3 = new vProperty("VEVENT"); $component->AddProperty($newcomponent); $component->AddProperty($newcomponent2); diff --git a/tests/myPropertyTest.php b/tests/myPropertyTest.php index 30c0682..218d6c3 100644 --- a/tests/myPropertyTest.php +++ b/tests/myPropertyTest.php @@ -9,7 +9,7 @@ require_once 'inc/vComponent.php'; -class myPropertyTest extends PHPUnit_Framework_TestCase { +class vPropertyTest extends PHPUnit_Framework_TestCase { function getData($filename){ $file = fopen($filename, 'r'); @@ -78,14 +78,14 @@ class myPropertyTest extends PHPUnit_Framework_TestCase { public function testPropertyRenderFromString(){ - $property = new myProperty('PRODID:-//davical.org//NONSGML AWL Calendar//EN'); + $property = new vProperty('PRODID:-//davical.org//NONSGML AWL Calendar//EN'); $rendered = $property->Render(); $this->assertStringStartsWith('PRODID:-//davical.org//NONSGML AWL Calendar//EN', $rendered); } public function testPropertyRenderFromParams(){ - $property = new myProperty(); + $property = new vProperty(); $property->Name('PRODID'); $property->Value('-//davical.org//NONSGML AWL Calendar//EN'); $rendered = $property->Render(); @@ -93,7 +93,7 @@ class myPropertyTest extends PHPUnit_Framework_TestCase { } public function testPropertyRenderFromStringChangeName(){ - $property = new myProperty('PRODID:-//davical.org//NONSGML AWL Calendar//EN'); + $property = new vProperty('PRODID:-//davical.org//NONSGML AWL Calendar//EN'); $property->Name('VERSION'); @@ -102,7 +102,7 @@ class myPropertyTest extends PHPUnit_Framework_TestCase { } public function testSetParameterValue(){ - $property = new myProperty(); + $property = new vProperty(); $property->SetParameterValue("hello", "world"); @@ -111,7 +111,7 @@ class myPropertyTest extends PHPUnit_Framework_TestCase { } public function testSetParameterValueRender(){ - $property = new myProperty(); + $property = new vProperty(); $property->Name("universe"); $property->SetParameterValue("hello", "world"); -- 2.11.4.GIT