PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Resources/Private/vendor/vcard/tests/VCardTest.php

https://gitlab.com/deichbrise/vcard-viewhelper
PHP | 355 lines | 202 code | 50 blank | 103 comment | 4 complexity | 214068826163405a76f15a3885f09ba4 MD5 | raw file
  1. <?php
  2. namespace JeroenDesloovere\VCard\tests;
  3. // required to load
  4. require_once __DIR__ . '/../vendor/autoload.php';
  5. /*
  6. * This file is part of the VCard PHP Class from Jeroen Desloovere.
  7. *
  8. * For the full copyright and license information, please view the license
  9. * file that was distributed with this source code.
  10. */
  11. use JeroenDesloovere\VCard\VCard;
  12. /**
  13. * This class will test our VCard PHP Class which can generate VCards.
  14. *
  15. * @author Jeroen Desloovere <info@jeroendesloovere.be>
  16. */
  17. class VCardTest extends \PHPUnit_Framework_TestCase
  18. {
  19. /**
  20. * @var VCard
  21. */
  22. protected $vcard = null;
  23. /**
  24. * Data provider for testEmail()
  25. *
  26. * @return array
  27. */
  28. public function emailDataProvider()
  29. {
  30. return array(
  31. array(array('john@doe.com')),
  32. array(array('john@doe.com', 'WORK' => 'john@work.com')),
  33. array(array('WORK' => 'john@work.com', 'HOME' => 'john@home.com')),
  34. array(array('PREF;WORK' => 'john@work.com', 'HOME' => 'john@home.com')),
  35. );
  36. }
  37. /**
  38. * Set up before class
  39. *
  40. * @return void
  41. */
  42. public function setUp()
  43. {
  44. // set timezone
  45. date_default_timezone_set('Europe/Brussels');
  46. $this->vcard = new VCard();
  47. $this->firstName = 'Jeroen';
  48. $this->lastName = 'Desloovere';
  49. $this->additional = '&';
  50. $this->prefix = 'Mister';
  51. $this->suffix = 'Junior';
  52. $this->emailAddress1 = '';
  53. $this->emailAddress2 = '';
  54. $this->firstName2 = 'Ali';
  55. $this->lastName2 = 'ÖZSÜT';
  56. $this->firstName3 = 'Garçon';
  57. $this->lastName3 = 'Jéroèn';
  58. }
  59. /**
  60. * Tear down after class
  61. */
  62. public function tearDown()
  63. {
  64. $this->vcard = null;
  65. }
  66. public function testAddAddress()
  67. {
  68. $this->assertEquals($this->vcard, $this->vcard->addAddress());
  69. }
  70. public function testAddBirthday()
  71. {
  72. $this->assertEquals($this->vcard, $this->vcard->addBirthday(''));
  73. }
  74. public function testAddCompany()
  75. {
  76. $this->assertEquals($this->vcard, $this->vcard->addCompany(''));
  77. }
  78. public function testAddEmail()
  79. {
  80. $this->assertEquals($this->vcard, $this->vcard->addEmail($this->emailAddress1));
  81. $this->assertEquals($this->vcard, $this->vcard->addEmail($this->emailAddress2));
  82. $this->assertEquals(2, count($this->vcard->getProperties()));
  83. }
  84. public function testAddJobTitle()
  85. {
  86. $this->assertEquals($this->vcard, $this->vcard->addJobtitle(''));
  87. }
  88. public function testAddRole()
  89. {
  90. $this->assertEquals($this->vcard, $this->vcard->addRole(''));
  91. }
  92. public function testAddName()
  93. {
  94. $this->assertEquals($this->vcard, $this->vcard->addName(''));
  95. }
  96. public function testAddNote()
  97. {
  98. $this->assertEquals($this->vcard, $this->vcard->addNote(''));
  99. }
  100. public function testAddPhoneNumber()
  101. {
  102. $this->assertEquals($this->vcard, $this->vcard->addPhoneNumber(''));
  103. $this->assertEquals($this->vcard, $this->vcard->addPhoneNumber(''));
  104. $this->assertEquals(2, count($this->vcard->getProperties()));
  105. }
  106. public function testAddPhotoWithJpgPhoto()
  107. {
  108. $return = $this->vcard->addPhoto(__DIR__ . '/image.jpg', true);
  109. $this->assertEquals($this->vcard, $return);
  110. }
  111. public function testAddLogoWithJpgImage()
  112. {
  113. $return = $this->vcard->addLogo(__DIR__ . '/image.jpg', true);
  114. $this->assertEquals($this->vcard, $return);
  115. }
  116. public function testAddLogoWithJpgImageNoInclude()
  117. {
  118. $return = $this->vcard->addLogo(__DIR__ . '/image.jpg', false);
  119. $this->assertEquals($this->vcard, $return);
  120. }
  121. public function testAddUrl()
  122. {
  123. $this->assertEquals($this->vcard, $this->vcard->addUrl('1'));
  124. $this->assertEquals($this->vcard, $this->vcard->addUrl('2'));
  125. $this->assertEquals(2, count($this->vcard->getProperties()));
  126. }
  127. /**
  128. * Test adding photo with no value
  129. *
  130. * @expectedException JeroenDesloovere\VCard\VCardMediaException
  131. * @expectedExceptionMessage Nothing returned from URL.
  132. */
  133. public function testAddPhotoWithNoValue()
  134. {
  135. $this->vcard->addPhoto(__DIR__ . '/emptyfile', true);
  136. }
  137. /**
  138. * Test adding logo with no value
  139. *
  140. * @expectedException JeroenDesloovere\VCard\VCardMediaException
  141. * @t@github.com:jeroendesloovere/vcard.gitexpectedExceptionMessage Nothing returned from URL.
  142. */
  143. public function testAddLogoWithNoValue()
  144. {
  145. $this->vcard->addLogo(__DIR__ . '/emptyfile', true);
  146. }
  147. /**
  148. * Test adding photo with no photo
  149. *
  150. * @expectedException JeroenDesloovere\VCard\VCardMediaException
  151. * @expectedExceptionMessage Returned data aren't an image.
  152. */
  153. public function testAddPhotoWithNoPhoto()
  154. {
  155. $this->vcard->addPhoto(__DIR__ . '/wrongfile', true);
  156. }
  157. /**
  158. * Test adding logo with no image
  159. *
  160. * @expectedException JeroenDesloovere\VCard\VCardMediaException
  161. * @expectedExceptionMessage Returned data aren't an image.
  162. */
  163. public function testAddLogoWithNoImage()
  164. {
  165. $this->vcard->addLogo(__DIR__ . '/wrongfile', true);
  166. }
  167. /**
  168. * Test charset
  169. */
  170. public function testCharset()
  171. {
  172. $charset = 'ISO-8859-1';
  173. $this->vcard->setCharset($charset);
  174. $this->assertEquals($charset, $this->vcard->getCharset());
  175. }
  176. /**
  177. * Test Email
  178. *
  179. * @dataProvider emailDataProvider $emails
  180. */
  181. public function testEmail($emails = array())
  182. {
  183. foreach ($emails as $key => $email) {
  184. if (is_string($key)) {
  185. $this->vcard->addEmail($email, $key);
  186. } else {
  187. $this->vcard->addEmail($email);
  188. }
  189. }
  190. foreach ($emails as $key => $email) {
  191. if (is_string($key)) {
  192. $this->assertContains('EMAIL;INTERNET;' . $key . ':' . $email, $this->vcard->getOutput());
  193. } else {
  194. $this->assertContains('EMAIL;INTERNET:' . $email, $this->vcard->getOutput());
  195. }
  196. }
  197. }
  198. /**
  199. * Test first name and last name
  200. */
  201. public function testFirstNameAndLastName()
  202. {
  203. $this->vcard->addName(
  204. $this->lastName,
  205. $this->firstName
  206. );
  207. $this->assertEquals('jeroen-desloovere', $this->vcard->getFilename());
  208. }
  209. /**
  210. * Test full blown name
  211. */
  212. public function testFullBlownName()
  213. {
  214. $this->vcard->addName(
  215. $this->lastName,
  216. $this->firstName,
  217. $this->additional,
  218. $this->prefix,
  219. $this->suffix
  220. );
  221. $this->assertEquals('mister-jeroen-desloovere-junior', $this->vcard->getFilename());
  222. }
  223. /**
  224. * Test multiple birthdays
  225. *
  226. * @expectedException JeroenDesloovere\VCard\Exception
  227. */
  228. public function testMultipleBirthdays()
  229. {
  230. $this->assertEquals($this->vcard, $this->vcard->addBirthday('1'));
  231. $this->assertEquals($this->vcard, $this->vcard->addBirthday('2'));
  232. }
  233. /**
  234. * Test multiple companies
  235. *
  236. * @expectedException JeroenDesloovere\VCard\Exception
  237. */
  238. public function testMultipleCompanies()
  239. {
  240. $this->assertEquals($this->vcard, $this->vcard->addCompany('1'));
  241. $this->assertEquals($this->vcard, $this->vcard->addCompany('2'));
  242. }
  243. /**
  244. * Test multiple job titles
  245. *
  246. * @expectedException JeroenDesloovere\VCard\Exception
  247. */
  248. public function testMultipleJobtitles()
  249. {
  250. $this->assertEquals($this->vcard, $this->vcard->addJobtitle('1'));
  251. $this->assertEquals($this->vcard, $this->vcard->addJobtitle('2'));
  252. }
  253. /**
  254. * Test multiple roles
  255. *
  256. * @expectedException JeroenDesloovere\VCard\Exception
  257. */
  258. public function testMultipleRoles()
  259. {
  260. $this->assertEquals($this->vcard, $this->vcard->addRole('1'));
  261. $this->assertEquals($this->vcard, $this->vcard->addRole('2'));
  262. }
  263. /**
  264. * Test multiple names
  265. *
  266. * @expectedException JeroenDesloovere\VCard\Exception
  267. */
  268. public function testMultipleNames()
  269. {
  270. $this->assertEquals($this->vcard, $this->vcard->addName('1'));
  271. $this->assertEquals($this->vcard, $this->vcard->addName('2'));
  272. }
  273. /**
  274. * Test multiple notes
  275. *
  276. * @expectedException JeroenDesloovere\VCard\Exception
  277. */
  278. public function testMultipleNotes()
  279. {
  280. $this->assertEquals($this->vcard, $this->vcard->addNote('1'));
  281. $this->assertEquals($this->vcard, $this->vcard->addNote('2'));
  282. }
  283. /**
  284. * Test special first name and last name
  285. */
  286. public function testSpecialFirstNameAndLastName()
  287. {
  288. $this->vcard->addName(
  289. $this->lastName2,
  290. $this->firstName2
  291. );
  292. $this->assertEquals('ali-ozsut', $this->vcard->getFilename());
  293. }
  294. /**
  295. * Test special first name and last name
  296. */
  297. public function testSpecialFirstNameAndLastName2()
  298. {
  299. $this->vcard->addName(
  300. $this->lastName3,
  301. $this->firstName3
  302. );
  303. $this->assertEquals('garcon-jeroen', $this->vcard->getFilename());
  304. }
  305. }