ContactTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace CMText\RichContent\Common;
  3. use CMText\Exceptions\ContactException;
  4. use PHPUnit\Framework\TestCase;
  5. class ContactTest extends TestCase
  6. {
  7. private $contactProperties = [];
  8. public function __construct($name = null, array $data = array(), $dataName = '')
  9. {
  10. parent::__construct($name, $data, $dataName);
  11. // set up all the Contact properties
  12. $this->contactProperties['address'] = new \CMText\RichContent\Common\ContactAddress('Breda', 'Netherlands', 'NL');
  13. $this->contactProperties['birthday'] = new \CMText\RichContent\Common\ContactBirthday( new \DateTime() );
  14. $this->contactProperties['email'] = new \CMText\RichContent\Common\ContactEmail('info@cm.com');
  15. $this->contactProperties['name'] = new \CMText\RichContent\Common\ContactName('CM.com Be part of it.');
  16. $this->contactProperties['organization'] = new \CMText\RichContent\Common\ContactOrganization('CM.com', 'Development');
  17. $this->contactProperties['phonenumber'] = new \CMText\RichContent\Common\ContactPhonenumber('+31765727000');
  18. $this->contactProperties['url'] = new \CMText\RichContent\Common\ContactUrl('https://cm.com');
  19. }
  20. public function testJsonSerialize()
  21. {
  22. $this->assertJson( json_encode(new Contact()) );
  23. }
  24. public function testAddUrl()
  25. {
  26. $this->assertObjectHasAttribute(
  27. 'urls',
  28. (new Contact(
  29. $this->contactProperties['url']
  30. ))->jsonSerialize()
  31. );
  32. }
  33. public function testAddPhonenumber()
  34. {
  35. $this->assertObjectHasAttribute(
  36. 'phones',
  37. (new Contact(
  38. $this->contactProperties['phonenumber']
  39. ))->jsonSerialize()
  40. );
  41. }
  42. public function testSetOrganization()
  43. {
  44. $this->assertObjectHasAttribute(
  45. 'org',
  46. (new Contact(
  47. $this->contactProperties['organization']
  48. ))->jsonSerialize()
  49. );
  50. }
  51. public function test__construct()
  52. {
  53. // empty Contact initialization
  54. $this->assertInstanceOf(
  55. Contact::class,
  56. new Contact()
  57. );
  58. // partial Contact initialization
  59. $this->assertInstanceOf(
  60. Contact::class,
  61. new Contact(
  62. $this->contactProperties['birthday'],
  63. [
  64. $this->contactProperties['url'],
  65. $this->contactProperties['url'],
  66. ]
  67. )
  68. );
  69. // full Contact initialization
  70. $this->assertInstanceOf(
  71. Contact::class,
  72. new Contact(
  73. $this->contactProperties['address'],
  74. $this->contactProperties['birthday'],
  75. $this->contactProperties['email'],
  76. $this->contactProperties['name'],
  77. $this->contactProperties['organization'],
  78. $this->contactProperties['phonenumber'],
  79. $this->contactProperties['url']
  80. )
  81. );
  82. }
  83. public function testSetBirthday()
  84. {
  85. $this->assertObjectHasAttribute(
  86. 'birthday',
  87. (new Contact(
  88. $this->contactProperties['birthday']
  89. ))->jsonSerialize()
  90. );
  91. }
  92. public function testSetName()
  93. {
  94. $this->assertObjectHasAttribute(
  95. 'name',
  96. (new Contact(
  97. $this->contactProperties['name']
  98. ))->jsonSerialize()
  99. );
  100. }
  101. public function testAddEmail()
  102. {
  103. $this->assertObjectHasAttribute(
  104. 'emails',
  105. (new Contact(
  106. $this->contactProperties['email']
  107. ))->jsonSerialize()
  108. );
  109. }
  110. public function testAddAddress()
  111. {
  112. $this->assertObjectHasAttribute(
  113. 'addresses',
  114. (new Contact(
  115. $this->contactProperties['address']
  116. ))->jsonSerialize()
  117. );
  118. }
  119. public function testContactException()
  120. {
  121. $this->expectException(ContactException::class);
  122. new Contact('just a string');
  123. }
  124. }