PageRenderTime 55ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/MailRoute/API/Tests/TestClient.php

https://github.com/MailRoute/mailroute_php
PHP | 1731 lines | 1649 code | 72 blank | 10 comment | 4 complexity | a62e8d6f88182375359afe75e243daaa MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. namespace MailRoute\API\Tests;
  3. use Jamm\Tester\ClassTest;
  4. use MailRoute\API\AntiSpamMode;
  5. use MailRoute\API\Entity\Admins;
  6. use MailRoute\API\Entity\ContactReseller;
  7. use MailRoute\API\Entity\Customer;
  8. use MailRoute\API\Entity\EmailAccount;
  9. use MailRoute\API\Entity\NotificationAccountTask;
  10. use MailRoute\API\Entity\NotificationDomainTask;
  11. use MailRoute\API\Entity\Reseller;
  12. use MailRoute\API\Exception;
  13. use MailRoute\API\IClient;
  14. use MailRoute\API\NotFoundException;
  15. use MailRoute\API\ValidationException;
  16. class TestClient extends ClassTest
  17. {
  18. /** @var ClientMock */
  19. private $Client;
  20. public function __construct(IClient $Client)
  21. {
  22. $this->Client = $Client;
  23. $this->Client->setDeleteNotFoundIsError(true);
  24. $this->skipTest('testEmailAccountBulkAddAlias');
  25. //$this->skipAllExcept(array('testResellerCreateAndDeleteAdmin', 'testCustomerCreateAdmin', 'testCustomerDeleteAdmin'));
  26. }
  27. public function testGetRootSchema()
  28. {
  29. $result = $this->Client->GET();
  30. $this->assertIsArray($result);
  31. $this->assertTrue(isset($result['reseller']));
  32. }
  33. public function testSchema()
  34. {
  35. $result = $this->Client->GET('reseller/schema');
  36. $this->assertIsArray($result);
  37. $this->assertTrue(isset($result['allowed_detail_http_methods']));
  38. }
  39. public function testResellerPOST()
  40. {
  41. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999);
  42. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  43. $this->assertTrue(is_object($Reseller));
  44. $this->assertEquals($Reseller->getName(), $reseller_name);
  45. $result = $this->Client->API()->Reseller()->filter(array('name' => $reseller_name))->fetchList();
  46. $this->assertIsArray($result);
  47. $this->assertEquals(count($result), 1);
  48. $this->assertTrue($Reseller->delete());
  49. }
  50. public function testResellerPOSTDuplicate()
  51. {
  52. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999);
  53. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  54. try
  55. {
  56. $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  57. $this->assertTrue(false)->addCommentary('Duplicate was created successfully');
  58. }
  59. catch (Exception $E)
  60. {
  61. $this->assertTrue(true);
  62. }
  63. $this->assertTrue($Reseller->delete());
  64. }
  65. public function testResellerList()
  66. {
  67. $reseller_name = 'test '.microtime(1);
  68. /** @var Reseller[] $resellers */
  69. $resellers = array();
  70. $NewReseller = new Reseller($this->Client);
  71. $NewReseller->setName($reseller_name.'1');
  72. $resellers[] = $this->Client->API()->Reseller()->create($NewReseller);
  73. $resellers[] = $this->Client->API()->Reseller()->create(array('name' => $reseller_name.'2'));
  74. $resellers[] = $this->Client->API()->Reseller()->create(array('name' => $reseller_name.'3'));
  75. $resellers[] = $this->Client->API()->Reseller()->create(array('name' => $reseller_name.'4'));
  76. $resellers[] = $this->Client->API()->Reseller()->create(array('name' => $reseller_name.'5'));
  77. $resellers[] = $this->Client->API()->Reseller()->create(array('name' => $reseller_name.'6'));
  78. $result = $this->Client->API()->Reseller()->offset(1)->limit(5)->fetchList();
  79. $this->assertIsArray($result);
  80. $this->assertTrue(count($result)==5)->addCommentary($result);
  81. foreach ($resellers as $Reseller)
  82. {
  83. $this->assertTrue($Reseller->delete());
  84. }
  85. }
  86. public function testContactResellerPOST()
  87. {
  88. $email = 'test@example.com';
  89. $Reseller = $this->Client->API()->Reseller()->create(array('name' => 'test contactReseller '.microtime(1).mt_rand(1000, 9999)));
  90. $Item = new ContactReseller($this->Client);
  91. $Item->setEmail($email);
  92. $Item->setReseller($Reseller->getResourceUri());
  93. $ContactReseller = $this->Client->API()->ContactReseller()->create($Item);
  94. $this->assertTrue(is_object($ContactReseller));
  95. $this->assertEquals($ContactReseller->getEmail(), $email);
  96. $this->assertEquals($ContactReseller->getReseller()->getResourceUri(), $Reseller->getResourceUri());
  97. $Item = new ContactReseller($this->Client);
  98. $Item->setReseller('not_existing');
  99. try
  100. {
  101. $ContactReseller = $this->Client->API()->ContactReseller()->create($Item);
  102. $this->assertTrue(false);
  103. }
  104. catch (Exception $Exception)
  105. {
  106. $this->assertTrue(true);
  107. }
  108. $this->assertTrue($ContactReseller->delete());
  109. $this->assertTrue($Reseller->delete());
  110. }
  111. public function testResellerDELETE()
  112. {
  113. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999).'_del';
  114. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  115. $this->assertTrue(is_object($Reseller));
  116. $this->assertEquals($Reseller->getName(), $reseller_name)->addCommentary($Reseller);
  117. $result = $Reseller->delete();
  118. $this->assertTrue($result);
  119. try
  120. {
  121. $result = $this->Client->API()->Reseller()->get($Reseller->getId());
  122. }
  123. catch (Exception $E)
  124. {
  125. $result = false;
  126. }
  127. $this->assertTrue(!$result)->addCommentary(gettype($result).': ')->addCommentary($result);
  128. }
  129. public function testResellerPUT()
  130. {
  131. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999).'_put';
  132. $NewReseller = new Reseller($this->Client);
  133. $NewReseller->setName($reseller_name);
  134. $Reseller = $this->Client->API()->Reseller()->create($NewReseller);
  135. $this->assertEquals($Reseller->getName(), $reseller_name);
  136. $Reseller->setName($reseller_name.'_updated');
  137. try
  138. {
  139. $Reseller = $this->Client->API()->Reseller()->update($Reseller);
  140. }
  141. catch (\Exception $E)
  142. {
  143. $this->assertTrue(false);
  144. }
  145. $this->assertEquals($Reseller->getName(), $reseller_name.'_updated', true);
  146. $Reseller->setName($reseller_name.'_saved');
  147. try
  148. {
  149. $Reseller->save();
  150. }
  151. catch (\Exception $E)
  152. {
  153. $this->assertTrue(false);
  154. }
  155. $Reseller = $this->Client->API()->Reseller()->get($Reseller->getId());
  156. $this->assertEquals($Reseller->getName(), $reseller_name.'_saved', true);
  157. $this->assertTrue($Reseller->delete());
  158. $ResellerWithoutID = new Reseller($this->Client);
  159. try
  160. {
  161. $this->Client->API()->Reseller()->update($Reseller);
  162. $this->assertTrue(false);
  163. }
  164. catch (Exception $E)
  165. {
  166. $this->assertTrue(true);
  167. }
  168. try
  169. {
  170. $ResellerWithoutID->save();
  171. $this->assertTrue(false);
  172. }
  173. catch (Exception $E)
  174. {
  175. $this->assertTrue(true);
  176. }
  177. }
  178. public function testSearch()
  179. {
  180. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999);
  181. /** @var Reseller[] $resellers */
  182. $resellers = array();
  183. $NewReseller = new Reseller($this->Client);
  184. $NewReseller->setName($reseller_name.'1');
  185. $resellers[] = $this->Client->API()->Reseller()->create($NewReseller);
  186. $NewReseller->setName($reseller_name.'2');
  187. $resellers[] = $this->Client->API()->Reseller()->create($NewReseller);
  188. $result = $this->Client->API()->Reseller()->search($reseller_name);
  189. $this->assertIsArray($result);
  190. $this->assertIsObject($result[0]);
  191. $this->assertEquals($result[1]->getResourceURI(), $resellers[1]->getResourceUri());
  192. foreach ($resellers as $Reseller)
  193. {
  194. $this->assertTrue($Reseller->delete());
  195. }
  196. }
  197. public function testResellerCreateAndDeleteAdmin()
  198. {
  199. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999).'create_admin';
  200. $NewReseller = new Reseller($this->Client);
  201. $NewReseller->setName($reseller_name);
  202. $Reseller = $this->Client->API()->Reseller()->create($NewReseller);
  203. try
  204. {
  205. $Admin = $Reseller->createAdmin('test@example.com');
  206. $this->assertIsObject($Admin);
  207. $this->assertEquals($Admin->getEmail(), 'test@example.com');
  208. $this->assertEquals($Admin->getReseller()->getResourceUri(), $Reseller->getResourceUri());
  209. $this->assertTrue($Reseller->deleteAdmin('test@example.com'));
  210. }
  211. catch (Exception $E)
  212. {
  213. $this->assertTrue(false)->addCommentary($E->getResponse());
  214. }
  215. try
  216. {
  217. $Reseller->createAdmin('--', 0);
  218. $this->assertTrue(false);
  219. }
  220. catch (ValidationException $E)
  221. {
  222. $this->assertTrue(true);
  223. }
  224. $this->assertTrue($Reseller->delete());
  225. }
  226. public function testResellerGetContacts()
  227. {
  228. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999).__FUNCTION__;
  229. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  230. for ($i = 0; $i < 5; $i++)
  231. {
  232. $this->Client->API()->ContactReseller()->create(array(
  233. 'reseller' => $this->Client->getAPIPathPrefix().$Reseller->getApiEntityResource().'/'.$Reseller->getId().'/',
  234. 'email' => 'reseller_contact@example.com'
  235. ));
  236. }
  237. $Contacts = $Reseller->getContacts();
  238. $this->assertIsArray($Contacts);
  239. $this->assertIsObject($Contacts[0]);
  240. $this->assertEquals($Contacts[0]->getReseller()->getResourceUri(), $Reseller->getResourceUri());
  241. $this->assertEquals($Contacts[0]->getEmail(), 'reseller_contact@example.com');
  242. foreach ($Contacts as $Contact)
  243. {
  244. $this->assertTrue($Contact->delete());
  245. }
  246. $this->assertTrue($Reseller->delete());
  247. }
  248. public function testResellerCreateContact()
  249. {
  250. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999).__FUNCTION__;
  251. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  252. $result = $Reseller->createContact('contact@example.com');
  253. $this->assertIsObject($result);
  254. $this->assertEquals($result->getEmail(), 'contact@example.com');
  255. $contacts = $Reseller->getContacts();
  256. $this->assertEquals(count($contacts), 1);
  257. $this->assertEquals($contacts[0]->getEmail(), 'contact@example.com');
  258. $this->assertEquals($contacts[0]->getReseller()->getResourceUri(), $Reseller->getResourceUri());
  259. $this->assertTrue($result->delete());
  260. $this->assertTrue($Reseller->delete());
  261. try
  262. {
  263. $Admin = $Reseller->createAdmin('', 0);
  264. $this->assertTrue(false);
  265. $this->assertTrue($Admin->delete());
  266. }
  267. catch (Exception $E)
  268. {
  269. $this->assertTrue(true);
  270. }
  271. }
  272. public function testResellerCreateCustomer()
  273. {
  274. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999).__FUNCTION__;
  275. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  276. $result = $Reseller->createCustomer('customer'.$reseller_name);
  277. $this->assertIsObject($result);
  278. $this->assertEquals($result->getName(), 'customer'.$reseller_name);
  279. $Customer = $this->Client->API()->Customer()->get($result->getId());
  280. $this->assertEquals($Customer->getName(), 'customer'.$reseller_name);
  281. $this->assertEquals($Customer->getReseller()->getResourceUri(), $Reseller->getResourceUri());
  282. $this->assertTrue($result->delete());
  283. $this->assertTrue($Reseller->delete());
  284. try
  285. {
  286. $Customer = $Reseller->createCustomer('');
  287. $this->assertTrue(false);
  288. $Customer->delete();
  289. }
  290. catch (Exception $E)
  291. {
  292. $this->assertTrue(true);
  293. }
  294. }
  295. public function testCustomerCreateContact()
  296. {
  297. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).mt_rand(1, 9999).__FUNCTION__;
  298. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  299. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  300. $result = $Customer->createContact('customer@example.com');
  301. $this->assertIsObject($result);
  302. $this->assertEquals($result->getEmail(), 'customer@example.com');
  303. $Contact = $this->Client->API()->ContactCustomer()->get($result->getId());
  304. $this->assertEquals($Contact->getEmail(), $result->getEmail());
  305. $this->assertEquals($Contact->getCustomer()->getResourceUri(), $Customer->getResourceUri());
  306. $this->assertTrue($result->delete());
  307. $this->assertTrue($Customer->delete());
  308. $this->assertTrue($Reseller->delete());
  309. try
  310. {
  311. $Contact = $Customer->createContact('');
  312. $this->assertTrue(false);
  313. $Contact->delete();
  314. }
  315. catch (Exception $E)
  316. {
  317. $this->assertTrue(true);
  318. }
  319. }
  320. public function testCustomerCreateAdmin()
  321. {
  322. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).mt_rand(1, 9999).__FUNCTION__;
  323. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  324. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  325. $result = $Customer->createAdmin('admin_customer@example.com');
  326. $this->assertIsObject($result);
  327. $this->assertEquals($result->getEmail(), 'admin_customer@example.com');
  328. $Admin = $this->Client->API()->Admins()->get($result->getId());
  329. $this->assertEquals($Admin->getEmail(), $result->getEmail());
  330. $this->assertEquals($Admin->getCustomer()->getResourceUri(), $Customer->getResourceUri());
  331. $this->assertTrue($result->delete());
  332. $this->assertTrue($Customer->delete());
  333. $this->assertTrue($Reseller->delete());
  334. try
  335. {
  336. $Admin = $Customer->createAdmin('');
  337. $this->assertTrue(false);
  338. $Admin->delete();
  339. }
  340. catch (Exception $E)
  341. {
  342. $this->assertTrue(true);
  343. }
  344. }
  345. public function testCustomerDeleteAdmin()
  346. {
  347. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).mt_rand(1, 9999).__FUNCTION__;
  348. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  349. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  350. $adm_email = 'admin_customer'.md5($reseller_name).'@example.com';
  351. $Customer->createAdmin($adm_email);
  352. $Customer->createAdmin('2'.$adm_email);
  353. $result = $Customer->deleteAdmin($adm_email);
  354. $this->assertTrueStrict($result);
  355. $RefreshCustomer = $this->Client->API()->Customer()->get($Customer->getId());
  356. /** @var Admins[] $new_list */
  357. $new_list = $RefreshCustomer->getAdmins();
  358. $this->assertEquals(count($new_list), 1, true);
  359. $this->assertEquals($new_list[0]->getEmail(), '2'.$adm_email);
  360. $this->assertTrue($new_list[0]->delete());
  361. $this->assertTrue($Customer->delete());
  362. $this->assertTrue($Reseller->delete());
  363. try
  364. {
  365. $Customer->deleteAdmin('');
  366. $this->assertTrue(false);
  367. }
  368. catch (Exception $E)
  369. {
  370. $this->assertTrue(true);
  371. }
  372. }
  373. public function testCustomerCreateDomain()
  374. {
  375. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).mt_rand(1, 9999).__FUNCTION__;
  376. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  377. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  378. $d = 'domain'.md5(microtime(1).mt_rand(1, 9999).mt_rand(1, 9999).__LINE__).'.name';
  379. $result = $Customer->createDomain($d);
  380. $this->assertIsObject($result);
  381. $this->assertEquals($result->getName(), $d);
  382. try
  383. {
  384. $Domain = $Customer->createDomain('');
  385. $this->assertTrue(false);
  386. $Domain->delete();
  387. }
  388. catch (Exception $E)
  389. {
  390. $this->assertTrue(true);
  391. }
  392. $this->assertTrue($result->delete());
  393. $this->assertTrue($Customer->delete());
  394. $this->assertTrue($Reseller->delete());
  395. }
  396. public function testDomainMoveToCustomer()
  397. {
  398. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  399. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  400. $Customer1 = $Reseller->createCustomer('customer1'.$reseller_name);
  401. $Customer2 = $Reseller->createCustomer('customer2'.$reseller_name);
  402. $Domain = $Customer1->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  403. $this->assertEquals($Domain->getCustomer()->getResourceUri(), $Customer1->getResourceUri());
  404. $result = $Domain->moveToCustomer($Customer2);
  405. $this->assertTrueStrict($result);
  406. $FreshDomain = $this->Client->API()->Domain()->get($Domain->getId());
  407. $this->assertEquals($FreshDomain->getCustomer()->getResourceUri(), $Customer2->getResourceUri());
  408. try
  409. {
  410. $response = $Domain->moveToCustomer(new Customer($this->Client));
  411. $this->assertTrue(false)->addCommentary($response);
  412. }
  413. catch (Exception $E)
  414. {
  415. $this->assertTrue(true);
  416. }
  417. $this->assertTrue($Domain->delete());
  418. $this->assertTrue($Customer2->delete());
  419. $this->assertTrue($Customer1->delete());
  420. $this->assertTrue($Reseller->delete());
  421. }
  422. public function testDomainCreateContact()
  423. {
  424. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  425. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  426. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  427. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  428. $email = 'domain.contact.'.md5($Domain->getResourceUri()).'@example.com';
  429. $result = $Domain->createContact($email);
  430. $this->assertIsObject($result);
  431. $this->assertEquals($result->getEmail(), $email);
  432. $this->assertEquals($result->getDomain()->getResourceUri(), $Domain->getResourceUri());
  433. try
  434. {
  435. $C = $Domain->createContact('');
  436. $this->assertTrue(false);
  437. $C->delete();
  438. }
  439. catch (Exception $E)
  440. {
  441. $this->assertTrue(true);
  442. }
  443. $this->assertTrue($result->delete());
  444. $this->assertTrue($Domain->delete());
  445. $this->assertTrue($Customer->delete());
  446. $this->assertTrue($Reseller->delete());
  447. }
  448. public function testDomainCreateMailServer()
  449. {
  450. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  451. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  452. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  453. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  454. $result = $Domain->createMailServer('127.0.0.1');
  455. $this->assertIsObject($result);
  456. $this->assertEquals($result->getServer(), '127.0.0.1');
  457. $Server = $this->Client->API()->MailServer()->get($result->getId());
  458. $this->assertEquals($Server->getDomain()->getResourceUri(), $Domain->getResourceUri());
  459. try
  460. {
  461. $S = $Domain->createMailServer('');
  462. $this->assertTrue(false);
  463. $S->delete();
  464. }
  465. catch (Exception $E)
  466. {
  467. $this->assertTrue(true);
  468. }
  469. $this->assertTrue($result->delete());
  470. $this->assertTrue($Domain->delete());
  471. $this->assertTrue($Customer->delete());
  472. $this->assertTrue($Reseller->delete());
  473. }
  474. public function testDomainCreateOutboundServer()
  475. {
  476. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  477. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  478. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  479. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  480. $result = $Domain->createOutboundServer('127.0.0.1');
  481. $this->assertIsObject($result);
  482. $this->assertEquals($result->getServer(), '127.0.0.1');
  483. $Server = $this->Client->API()->OutboundServer()->get($result->getId());
  484. $this->assertEquals($Server->getDomain()->getResourceUri(), $Domain->getResourceUri());
  485. try
  486. {
  487. $S = $Domain->createOutboundServer('');
  488. $this->assertTrue(false);
  489. $S->delete();
  490. }
  491. catch (Exception $E)
  492. {
  493. $this->assertTrue(true);
  494. }
  495. $this->assertTrue($result->delete());
  496. $this->assertTrue($Domain->delete());
  497. $this->assertTrue($Customer->delete());
  498. $this->assertTrue($Reseller->delete());
  499. }
  500. public function testDomainCreateEmailAccount()
  501. {
  502. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  503. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  504. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  505. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  506. $lp = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  507. $result = $Domain->createEmailAccount($lp);
  508. $this->assertIsObject($result);
  509. $this->assertEquals($result->getLocalpart(), $lp);
  510. $EmailAccount = $this->Client->API()->EmailAccount()->get($result->getId());
  511. $this->assertEquals($EmailAccount->getLocalpart(), $lp);
  512. $this->assertEquals($EmailAccount->getResourceUri(), $result->getResourceUri());
  513. $this->assertEquals($EmailAccount->getDomain()->getResourceUri(), $Domain->getResourceUri());
  514. try
  515. {
  516. $EA = $Domain->createEmailAccount('');
  517. $this->assertTrue(false);
  518. $EA->delete();
  519. }
  520. catch (Exception $E)
  521. {
  522. $this->assertTrue(true);
  523. }
  524. $this->assertTrue($result->delete());
  525. $this->assertTrue($Domain->delete());
  526. $this->assertTrue($Customer->delete());
  527. $this->assertTrue($Reseller->delete());
  528. }
  529. public function testDomainBulkCreateEmailAccount()
  530. {
  531. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  532. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  533. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  534. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  535. $localparts = array();
  536. for ($i = 0; $i < 5; $i++)
  537. {
  538. $localparts[] = array('localpart' => $i);
  539. }
  540. $result = $Domain->bulkCreateEmailAccount($localparts);
  541. $this->assertIsObject($result[0]);
  542. $this->assertIsObject($result[0]);
  543. foreach ($result as $key => $EmailAccount)
  544. {
  545. if (is_a($EmailAccount, 'MailRoute\\API\\Exception'))
  546. {
  547. /** @var Exception $EmailAccount */
  548. $this->assertTrue(false)->addCommentary('Exception: ')->addCommentary($EmailAccount->getResponse());
  549. continue;
  550. }
  551. $this->assertEquals($EmailAccount->getLocalpart(), $key);
  552. $this->assertTrue($EmailAccount->delete());
  553. }
  554. try
  555. {
  556. $Domain->bulkCreateEmailAccount(array('z' => 1));
  557. $this->assertTrue(false);
  558. }
  559. catch (Exception $E)
  560. {
  561. $this->assertTrue(true);
  562. }
  563. $this->assertTrue($Domain->delete());
  564. $this->assertTrue($Customer->delete());
  565. $this->assertTrue($Reseller->delete());
  566. }
  567. public function testDomainCreateAlias()
  568. {
  569. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  570. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  571. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  572. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  573. $name = 'domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name';
  574. $result = $Domain->createAlias($name);
  575. $this->assertIsObject($result);
  576. $this->assertEquals($result->getName(), $name);
  577. $DomainAlias = $this->Client->API()->DomainAlias()->get($result->getId());
  578. $this->assertEquals($DomainAlias->getDomain()->getResourceUri(), $Domain->getResourceUri());
  579. try
  580. {
  581. $DA = $Domain->createAlias('');
  582. $this->assertTrue(false);
  583. $DA->delete();
  584. }
  585. catch (Exception $E)
  586. {
  587. $this->assertTrue(true);
  588. }
  589. $this->assertTrue($result->delete());
  590. $this->assertTrue($Domain->delete());
  591. $this->assertTrue($Customer->delete());
  592. $this->assertTrue($Reseller->delete());
  593. }
  594. public function testDomainAddToBlackList()
  595. {
  596. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  597. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  598. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  599. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  600. $email = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5).'@example.com';
  601. $result = $Domain->addToBlackList($email);
  602. $this->assertIsObject($result);
  603. $this->assertEquals($result->getWb(), 'b');
  604. $this->assertEquals($result->getEmail(), $email);
  605. $BlackList = $this->Client->API()->Wblist()->get($result->getId());
  606. $this->assertEquals($BlackList->getEmail(), $email);
  607. $this->assertEquals($BlackList->getResourceUri(), $result->getResourceUri());
  608. $this->assertEquals($BlackList->getDomain()->getResourceUri(), $Domain->getResourceUri());
  609. try
  610. {
  611. $BL = $Domain->addToBlackList('');
  612. $this->assertTrue(false);
  613. $BL->delete();
  614. }
  615. catch (Exception $E)
  616. {
  617. $this->assertTrue(true);
  618. }
  619. $this->assertTrue($result->delete());
  620. $this->assertTrue($Domain->delete());
  621. $this->assertTrue($Customer->delete());
  622. $this->assertTrue($Reseller->delete());
  623. }
  624. public function testDomainAddToWhiteList()
  625. {
  626. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  627. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  628. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  629. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  630. $email = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5).'@example.com';
  631. $result = $Domain->addToWhiteList($email);
  632. $this->assertIsObject($result);
  633. $this->assertEquals($result->getWb(), 'w');
  634. $this->assertEquals($result->getEmail(), $email);
  635. $WhiteList = $this->Client->API()->Wblist()->get($result->getId());
  636. $this->assertEquals($WhiteList->getEmail(), $email);
  637. $this->assertEquals($WhiteList->getResourceUri(), $result->getResourceUri());
  638. $this->assertEquals($WhiteList->getDomain()->getResourceUri(), $Domain->getResourceUri());
  639. try
  640. {
  641. $WL = $Domain->addToWhiteList('');
  642. $this->assertTrue(false);
  643. $WL->delete();
  644. }
  645. catch (Exception $E)
  646. {
  647. $this->assertTrue(true);
  648. }
  649. $this->assertTrue($result->delete());
  650. $this->assertTrue($Domain->delete());
  651. $this->assertTrue($Customer->delete());
  652. $this->assertTrue($Reseller->delete());
  653. }
  654. public function testEmailAccountAddAlias()
  655. {
  656. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  657. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  658. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  659. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  660. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  661. $EmailAccount = $Domain->createEmailAccount($localpart);
  662. $result = $EmailAccount->addAlias($localpart.'alias');
  663. $this->assertIsObject($result);
  664. $this->assertEquals($result->getLocalpart(), $localpart.'alias');
  665. $this->assertEquals($result->getEmailAccount()->getId(), $EmailAccount->getId());
  666. $Alias = $this->Client->API()->LocalpartAlias()->get($result->getId());
  667. $this->assertEquals($Alias->getResourceUri(), $result->getResourceUri());
  668. $this->assertEquals($Alias->getLocalpart(), $result->getLocalpart());
  669. try
  670. {
  671. $LA = $EmailAccount->addAlias('');
  672. $this->assertTrue(false);
  673. $LA->delete();
  674. }
  675. catch (Exception $E)
  676. {
  677. $this->assertTrue(true);
  678. }
  679. $this->assertTrue($result->delete());
  680. $this->assertTrue($EmailAccount->delete());
  681. $this->assertTrue($Domain->delete());
  682. $this->assertTrue($Customer->delete());
  683. $this->assertTrue($Reseller->delete());
  684. }
  685. public function testEmailAccountBulkAddAlias()
  686. {
  687. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  688. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  689. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  690. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  691. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  692. $EmailAccount = $Domain->createEmailAccount($localpart);
  693. $aliases = array();
  694. for ($i = 0; $i < 3; $i++)
  695. {
  696. $aliases[] = $localpart.'alias'.$i;
  697. }
  698. try
  699. {
  700. $result = $EmailAccount->bulkAddAlias($aliases);
  701. $this->assertTrueStrict($result);
  702. $aliases = $EmailAccount->getLocalpartAliases();
  703. $this->assertIsObject($aliases[0]);
  704. foreach ($aliases as $Alias)
  705. {
  706. $this->assertEquals($Alias->getEmailAccount()->getResourceUri(), $EmailAccount->getResourceUri());
  707. $this->assertTrue($Alias->delete());
  708. }
  709. }
  710. catch (Exception $E)
  711. {
  712. $this->assertTrue(false)->addCommentary($E->getMessage());
  713. }
  714. try
  715. {
  716. $EmailAccount->bulkAddAlias(array('z' => 5));
  717. $this->assertTrue(false);
  718. }
  719. catch (Exception $E)
  720. {
  721. $this->assertTrue(true);
  722. }
  723. $this->assertTrue($EmailAccount->delete());
  724. $this->assertTrue($Domain->delete());
  725. $this->assertTrue($Customer->delete());
  726. $this->assertTrue($Reseller->delete());
  727. }
  728. public function testEmailAccountAddToBlackList()
  729. {
  730. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  731. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  732. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  733. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  734. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  735. $EmailAccount = $Domain->createEmailAccount($localpart);
  736. $blacklisted_email = $localpart.'@example.com';
  737. $result = $EmailAccount->addToBlackList($blacklisted_email);
  738. $this->assertIsObject($result);
  739. $this->assertEquals($result->getEmail(), $blacklisted_email);
  740. $this->assertEquals($result->getEmailAccount()->getResourceUri(), $EmailAccount->getResourceUri());
  741. $BlackList = $this->Client->API()->Wblist()->get($result->getId());
  742. $this->assertEquals($BlackList->getWb(), 'b');
  743. $this->assertEquals($BlackList->getEmail(), $blacklisted_email);
  744. $this->assertEquals($BlackList->getResourceUri(), $result->getResourceUri());
  745. try
  746. {
  747. $BL = $Domain->addToBlackList('');
  748. $this->assertTrue(false);
  749. $BL->delete();
  750. }
  751. catch (Exception $E)
  752. {
  753. $this->assertTrue(true);
  754. }
  755. $this->assertTrue($result->delete());
  756. $this->assertTrue($EmailAccount->delete());
  757. $this->assertTrue($Domain->delete());
  758. $this->assertTrue($Customer->delete());
  759. $this->assertTrue($Reseller->delete());
  760. }
  761. public function testEmailAccountAddToWhiteList()
  762. {
  763. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  764. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  765. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  766. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  767. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  768. $EmailAccount = $Domain->createEmailAccount($localpart);
  769. $whitelisted_email = $localpart.'@example.com';
  770. $result = $EmailAccount->addToWhiteList($whitelisted_email);
  771. $this->assertIsObject($result);
  772. $this->assertEquals($result->getEmail(), $whitelisted_email);
  773. $this->assertEquals($result->getEmailAccount()->getResourceUri(), $EmailAccount->getResourceUri());
  774. $WhiteList = $this->Client->API()->Wblist()->get($result->getId());
  775. $this->assertEquals($WhiteList->getWb(), 'w');
  776. $this->assertEquals($WhiteList->getEmail(), $whitelisted_email);
  777. $this->assertEquals($WhiteList->getResourceUri(), $result->getResourceUri());
  778. try
  779. {
  780. $WL = $Domain->addToWhiteList('');
  781. $this->assertTrue(false);
  782. $WL->delete();
  783. }
  784. catch (Exception $E)
  785. {
  786. $this->assertTrue(true);
  787. }
  788. $this->assertTrue($result->delete());
  789. $this->assertTrue($EmailAccount->delete());
  790. $this->assertTrue($Domain->delete());
  791. $this->assertTrue($Customer->delete());
  792. $this->assertTrue($Reseller->delete());
  793. }
  794. public function testEmailAccountMakeAliasesFrom()
  795. {
  796. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  797. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  798. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  799. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  800. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  801. $EmailAccount = $Domain->createEmailAccount($localpart);
  802. $to_aliases = array();
  803. foreach (range(1, 5) as $i)
  804. {
  805. $to_aliases[] = $Domain->createEmailAccount($localpart.$i);
  806. }
  807. try
  808. {
  809. $result = $EmailAccount->makeAliasesFrom($to_aliases);
  810. $this->assertTrue($result);
  811. }
  812. catch (Exception $E)
  813. {
  814. $this->assertTrue(false)->addCommentary($E->getResponse());
  815. }
  816. $aliases = $EmailAccount->getLocalpartAliases();
  817. $this->assertEquals(count($aliases), 5);
  818. $this->assertEquals($aliases[0]->getEmailAccount()->getResourceUri(), $EmailAccount->getResourceUri());
  819. try
  820. {
  821. $EmailAccount->makeAliasesFrom(array(new EmailAccount($this->Client)));
  822. $this->assertTrue(false);
  823. }
  824. catch (Exception $E)
  825. {
  826. $this->assertTrue(true);
  827. }
  828. $this->assertTrue($EmailAccount->delete());
  829. $this->assertTrue($Domain->delete());
  830. $this->assertTrue($Customer->delete());
  831. $this->assertTrue($Reseller->delete());
  832. }
  833. public function testResellerDeleteContact()
  834. {
  835. $reseller_name = 'test '.microtime(1).mt_rand(1000, 9999).__FUNCTION__;
  836. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  837. $email = 'contact@example.com';
  838. $Contact = $Reseller->createContact($email);
  839. try
  840. {
  841. $result = $Reseller->deleteContact($email);
  842. }
  843. catch (Exception $E)
  844. {
  845. $this->assertTrue(false)->addCommentary($E->getResponse());
  846. $Reseller->delete();
  847. return false;
  848. }
  849. $this->assertEquals($result, 1);
  850. try
  851. {
  852. $this->Client->API()->ContactReseller()->get($Contact->getId());
  853. $this->assertTrue(false)->addCommentary('was not deleted');
  854. }
  855. catch (NotFoundException $Exception)
  856. {
  857. $this->assertTrue(true);
  858. }
  859. $this->assertTrue($Reseller->delete());
  860. }
  861. public function testCustomerDeleteContact()
  862. {
  863. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).mt_rand(1, 9999).__FUNCTION__;
  864. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  865. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  866. $email = 'customer@example.com';
  867. $Contact = $Customer->createContact($email);
  868. $result = $Customer->deleteContact($email);
  869. try
  870. {
  871. $this->Client->API()->ContactCustomer()->get($Contact->getId());
  872. $this->assertTrue(false)->addCommentary('was not deleted');
  873. }
  874. catch (NotFoundException $Exception)
  875. {
  876. $this->assertTrue(true);
  877. }
  878. $this->assertEquals($result, 1);
  879. $this->assertTrue($Customer->delete());
  880. $this->assertTrue($Reseller->delete());
  881. }
  882. public function testDomainDeleteContact()
  883. {
  884. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  885. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  886. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  887. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  888. $email = 'domain.contact.'.md5($Domain->getResourceUri()).'@example.com';
  889. $Contact = $Domain->createContact($email);
  890. $result = $Domain->deleteContact($email);
  891. $this->assertEquals($result, 1);
  892. try
  893. {
  894. $this->Client->API()->ContactDomain()->get($Contact->getId());
  895. $this->assertTrue(false)->addCommentary('was not deleted');
  896. }
  897. catch (NotFoundException $E)
  898. {
  899. $this->assertTrue(true);
  900. }
  901. $this->assertTrue($Domain->delete());
  902. $this->assertTrue($Customer->delete());
  903. $this->assertTrue($Reseller->delete());
  904. }
  905. public function testEmailAccountRegenerateApiKey()
  906. {
  907. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  908. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  909. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  910. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  911. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  912. $EmailAccount = $Domain->createEmailAccount($localpart);
  913. $result = $EmailAccount->regenerateApiKey();
  914. $this->assertTrue($result!==false)->addCommentary($result);
  915. $this->assertIsValueOfType($result, 'string')->addCommentary($result);
  916. $this->assertTrue(strlen($result) > 0);
  917. $this->assertTrue($EmailAccount->delete());
  918. $this->assertTrue($Domain->delete());
  919. $this->assertTrue($Customer->delete());
  920. $this->assertTrue($Reseller->delete());
  921. }
  922. public function testEmailAccountUseDomainPolicy()
  923. {
  924. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  925. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  926. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  927. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  928. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  929. $EmailAccount = $Domain->createEmailAccount($localpart);
  930. $Domain->setUserlistComplete(1);
  931. $Domain->save();
  932. try
  933. {
  934. $result = $EmailAccount->useDomainPolicy();
  935. }
  936. catch (Exception $E)
  937. {
  938. $this->assertTrue(false)->addCommentary($E->getMessage());
  939. $EmailAccount->delete();
  940. $Domain->delete();
  941. $Customer->delete();
  942. $Reseller->delete();
  943. return false;
  944. }
  945. $this->assertTrue($result);
  946. $SelfPolicy = $EmailAccount->getPolicy();
  947. $this->assertTrue($SelfPolicy->getUseDomainPolicy());
  948. $Policy = $EmailAccount->getActivePolicy();
  949. $this->assertEquals($Policy->getResourceUri(), $Domain->getPolicy()->getResourceUri());
  950. $this->assertInstanceOf($Policy, 'MailRoute\\API\\Entity\\PolicyDomain');
  951. $this->assertTrue($EmailAccount->delete());
  952. $this->assertTrue($Domain->delete());
  953. $this->assertTrue($Customer->delete());
  954. $this->assertTrue($Reseller->delete());
  955. }
  956. public function testEmailAccountUseSelfPolicy()
  957. {
  958. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  959. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  960. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  961. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  962. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  963. $EmailAccount = $Domain->createEmailAccount($localpart);
  964. $Domain->setUserlistComplete(1);
  965. $Domain->save();
  966. try
  967. {
  968. $result = $EmailAccount->useSelfPolicy();
  969. }
  970. catch (Exception $E)
  971. {
  972. $this->assertTrue(false)->addCommentary($E->getMessage());
  973. $EmailAccount->delete();
  974. $Domain->delete();
  975. $Customer->delete();
  976. $Reseller->delete();
  977. return false;
  978. }
  979. $this->assertTrue($result);
  980. $SelfPolicy = $EmailAccount->getPolicy();
  981. $this->assertTrue(!$SelfPolicy->getUseDomainPolicy());
  982. $Policy = $EmailAccount->getActivePolicy();
  983. $this->assertTrue($Policy->getResourceUri()!=$Domain->getPolicy()->getResourceUri());
  984. $this->assertEquals($Policy->getResourceUri(), $SelfPolicy->getResourceUri());
  985. $this->assertInstanceOf($Policy, 'MailRoute\\API\\Entity\\PolicyUser');
  986. $this->assertTrue($EmailAccount->delete());
  987. $this->assertTrue($Domain->delete());
  988. $this->assertTrue($Customer->delete());
  989. $this->assertTrue($Reseller->delete());
  990. }
  991. public function testEmailAccountGetActivePolicy()
  992. {
  993. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  994. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  995. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  996. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  997. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  998. $EmailAccount = $Domain->createEmailAccount($localpart);
  999. $Domain->setUserlistComplete(1);
  1000. $Domain->save();
  1001. $EmailAccount->useDomainPolicy();
  1002. $result = $EmailAccount->getActivePolicy();
  1003. $this->assertInstanceOf($result, 'MailRoute\\API\\Entity\\PolicyDomain');
  1004. $this->assertEquals($result->getResourceUri(), $Domain->getPolicy()->getResourceUri());
  1005. $EmailAccount->useSelfPolicy();
  1006. $result = $EmailAccount->getActivePolicy();
  1007. $this->assertInstanceOf($result, 'MailRoute\\API\\Entity\\PolicyUser');
  1008. $this->assertTrue($EmailAccount->delete());
  1009. $this->assertTrue($Domain->delete());
  1010. $this->assertTrue($Customer->delete());
  1011. $this->assertTrue($Reseller->delete());
  1012. }
  1013. public function testEmailAccountUseDomainNotification()
  1014. {
  1015. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  1016. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  1017. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  1018. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  1019. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  1020. $EmailAccount = $Domain->createEmailAccount($localpart);
  1021. $this->assertTrue($EmailAccount->useDomainNotifications());
  1022. $result = $EmailAccount->getActiveNotificationTasks();
  1023. $this->assertIsArray($result);
  1024. $this->assertInstanceOf($result[0], 'MailRoute\\API\\Entity\\NotificationDomainTask');
  1025. /** @var NotificationDomainTask $DomainNotificationTask */
  1026. list($DomainNotificationTask) = $Domain->getNotificationTasks();
  1027. $this->assertEquals($result[0]->getResourceUri(), $DomainNotificationTask->getResourceUri());
  1028. $this->assertTrue($EmailAccount->useSelfNotifications());
  1029. $result = $EmailAccount->getActiveNotificationTasks();
  1030. $this->assertIsArray($result);
  1031. $this->assertInstanceOf($result[0], 'MailRoute\\API\\Entity\\NotificationAccountTask');
  1032. /** @var NotificationAccountTask $SelfNotificationTask */
  1033. list($SelfNotificationTask) = $EmailAccount->getNotificationTasks();
  1034. $this->assertEquals($result[0]->getResourceUri(), $SelfNotificationTask->getResourceUri());
  1035. $this->assertTrue($EmailAccount->delete());
  1036. $this->assertTrue($Domain->delete());
  1037. $this->assertTrue($Customer->delete());
  1038. $this->assertTrue($Reseller->delete());
  1039. }
  1040. public function testEmailAccountCreate()
  1041. {
  1042. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  1043. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  1044. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  1045. $domain_name = 'domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name';
  1046. $Domain = $Customer->createDomain($domain_name);
  1047. $result = $this->Client->API()->EmailAccount()->create(array('email' => 'email@'.$domain_name));
  1048. $this->assertInstanceOf($result, 'MailRoute\\API\\Entity\\EmailAccount');
  1049. $this->assertEquals($result->getLocalpart(), 'email');
  1050. $this->assertEquals($result->getDomain()->getResourceUri(), $Domain->getResourceUri());
  1051. $FromServer = $this->Client->API()->EmailAccount()->get($result->getId());
  1052. $this->assertEquals($result->getResourceUri(), $FromServer->getResourceUri());
  1053. $result = $this->Client->API()->EmailAccount()->create(array('email' => 'email2@example.com', 'domain' => $Domain->getResourceUri()));
  1054. $this->assertInstanceOf($result, 'MailRoute\\API\\Entity\\EmailAccount');
  1055. $this->assertEquals($result->getLocalpart(), 'email2');
  1056. $this->assertEquals($result->getDomain()->getResourceUri(), $Domain->getResourceUri());
  1057. try
  1058. {
  1059. $this->Client->API()->EmailAccount()->create(array('email' => 'email@not_existing_example.com'));
  1060. $this->assertTrue(false)->addCommentary('exception expected');
  1061. }
  1062. catch (NotFoundException $E)
  1063. {
  1064. $this->assertTrue(true);
  1065. }
  1066. $this->assertTrue($result->delete());
  1067. $this->assertTrue($Domain->delete());
  1068. $this->assertTrue($Customer->delete());
  1069. $this->assertTrue($Reseller->delete());
  1070. }
  1071. public function testEmailAccountMassDelete()
  1072. {
  1073. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  1074. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  1075. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  1076. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  1077. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  1078. $EmailAccount = $Domain->createEmailAccount($localpart);
  1079. $id_list[] = $EmailAccount->getId();
  1080. foreach (range(1, 3) as $i)
  1081. {
  1082. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).$i.__LINE__), 5);
  1083. $EmailAccount = $Domain->createEmailAccount($localpart);
  1084. $id_list[] = $EmailAccount->getId();
  1085. }
  1086. try
  1087. {
  1088. $result = $EmailAccount->massDelete($id_list);
  1089. }
  1090. catch (Exception $E)
  1091. {
  1092. $result = false;
  1093. }
  1094. $this->assertTrue($result);
  1095. foreach ($id_list as $id)
  1096. {
  1097. try
  1098. {
  1099. $result = $this->Client->API()->EmailAccount()->get($id);
  1100. $this->assertTrue(false);
  1101. $result->delete();
  1102. }
  1103. catch (NotFoundException $E)
  1104. {
  1105. $this->assertTrue(true);
  1106. }
  1107. }
  1108. try
  1109. {
  1110. $EmailAccount->massDelete(array());
  1111. $this->assertTrue(false);
  1112. }
  1113. catch (Exception $E)
  1114. {
  1115. $this->assertTrue(true);
  1116. }
  1117. try
  1118. {
  1119. $EmailAccount->massDelete(array('x', 'y', 'z'));
  1120. $this->assertTrue(false);
  1121. }
  1122. catch (Exception $E)
  1123. {
  1124. $this->assertTrue(true);
  1125. }
  1126. $this->assertTrue($Domain->delete());
  1127. $this->assertTrue($Customer->delete());
  1128. $this->assertTrue($Reseller->delete());
  1129. }
  1130. public function testEmailAccountMassAdd()
  1131. {
  1132. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  1133. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  1134. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  1135. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  1136. $localparts = array();
  1137. foreach (range(1, 3) as $i)
  1138. {
  1139. $localparts[] = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5).$i;
  1140. }
  1141. try
  1142. {
  1143. $result = $this->Client->API()->EmailAccount()->bulkCreate(array('localparts' => $localparts, 'domain' => $Domain->getResourceUri()));
  1144. $this->assertTrue($result);
  1145. $check_list = $Domain->getEmailAccounts();
  1146. $this->assertEquals(count($check_list), count($localparts));
  1147. foreach ($check_list as $CheckEmailAccount)
  1148. {
  1149. $this->assertTrue(in_array($CheckEmailAccount->getLocalpart(), $localparts));
  1150. }
  1151. $this->assertEquals($check_list[0]->getDomain()->getResourceUri(), $Domain->getResourceUri());
  1152. }
  1153. catch (Exception $E)
  1154. {
  1155. $this->assertTrue(false);
  1156. }
  1157. try
  1158. {
  1159. $this->Client->API()->EmailAccount()->bulkCreate(array());
  1160. $this->assertTrue(false);
  1161. }
  1162. catch (Exception $E)
  1163. {
  1164. $this->assertTrue(true);
  1165. }
  1166. try
  1167. {
  1168. $this->Client->API()->EmailAccount()->bulkCreate(array('localparts' => array()));
  1169. $this->assertTrue(false);
  1170. }
  1171. catch (Exception $E)
  1172. {
  1173. $this->assertTrue(true);
  1174. }
  1175. try
  1176. {
  1177. $this->Client->API()->EmailAccount()->bulkCreate(array('localparts' => 1));
  1178. $this->assertTrue(false);
  1179. }
  1180. catch (Exception $E)
  1181. {
  1182. $this->assertTrue(true);
  1183. }
  1184. $this->assertTrue($Domain->delete());
  1185. $this->assertTrue($Customer->delete());
  1186. $this->assertTrue($Reseller->delete());
  1187. }
  1188. public function testPolicyEnableDisableMethods()
  1189. {
  1190. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  1191. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  1192. $Customer = $Reseller->createCustomer('customer'.$reseller_name);
  1193. $Domain = $Customer->createDomain('domain'.md5(microtime(1).mt_rand(1, 9999).__LINE__).'.name');
  1194. $localpart = substr(md5(microtime(1).mt_rand(1, 9999).__LINE__), 5);
  1195. $EmailAccount = $Domain->createEmailAccount($localpart);
  1196. $EmailAccount->useDomainPolicy();
  1197. $EmailAccount = $this->Client->API()->EmailAccount()->get($EmailAccount->getId());
  1198. $Policy = $EmailAccount->getActivePolicy();
  1199. $this->assertTrue($Policy->enableBadHdrFilter());
  1200. $this->assertEquals($Policy->getBypassHeaderChecks(), 'Y');
  1201. $ServerPolicy = $this->Client->API()->PolicyDomain()->get($Policy->getId());
  1202. $this->assertEquals($ServerPolicy->getBypassHeaderChecks(), 'Y');
  1203. $this->assertTrue($Policy->disableBadHdrFilter());
  1204. $this->assertEquals($Policy->getBypassHeaderChecks(), 'N');
  1205. $ServerPolicy = $this->Client->API()->PolicyDomain()->get($Policy->getId());
  1206. $this->assertEquals($ServerPolicy->getBypassHeaderChecks(), 'N');
  1207. $this->assertTrue($Policy->enableBannedFilter());
  1208. $this->assertEquals($Policy->getBypassBannedChecks(), 'Y');
  1209. $this->assertTrue($Policy->disableBannedFilter());
  1210. $this->assertEquals($Policy->getBypassBannedChecks(), 'N');
  1211. $this->assertTrue($Policy->enableSpamFiltering());
  1212. $this->assertEquals($Policy->getBypassSpamChecks(), 'Y');
  1213. $this->assertTrue($Policy->disableSpamFiltering());
  1214. $this->assertEquals($Policy->getBypassSpamChecks(), 'N');
  1215. $this->assertTrue($Policy->enableVirusFiltering());
  1216. $this->assertEquals($Policy->getBypassVirusChecks(), 'Y');
  1217. $this->assertTrue($Policy->disableVirusFiltering());
  1218. $this->assertEquals($Policy->getBypassVirusChecks(), 'N');
  1219. $this->assertTrue($Policy->disableVirusFiltering());
  1220. $ServerPolicy = $this->Client->API()->PolicyDomain()->get($Policy->getId());
  1221. $this->assertEquals($ServerPolicy->getBypassVirusChecks(), 'N');
  1222. $this->assertTrue($Policy->setAntiSpamMode(AntiSpamMode::lenient));
  1223. $this->assertTrue($EmailAccount->delete());
  1224. $this->assertTrue($Domain->delete());
  1225. $this->assertTrue($Customer->delete());
  1226. $this->assertTrue($Reseller->delete());
  1227. }
  1228. public function testResellerGetCustomers()
  1229. {
  1230. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  1231. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  1232. $this->assertEquals(count($Reseller->getCustomers()), 0);
  1233. $Reseller->createCustomer('customer1'.$reseller_name);
  1234. $Reseller->createCustomer('customer2'.$reseller_name);
  1235. $Reseller->createCustomer('customer3'.$reseller_name);
  1236. $result = $Reseller->getCustomers();
  1237. $this->assertEquals(count($result), 3);
  1238. $this->assertIsObject($result[0]);
  1239. foreach ($result as $Customer)
  1240. {
  1241. $this->assertEquals($Customer->getReseller()->getResourceUri(), $Reseller->getResourceUri());
  1242. $this->assertTrue($Customer->delete());
  1243. }
  1244. $this->assertTrue($Reseller->delete());
  1245. }
  1246. public function testResellerGetBrandingInfo()
  1247. {
  1248. $reseller_name = 'test '.microtime(1).mt_rand(1, 9999).__FUNCTION__;
  1249. $Reseller = $this->Client->API()->Reseller()->create(array('name' => $reseller_name));
  1250. $result = $Reseller->getBrandingInfo();
  1251. $this->assertIsObject($result);
  1252. $this->assertInstanceOf($result, 'MailRoute\\API\\Entity\\Brandinginfo');
  1253. $this->assertEquals($result

Large files files are truncated, but you can click here to view the full file