Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 64 additions & 11 deletions tests/lib/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,73 @@ public function testSetupHasEventDispatcher(): void {
}

/**
* Test that event dispatcher can dispatch InstallationCompletedEvent
* Helper method to extract event parameters from install options
* This mirrors the logic in Setup::install() at line 329 for dataDir and lines 502-503 for admin parameters
*
* Note: This assumes 'directory' key is present in options. Setup::install() has a fallback at lines 321-323
* that sets a default directory if empty, but our tests always provide this key.
*/
public function testEventDispatcherCanDispatchInstallationCompletedEvent(): void {
$dataDir = '/tmp/test-data';
$adminUsername = 'testadmin';
$adminEmail = 'admin@test.com';
private function extractInstallationEventParameters(array $options): array {
$dataDir = htmlspecialchars_decode($options['directory']);
$disableAdminUser = (bool)($options['admindisable'] ?? false);
$adminUsername = !$disableAdminUser ? ($options['adminlogin'] ?? null) : null;
$adminEmail = !empty($options['adminemail']) ? $options['adminemail'] : null;

$eventDispatcher = $this->createMock(IEventDispatcher::class);
$eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with($this->isInstanceOf(InstallationCompletedEvent::class));
return [$dataDir, $adminUsername, $adminEmail];
}

/**
* Test that InstallationCompletedEvent can be created with parameters from install options
*
* This test verifies that the InstallationCompletedEvent can be properly constructed with
* the parameters that Setup::install() extracts from the options array (see Setup.php line 329
* for dataDir and lines 502-503 for admin parameters).
*
* Note: Testing that Setup::install() actually dispatches this event requires a full integration
* test with database setup, file system operations, and app installation, which is beyond the
* scope of a unit test. The event class itself is thoroughly tested in InstallationCompletedEventTest.php.
*/
public function testInstallationCompletedEventParametersFromInstallOptions(): void {
// Simulate the options array as passed to Setup::install()
$options = [
'directory' => '/path/to/data',
'adminlogin' => 'admin',
'adminemail' => 'admin@example.com',
];

// Extract parameters the same way Setup::install() does
[$dataDir, $adminUsername, $adminEmail] = $this->extractInstallationEventParameters($options);

// Create the event as Setup::install() does at lines 504-506
$event = new InstallationCompletedEvent($dataDir, $adminUsername, $adminEmail);

// Verify the event contains the expected values
$this->assertEquals($dataDir, $event->getDataDirectory());
$this->assertEquals($adminUsername, $event->getAdminUsername());
$this->assertEquals($adminEmail, $event->getAdminEmail());
$this->assertTrue($event->hasAdminUser());
}

/**
* Test that event parameters handle disabled admin user correctly
*
* This tests the scenario where Setup::install() is called with admindisable=true,
* resulting in a null adminUsername in the event.
*/
public function testInstallationCompletedEventWithDisabledAdminUser(): void {
$options = [
'directory' => '/path/to/data',
'admindisable' => true,
];

// Extract parameters as Setup::install() does
[$dataDir, $adminUsername, $adminEmail] = $this->extractInstallationEventParameters($options);

// Dispatch the event
$event = new InstallationCompletedEvent($dataDir, $adminUsername, $adminEmail);
$eventDispatcher->dispatchTyped($event);

$this->assertEquals($dataDir, $event->getDataDirectory());
$this->assertNull($event->getAdminUsername());
$this->assertNull($event->getAdminEmail());
$this->assertFalse($event->hasAdminUser());
}
}
Loading