diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2024-06-14 16:41:38 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2024-06-14 16:43:38 +0200 |
commit | d7607906430242d45fd1526abd7c2cdc7b49990f (patch) | |
tree | c05fe2f958459c604fd6d0bb83ff7ecbfbf9cf1e /tests/unit | |
parent | 1ed8383c33530b221ef34ad1c5e9b3b80eab94fa (diff) | |
download | volse-hubzilla-d7607906430242d45fd1526abd7c2cdc7b49990f.tar.gz volse-hubzilla-d7607906430242d45fd1526abd7c2cdc7b49990f.tar.bz2 volse-hubzilla-d7607906430242d45fd1526abd7c2cdc7b49990f.zip |
Add basic test for create_identity function.
Not an exhaustive test for now, but does at least excercise some of the
code.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/CreateIdentityTest.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/unit/CreateIdentityTest.php b/tests/unit/CreateIdentityTest.php new file mode 100644 index 000000000..a5e0f278a --- /dev/null +++ b/tests/unit/CreateIdentityTest.php @@ -0,0 +1,65 @@ +<?php +/** + * Unit tests for the `create_identity` function. + * + * SPDX-FileCopyrightText: 2024 Hubzilla Community + * SPDX-FileContributor: Harald Eilertsen + * + * SPDX-License-Identifier: MIT + */ + +namespace Zotlabs\Tests\Unit; + +class CreateIdentityTest extends UnitTestCase { + + private bool $queueworker_started = false; + + public function test_empty_args() { + insert_hook('proc_run', [$this, 'proc_run_hook']); + $result = create_identity([]); + $this->assertEquals( + ['success' => false, 'message' => 'No account identifier'], + $result); + + $this->assertFalse($this->queueworker_started); + } + + public function test_create_new_channel_with_valid_account_id(): void { + insert_hook('proc_run', [$this, 'proc_run_hook']); + $result = create_identity([ + 'account_id' => $this->fixtures['account'][0]['account_id'], + 'nickname' => 'testuser', + 'name' => 'Olga Testuser', + ]); + + $this->assertTrue($result['success']); + $this->assertTrue($this->queueworker_started); + } + + public function test_create_new_channel_with_nnexistant_account_id(): void { + insert_hook('proc_run', [$this, 'proc_run_hook']); + $result = create_identity([ + 'account_id' => 666, + 'nickname' => 'testuser', + 'name' => 'Olga Testuser', + ]); + + /* + * We would expect this fo fail, but... + * + * The create_identity function will happily create a new channel with an + * non-existent account_id. The New_channel module will perform a check + * to ensure that only valid (and logged in) accounts can create a new channel. + * + * This is a bit weak, but for now we let it pass... + */ + $this->assertTrue($result['success']); + $this->assertTrue($this->queueworker_started); + } + + public function proc_run_hook(array &$args): void { + $args['run_cmd'] = false; + $this->queueworker_started = + $args['args'] === ['php', 'Zotlabs/Daemon/Master.php', 'Queueworker']; + } +} |