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
@@ -3,6 +3,9 @@ module Web
3
3
  class Typesettings
4
4
 
5
5
  attr_accessor :template_id
6
+
7
+ # accepts a Hash, where the key tells the column
8
+ # { 1 => [Web::PortletPreferences, ...], 2 => [...], ... }
6
9
  attr_accessor :portlets
7
10
 
8
11
  # Takes either existing raw typesettings string (to be parsed) or a Hash, when clean Typesettings is created.
@@ -15,7 +18,7 @@ module Web
15
18
  end
16
19
  end
17
20
 
18
- # Parses raw typesettings String into internal format.
21
+ # Parses raw typesettings String into an object (self).
19
22
  def read(raw)
20
23
  _x = raw.split(/\n/)
21
24
  #puts _x.inspect
@@ -53,11 +56,11 @@ module Web
53
56
  return s
54
57
  end
55
58
 
56
- # Accepts a PortletName as the first parameter,
59
+ # Accepts a PortletProperties as the first parameter,
57
60
  # the second parameter acceps a Hash {:column => nr} where nr is the column to place the portlet.
58
61
  def method_missing(method, *args, &block)
59
62
  begin
60
- portlet = Web::PortletName.find_by_name(method.to_s)
63
+ portlet = Web::PortletProperties.find_by_name(method.to_s)
61
64
  return nil unless portlet
62
65
 
63
66
  column = 1
@@ -81,18 +84,40 @@ module Web
81
84
  def parse
82
85
  columns = []
83
86
  @portlets.each_pair do |column,portlets|
84
- columns << "column-%i=%s," % [column, portlets.join(",")]
87
+ # handle several portlet types
88
+ portletids = []
89
+ portlets.each do |p|
90
+ next if p.nil?
91
+ if p.is_a?(String)
92
+ portletids << p
93
+ elsif (p.is_a?(Web::Portlet) or p.is_a?(Web::PortletPreferences))
94
+ portletids << p.portletid
95
+ else
96
+ raise 'Unknown portlet type %s' % p.class
97
+ end
98
+ end
99
+ columns << "column-%i=%s," % [column, portletids.join(",")]
85
100
  end
86
101
  columns.join("\n")
87
102
  end
88
103
 
89
104
  # Does this Typesettings include this portlet?
105
+ #
106
+ # This does not separate instantiated or non-instantiated portlets.
107
+ # Instantiated portlets do not theoretically match (TODO: test),
108
+ # as the portletid in the layout's typesettings contains the _INSTANCE_xxxx suffix.
109
+ #
110
+ #
90
111
  # Params:
91
- # - portlet (either name as String, or Web::PortletName)
112
+ # - portlet (either name as String, or Web::PortletProperties)
92
113
  def include?(args)
93
114
  if args.is_a?(String)
94
- p = Web::PortletName.find_by_name args
95
- elsif args.is_a?(Web::PortletName)
115
+ p = Web::PortletProperties.find_by_name args
116
+ elsif args.is_a?(Web::PortletProperties)
117
+ p = args
118
+ elsif args.is_a?(Web::PortletPreferences)
119
+ p = args
120
+ elsif args.is_a?(Web::Portlet)
96
121
  p = args
97
122
  else
98
123
  raise 'Invalid input class: %s' % args.class
data/lportal.rb CHANGED
@@ -4,10 +4,23 @@ require 'active_record'
4
4
  file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
5
5
  this_dir = File.dirname(File.expand_path(file))
6
6
 
7
- require this_dir+'/version'
7
+ require File.join(this_dir,'version')
8
8
 
9
- # include all ruby files
10
- Find.find(this_dir+'/lib') do |file|
9
+ # set the migrations directory for Caterpillar
10
+ LPORTAL_MIGRATIONS=File.expand_path(
11
+ File.join(this_dir,'migrations')
12
+ )
13
+
14
+ # make models able to act resourceful
15
+ require File.join(this_dir,'lib','acts','resourceful')
16
+ ActiveRecord::Base.class_eval { include Acts::Resourceful }
17
+
18
+ # Define Liferay (asset viewer) portlets.
19
+ # This class is for defining specific portlet functionality.
20
+ require File.join(this_dir,'portlets')
21
+
22
+ # include all models from lib
23
+ Find.find(File.join(this_dir,'lib')) do |file|
11
24
  if FileTest.directory?(file)
12
25
  if File.basename(file) == "deprecated"
13
26
  Find.prune # Don't look any further into this directory.
@@ -18,3 +31,17 @@ Find.find(this_dir+'/lib') do |file|
18
31
  require file if file[/.rb$/]
19
32
  end
20
33
  end
34
+
35
+ # define this database's schema version
36
+ require File.join(this_dir,'schema')
37
+ release = Release.current
38
+ last_supported_release = 5201
39
+ Lportal::Schema.buildnumber = (release ? release.buildnumber : last_supported_release)
40
+
41
+ msg = 'Using Liferay schema build %i, version %s' % [
42
+ Lportal::Schema.buildnumber, Lportal::Schema.version]
43
+
44
+ puts msg
45
+
46
+ defined?(RAILS_DEFAULT_LOGGER) ?
47
+ RAILS_DEFAULT_LOGGER.info(msg) : STDOUT.puts(msg)
@@ -0,0 +1,64 @@
1
+ class AddSequences < ActiveRecord::Migration
2
+ @@tables = [
3
+ Account,
4
+ Address,
5
+ Announcement::Delivery,
6
+ Announcement::Entry,
7
+ Contact,
8
+ Group,
9
+ Permission,
10
+ Phone,
11
+ ResourceCode,
12
+ Resource,
13
+ Role,
14
+ User,
15
+ MB::Category,
16
+ MB::Discussion,
17
+ MB::Message,
18
+ MB::MessageFlag,
19
+ MB::StatsUser,
20
+ MB::Thread,
21
+ RatingsStats,
22
+ SocialActivity,
23
+ SocialRelation,
24
+ Tag::Asset,
25
+ Tag::Entry,
26
+ Tag::Property,
27
+ Web::Layout,
28
+ Web::LayoutSet,
29
+ Web::PortletPreferences,
30
+ Web::Portlet
31
+ ]
32
+
33
+ def self.up
34
+ STDOUT.puts 'This migration does not do anything.'
35
+ STDOUT.puts 'The process is not refined properly yet, and could be quite disastrous if reverted unappropriately.'
36
+ STDOUT.puts 'If you are sure you need the sequences, copy this file to db/migrate and modify it.'
37
+ STDOUT.puts __FILE__
38
+
39
+ start = 8400000 # bigint = 8^8 bytes = 16 million bits, this is halfway up the possible range, rounded up
40
+ sql = ""
41
+ @@tables.each do |model|
42
+ table = model.table_name
43
+ primkey = model.primary_key
44
+ seq = table+'_'+primkey+'_seq'
45
+ sql += "CREATE SEQUENCE #{seq} START #{start}; ALTER TABLE #{table} ALTER #{primkey} SET default nextval('#{seq}');"
46
+ end
47
+
48
+ # To activate, uncomment this line.
49
+ #ActiveRecord::Base.connection.execute(sql)
50
+ end
51
+
52
+ # This is VERY DANGEROUS and may lead to breakage.
53
+ def self.down
54
+ STDOUT.puts 'Nothing will happen.'
55
+ # sql = ""
56
+ # @@tables.each do |model|
57
+ # table = model.table_name
58
+ # primkey = model.primary_key
59
+ # seq = table+'_'+primkey+'_seq'
60
+ # sql += "ALTER TABLE #{table} ALTER #{primkey} DROP default; DROP SEQUENCE #{seq};"
61
+ # end
62
+ # ActiveRecord::Base.connection.execute(sql)
63
+ end
64
+ end
@@ -0,0 +1,19 @@
1
+ class PortletProperties < ActiveRecord::Migration
2
+ def self.up
3
+ # dealing with tables that have no id is a pain with ActiveRecord,
4
+ # and using the 'id' column for portletid does not work either,
5
+ # ActiveRecord does not let that column to be set manually.
6
+ create_table :portletproperties do |t|
7
+ t.column :portletid, :string, :null => false
8
+ t.column :name, :string, :null => false
9
+ t.column :title, :string, :null => false
10
+ t.column :instanceable, :boolean, :null => false, :default => true
11
+ end
12
+ ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS portlet_names")
13
+ end
14
+
15
+ def self.down
16
+ drop_table :portletproperties
17
+ #ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS portletproperties")
18
+ end
19
+ end
data/portlets.rb ADDED
@@ -0,0 +1,76 @@
1
+ module Lportal # :nodoc:
2
+ # Liferay portlet functionalities.
3
+ # These are accessable in Web::PortletPreferences.
4
+ #
5
+ # Adds +path+, that is based on the name of the portlet.
6
+ module Portlets
7
+ def self.included(base)
8
+ #base.extend(ClassMethods)
9
+ end
10
+
11
+ include ERB::Util # for u()
12
+
13
+ def redirect
14
+ u('javascript: history.go(-1)')
15
+ end
16
+
17
+ # params:
18
+ # - content_id or asset
19
+ def asset_publisher_path(params)
20
+ asset = params[:asset]
21
+ raise 'No asset' unless asset
22
+ raise ('Asset %i has no resource' % asset.id) unless asset.resource
23
+ content_id = asset.resource.id
24
+ _path = [
25
+ '-',
26
+ 'asset_publisher',
27
+ self.instance_id,
28
+ 'content',
29
+ content_id
30
+ ].join('/')
31
+ '%s/%s?redirect=%s' % [self.layout.path, _path, redirect]
32
+ end
33
+
34
+ # params:
35
+ # - asset_id
36
+ def tagged_content_path(params)
37
+ asset = params[:asset]
38
+ raise 'No asset' unless asset
39
+
40
+ params = "?p_p_id=#{portletid}"+\
41
+ "&p_p_lifecycle=0"+\
42
+ "&p_p_state=normal"+\
43
+ "&p_p_mode=view"+\
44
+ "&_#{portletid}_struts_action=%2Ftagged_content%2Fview_content"+\
45
+ "&_#{portletid}_assetId=#{asset.id}"+\
46
+ "&_#{portletid}_redirect=#{redirect}"
47
+ # &p_p_col_id=column-1&p_p_col_count=1
48
+ path = self.layout.path + params
49
+ end
50
+
51
+
52
+ # Meta method that calls the actual method that yields the path to the portlet instance.
53
+ # In essence this is a singleton method based on the name of the portlet.
54
+ def path(args={})
55
+ unless self.name
56
+ logger.warn '%s has no name' % self.class
57
+ return ''
58
+ end
59
+ unless self.layout
60
+ logger.warn 'No layout given'
61
+ return ''
62
+ end
63
+
64
+ logger.debug 'Generating path for portlet %s' % self.name
65
+ method = self.name+'_path'
66
+ if self.respond_to?(method)
67
+ return self.send(method, args)
68
+ else
69
+ # unknown path
70
+ logger.warn 'Unknown path requested for portlet %s' % self.name
71
+ return ''
72
+ end
73
+ end
74
+
75
+ end
76
+ end
data/schema.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Lportal
2
+ # The schema version of the Liferay database.
3
+ # The +buildnumber+ class variable is set when lportal is loaded,
4
+ # and is a Fixnum of form 5201, for example.
5
+ # the +version+ method is a String of form '5.2.x'.
6
+ class Schema
7
+ @@BUILD = nil
8
+ @@VERSION = nil
9
+
10
+ def self.buildnumber
11
+ @@BUILD
12
+ end
13
+
14
+ # setter for buildnumber
15
+ def self.buildnumber=(val)
16
+ @@BUILD = val
17
+ end
18
+
19
+ def self.version
20
+ unless @@VERSION
21
+ return nil if @@BUILD.nil?
22
+ @@VERSION = '%s.%s.%d' % @@BUILD.to_s.scan(/(.)(.)(..)/).flatten
23
+ end
24
+ return @@VERSION
25
+ end
26
+
27
+ def self.version=(val)
28
+ @@VERSION = val
29
+ end
30
+
31
+ end
32
+ end
33
+
34
+
@@ -2,11 +2,17 @@ require 'test_helper'
2
2
 
3
3
  class CompanyTest < ActiveSupport::TestCase
4
4
  fixtures [
5
+ :company,
6
+ :user_, :group_,
5
7
  :account_, :organization_, :contact_,
6
8
  :layout, :layoutset,
7
9
  :resource_, :resourcecode
8
10
  ]
9
11
 
12
+ def setup
13
+ @companies = Company.all
14
+ flunk 'No companies in database!' unless @companies.any?
15
+ end
10
16
 
11
17
  # each company must have an account
12
18
  def test_account
@@ -50,24 +56,30 @@ class CompanyTest < ActiveSupport::TestCase
50
56
  end
51
57
  end
52
58
 
53
- # each company must have organization(s)
54
59
  def test_organizations
55
60
  @companies.each do |c|
56
- assert !c.organizations.empty?, "#{c.id} has no organizations"
61
+ c.organizations.each do |o|
62
+ assert_not_nil o
63
+ end
57
64
  end
58
65
  end
59
66
 
60
67
  def test_administrators
61
68
  @companies.each do |c|
62
- assert !c.administrators.empty?, "#{c.id} has no administrators"
69
+ assert c.administrators.size > 0, 'Company %s (%i) does not have administrators' % [c.webid, c.id]
63
70
  end
64
71
  end
65
72
 
66
- # ?
67
- # def test_resource
68
- # @companies.each do |x|
69
- # assert !x.resource.nil?, "#{x.id} has no resource"
70
- # end
71
- # end
73
+ def test_guest
74
+ @companies.each do |c|
75
+ assert_not_nil c.guest, 'Company %i does not have a guest account' % c.id
76
+ end
77
+ end
78
+
79
+ def test_guest_group
80
+ @companies.each do |c|
81
+ assert_not_nil c.guest_group
82
+ end
83
+ end
72
84
 
73
85
  end
@@ -1,9 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class DlFileTest < ActiveSupport::TestCase
4
+ fixtures [:dlfileentry, :company, :user_, :tagsasset]
4
5
 
5
6
  def setup
6
- @files = DLFile.all
7
+ @files = DlFile.all
7
8
  end
8
9
 
9
10
  def test_company
@@ -3,23 +3,37 @@ require 'test_helper'
3
3
  class GroupTest < ActiveSupport::TestCase
4
4
  fixtures [
5
5
  :organization_,
6
+ :groups_orgs,
6
7
  :users_orgs,
7
8
  :usergroup,
8
9
  :role_,
9
10
  :classname_
10
11
  ]
12
+ # to test asset_viewer_portlet, these are required
13
+ fixtures << [
14
+ :portlet, :portletproperties, :portletpreferences,
15
+ :layout,
16
+ :tagsasset,
17
+ :igimage,
18
+ :mbmessage,
19
+ :blogsentry,
20
+ :wikipage,
21
+ :bookmarksentry,
22
+ :journalarticle,
23
+ :dlfileentry
24
+ ]
11
25
 
12
26
  def setup
13
- @groups = Group.find :all
14
- assert !@groups.empty?, "No groups"
27
+ @groups = Group.all
28
+ flunk 'No groups in database!' unless @groups.any?
15
29
 
16
30
  @company = Company.first
17
- flunk 'No company!' unless @company
31
+ flunk 'No companies in database!' unless @company
18
32
  end
19
33
 
20
34
  def test_create_group
35
+ flunk ('No administrators in Company %i!' % @company.id) unless @company.administrators.any?
21
36
  user = @company.administrators.first
22
- flunk 'No user!' unless user
23
37
 
24
38
  # Type Group
25
39
  group = Group.create(
@@ -47,7 +61,7 @@ class GroupTest < ActiveSupport::TestCase
47
61
 
48
62
  # Permissions to administrators
49
63
  group.company.administrators.each do |user|
50
- assert user.user_permissions.include?(p)
64
+ assert user.permissions.include?(p)
51
65
  end
52
66
  end
53
67
  end
@@ -92,14 +106,14 @@ class GroupTest < ActiveSupport::TestCase
92
106
  # each group must belong to a company
93
107
  def test_company
94
108
  @groups.each do |x|
95
- assert !x.company.nil?, "#{x.id} belongs to no company"
109
+ assert_not_nil x.company
96
110
  end
97
111
  end
98
112
 
99
113
  def test_organizations
100
114
  @groups.each do |x|
101
115
  x.organizations.each do |org|
102
- assert organization.nil?, "#{x.id} has_and_belongs_to to unknown organization #{org.inspect}"
116
+ assert_not_nil org
103
117
  end
104
118
  end
105
119
  end
@@ -107,7 +121,7 @@ class GroupTest < ActiveSupport::TestCase
107
121
  def test_roles
108
122
  @groups.each do |x|
109
123
  x.roles.each do |role|
110
- assert role.nil?, "#{x.id} has_and_belongs_to an unknown role #{role.inspect}"
124
+ assert_not_nil role
111
125
  end
112
126
  end
113
127
  end
@@ -115,7 +129,7 @@ class GroupTest < ActiveSupport::TestCase
115
129
  def test_permissions
116
130
  @groups.each do |x|
117
131
  x.permissions.each do |permission|
118
- assert permission.nil?, "#{x.id} has_and_belongs_to an unknown permission #{permission.inspect}"
132
+ assert_not_nil permission
119
133
  end
120
134
  end
121
135
  end
@@ -123,22 +137,28 @@ class GroupTest < ActiveSupport::TestCase
123
137
  def test_usergroups
124
138
  @groups.each do |x|
125
139
  x.usergroups.each do |usergroup|
126
- assert usergroup.nil?, "#{x.id} has_and_belongs_to an unknown usergroup #{usergroup.inspect}"
140
+ assert_not_nil usergroup
127
141
  end
128
142
  end
129
143
  end
130
144
 
131
- # each group must belong to a creator
132
- def test_creator
145
+ # # each group must belong to a creator
146
+ # def test_creator
147
+ # @groups.each do |x|
148
+ # # assert !x.creator.nil?, "#{x.id} has no creator"
149
+ # end
150
+ # end
151
+
152
+ def test_mbcategories
133
153
  @groups.each do |x|
134
- # assert !x.creator.nil?, "#{x.id} has no creator"
154
+ assert_not_nil x.mbcategories
135
155
  end
136
156
  end
137
157
 
138
158
  # each group must have a friendlyurl
139
159
  def test_friendlyurl
140
160
  @groups.each do |x|
141
- assert !x.friendlyurl.nil?, "#{x.id} has no friendlyurl"
161
+ assert_not_nil x.friendlyurl
142
162
  end
143
163
  end
144
164
 
@@ -152,6 +172,24 @@ class GroupTest < ActiveSupport::TestCase
152
172
  end
153
173
  end
154
174
 
175
+ def test_public_layouts
176
+ @groups.each do |g|
177
+ g.public_layouts.each do |l|
178
+ assert_equal g, l.group
179
+ assert l.is_public?
180
+ end
181
+ end
182
+ end
183
+
184
+ def test_private_layouts
185
+ @groups.each do |g|
186
+ g.private_layouts.each do |l|
187
+ assert_equal g, l.group
188
+ assert l.is_private?
189
+ end
190
+ end
191
+ end
192
+
155
193
  def test_members
156
194
  @groups.each do |x|
157
195
  if x.owner.kind_of?(Organization)
@@ -165,20 +203,40 @@ class GroupTest < ActiveSupport::TestCase
165
203
  if x.private_layouts.any?
166
204
  assert_not_nil x.path(:private)
167
205
  else
168
- assert_nil x.path(:private)
206
+ assert_equal '', x.path(:private)
169
207
  end
170
208
  if x.public_layouts.any?
171
209
  assert_not_nil x.path(:public)
172
210
  else
173
- assert_nil x.path(:public)
211
+ assert_equal '', x.path(:public)
174
212
  end
175
213
  end
176
214
  end
177
215
 
216
+ def test_asset_viewer_portlet
217
+ @groups.each do |group|
218
+ asset = Tag::Asset.first
219
+ flunk 'No asset to test on' unless asset
220
+
221
+ portletpreferences = group.asset_viewer_portlet
222
+ assert_equal Web::PortletPreferences, portletpreferences.class
223
+ assert_not_nil portletpreferences.path(:asset => asset)
224
+
225
+ assert_not_nil portletpreferences.layout
226
+ assert_equal group, portletpreferences.layout.group
227
+ assert_equal group.companyid, portletpreferences.layout.companyid
228
+
229
+ # 2nd time the portlet should be retrieved from DB
230
+ group.reload
231
+ assert_equal portletpreferences, group.asset_viewer_portlet
232
+ end
233
+ end
234
+
178
235
  # def test_resource
179
236
  # @groups.each do |x|
180
237
  # # assert !x.resource.nil?, "#{x.id} has no resource"
181
238
  # end
182
239
  # end
183
240
 
241
+
184
242
  end
@@ -4,7 +4,9 @@ class Journal::ArticleTest < ActiveSupport::TestCase
4
4
  fixtures [
5
5
  :journalarticle,
6
6
  :journalarticleresource,
7
- :tagsasset
7
+ :tagsasset,
8
+ :tagsproperty,
9
+ :portlet
8
10
  ]
9
11
 
10
12
  def setup
@@ -48,5 +50,17 @@ class Journal::ArticleTest < ActiveSupport::TestCase
48
50
  end
49
51
  end
50
52
 
53
+ # def test_properties
54
+ # @articles.each do |x|
55
+ # assert_not_nil x.properties
56
+ # assert !x.properties.empty?
57
+ # end
58
+ # end
59
+
60
+ def test_path
61
+ @articles.each do |x|
62
+ assert_not_nil x.path
63
+ end
64
+ end
51
65
 
52
66
  end
@@ -8,13 +8,13 @@ class MB::CategoryTest < ActiveSupport::TestCase
8
8
  :mbthread,
9
9
  :group_,
10
10
  :layout,
11
- :portlet_names
11
+ :portletproperties
12
12
  ]
13
13
 
14
+
14
15
  def setup
15
16
  @categories = MB::Category.all
16
- @rootcategory = MB::Category.find 0
17
- @categories.delete @rootcategory
17
+ flunk 'No categories to test' unless @categories.any?
18
18
  end
19
19
 
20
20
  def test_create
@@ -62,46 +62,43 @@ class MB::CategoryTest < ActiveSupport::TestCase
62
62
  p = Permission.find(:first,
63
63
  :conditions => "companyid=#{category.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
64
64
  assert_not_nil p
65
- assert user.user_permissions.include?(p)
65
+ assert user.permissions.include?(p)
66
66
  end
67
67
  end
68
68
 
69
69
  # each article must belong to a company
70
70
  def test_company
71
71
  @categories.each do |x|
72
- assert_not_nil x.company, "#{x.id} belongs to no company"
72
+ assert_not_nil x.company, "Category #{x.id} belongs to no company"
73
73
  end
74
74
  end
75
75
 
76
76
  def test_group
77
77
  @categories.each do |x|
78
- assert_not_nil x.group, "#{x.id} belongs to no group!"
78
+ assert_not_nil x.group, "Category #{x.id} belongs to no group!"
79
79
  end
80
80
  end
81
81
 
82
82
  def test_user
83
83
  @categories.each do |x|
84
- assert_not_nil x.user, "#{x.id} belongs to no user!"
84
+ assert_not_nil x.user, "Category #{x.id} belongs to no user!"
85
85
  end
86
86
  end
87
87
 
88
88
  def test_parent
89
89
  @categories.each do |x|
90
90
  unless x.parentcategoryid == 0 then
91
- assert_not_nil x.parent, "#{x.id} refers to parent category #{x.parentcategoryid} which does not exist"
91
+ assert_not_nil x.parent, "Category #{x.id} refers to parent category #{x.parentcategoryid} which does not exist"
92
92
  end
93
93
  end
94
94
  end
95
95
 
96
- def test_root
97
- assert_equal 0, @rootcategory.companyid
98
- assert_equal 0, @rootcategory.groupid
99
- assert_equal 0, @rootcategory.userid
100
- assert_equal 0, @rootcategory.parentcategoryid
101
- end
102
-
103
96
  def test_path
104
97
  @categories.each do |x|
98
+ unless x.group
99
+ STDERR.puts 'WARN: message_boards category %i does not belong to a group' % x.id
100
+ next
101
+ end
105
102
  if x.group.layouts_include?('message_boards')
106
103
  assert_not_nil x.path
107
104
  else