Skip to content

Commit

Permalink
Merge pull request #37 from jeroendesloovere/pr/35
Browse files Browse the repository at this point in the history
Pr/35
  • Loading branch information
jeroendesloovere committed May 20, 2015
2 parents 7bbbd93 + 696e0a9 commit 39ff86f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 13 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"php": ">=5.3.3",
"behat/transliterator": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "4.6.*"
},
"autoload": {
"psr-4": { "JeroenDesloovere\\VCard\\": "src/" }
}
Expand Down
31 changes: 26 additions & 5 deletions src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@ public function addCompany($company)
* Add email
*
* @param string $address The e-mail address
* @param string [optional] $type The type of the email address
* $type may be PREF | WORK | HOME
* or any combination of these: e.g. "PREF;WORK"
* @return $this
*/
public function addEmail($address)
public function addEmail($address, $type = '')
{
$this->setProperty('EMAIL;INTERNET', $address);
$this->setProperty(
'EMAIL;INTERNET' . (($type != '') ? ';' . $type : ''),
$address
);

return $this;
}
Expand Down Expand Up @@ -352,6 +358,21 @@ public function buildVCalendar()
return $string;
}

/**
* Returns the browser user agent string.
*
* @return string
*/
protected function getUserAgent()
{
if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
$browser = strtolower($_SERVER['HTTP_USER_AGENT']);
} else {
$browser = 'unknown';
}
return $browser;
}

/**
* Decode
*
Expand Down Expand Up @@ -461,7 +482,7 @@ public function getHeaders($asAssociative)
'Connection' => $connection
);
}

return array(
'Content-type: ' . $contentType,
'Content-Disposition: ' . $contentDisposition,
Expand Down Expand Up @@ -491,7 +512,7 @@ public function getOutput()
public function isIOS()
{
// get user agent
$browser = strtolower($_SERVER['HTTP_USER_AGENT']);
$browser = $this->getUserAgent();

return (strpos($browser, 'iphone') || strpos($browser, 'ipod') || strpos($browser, 'ipad'));
}
Expand Down Expand Up @@ -578,7 +599,7 @@ private function setProperty($key, $value)
*/
protected function shouldAttachmentBeCal()
{
$browser = strtolower($_SERVER['HTTP_USER_AGENT']);
$browser = $this->getUserAgent();

$matches = array();
preg_match('/os (\d+)_(\d+)\s+/', $browser, $matches);
Expand Down
60 changes: 52 additions & 8 deletions tests/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,29 @@
*/
class VCardTest extends \PHPUnit_Framework_TestCase
{
/**
* @var VCard
*/
protected $vcard = null;

/**
* Data provider for testEmail()
*
* @return array
*/
public function emailDataProvider() {
return array(
array(array('[email protected]')),
array(array('[email protected]', 'WORK' => '[email protected]')),
array(array('WORK' => '[email protected]', 'HOME' => '[email protected]')),
array(array('PREF;WORK' => '[email protected]', 'HOME' => '[email protected]')),
);
}

/**
* Set up before class
*
* @return SocialMedia
* @return void
*/
public function setUp()
{
Expand Down Expand Up @@ -106,7 +125,32 @@ public function testFullBlownName()
$this->assertEquals('mister-jeroen-desloovere-junior', $this->vcard->getFilename());
}

public function testAddAdress()
<<<<<<< HEAD
/**
* @test
* @dataProvider emailDataProvider
*/
public function testEmail($emails = array())
{
foreach ($emails as $key => $email) {
if (is_string($key)) {
$this->vcard->addEmail($email, $key);
} else {
$this->vcard->addEmail($email);
}
}

foreach ($emails as $key => $email) {
if (is_string($key)) {
$this->assertContains('EMAIL;INTERNET;' . $key . ':' . $email, $this->vcard->getOutput());
} else {
$this->assertContains('EMAIL;INTERNET:' . $email, $this->vcard->getOutput());
}

}
}

public function testAddAddress()
{
$this->assertEquals($this->vcard, $this->vcard->addAddress());
}
Expand All @@ -126,7 +170,7 @@ public function testAddEmail()
$this->assertEquals($this->vcard, $this->vcard->addEmail(''));
}

public function testAddjobtitle()
public function testAddJobTitle()
{
$this->assertEquals($this->vcard, $this->vcard->addJobtitle(''));
}
Expand All @@ -146,15 +190,15 @@ public function testAddPhoneNumber()
$this->assertEquals($this->vcard, $this->vcard->addPhoneNumber(''));
}

public function testAddUrl()
{
$this->assertEquals($this->vcard, $this->vcard->addUrl(''));
}

public function testAddPhotoWithJpgPhoto()
{
$return = $this->vcard->addPhoto(__DIR__.'/image.jpg', true);

$this->assertEquals($this->vcard, $return);
}

public function testAddUrl()
{
$this->assertEquals($this->vcard, $this->vcard->addUrl(''));
}
}

0 comments on commit 39ff86f

Please sign in to comment.