Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

121 řádky
3.4KB

  1. <?php
  2. namespace Tests\Feature;
  3. use App\Kintone\KintoneAccess;
  4. use App\Kintone\KintoneRecordQuery;
  5. use App\Kintone\KintoneRecordQueryOperator;
  6. use App\Kintone\Models\CarRoom;
  7. use App\Kintone\Models\Customer;
  8. use App\Kintone\Models\Small;
  9. use App\Middlewares\Now;
  10. use Illuminate\Support\Collection;
  11. use Tests\TestCase;
  12. class KintoneAccessTest extends TestCase
  13. {
  14. /**
  15. * A basic feature test example.
  16. */
  17. public function test_access(): void
  18. {
  19. $model = new Customer();
  20. $access = new KintoneAccess(Customer::class);
  21. $access->find(1, $model);
  22. $this->assertEquals("林田商会", $model->getStr(Customer::FIELD_CUSTOMER_NAME));
  23. $memo = Now::get()->format("YmdHis");
  24. $model->set(Customer::FIELD_CUSTOMER_MEMO, $memo);
  25. $beforeRevision = $model->getRevision();
  26. $access->update($model);
  27. $afterRevision = $model->getRevision();
  28. $this->assertEquals($beforeRevision + 1, $afterRevision);
  29. // 再度データを取得して項目が更新されていることを確認
  30. $model = new Customer();
  31. $access->find(1, $model);
  32. $this->assertEquals($memo, $model->getStr(Customer::FIELD_CUSTOMER_MEMO));
  33. }
  34. public function test_CarRoom(): void
  35. {
  36. $model = new CarRoom();
  37. $access = new KintoneAccess(CarRoom::class);
  38. $access->find(1, $model);
  39. $this->assertEquals("岩渕パーク", $model->getStr(CarRoom::FIELD_PARK_NAME));
  40. $this->assertEquals("5000", $model->getTable(CarRoom::FIELD_TABLE_FEE)[0][CarRoom::FIELD_TABLE_FEE_AMOUNT_PER_MONTH]);
  41. $this->assertEquals("自転車", $model->get(CarRoom::FIELD_CAN_USE_VEHICLE_TYPE)[0]);
  42. $this->assertEquals("普通自動車", $model->get(CarRoom::FIELD_CAN_USE_VEHICLE_TYPE)[1]);
  43. }
  44. public function test_small()
  45. {
  46. $model = new Small();
  47. $access = new KintoneAccess(Small::class);
  48. $model->set(Small::FIELD_NAME, "iwabuchi");
  49. $model->set(Small::FIELD_AGE, "32");
  50. $res = $access->create($model);
  51. $this->assertTrue($res->ok());
  52. }
  53. /**
  54. * @group cursor
  55. */
  56. public function test_cursor()
  57. {
  58. $access = new KintoneAccess(Small::class);
  59. $now = Now::get();
  60. $query = Small::query()
  61. ->whereIn(Small::FIELD_NAME, ["iwabuchi", "aa"])
  62. ->where(Small::FIELD_AGE, 32)
  63. ->whereDateTime(Small::FIELD_CREATED_TIME, $now, KintoneRecordQueryOperator::LT);
  64. $access->createCursor($query);
  65. $ret = $access->next();
  66. $this->assertTrue($ret instanceof Collection);
  67. $this->assertSame(1, $ret->count());
  68. $this->assertSame("iwabuchi", $ret->first()->getStr(Small::FIELD_NAME));
  69. }
  70. /**
  71. * @group cursor
  72. */
  73. public function test_cursor_all()
  74. {
  75. $access = new KintoneAccess(Small::class);
  76. $now = Now::get();
  77. $query = Small::query()
  78. ->orderByAsc(Small::FIELD_NAME);
  79. $ret = $access->all($query, [
  80. Small::FIELD_NAME,
  81. Small::FIELD_AGE,
  82. ]);
  83. $this->assertTrue($ret instanceof Collection);
  84. $this->assertSame(2, $ret->count());
  85. $first = $ret->first();
  86. $this->assertInstanceOf(Small::class, $first);
  87. $this->assertSame("iwabuchi", $ret->first()->getStr(Small::FIELD_NAME));
  88. $this->assertSame(32, $ret->first()->getNumber(Small::FIELD_AGE));
  89. }
  90. }