]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/services/test/service_menu_deinstallation_test.rb
Fix untranslated spinbox suffix strings
[dolphin.git] / src / settings / services / test / service_menu_deinstallation_test.rb
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2019 Harald Sitter <sitter@kde.org>
4 #
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.
9 #
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.
14 #
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
19
20 require_relative 'test_helper'
21
22 require 'tmpdir'
23
24 class ServiceMenuDeinstallationTest < Test::Unit::TestCase
25 def setup
26 @tmpdir = Dir.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}")
27 @pwdir = Dir.pwd
28 Dir.chdir(@tmpdir)
29
30 ENV['XDG_DATA_HOME'] = File.join(@tmpdir, 'data')
31 end
32
33 def teardown
34 Dir.chdir(@pwdir)
35 FileUtils.rm_rf(@tmpdir)
36
37 ENV.delete('XDG_DATA_HOME')
38 end
39
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)
46 #!/bin/sh
47 set -e
48 cat deinstall.sh
49 touch #{@tmpdir}/deinstall.sh-run
50 DEINSTALL_SH
51 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
52 #!/bin/sh
53 set -e
54 cat install.sh
55 touch #{@tmpdir}/install.sh-run
56 INSTALL_SH
57
58 assert(system('servicemenuinstaller', 'uninstall', archive_base))
59
60 # deinstaller should be run
61 # installer should not be run
62 # archive_dir should have been correctly removed
63
64 assert_path_exist('deinstall.sh-run')
65 assert_path_not_exist('install.sh-run')
66 assert_path_not_exist(archive_dir)
67 end
68
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)
74
75 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
76 #!/bin/sh
77 if [ "$@" = "--uninstall" ]; then
78 touch #{@tmpdir}/install.sh-run
79 exit 0
80 fi
81 exit 1
82 INSTALL_SH
83
84 assert(system('servicemenuinstaller', 'uninstall', archive_base))
85
86 assert_path_not_exist('deinstall.sh-run')
87 assert_path_exist('install.sh-run')
88 assert_path_not_exist(archive_dir)
89 end
90
91 # no scripts in sight
92 def test_run_fail
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)
97
98 refute(system('servicemenuinstaller', 'uninstall', archive_base))
99
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
102 # - sitter, 2019
103 assert_path_exist(archive_dir)
104 end
105
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.
109 def test_run_desktop
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)
114
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)
119
120 assert(system('servicemenuinstaller', 'uninstall', downloaded_file))
121
122 assert_path_exist(downloaded_file)
123 assert_path_not_exist(installed_file)
124 end
125 end