cirandas.net

ref: master

test/unit/box_test.rb


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require_relative "../test_helper"

class BoxTest < ActiveSupport::TestCase

  def setup
    Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  end

  should 'retrieve environment based on owner' do
    profile = fast_create(Profile)
    box = fast_create(Box, :owner_id => profile.id, :owner_type => 'Profile')
    assert_equal profile.environment, box.environment

    box = fast_create(Box, :owner_id => Environment.default.id, :owner_type => 'Environment')
    assert_equal Environment.default, box.environment
  end

  should 'list allowed blocks for center box' do
    blocks = Box.new.tap { |b| b.position = 1 }.acceptable_blocks

    refute blocks.include?('.block')
    refute blocks.include?('.disabled-enterprise-message-block')
    refute blocks.include?('.featured-products-block')
    refute blocks.include?('.products-block')
    refute blocks.include?('.profile-info-block')
    refute blocks.include?('.profile-list-block')
    refute blocks.include?('.profile-search-block')
    refute blocks.include?('.slideshow-block')
    refute blocks.include?('.location-block')

    assert blocks.include?('.article-block')
    assert blocks.include?('.blog-archives-block')
    assert blocks.include?('.categories-block')
    assert blocks.include?('.communities-block')
    assert blocks.include?('.enterprises-block')
    assert blocks.include?('.fans-block')
    assert blocks.include?('.favorite-enterprises-block')
    assert blocks.include?('.feed-reader-block')
    assert blocks.include?('.highlights-block')
    assert blocks.include?('.link-list-block')
    assert blocks.include?('.login-block')
    assert blocks.include?('.main-block')
    assert blocks.include?('.my-network-block')
    assert blocks.include?('.profile-image-block')
    assert blocks.include?('.raw-html-block')
    assert blocks.include?('.recent-documents-block')
    assert blocks.include?('.tags-cloud-block')
    assert blocks.include?('.interest-tags-block')
    assert blocks.include?('.menu-block')
  end

  should 'list allowed blocks for box at position 2' do
    blocks = Box.new.tap { |b| b.position = 2 }.acceptable_blocks

    refute blocks.include?('.main-block')
    refute blocks.include?('.block')
    refute blocks.include?('.profile-list-block')

    assert blocks.include?('.article-block')
    assert blocks.include?('.blog-archives-block')
    assert blocks.include?('.categories-block')
    assert blocks.include?('.communities-block')
    assert blocks.include?('.disabled-enterprise-message-block')
    assert blocks.include?('.enterprises-block')
    assert blocks.include?('.fans-block')
    assert blocks.include?('.favorite-enterprises-block')
    assert blocks.include?('.feed-reader-block')
    assert blocks.include?('.highlights-block')
    assert blocks.include?('.link-list-block')
    assert blocks.include?('.location-block')
    assert blocks.include?('.login-block')
    assert blocks.include?('.my-network-block')
    assert blocks.include?('.profile-image-block')
    assert blocks.include?('.profile-info-block')
    assert blocks.include?('.profile-search-block')
    assert blocks.include?('.raw-html-block')
    assert blocks.include?('.recent-documents-block')
    assert blocks.include?('.slideshow-block')
    assert blocks.include?('.tags-cloud-block')
    assert blocks.include?('.interest-tags-block')
    assert blocks.include?('.menu-block')
  end

  should 'list plugin block as allowed for box at position 1' do
    class SomePlugin < Noosfero::Plugin
      def self.extra_blocks
        { PluginBlock => {:position => 1} }
      end
    end
    class PluginBlock < Block
      def self.to_s; 'plugin-block'; end
    end
    Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])

    blocks = build(Box, :position => 1).acceptable_blocks
    assert blocks.include?('box-test_plugin-block')
  end

  should 'list plugin block as allowed for box at position 2' do
    class SomePlugin < Noosfero::Plugin
      def self.extra_blocks
        { PluginBlock => {:position => 2} }
      end
    end
    class PluginBlock < Block
      def self.to_s; 'plugin-block'; end
    end
    Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])

    blocks = build(Box, :position => 2).acceptable_blocks
    assert blocks.include?('box-test_plugin-block')
  end

  should 'list plugin block as allowed for the right holder' do
    class SomePlugin < Noosfero::Plugin
      def self.extra_blocks
        { PluginBlock => {:position => 1, :type => [Person, Enterprise]} }
      end
    end
    class PluginBlock < Block
      def self.to_s; 'plugin-block'; end
    end
    Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])

    blocks = build(Box, :position => 1, :owner => Person.new).acceptable_blocks
    assert blocks.include?('box-test_plugin-block')

    blocks = build(Box, :position => 1, :owner => Enterprise.new).acceptable_blocks
    assert blocks.include?('box-test_plugin-block')

    blocks = build(Box, :position => 1, :owner => Community.new).acceptable_blocks
    refute blocks.include?('box-test_plugin-block')
  end

  should 'list only boxes with a postion greater than zero' do
    profile = fast_create(Profile)
    box = fast_create(Box, :owner_id => profile.id, :owner_type => 'Profile', :position => 0)
    box2 = fast_create(Box, :owner_id => profile.id, :owner_type => 'Profile', :position => 1)
    assert_equal [box2], profile.boxes.with_position
  end

end