DisplayedAttributesTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tests\Settings;
  4. use Tests\TestCase;
  5. final class DisplayedAttributesTest extends TestCase
  6. {
  7. public function testGetDefaultDisplayedAttributes(): void
  8. {
  9. $indexA = $this->client->createIndex('indexA');
  10. $indexB = $this->client->createIndex('indexB', ['primaryKey' => 'objectID']);
  11. $attributesA = $indexA->getDisplayedAttributes();
  12. $attributesB = $indexB->getDisplayedAttributes();
  13. $this->assertIsArray($attributesA);
  14. $this->assertEquals(['*'], $attributesA);
  15. $this->assertIsArray($attributesB);
  16. $this->assertEquals(['*'], $attributesB);
  17. }
  18. public function testUpdateDisplayedAttributes(): void
  19. {
  20. $newAttributes = ['title'];
  21. $index = $this->client->createIndex('index');
  22. $promise = $index->updateDisplayedAttributes($newAttributes);
  23. $this->assertIsValidPromise($promise);
  24. $index->waitForPendingUpdate($promise['updateId']);
  25. $displayedAttributes = $index->getDisplayedAttributes();
  26. $this->assertIsArray($displayedAttributes);
  27. $this->assertEquals($newAttributes, $displayedAttributes);
  28. }
  29. public function testResetDisplayedAttributes(): void
  30. {
  31. $index = $this->client->createIndex('index');
  32. $newAttributes = ['title'];
  33. $promise = $index->updateDisplayedAttributes($newAttributes);
  34. $index->waitForPendingUpdate($promise['updateId']);
  35. $promise = $index->resetDisplayedAttributes();
  36. $this->assertIsValidPromise($promise);
  37. $index->waitForPendingUpdate($promise['updateId']);
  38. $displayedAttributes = $index->getDisplayedAttributes();
  39. $this->assertIsArray($displayedAttributes);
  40. $this->assertEquals(['*'], $displayedAttributes);
  41. }
  42. }