/tests/sync_app/Controller/SyncMappingEntityControllerTest.php

https://gitlab.com/vietcoop/sync.app · PHP · 109 lines · 79 code · 18 blank · 12 comment · 0 complexity · 39116ef085b91fbc2af5a0565b153ce2 MD5 · raw file

  1. <?php
  2. namespace GoCatalyze\SyncApp\Testing\Controller;
  3. use GoCatalyze\SyncApp\Controller\ServiceInstaceController;
  4. use GoCatalyze\SyncApp\Controller\MappingController;
  5. use GoCatalyze\SyncApp\Testing\BaseTestCase;
  6. class MappingControllerTest extends BaseTestCase
  7. {
  8. private function createDrupalInstance()
  9. {
  10. $data = [
  11. 'service_name' => 'drupal',
  12. 'description' => 'A demo Drupal Instance',
  13. 'options' => [
  14. 'host' => 'http://127.0.0.1/drupal',
  15. ],
  16. 'entity_info' => [
  17. 'node' => ['entity keys' => ['id' => 'nid']],
  18. 'user' => ['entity keys' => ['id' => 'uid']],
  19. ]
  20. ];
  21. $controller = new ServiceInstaceController($this->app);
  22. $response = $controller->post($data);
  23. $this->assertNotEmpty($response['id']);
  24. return $response['id'];
  25. }
  26. private function createSaleforceInstance()
  27. {
  28. $data = [
  29. 'service_name' => 'salesforce',
  30. 'description' => 'A demo Salesforce Instance',
  31. 'options' => [
  32. 'token' => 'MySaleforceToken',
  33. ],
  34. 'entity_info' => [
  35. 'Contact' => []
  36. ]
  37. ];
  38. $controller = new ServiceInstaceController($this->app);
  39. $response = $controller->post($data);
  40. $this->assertNotEmpty($response['id']);
  41. return $response['id'];
  42. }
  43. public function testCRUD()
  44. {
  45. $data = [
  46. 'status' => true,
  47. 'description' => 'Drupal to Saleforce mapping',
  48. 'source' => [
  49. 'service_instance' => $this->createDrupalInstance(),
  50. 'entity_type' => 'drupal.entity',
  51. 'remote_entity_type' => 'user',
  52. ],
  53. 'destination' => [
  54. 'service_instance' => $this->createSaleforceInstance(),
  55. 'entity_type' => 'salesforce.entity',
  56. 'remote_entity_type' => 'Contact',
  57. ],
  58. 'mapping' => [
  59. ['source' => 'uid', 'destination' => 'id'],
  60. ['source' => 'mail', 'destination' => 'email']
  61. ]
  62. ];
  63. $controller = new MappingController($this->app);
  64. // ---------------------
  65. // Create
  66. // ---------------------
  67. $response = $controller->post($data);
  68. $this->assertArrayHasKey('id', $response);
  69. $this->assertGreaterThan(0, $response['id']);
  70. // ---------------------
  71. // Get
  72. // ---------------------
  73. $mapping = $controller->get($response['id']);
  74. $this->assertGreaterThan(0, $mapping['id']);
  75. $this->assertTrue($mapping['status']);
  76. $this->assertEquals($data['description'], $mapping['description']);
  77. // ---------------------
  78. // Update
  79. // ---------------------
  80. $data['description'] .= ' (updated)';
  81. $controller->put($mapping['id'], $data);
  82. $mapping = $controller->get($mapping['id']);
  83. $this->assertEquals($data['description'], $mapping['description']);
  84. // ---------------------
  85. // Delete
  86. // ---------------------
  87. $controller->delete($mapping['id']);
  88. $this->setExpectedException('Luracast\Restler\RestException');
  89. $controller->get($mapping['id']);
  90. }
  91. }