@@ -113,4 +113,42 @@ public function test_removes_full_log_and_creates_new()
113113
114114 assertTrue (filesize ($ logger ->get_log_file_path ()) < 1048576 , 'log file rotated and less than 1MB ' );
115115 }
116+
117+ public function test_clears_logs_when_turned_on () {
118+ $ log_dir_path = 'wp-content/uploads/tiny-compress-logs ' ;
119+ vfsStream::newDirectory ($ log_dir_path )->at ($ this ->vfs );
120+ $ log_dir = $ this ->vfs ->getChild ($ log_dir_path );
121+ vfsStream::newFile ('tiny-compress.log ' )
122+ ->withContent ('Some existing log content ' )
123+ ->at ($ log_dir );
124+
125+ $ logger = Tiny_Logger::get_instance ();
126+ $ log_path = $ logger ->get_log_file_path ();
127+
128+ assertTrue (file_exists ($ log_path ), 'log file should exist ' );
129+
130+ Tiny_Logger::on_save_log_enabled ( 'on ' , 'off ' , null );
131+
132+ assertFalse ( file_exists ($ log_path ), 'log file should be deleted after turning on logging ' );
133+ }
134+
135+ public function test_keeps_logs_when_unchanged () {
136+ $ log_dir_path = 'wp-content/uploads/tiny-compress-logs ' ;
137+ vfsStream::newDirectory ($ log_dir_path )->at ($ this ->vfs );
138+ $ log_dir = $ this ->vfs ->getChild ($ log_dir_path );
139+ vfsStream::newFile ('tiny-compress.log ' )
140+ ->withContent ('Some existing log content ' )
141+ ->at ($ log_dir );
142+
143+ $ logger = Tiny_Logger::get_instance ();
144+ $ log_path = $ logger ->get_log_file_path ();
145+
146+ assertTrue (file_exists ($ log_path ), 'log file should exist ' );
147+
148+ Tiny_Logger::on_save_log_enabled ( 'on ' , 'on ' , null );
149+
150+ assertTrue ( file_exists ($ log_path ), 'log file should still exist when settings remain unchanged ' );
151+
152+ unlink ($ log_path );
153+ }
116154}
0 commit comments