From dc255a4ecf275af4d9030701b9be027435c2e47b Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 13 Nov 2025 21:32:24 +0100 Subject: [PATCH] Begin tests for Profiles module --- tests/unit/Module/ProfilesTest.php | 100 +++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/unit/Module/ProfilesTest.php diff --git a/tests/unit/Module/ProfilesTest.php b/tests/unit/Module/ProfilesTest.php new file mode 100644 index 000000000..2dc88f9b6 --- /dev/null +++ b/tests/unit/Module/ProfilesTest.php @@ -0,0 +1,100 @@ + + * + * SPDX-License-Identifier: MIT + */ + +namespace Zotlabs\Tests\Unit\Module; + +use App; +use PDOStatement; + +/** + * Tests for the Profiles module + */ +class ProfilesTest extends TestCase +{ + public function testDisplaysProfileEditFormIfMultiProfilesDisabled(): void { + // Set up the channel we'll be making the request for + $channel = $this->fixtures['channel'][0]; + App::set_channel($channel); + + // And set up the default profile + $this->createDefaultProfile($channel); + + // Replace calls to 'local_channel' and make sure they return + // the id of the current channel. + $local_channel_mock = + $this->getFunctionMock('Zotlabs\Module', 'local_channel') + ->expects($this->any()) + ->willReturn($channel['channel_id']); + + // Replace calls to 'feature_enabled', and make it unconditionally + // return true. This is called by the Profiles module to check that + // multiple profiles are enabled. + $feature_enabled_mock = + $this->getFunctionMock('Zotlabs\Module', 'feature_enabled') + ->expects($this->any()) + ->willReturn(false); + + // Simulate a GET request to the module + $this->get('profiles'); + + // Check that the rendered page has the expected entry. + $this->assertPageContains('
fixtures['channel'][0]; + App::set_channel($channel); + + // And set up the default profile + $this->createDefaultProfile($channel); + + // Replace calls to 'local_channel' and make sure they return + // the id of the current channel. + $local_channel_mock = + $this->getFunctionMock('Zotlabs\Module', 'local_channel') + ->expects($this->any()) + ->willReturn($channel['channel_id']); + + // Replace calls to 'feature_enabled', and make it unconditionally + // return true. This is called by the Profiles module to check that + // multiple profiles are enabled. + $feature_enabled_mock = + $this->getFunctionMock('Zotlabs\Module', 'feature_enabled') + ->expects($this->once()) + ->willReturn(true); + + // Simulate a GET request to the module + $this->get('profiles'); + + // Check that the rendered page has the expected entry. + $this->assertPageContains('Default Profile'); + } + + /** + * Helper function to create the default profile for a channel + * + * @param array $channel An associative array containing the channel. + */ + private function createDefaultProfile(array $channel): void { + $res = profile_store_lowlevel([ + 'aid' => intval($channel['channel_account_id']), + 'uid' => intval($channel['channel_id']), + 'profile_guid' => random_string(), + 'profile_name' => t('Default Profile'), + 'is_default' => 1, + 'publish' => true, + 'fullname' => $channel['channel_name'], + 'photo' => z_root() . "/photo/profile/l/{$channel['channel_id']}", + 'thumb' => z_root() . "/photo/profile/m/{$channel['channel_id']}" + ]); + + $this->assertInstanceOf(PDOStatement::class, $res); + $this->assertEquals('00000', $res->errorCode()); + } +}