3 # Copyright (C) 2019 Harald Sitter <sitter@kde.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the
17 # Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 require_relative
'test_helper'
24 class ServiceMenuDeinstallationTest
< Test
::Unit::TestCase
26 @tmpdir = Dir
.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}")
30 ENV['XDG_DATA_HOME'] = File
.join(@tmpdir, 'data')
35 FileUtils
.rm_rf(@tmpdir)
37 ENV.delete('XDG_DATA_HOME')
40 def test_run_deinstall
41 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
42 archive_base
= "#{service_dir}/foo.zip"
43 archive_dir
= "#{archive_base}-dir/foo-1.1/"
44 FileUtils
.mkpath(archive_dir
)
45 File
.write("#{archive_dir}/deinstall.sh", <<-DEINSTALL_SH)
49 touch #{@tmpdir}/deinstall.sh-run
51 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
55 touch #{@tmpdir}/install.sh-run
58 assert(system('servicemenuinstaller', 'uninstall', archive_base
))
60 # deinstaller should be run
61 # installer should not be run
62 # archive_dir should have been correctly removed
64 assert_path_exist('deinstall.sh-run')
65 assert_path_not_exist('install.sh-run')
66 assert_path_not_exist(archive_dir
)
69 def test_run_install_with_arg
70 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
71 archive_base
= "#{service_dir}/foo.zip"
72 archive_dir
= "#{archive_base}-dir/foo-1.1/"
73 FileUtils
.mkpath(archive_dir
)
75 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
77 if [ "$@" = "--uninstall" ]; then
78 touch #{@tmpdir}/install.sh-run
84 assert(system('servicemenuinstaller', 'uninstall', archive_base
))
86 assert_path_not_exist('deinstall.sh-run')
87 assert_path_exist('install.sh-run')
88 assert_path_not_exist(archive_dir
)
93 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
94 archive_base
= "#{service_dir}/foo.zip"
95 archive_dir
= "#{archive_base}-dir/foo-1.1/"
96 FileUtils
.mkpath(archive_dir
)
98 refute(system('servicemenuinstaller', 'uninstall', archive_base
))
100 # I am unsure if deinstallation really should keep the files around. But
101 # that's how it behaved originally so it's supposedly intentional
103 assert_path_exist(archive_dir
)
106 # For desktop files things are a bit special. There is one in .local/share/servicemenu-download
107 # and another in the actual ServiceMenus dir. The latter gets removed by the
108 # script, the former by KNS.
110 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
111 downloaded_file
= "#{service_dir}/foo.desktop"
112 FileUtils
.mkpath(service_dir
)
113 FileUtils
.touch(downloaded_file
)
115 menu_dir
= "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/"
116 installed_file
= "#{menu_dir}/foo.desktop"
117 FileUtils
.mkpath(menu_dir
)
118 FileUtils
.touch(installed_file
)
120 assert(system('servicemenuinstaller', 'uninstall', downloaded_file
))
122 assert_path_exist(downloaded_file
)
123 assert_path_not_exist(installed_file
)