]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/acceptance/mod_php_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / acceptance / mod_php_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apache::mod::php class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4   case fact('osfamily')
5   when 'Debian'
6     vhost_dir    = '/etc/apache2/sites-enabled'
7     mod_dir      = '/etc/apache2/mods-available'
8     service_name = 'apache2'
9   when 'RedHat'
10     vhost_dir    = '/etc/httpd/conf.d'
11     mod_dir      = '/etc/httpd/conf.d'
12     service_name = 'httpd'
13   when 'FreeBSD'
14     vhost_dir    = '/usr/local/etc/apache24/Vhosts'
15     mod_dir      = '/usr/local/etc/apache24/Modules'
16     service_name = 'apache24'
17   when 'Gentoo'
18     vhost_dir    = '/etc/apache2/vhosts.d'
19     mod_dir      = '/etc/apache2/modules.d'
20     service_name = 'apache2'
21   end
22
23   context "default php config" do
24     it 'succeeds in puppeting php' do
25       pp= <<-EOS
26         class { 'apache':
27           mpm_module => 'prefork',
28         }
29         class { 'apache::mod::php': }
30         apache::vhost { 'php.example.com':
31           port    => '80',
32           docroot => '/var/www/php',
33         }
34         host { 'php.example.com': ip => '127.0.0.1', }
35         file { '/var/www/php/index.php':
36           ensure  => file,
37           content => "<?php phpinfo(); ?>\\n",
38         }
39       EOS
40       apply_manifest(pp, :catch_failures => true)
41     end
42
43     describe service(service_name) do
44       it { is_expected.to be_enabled }
45       it { is_expected.to be_running }
46     end
47
48     describe file("#{mod_dir}/php5.conf") do
49       it { is_expected.to contain "DirectoryIndex index.php" }
50     end
51
52     it 'should answer to php.example.com' do
53       shell("/usr/bin/curl php.example.com:80") do |r|
54         expect(r.stdout).to match(/PHP Version/)
55         expect(r.exit_code).to eq(0)
56       end
57     end
58   end
59
60   context "custom extensions, php_flag, php_value, php_admin_flag, and php_admin_value" do
61     it 'succeeds in puppeting php' do
62       pp= <<-EOS
63         class { 'apache':
64           mpm_module => 'prefork',
65         }
66         class { 'apache::mod::php':
67           extensions => ['.php','.php5'],
68         }
69         apache::vhost { 'php.example.com':
70           port             => '80',
71           docroot          => '/var/www/php',
72           php_values       => { 'include_path' => '.:/usr/share/pear:/usr/bin/php', },
73           php_flags        => { 'display_errors' => 'on', },
74           php_admin_values => { 'open_basedir' => '/var/www/php/:/usr/share/pear/', },
75           php_admin_flags  => { 'engine' => 'on', },
76         }
77         host { 'php.example.com': ip => '127.0.0.1', }
78         file { '/var/www/php/index.php5':
79           ensure  => file,
80           content => "<?php phpinfo(); ?>\\n",
81         }
82       EOS
83       apply_manifest(pp, :catch_failures => true)
84     end
85
86     describe service(service_name) do
87       it { is_expected.to be_enabled }
88       it { is_expected.to be_running }
89     end
90
91     describe file("#{vhost_dir}/25-php.example.com.conf") do
92       it { is_expected.to contain "  php_flag display_errors on" }
93       it { is_expected.to contain "  php_value include_path .:/usr/share/pear:/usr/bin/php" }
94       it { is_expected.to contain "  php_admin_flag engine on" }
95       it { is_expected.to contain "  php_admin_value open_basedir /var/www/php/:/usr/share/pear/" }
96     end
97
98     it 'should answer to php.example.com' do
99       shell("/usr/bin/curl php.example.com:80") do |r|
100         expect(r.stdout).to match(/\/usr\/share\/pear\//)
101         expect(r.exit_code).to eq(0)
102       end
103     end
104   end
105
106   context "provide custom config file" do
107     it 'succeeds in puppeting php' do
108       pp= <<-EOS
109         class {'apache':
110           mpm_module => 'prefork',
111         }
112         class {'apache::mod::php':
113           content => '# somecontent',
114         }
115       EOS
116       apply_manifest(pp, :catch_failures => true)
117     end
118
119     describe file("#{mod_dir}/php5.conf") do
120       it { should contain "# somecontent" }
121     end
122   end
123
124   context "provide content and template config file" do
125     it 'succeeds in puppeting php' do
126       pp= <<-EOS
127         class {'apache':
128           mpm_module => 'prefork',
129         }
130         class {'apache::mod::php':
131           content  => '# somecontent',
132           template => 'apache/mod/php5.conf.erb',
133         }
134       EOS
135       apply_manifest(pp, :catch_failures => true)
136     end
137
138     describe file("#{mod_dir}/php5.conf") do
139       it { should contain "# somecontent" }
140     end
141   end
142
143 end