<?php

require_once '../library/Atmail/Vcard.php';
class ContactTests extends PHPUnit_Framework_TestCase
{
    public function testVCard2ContactImport()
    {
    	$vcard = new Vcard();
      	$contacts = $vcard->build('vcard2_test.vcf'); 		

		$contactsCount = 0;
		//print_r($contacts);
		foreach($contacts as $contact)	
		{
			
			//print $contact;
			//print_r( $contact);
			$contact = strtolower($contact);
			$importContact = $vcard->viewPart($contact);
		
			//cleanup string
			$contact =str_replace(";type=pref", "",$contact);
			$contact =str_replace(";charset=utf-8", "",$contact);
			$contact =str_replace(";value=uri:tel:+", "",$contact);
			$contact =str_replace("label=", ";",$contact);
			$contact =str_replace(":", "",$contact);
			$contact =str_replace('"', "",$contact);
			$contact =str_replace(';voice', "",$contact);
			$contact =str_replace(',voice', "",$contact);
			$contact =str_replace('type=', "",$contact);
			$contact =str_replace('pref;', "",$contact);
	
	
			$contactNamePart1 =  explode('fn',$contact);

			
			for ($i=0;$i <count($contactNamePart1); $i++){
				$contactName = $contactNamePart1[$i];
				
			}

			$contactNamePart2 = explode("\n", $contactName);	
		
			$contactFullyName = $contactNamePart2[0];
			$contactFullyNameSplit =  explode(' ',$contactFullyName);
		
			$firstName = $contactFullyNameSplit[0];
		
			$this->assertEquals("forrest", $firstName);
		}
	
	  
    }

	 public function testVCard3ContactImport()
    {
    
		$vcard2 = new Vcard();
		$contactsV3 = $vcard2->build('vcard3_test.vcf'); 		
	
		$contactsCount = 0;
		//print_r($contacts);
		foreach($contactsV3 as $contactV3)	
		{
			
			//print $contact;
			//print_r( $contact);
			$contactV3 = strtolower($contactV3);
			$importContact = $vcard2->viewPart($contactV3);
		
			//cleanup string
			$contactV3 =str_replace(";type=pref", "",$contactV3);
			$contactV3 =str_replace(";charset=utf-8", "",$contactV3);
			$contactV3 =str_replace(";value=uri:tel:+", "",$contactV3);
			$contactV3 =str_replace("label=", ";",$contactV3);
			$contactV3 =str_replace(":", "",$contactV3);
			$contactV3 =str_replace('"', "",$contactV3);
			$contactV3 =str_replace(';voice', "",$contactV3);
			$contactV3 =str_replace(',voice', "",$contactV3);
			$contactV3 =str_replace('type=', "",$contactV3);
			$contactV3 =str_replace('pref;', "",$contactV3);
	
			
			$contactNamePart1 =  explode('end:vcard',$contactV3);
		
			// get contact name
			$contactNamePart1 =  explode('fn',$contactV3);

			for ($i=0;$i <count($contactNamePart1); $i++){
				$contactName = $contactNamePart1[$i];
				
			}
			
			$contactNamePart2 = explode("\n", $contactName);	
			$contactFullyName = $contactNamePart2[0];
			$contactFullyNameSplit =  explode(' ',$contactFullyName);
			$firstName = $contactFullyNameSplit[0];
		
			$this->assertEquals("forrestv3", $firstName);
		}
	
    }

	 public function testVCard4ContactImport()
    {
		$vcard3 = new Vcard();
		$contactsV4 = $vcard3->build('vcard4_test.vcf'); 		

		$contactsCount = 0;
		//print_r($contacts);
		foreach($contactsV4 as $contactV4)	
		{
			
			//print $contact;
			//print_r( $contact);
			$contactV4 = strtolower($contactV4);
			$importContact = $vcard3->viewPart($contactV4);
		
			//cleanup string
			$contactV4 =str_replace(";type=pref", "",$contactV4);
			$contactV4 =str_replace(";charset=utf-8", "",$contactV4);
			$contactV4 =str_replace(";value=uri:tel:+", "",$contactV4);
			$contactV4 =str_replace("label=", ";",$contactV4);
			$contactV4 =str_replace(":", "",$contactV4);
			$contactV4 =str_replace('"', "",$contactV4);
			$contactV4 =str_replace(';voice', "",$contactV4);
			$contactV4 =str_replace(',voice', "",$contactV4);
			$contactV4 =str_replace('type=', "",$contactV4);
			$contactV4 =str_replace('pref;', "",$contactV4);
	
			
			$contactNamePart1 =  explode('end:vcard',$contactV4);
		
			// get contact name
			$contactNamePart1 =  explode('fn',$contactV4);

			for ($i=0;$i <count($contactNamePart1); $i++){
				$contactName = $contactNamePart1[$i];
				
			}
			
			$contactNamePart2 = explode("\n", $contactName);		
			$contactFullyName = $contactNamePart2[0];
			$contactFullyNameSplit =  explode(' ',$contactFullyName);
			$firstName = $contactFullyNameSplit[0];
		
			$this->assertEquals("forrestv4", $firstName);
		}

    }
 }
  

?>
