cirandas.net

ref: master

plugins/video/test/unit/video_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
require_relative '../test_helper'

class VideoTest < ActiveSupport::TestCase

  include AuthenticatedTestHelper
  fixtures :users, :environments

  def setup
    @video = VideoPlugin::Video.new
  end

  should "define its type_name as video" do
    assert_equal VideoPlugin::Video.type_name, _('Video')
  end

  should "display version" do
    assert @video.can_display_versions?
  end

  should "define its short_description" do
    assert_equal VideoPlugin::Video.short_description, _('Embedded Video')
  end

  should "define its description" do
    assert_equal VideoPlugin::Video.description, _('Display embedded videos.')
  end

  should "define a fitted_width" do
    assert_equal @video.fitted_width, 499
  end

  should "eval a fitted_height" do
    @video.video_height = 1000
    @video.video_width =  2000
    fitted_height = ((@video.fitted_width * @video.video_height) / @video.video_width).to_i
    assert_equal fitted_height, @video.fitted_height
  end

  should "define a thumbnail_fitted_width" do
    assert_equal @video.thumbnail_fitted_width, 80
  end

  should "eval a thumbnail_fitted_height" do
    @video.video_thumbnail_height = 60
    @video.video_thumbnail_width =  30
    thumbnail_fitted_height = ((@video.thumbnail_fitted_width * @video.video_thumbnail_height) / @video.video_thumbnail_width).to_i
    assert_equal thumbnail_fitted_height, @video.thumbnail_fitted_height
  end

  should "have dimensions of default thumbnail" do
    assert @video.video_thumbnail_height.present? && @video.video_thumbnail_height > 0
    assert @video.video_thumbnail_width.present? && @video.video_thumbnail_width > 0
  end

  should "show a no_browser_support_message" do
    assert_equal @video.no_browser_support_message, '<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>'
  end


  ### Tests for YouTube

  should "is_youtube return true when the url contains http://youtube.com" do
    @video.video_url = "http://youtube.com/?v=XXXXX"
    assert @video.is_youtube?
  end

  should "is_youtube return true when the url contains https://youtube.com" do
    @video.video_url = "https://youtube.com/?v=XXXXX"
    assert @video.is_youtube?
  end

  should "is_youtube return false when the url contains an invalid youtube link" do
    @video.video_url = "http://www.yt.com/?v=XXXXX"
    assert !@video.is_youtube?
  end

  ### Tests for vimeo

  should "is_vimeo return true when the url contains vimeo.com" do
    @video.video_url = "vimeo.com/09898"
    assert @video.is_vimeo?
  end

  should "is_vimeo return false when the url not contains vimeo video ID" do
    @video.video_url = "vimeo.com/home"
    assert !@video.is_vimeo?
  end

  should "is_vimeo return true for https://vimeo.com/channels/staffpicks/XXXXXXXXXX" do
    @video.video_url = "https://vimeo.com/channels/staffpicks/122325664"
    assert @video.is_vimeo?
  end

  should "mime-type return video/webm if url ends with webm" do
    url = "http://www.vmsd.com/98979.webm"
    assert_equal 'video/webm', @video.class.mime_type(url)
  end

  should "mime-type return video/ogg if url ends with ogg" do
    url = "http://www.vmsd.com/98979.ogg"
    assert_equal 'video/ogg', @video.class.mime_type(url)
  end

  should "mime-type return video/unknown if platform is youtube" do
    url = "https://youtube.com/?v=XXXXX"
    assert_equal 'video/unknown', @video.class.mime_type(url)
  end

  should "mime-type return video/unknown if platform is vimeo" do
    url = "http://vimeo.com/98979"
    assert_equal 'video/unknown', @video.class.mime_type(url)
  end

  should "mime-type return video/mp4 if url ends with mp4" do
    url = "http://www.vmsd.com/98979.mp4"
    assert_equal 'video/mp4', @video.class.mime_type(url)
  end

end