PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Keboola/Writer/GoodData/FunctionalTest.php

https://github.com/keboola/gooddata-writer-php-client
PHP | 143 lines | 112 code | 23 blank | 8 comment | 10 complexity | 67fd3d7d7c4db90dd55780fbeb3dce09 MD5 | raw file
  1. <?php
  2. /**
  3. * @user Jakub Matejka <jakub@keboola.com>
  4. * @date 2012-11-26
  5. *
  6. */
  7. namespace Keboola\Writer\GoodData;
  8. require_once 'config.php';
  9. class FunctionalTest extends \PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @var \Keboola\Writer\GoodData\Client
  13. */
  14. protected $client;
  15. public function setUp()
  16. {
  17. $this->client = \Keboola\Writer\GoodData\Client::factory(array(
  18. 'url' => GOODDATA_WRITER_API_URL,
  19. 'token' => STORAGE_API_TOKEN
  20. ));
  21. foreach ($this->client->getWriters() as $writer) {
  22. if ($writer['id'] != FUNCTIONAL_WRITER_ID) {
  23. $this->client->deleteWriter($writer['id']);
  24. }
  25. }
  26. }
  27. public function testConfiguration()
  28. {
  29. $result = $this->client->getTables(FUNCTIONAL_WRITER_ID);
  30. $this->assertArrayHasKey('tables', $result, "Result of GET API call /tables should contain 'tables' key");
  31. $this->assertCount(2, $result['tables'], "Result of GET API call /tables should return two configured tables");
  32. $categoriesFound = false;
  33. $productsFound = false;
  34. foreach ($result['tables'] as $t) {
  35. $this->assertArrayHasKey('id', $t, "Configured table of GET API call /tables should contain 'id' key");
  36. $this->assertArrayHasKey('bucket', $t, "Configured table of GET API call /tables should contain 'bucket' key");
  37. $this->assertArrayHasKey('name', $t, "Configured table of GET API call /tables should contain 'name' key");
  38. $this->assertArrayHasKey('export', $t, "Configured table of GET API call /tables should contain 'export' key");
  39. $this->assertArrayHasKey('isExported', $t, "Configured table of GET API call /tables should contain 'isExported' key");
  40. $this->assertArrayHasKey('lastChangeDate', $t, "Configured table of GET API call /tables should contain 'lastChangeDate' key");
  41. if ($t['id'] == 'out.c-main.categories') $categoriesFound = true;
  42. if ($t['id'] == 'out.c-main.products') $productsFound = true;
  43. }
  44. $this->assertTrue($categoriesFound, "Result of GET API call /tables should return configured table Categories");
  45. $this->assertTrue($productsFound, "Result of GET API call /tables should return configured table Products");
  46. $tableId = 'out.c-main.products';
  47. $result = $this->client->getTable(FUNCTIONAL_WRITER_ID, $tableId);
  48. $this->assertArrayHasKey('table', $result, "Result of GET API call /tables?tableId= should contain 'table' key");
  49. $this->assertArrayHasKey('id', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.id' key");
  50. $this->assertArrayHasKey('name', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.name' key");
  51. $this->assertArrayHasKey('export', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.export' key");
  52. $this->assertArrayHasKey('isExported', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.isExported' key");
  53. $this->assertArrayHasKey('lastChangeDate', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.lastChangeDate' key");
  54. $this->assertArrayHasKey('incrementalLoad', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.incrementalLoad' key");
  55. $this->assertArrayHasKey('ignoreFilter', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.ignoreFilter' key");
  56. $this->assertArrayHasKey('columns', $result['table'], "Result of GET API call /tables?tableId= should contain 'table.columns' key");
  57. $column = current($result['table']['columns']);
  58. $this->assertArrayHasKey('name', $column, "Result of GET API call /tables?tableId= should contain column with 'name' key");
  59. $this->assertArrayHasKey('gdName', $column, "Result of GET API call /tables?tableId= should contain column with 'gdName' key");
  60. $this->assertArrayHasKey('type', $column, "Result of GET API call /tables?tableId= should contain column with 'type' key");
  61. $oldName = $result['table']['name'];
  62. $newName = uniqid();
  63. $columnId = $column['name'];
  64. $oldColumnName = $column['gdName'];
  65. $newColumnName = uniqid();
  66. $this->client->updateTable(FUNCTIONAL_WRITER_ID, $tableId, $newName);
  67. $this->client->updateTableColumn(FUNCTIONAL_WRITER_ID, $tableId, $column['name'], array('gdName' => $newColumnName));
  68. $result = $this->client->getTable(FUNCTIONAL_WRITER_ID, $tableId);
  69. $this->assertEquals($newName, $result['table']['name'], 'Table out.c-main.products should have new name');
  70. $column = array();
  71. foreach ($result['table']['columns'] as $c) {
  72. if ($c['name'] == $columnId) {
  73. $column = $c;
  74. }
  75. }
  76. $this->assertEquals($newColumnName, $column['gdName'], 'Table out.c-main.products should have column with new name');
  77. $this->client->updateTable(FUNCTIONAL_WRITER_ID, $tableId, $oldName);
  78. $this->client->updateTableColumns(FUNCTIONAL_WRITER_ID, $tableId, array(array('name' => $column['name'], 'gdName' => $oldColumnName)));
  79. $result = $this->client->getTable(FUNCTIONAL_WRITER_ID, $tableId);
  80. $this->assertEquals($oldName, $result['table']['name'], 'Table out.c-main.products should have old name back');
  81. $column = array();
  82. foreach ($result['table']['columns'] as $c) {
  83. if ($c['name'] == $columnId) {
  84. $column = $c;
  85. }
  86. }
  87. $this->assertEquals($oldColumnName, $column['gdName'], 'Table out.c-main.products should have column with old name back');
  88. }
  89. public function testUpload()
  90. {
  91. $result = $this->client->uploadProject(FUNCTIONAL_WRITER_ID);
  92. $this->assertArrayHasKey('status', $result, "Result of API call 'upload-project' should contain 'status' key");
  93. $this->assertEquals('success', $result['status'], "Result of API call 'upload-project' should contain 'status' key with value 'success'");
  94. $result = $this->client->uploadTable(FUNCTIONAL_WRITER_ID, 'out.c-main.categories');
  95. $this->assertArrayHasKey('status', $result, "Result of API call 'upload-table' should contain 'status' key");
  96. $this->assertEquals('success', $result['status'], "Result of API call 'upload-table' should contain 'status' key with value 'success'");
  97. $result = $this->client->updateModel(FUNCTIONAL_WRITER_ID, 'out.c-main.categories');
  98. $this->assertArrayHasKey('status', $result, "Result of API call 'update-model' should contain 'status' key");
  99. $this->assertEquals('success', $result['status'], "Result of API call 'update-model' should contain 'status' key with value 'success'");
  100. $result = $this->client->loadData(FUNCTIONAL_WRITER_ID, array('out.c-main.categories', 'out.c-main.products'));
  101. $this->assertArrayHasKey('status', $result, "Result of API call 'load-data' should contain 'status' key");
  102. $this->assertEquals('success', $result['status'], "Result of API call 'load-data' should contain 'status' key with value 'success'");
  103. }
  104. public function testCreateUserAndProject()
  105. {
  106. $writerId = 'test' . uniqid();
  107. $this->client->createWriter($writerId);
  108. $email = uniqid() . '@' . uniqid() . '.com';
  109. $result = $this->client->createUser($writerId, $email, uniqid(), 'functional', 'test user');
  110. $this->assertArrayHasKey('uid', $result, "Result of createUser request should return uid of created user");
  111. $result = $this->client->createProject($writerId, '[Test] functional ' . uniqid());
  112. $this->assertArrayHasKey('pid', $result, "Result of createProject request should return pid of created project");
  113. $pid = $result['pid'];
  114. $result = $this->client->addUserToProject($writerId, $pid, $email);
  115. $this->assertArrayHasKey('status', $result, "Result of addUserToProject request should return status");
  116. $this->assertEquals('success', $result['status'], "Result of addUserToProject request should contain 'status' key with value 'success'");
  117. $result = $this->client->getSsoLink($writerId, $pid, $email);
  118. $this->assertNotEmpty($result, "Result of getSsoLink request should contain link");
  119. }
  120. }