Merge pull request 'Add --json to polls list and polls show' (#87) from feature/polls-json into main
CI / Deploy / PHP 8.4 (push) Successful in 1m16s
CI / Deploy / PHP 8.5 (push) Successful in 1m17s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 5s

Reviewed-on: #87
This commit was merged in pull request #87.
This commit is contained in:
gnilebein committed 2026-11-16 14:05:55 +01:00
commit 4f03414d7a
6 files changed
+115 -2

No files matched your search

@@ -103,6 +103,46 @@ class PollsCommandsTest extends TestCase
$this->assertExitError();
}
public function testListAndShowAsJson(): void
{
[$old, $token] = $this->createPoll('Alt <b>&</b>', 'alt@example.org');
$this->createPoll('Neu', 'neu@example.org');
$this->age($old->id, 120);
$this->exec('polls list --json');
$this->assertExitSuccess();
$rows = json_decode(implode("
", $this->_out->messages()), true, flags: JSON_THROW_ON_ERROR);
$this->assertCount(2, $rows);
$this->assertSame('Alt <b>&</b>', $rows[0]['title']);
$this->assertSame('alt@example.org', $rows[0]['email']);
$this->assertTrue($rows[0]['expired']);
$this->assertFalse($rows[1]['expired']);
$this->assertNull($rows[1]['reminderSentAt']);
$this->assertArrayNotHasKey('adminUrl', $rows[0]);
$this->assertStringNotContainsString($token, implode('', $this->_out->messages()));
$this->exec('polls list --json --expired');
$this->assertCount(1, json_decode(implode("
", $this->_out->messages()), true));
$this->exec('polls list --json --email=gibtsnicht');
$this->assertSame([], json_decode(implode("
", $this->_out->messages()), true));
$this->exec('polls show ' . $old->id . ' --json');
$data = json_decode(implode("
", $this->_out->messages()), true, flags: JSON_THROW_ON_ERROR);
$this->assertSame($old->id, $data['id']);
$this->assertNull($data['adminUrl']);
$this->assertStringNotContainsString($token, implode('', $this->_out->messages()));
$this->exec('polls show ' . $old->id . ' --json --link');
$data = json_decode(implode("
", $this->_out->messages()), true, flags: JSON_THROW_ON_ERROR);
$this->assertSame('https://plenario.test/admin/' . $token, $data['adminUrl']);
}
public function testDeleteRemovesPollWithSlides(): void
{
[$poll] = $this->createPoll();