@@ -87,4 +87,60 @@ public function testAdjustRewriteBaseHtaccess(): void
8787 $ this ->assertTrue ($ configurator ->adjustRewriteBaseHtaccess ());
8888 $ this ->assertEquals ('/path/info ' , $ configurator ->getRewriteBase ());
8989 }
90+
91+ /**
92+ * @throws Exception
93+ * @throws \PHPUnit\Framework\MockObject\Exception
94+ */
95+ public function testAdjustRewriteBaseHtaccessUpdatesErrorDocumentWithRootPath (): void
96+ {
97+ // Set up a proper .htaccess file with ErrorDocument directive
98+ $ htaccessPath = dirname (__DIR__ , 2 ) . '/.htaccess ' ;
99+ $ htaccessContent = <<<'HTACCESS'
100+ <IfModule mod_rewrite.c>
101+ RewriteEngine On
102+ RewriteBase /phpmyfaq-test/
103+ ErrorDocument 404 /phpmyfaq-test/index.php?action=404
104+ </IfModule>
105+ HTACCESS;
106+ file_put_contents ($ htaccessPath , $ htaccessContent );
107+
108+ $ configuration = $ this ->createStub (Configuration::class);
109+ $ configuration ->method ('getRootPath ' )->willReturn (dirname (__DIR__ , 2 ));
110+ $ configuration ->method ('getDefaultUrl ' )->willReturn ('https://localhost/ ' );
111+ $ configurator = new EnvironmentConfigurator ($ configuration );
112+ $ this ->assertTrue ($ configurator ->adjustRewriteBaseHtaccess ());
113+
114+ // Read the .htaccess file and verify ErrorDocument 404 is set correctly
115+ $ htaccessContent = file_get_contents ($ htaccessPath );
116+ $ this ->assertStringContainsString ('ErrorDocument 404 /index.php?action=404 ' , $ htaccessContent );
117+ }
118+
119+ /**
120+ * @throws Exception
121+ * @throws \PHPUnit\Framework\MockObject\Exception
122+ */
123+ public function testAdjustRewriteBaseHtaccessUpdatesErrorDocumentWithSubdirectoryPath (): void
124+ {
125+ // Set up a proper .htaccess file with ErrorDocument directive
126+ $ htaccessPath = dirname (__DIR__ , 2 ) . '/.htaccess ' ;
127+ $ htaccessContent = <<<'HTACCESS'
128+ <IfModule mod_rewrite.c>
129+ RewriteEngine On
130+ RewriteBase /
131+ ErrorDocument 404 /index.php?action=404
132+ </IfModule>
133+ HTACCESS;
134+ file_put_contents ($ htaccessPath , $ htaccessContent );
135+
136+ $ configuration = $ this ->createStub (Configuration::class);
137+ $ configuration ->method ('getRootPath ' )->willReturn (dirname (__DIR__ , 2 ));
138+ $ configuration ->method ('getDefaultUrl ' )->willReturn ('https://localhost/faq/ ' );
139+ $ configurator = new EnvironmentConfigurator ($ configuration );
140+ $ this ->assertTrue ($ configurator ->adjustRewriteBaseHtaccess ());
141+
142+ // Read the .htaccess file and verify ErrorDocument 404 is set correctly
143+ $ htaccessContent = file_get_contents ($ htaccessPath );
144+ $ this ->assertStringContainsString ('ErrorDocument 404 /faq/index.php?action=404 ' , $ htaccessContent );
145+ }
90146}
0 commit comments