lportal 1.0.9 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/ChangeLog +71 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +6 -5
  4. data/Rakefile +23 -0
  5. data/init.rb +1 -1
  6. data/lib/acts/resourceful.rb +104 -0
  7. data/lib/company.rb +25 -0
  8. data/lib/group.rb +83 -29
  9. data/lib/journal/article.rb +8 -4
  10. data/lib/mb/category.rb +30 -59
  11. data/lib/mb/message.rb +24 -67
  12. data/lib/permission.rb +16 -0
  13. data/lib/release.rb +9 -0
  14. data/lib/resource.rb +19 -0
  15. data/lib/resource_code.rb +21 -1
  16. data/lib/role.rb +7 -27
  17. data/lib/tag/asset.rb +26 -4
  18. data/lib/user.rb +20 -23
  19. data/lib/web/layout.rb +134 -39
  20. data/lib/web/layout_set.rb +8 -4
  21. data/lib/web/portlet.rb +92 -20
  22. data/lib/web/portlet_preferences.rb +176 -13
  23. data/lib/web/portlet_properties.rb +32 -0
  24. data/lib/web/typesettings.rb +32 -7
  25. data/lportal.rb +30 -3
  26. data/migrations/20090101000001_add_sequences.rb +64 -0
  27. data/migrations/20090309000001_portlet_properties.rb +19 -0
  28. data/portlets.rb +76 -0
  29. data/schema.rb +34 -0
  30. data/test/unit/company_test.rb +21 -9
  31. data/test/unit/dl_file_test.rb +2 -1
  32. data/test/unit/group_test.rb +74 -16
  33. data/test/unit/journal/article_test.rb +15 -1
  34. data/test/unit/mb/category_test.rb +12 -15
  35. data/test/unit/mb/message_test.rb +3 -2
  36. data/test/unit/mb/thread_test.rb +1 -1
  37. data/test/unit/organization_test.rb +7 -2
  38. data/test/unit/phone_test.rb +2 -0
  39. data/test/unit/release_test.rb +25 -0
  40. data/test/unit/role_test.rb +7 -7
  41. data/test/unit/tag/asset_test.rb +59 -2
  42. data/test/unit/user_test.rb +73 -77
  43. data/test/unit/web/layout_set_test.rb +18 -1
  44. data/test/unit/web/layout_test.rb +191 -5
  45. data/test/unit/web/portlet_preferences_test.rb +314 -17
  46. data/test/unit/web/portlet_properties_test.rb +36 -0
  47. data/test/unit/web/portlet_test.rb +121 -19
  48. data/test/unit/web/typesettings_test.rb +24 -11
  49. data/version.rb +1 -2
  50. metadata +20 -6
  51. data/install.rb +0 -1
@@ -15,6 +15,7 @@ class MB::MessageTest < ActiveSupport::TestCase
15
15
 
16
16
  def setup
17
17
  @messages = MB::Message.all
18
+ flunk 'No messages to test' unless @messages.any?
18
19
  end
19
20
 
20
21
  def test_new_rootmsg
@@ -80,7 +81,7 @@ class MB::MessageTest < ActiveSupport::TestCase
80
81
  p = Permission.find(:first,
81
82
  :conditions => "companyid=#{msg.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
82
83
  assert_not_nil p
83
- assert user.user_permissions.include?(p)
84
+ assert user.permissions.include?(p)
84
85
  end
85
86
  end
86
87
 
@@ -155,7 +156,7 @@ class MB::MessageTest < ActiveSupport::TestCase
155
156
  p = Permission.find(:first,
156
157
  :conditions => "companyid=#{msg.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
157
158
  assert_not_nil p
158
- assert user.user_permissions.include?(p)
159
+ assert user.permissions.include?(p)
159
160
  end
160
161
 
161
162
  end
@@ -20,7 +20,7 @@ class MB::ThreadTest < ActiveSupport::TestCase
20
20
 
21
21
  def test_root
22
22
  @threads.each do |x|
23
- assert_not_nil x.root, "#{x.id} has no root message"
23
+ assert_not_nil x.rootmessage, "#{x.id} has no root message"
24
24
  end
25
25
  end
26
26
 
@@ -2,13 +2,18 @@ require 'test_helper'
2
2
 
3
3
  class OrganizationTest < ActiveSupport::TestCase
4
4
  fixtures [
5
- :organization_, :groups_orgs,
5
+ :company,
6
+ :organization_,
7
+ :user_,
8
+ :users_orgs,
9
+ :group_,
10
+ :groups_orgs,
6
11
  :classname_
7
12
  ]
8
13
 
9
14
  def setup
10
15
  @orgs = Organization.all
11
- assert !@orgs.empty?
16
+ flunk 'No organizations to test' unless @orgs.any?
12
17
  end
13
18
 
14
19
  # each organization must belong to a company
@@ -23,6 +23,8 @@ class PhoneTest < ActiveSupport::TestCase
23
23
  classnameid = Classname.find_by_value('com.liferay.portal.model.Contact').id
24
24
  assert_equal classnameid, phone.classnameid
25
25
 
26
+ assert_not_nil phone.classpk, phone.inspect
27
+ assert_not_nil phone.user.contact, 'User %i has no contact' % phone.user.id
26
28
  assert_equal phone.user.contact.id, phone.classpk
27
29
 
28
30
  # mobile = ListType.find_by_name('Mobile').id
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class ReleaseTest < ActiveSupport::TestCase
4
+ fixtures :release_
5
+
6
+ def test_releases
7
+ releases = Release.all
8
+ assert_not_nil releases
9
+ assert !releases.empty?, 'No releases found'
10
+ end
11
+
12
+ def test_current
13
+ assert_not_nil Release.current
14
+ end
15
+
16
+ def test_schema_version
17
+ assert_equal Release.current.buildnumber, Lportal::Schema.buildnumber
18
+ assert_equal Fixnum, Release.current.buildnumber.class
19
+
20
+ Lportal::Schema.buildnumber = 5100
21
+ assert_equal 5100, Lportal::Schema.buildnumber
22
+ assert_equal '5.1', Lportal::Schema.version
23
+ end
24
+
25
+ end
@@ -5,11 +5,11 @@ class RoleTest < ActiveSupport::TestCase
5
5
  :role_,
6
6
  :users_roles,
7
7
  :groups_roles,
8
- :permission_,
9
- :users_permissions,
10
- :groups_permissions,
11
- :resource_,
12
- :resourcecode
8
+ # :permission_,
9
+ # :users_permissions,
10
+ # :groups_permissions,
11
+ # :resource_,
12
+ # :resourcecode
13
13
  ]
14
14
 
15
15
  def setup
@@ -54,7 +54,7 @@ class RoleTest < ActiveSupport::TestCase
54
54
 
55
55
  # Permissions to administrators
56
56
  role.company.administrators.each do |user|
57
- assert user.user_permissions.include?(p)
57
+ assert user.permissions.include?(p)
58
58
  end
59
59
  end
60
60
  end
@@ -98,7 +98,7 @@ class RoleTest < ActiveSupport::TestCase
98
98
 
99
99
  # User + group permissions
100
100
  users.each do |user|
101
- assert !user.user_permissions.include?(p)
101
+ assert !user.permissions.include?(p)
102
102
  end
103
103
  groups.each do |group|
104
104
  assert !group.permissions.include?(p)
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class Tag::AssetTest < ActiveSupport::TestCase
4
4
  fixtures [
5
5
  :tagsasset, :tagsassets_tagsentries,
6
- :resource_, :resourcecode,
6
+ # :resource_, :resourcecode,
7
7
  :classname_,
8
8
  :igimage,
9
9
  :mbmessage,
@@ -11,11 +11,59 @@ class Tag::AssetTest < ActiveSupport::TestCase
11
11
  :wikipage,
12
12
  :bookmarksentry,
13
13
  :journalarticle,
14
- :dlfileentry
14
+ :dlfileentry,
15
+ :layout
15
16
  ]
16
17
 
17
18
  def setup
18
19
  @assets = Tag::Asset.all
20
+ # TODO: DRY up, the same creation code is in portlet test.
21
+ unless Web::Portlet.find_by_name('asset_publisher')
22
+ Company.all.each do |c|
23
+ Web::Portlet.create(
24
+ :companyid => c.id,
25
+ :portletid => '9998'
26
+ )
27
+ Web::PortletProperties.create(
28
+ :portletid => 9998,
29
+ :name => 'asset_publisher',
30
+ :title => ''
31
+ )
32
+ end
33
+ end
34
+ unless Web::Portlet.find_by_name('tagged_content')
35
+ Company.all.each do |c|
36
+ Web::Portlet.create(
37
+ :companyid => c.id,
38
+ :portletid => '9999'
39
+ )
40
+ Web::PortletProperties.create(
41
+ :portletid => 9999,
42
+ :name => 'tagged_content',
43
+ :title => ''
44
+ )
45
+ end
46
+ end
47
+ end
48
+
49
+ def test_path
50
+ @assets.each do |asset|
51
+ next if asset.groupid==0
52
+
53
+ [5100, 5200].each do |build|
54
+ Lportal::Schema.buildnumber = build
55
+
56
+ path = asset.path
57
+ assert_not_nil path
58
+ if build==5100
59
+ assert path[/#{asset.id}/], 'Path ”%s” does not contain asset id (%i)' % [path, asset.id]
60
+ assert path[/tagged_content/]
61
+ elsif build==5200
62
+ assert path[/#{asset.resource.id}/], 'Path ”%s” does not contain asset resource id (%i)' % [path, asset.resource.id]
63
+ assert path[/asset_publisher/]
64
+ end
65
+ end
66
+ end
19
67
  end
20
68
 
21
69
  def test_resource
@@ -52,10 +100,19 @@ class Tag::AssetTest < ActiveSupport::TestCase
52
100
  end
53
101
  end
54
102
 
103
+ def test_group
104
+ @assets.each do |asset|
105
+ next if asset.groupid==0
106
+ assert_not_nil asset.group
107
+ end
108
+ end
109
+
55
110
  def test_asset_types
56
111
  Tag::Asset.resource_types.each do |type|
57
112
  type.find(:all).each do |obj|
58
113
  if defined? obj.asset
114
+ # not all messages are tagged
115
+ next if obj.is_a?(MB::Message)
59
116
  assert_not_nil obj.asset, '%s (%i) has no Tag::Asset' % [obj.class, obj.id]
60
117
 
61
118
  # problems with versioned wiki and journal pages..
@@ -91,17 +91,17 @@ class UserTest < ActiveSupport::TestCase
91
91
  assert !resources.empty?
92
92
  resource = resources.first
93
93
  # counter
94
- assert_equal (counter_resource.currentid+100), counter_resource.reload.currentid
94
+ # assert_equal (counter_resource.currentid+100), counter_resource.reload.currentid
95
95
 
96
96
  # permissions
97
97
  user.class.actions.each do |action|
98
98
  p = resource.permissions.select{|_p| _p.actionid==action}.first
99
99
  assert_not_nil p
100
100
  assert_equal user.companyid, p.companyid
101
- assert user.user_permissions.include?(p)
101
+ assert user.permissions.include?(p)
102
102
  end
103
103
  # counter
104
- assert_equal (counter_permission.currentid+100), counter_permission.reload.currentid
104
+ # assert_equal (counter_permission.currentid+100), counter_permission.reload.currentid
105
105
 
106
106
  # announcementsdelivery
107
107
  ['general','news','test'].each do |type|
@@ -157,27 +157,27 @@ class UserTest < ActiveSupport::TestCase
157
157
  end
158
158
  end
159
159
 
160
- # organization membership
161
- def test_assign_organization_membership
162
- user = @users.first
163
-
164
- org_role = Role.find(:first, :conditions => "companyid=#{user.companyid} AND name='Organization Member'")
165
- assert_not_nil org_role
166
-
167
- @company.organizations.each do |org|
168
- user.assign_organization_membership(org)
169
- assert user.organizations.include?(org)
170
-
171
- # can ActiveRecord handle 3-way associations?
172
- r = ActiveRecord::Base.connection.execute(
173
- "SELECT * from usergrouprole WHERE userid=%i;" % user.id)
174
- assert_equal 1, r.result.size
175
- res = r.result.first
176
- assert_equal user.id, res[0].to_i
177
- assert_equal org.group.id, res[1].to_i
178
- assert_equal org_role.id, res[2].to_i
179
- end
180
- end
160
+ # # organization membership
161
+ # def test_assign_organization_membership
162
+ # user = @users.first
163
+ #
164
+ # org_role = Role.find(:first, :conditions => "companyid=#{user.companyid} AND name='Organization Member'")
165
+ # assert_not_nil org_role
166
+ #
167
+ # @company.organizations.each do |org|
168
+ # user.assign_organization_membership(org)
169
+ # assert user.organizations.include?(org)
170
+ #
171
+ # # can ActiveRecord handle 3-way associations?
172
+ # r = ActiveRecord::Base.connection.execute(
173
+ # "SELECT * from usergrouprole WHERE userid=%i;" % user.id)
174
+ # assert_equal 1, r.result.size
175
+ # res = r.result.first
176
+ # assert_equal user.id, res[0].to_i
177
+ # assert_equal org.group.id, res[1].to_i
178
+ # assert_equal org_role.id, res[2].to_i
179
+ # end
180
+ # end
181
181
 
182
182
  def test_gsm
183
183
  nr = Kernel.rand(10000000).to_s
@@ -236,66 +236,62 @@ class UserTest < ActiveSupport::TestCase
236
236
 
237
237
  # each user can have a personal group (hive)
238
238
  def test_hive
239
- @users.each do |x|
240
- group = x.hive
241
- if group
242
- # the group must have a proper classnameid
243
- _class = Classname.find_by_value x.liferay_class
244
- assert_not_nil _class
245
- assert_equal _class.id, group.classnameid, "#{x.id}'s personal group is not assigned to #{x.liferay_class}"
246
-
247
- assert_not_nil group.friendlyurl
248
-
249
- # if user is active, hive is active, and vice versa
250
- if x.is_active?
251
- assert group.is_active?, "#{x.id}'s personal group is not active"
252
- # there has to be layoutsets
253
- assert !group.layoutsets.empty?, "#{x.id}'s personal group does not have layoutsets"
254
-
255
- # ..except that Liferay-5.1.x doesn't seem to unactive the group
256
- else
257
- #assert !group.is_active?, "#{x.id}'s personal group is active, while the user is not"
258
-
259
- end
239
+ @users.each do |user|
240
+ group = user.hive
241
+ if user.is_guest?
242
+ assert_nil group
243
+ else
244
+ assert_not_nil group
260
245
  end
261
- end
262
- end
246
+ next unless group
247
+ # the group must have a proper classnameid
248
+ _class = Classname.find_by_value user.liferay_class
249
+ assert_not_nil _class
250
+ assert_equal _class.id, group.classnameid, "#{user.id}'s personal group is not assigned to #{user.liferay_class}"
263
251
 
264
- def test_gsm
265
- @users.each do |u|
266
- gsm = '+35840' + rand(10000000).to_s
267
- u.gsm = gsm
268
- phones = Phone.find(:all, :conditions => "userid = #{u.id}")
269
- assert !phones.empty?
270
- assert phones.collect(&:number).include?(gsm)
271
- end
272
- end
252
+ assert_not_nil group.friendlyurl
273
253
 
274
- def test_rigidity
275
- # each group must exist!
276
- groups = @users.map{|x| x.groups}.uniq
277
- groups.each do |group|
278
- assert_not_nil group, "Reference to non-existing group #{group.inspect}"
279
- end
254
+ # if user is active, hive is active, and vice versa
255
+ if user.is_active?
256
+ assert group.is_active?, "#{user.id}'s personal group is not active"
257
+ # there has to be layoutsets
258
+ assert !group.layoutsets.empty?, "#{user.id}'s personal group does not have layoutsets"
280
259
 
281
- # each role must exist!
282
- roles = @users.map{|x| x.roles}.uniq
283
- roles.each do |role|
284
- assert_not_nil role, "Reference to non-existing role #{role.inspect}"
285
- end
260
+ # ..eusercept that Liferay-5.1.user doesn't seem to unactive the group
261
+ else
262
+ #assert !group.is_active?, "#{user.id}'s personal group is active, while the user is not"
286
263
 
287
- # each permission must exist!
288
- perms = @users.map{|x| x.permissions}.uniq
289
- perms.each do |p|
290
- assert_not_nil p, "Reference to non-existing permission #{p.inspect}"
264
+ end
291
265
  end
292
266
  end
293
267
 
294
- def test_path
295
- @users.each do |u|
296
- assert_not_nil u.path(:public) if u.hive.public_layoutset
297
- assert_not_nil u.path(:private) if u.hive.private_layoutset
298
- end
299
- end
268
+ # def test_rigidity
269
+ # # each group must exist!
270
+ # groups = @users.map{|x| x.groups}.uniq
271
+ # groups.each do |group|
272
+ # assert_not_nil group, "Reference to non-existing group #{group.inspect}"
273
+ # end
274
+ #
275
+ # # each role must exist!
276
+ # roles = @users.map{|x| x.roles}.uniq
277
+ # roles.each do |role|
278
+ # assert_not_nil role, "Reference to non-existing role #{role.inspect}"
279
+ # end
280
+ #
281
+ # # each permission must exist!
282
+ # perms = @users.map{|x| x.permissions}.uniq
283
+ # perms.each do |p|
284
+ # assert_not_nil p, "Reference to non-existing permission #{p.inspect}"
285
+ # end
286
+ # end
287
+ #
288
+ # def test_path
289
+ # @users.each do |u|
290
+ # unless u.hive.nil?
291
+ # assert_not_nil u.path(:public), u.id if u.hive.public_layoutset
292
+ # assert_not_nil u.path(:private), u.id if u.hive.private_layoutset
293
+ # end
294
+ # end
295
+ # end
300
296
 
301
297
  end
@@ -1,7 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Web::LayoutSetTest < ActiveSupport::TestCase
4
- fixtures :layout, :layoutset, :portlet
4
+ fixtures [
5
+ :company,
6
+ :group_,
7
+ :layout, :layoutset,
8
+ :portlet,
9
+ :classname_
10
+ ]
5
11
 
6
12
  def setup
7
13
  @sets = Web::LayoutSet.all
@@ -25,6 +31,7 @@ class Web::LayoutSetTest < ActiveSupport::TestCase
25
31
  def test_group
26
32
  @sets.each do |x|
27
33
  group = x.group
34
+ next unless group
28
35
  assert_not_nil group, "#{x.id} belongs to no group"
29
36
  end
30
37
  end
@@ -32,6 +39,7 @@ class Web::LayoutSetTest < ActiveSupport::TestCase
32
39
  def test_public_layoutsets
33
40
  @sets.each do |x|
34
41
  group = x.group
42
+ next unless group
35
43
  assert_not_nil group.public_layoutset, "Group #{group.id} does not have a public layoutset"
36
44
  end
37
45
  end
@@ -39,6 +47,7 @@ class Web::LayoutSetTest < ActiveSupport::TestCase
39
47
  def test_private_layoutsets
40
48
  @sets.each do |x|
41
49
  group = x.group
50
+ next unless group
42
51
  assert_not_nil group.private_layoutset, "Group #{group.id} does not have a private layoutset"
43
52
  end
44
53
  end
@@ -50,6 +59,7 @@ class Web::LayoutSetTest < ActiveSupport::TestCase
50
59
 
51
60
  # each group must exist
52
61
  groups = @sets.map{|x| x.group}.uniq
62
+ groups.compact!
53
63
  groups.each do |group|
54
64
  assert_not_nil group, "Reference to non-existing group #{group.inspect}"
55
65
  end
@@ -64,6 +74,13 @@ class Web::LayoutSetTest < ActiveSupport::TestCase
64
74
  end
65
75
  end
66
76
 
77
+ def test_url_prefix
78
+ @sets.each do |x|
79
+ assert_not_nil x.url_prefix
80
+ end
81
+ end
82
+
83
+
67
84
  # # test /web/guest/home equivalent
68
85
  # # Guest doesn't always have home
69
86
  # def test_guest_layoutset
@@ -2,12 +2,18 @@ require 'test_helper'
2
2
 
3
3
  class Web::LayoutTest < ActiveSupport::TestCase
4
4
  fixtures [
5
- :layout, :layoutset, :portlet, :portletpreferences, :portlet_names, :resourcecode
5
+ :layout, :layoutset, :portlet, :portletpreferences, :resourcecode, :portletproperties
6
6
  ]
7
7
 
8
8
  def setup
9
- @layouts = Web::Layout.find :all
9
+ @layouts = Web::Layout.all
10
10
  assert !@layouts.empty?
11
+
12
+ group = Company.first.guest_group
13
+ @clean_layout = group.public_layouts.first #select{|l| l.friendlyurl=='/home'}.first
14
+
15
+ flunk ('No guest layouts in group %i' % group.id) unless @clean_layout
16
+ @clean_layout.settings = Web::Typesettings.new # clean it up
11
17
  end
12
18
 
13
19
  def test_create
@@ -59,8 +65,173 @@ class Web::LayoutTest < ActiveSupport::TestCase
59
65
  :conditions => "companyid=#{layout.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
60
66
  assert_not_nil p
61
67
 
62
- assert group.permissions.include?(p)
68
+
69
+ # group members can ADD_DISCUSSION and VIEW
70
+ if (actionid=='ADD_DISCUSSION' or actionid=='VIEW')
71
+ assert group.permissions.include?(p)
72
+ end
73
+
74
+ # guest is permitted to VIEW if the layout is public.
75
+ if layout.is_public? and actionid=='VIEW'
76
+ assert group.company.guest.permissions.include?(p)
77
+ end
78
+
63
79
  end
80
+
81
+ # # the layout management portlet (new in 5.2.x?)
82
+ # assert_not_nil Web::PortletPreferences.find(:first,
83
+ # :conditions => "plid=#{layout.plid} AND portletid='88'")
84
+ end
85
+
86
+ # tests .<<()
87
+ def test_append_to_self
88
+ layout = @clean_layout
89
+ portlet_name = 'tagged_content'
90
+
91
+ layout.settings = Web::Typesettings.new
92
+
93
+ ### instantiate a rails portlet as Web::Portlet
94
+ ### find a Liferay portlet (hello world)
95
+ [
96
+ Web::Portlet.first,
97
+ Web::Portlet.find_by_name('hello_world')
98
+ ].each do |portlet|
99
+ flunk 'No portlet to test on' unless portlet
100
+ assert_not_nil portlet.preferences
101
+ #puts portlet.inspect
102
+ # puts portlet.resource.inspect
103
+
104
+ # TODO: test instantiate & no instantiated portlets, already instantiated, test that preferences.id matches
105
+
106
+ layout.<<( portlet, {:location => { :column => 1 }})
107
+ #puts layout.inspect
108
+
109
+ ### OK. Let the testing begin
110
+
111
+ portlet.reload
112
+ group = layout.group
113
+ assert_equal group, portlet.preferences.layout.group
114
+ #assert_equal portlet.companyid, group.companyid
115
+
116
+ # COPY portletpreferences (portletpreferencesid, ownerid, ownertype, plid, portletid, preferences) FROM stdin;
117
+ # +10267 0 3 10264 guidance_communities_INSTANCE_Hs9t <portlet-preferences />
118
+
119
+ preferences = portlet.preferences
120
+ unless portlet.instanceable?
121
+ assert_not_nil preferences
122
+ assert_equal ({1=>[portlet.portletid]}), layout.settings.portlets
123
+
124
+ else
125
+ assert_not_nil preferences
126
+ # puts preferences.inspect
127
+ assert preferences.portletid[/INSTANCE/]
128
+ assert_equal layout.plid, preferences.plid
129
+
130
+ assert_equal ({1=>[preferences.portletid]}), layout.settings.portlets
131
+ end
132
+
133
+ # COPY resourcecode (codeid, companyid, name, scope) FROM stdin;
134
+ # +111 10178 guidance_communities 4
135
+ # +112 10178 guidance_communities 1
136
+ # +113 10178 guidance_communities 2
137
+
138
+ # COPY resource_ (resourceid, codeid, primkey) FROM stdin;
139
+ # +137 112 10178
140
+ # +138 113 10198
141
+ # +139 111 10264_LAYOUT_guidance_communities_INSTANCE_Hs9t
142
+
143
+ [1,2,4].each do |scope|
144
+ rc = preferences.resource_code(scope)
145
+ assert_not_nil rc
146
+ assert_equal layout.companyid, rc.companyid
147
+ # rc.name does not depend on instanceability
148
+ assert_equal portlet.portletid, rc.name
149
+
150
+ rc = preferences.resource_code(scope)
151
+ assert_not_nil rc
152
+ r = preferences.get_resource(:scope => scope)
153
+ assert_not_nil r
154
+ assert_equal r.codeid, rc.id
155
+ case scope
156
+ when 1
157
+ assert_equal layout.companyid.to_s, r.primkey
158
+ when 2
159
+ assert_equal group.id.to_s, r.primkey
160
+ when 4
161
+ assert_equal preferences.primkey, r.primkey
162
+ end
163
+ end
164
+
165
+ # COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
166
+ # +135 10178 VIEW 139
167
+ # +136 10178 CONFIGURATION 139
168
+
169
+ # COPY groups_permissions (groupid, permissionid) FROM stdin;
170
+ # +10198 135
171
+
172
+ # COPY users_permissions (userid, permissionid) FROM stdin;
173
+ # +10180 135
174
+
175
+ resource = preferences.get_resource(:scope => 4)
176
+ guest = group.company.guest
177
+ preferences.class.actions.each do |actionid|
178
+ p = Permission.find(:first,
179
+ :conditions => "companyid=#{group.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
180
+ assert_not_nil p
181
+ if actionid=='VIEW'
182
+ assert group.permissions.include?(p)
183
+
184
+ if layout.is_public?
185
+ assert guest.permissions.include?(p)
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ def test_append_portlets
193
+ layout = @clean_layout
194
+
195
+ login_portlet = Web::Portlet.find_by_name 'login'
196
+ assert_not_nil login_portlet
197
+ login_portlet.instanceable=false
198
+
199
+ hw_portlet = Web::Portlet.find_by_name 'hello_world'
200
+ assert_not_nil hw_portlet
201
+ hw_portlet.instanceable=true
202
+
203
+ layout.<<( login_portlet, {:location => { :column => 1 }})
204
+ layout.<<( hw_portlet, {:location => { :column => 2 }})
205
+
206
+ layout.save
207
+
208
+ assert_equal 2, layout.portlets.size
209
+
210
+ portletids = layout.portlets.collect(&:portletid)
211
+
212
+ assert portletids.include?(login_portlet.portletid)
213
+ assert (portletids && [/#{hw_portlet.portletid}_INSTANCE/]).any?
214
+ end
215
+
216
+ def test_columns
217
+ layout = @clean_layout
218
+
219
+ layout.columns=1
220
+ assert_equal '1_column', layout.settings.template_id
221
+
222
+ layout.columns=2
223
+ assert_equal '2_columns_ii', layout.settings.template_id
224
+ end
225
+
226
+ def test_name_string
227
+ layout = @clean_layout
228
+
229
+ # set the name.
230
+ #
231
+ # as the method 'name' returns the name in XML, name_string is a string representation.
232
+ name = 'front page'
233
+ layout.name_string = name
234
+ assert_equal name, layout.name_string
64
235
  end
65
236
 
66
237
  # each layout must belong to a company
@@ -127,17 +298,32 @@ class Web::LayoutTest < ActiveSupport::TestCase
127
298
  @layouts.each do |x|
128
299
  assert !x.typesettings.nil?, "#{x} has no typesettings"
129
300
 
301
+ x.portlets.each do |p|
302
+ if p.is_a?(Web::PortletPreferences)
303
+ assert_equal x, p.layout, 'Layout has a portlet(preferences) (%i) that does not belong there' % p.id
304
+ if p.portlet
305
+ assert p.portlet.instanceable?
306
+ end
307
+
308
+ else # not instantiated
309
+ assert_equal x, p.preferences.layout
310
+ assert !p.instanceable?
311
+ end
312
+ end
313
+
130
314
  # check portlets
131
315
  x.portletids.each do |id|
132
316
  next if id[/INSTANCE/]
133
- assert Web::Portlet.find_by_portletid(id), "Layout #{x.id} defines portlet #{id} but it is not found in the portlet table"
317
+ unless Web::Portlet.find_by_portletid(id)
318
+ STDERR.puts "WARN: Layout #{x.id} defines portlet #{id} but it is not found in the portlet table"
319
+ end
134
320
  end
135
321
 
136
322
  # check instances
137
323
  x.instances.each do |portlet|
138
324
  portletid = portlet.portletid
139
325
  next unless portletid[/INSTANCE/]
140
- assert Web::PortletPreferences.find_by_portletid(), "#{x.id} defines portlet instance #{portletid} but it is not found in portletpreferences"
326
+ assert Web::PortletPreferences.find_by_portletid(portletid), "#{x.id} defines portlet instance #{portletid} but it is not found in portletpreferences"
141
327
  end
142
328
  end
143
329
  end