Jump to content
Search

The new Ubuntu Wiki is live. Legacy content may be unavailable and page links may have changed. Read the announcement on Discourse.

Module:CCLicense/testcases

From Ubuntu Wiki

Documentation for this module may be created at Module:CCLicense/testcases/doc

local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local cclicense = require('Module:CCLicense')

function suite:getMockFrame(args)
    return {
        getParent = function() return { args = args } end,
        args = {},
        expandTemplate = function(_, templateData) return templateData end
    }
end

function suite:testCC0()
    local frame = self:getMockFrame({zero = "yes"})
    local res = cclicense.main(frame)
    
	self:assertEquals('This work has been dedicated to the public domain under the [https://creativecommons.org/publicdomain/zero/1.0/ CC0 1.0 Universal] Public Domain Dedication.', res.args.title)
    self:assertTrue(res.args.description:find('without asking permission', 1, true) ~= nil)
    self:assertEquals('CC0 1.0', res.args.shortname)
    self:assertEquals('CC0 1.0 Universal', res.args.longname)
    self:assertEquals('https://creativecommons.org/publicdomain/zero/1.0/', res.args.link)
    self:assertTrue(res.args.icons:find('Cc.logo.circle.svg|32px|class=skin-invert-image', 1, true) ~= nil)
    self:assertTrue(res.args.icons:find('Cc-zero_white.svg|32px', 1, true) ~= nil)
    
    self:assertEquals('false', res.args.linkreq)
    self:assertEquals('false', res.args.attrreq)
    self:assertEquals('false', res.args.nonfree)
    self:assertEquals(nil, res.args.attr)
end

function suite:testCCBYSA40WithAttr()
    local frame = self:getMockFrame({by = "1", sa = "true", version = "4.0", attr = "Canonical Ltd."})
    local res = cclicense.main(frame)
    
    self:assertEquals('This file is licensed under the [https://creativecommons.org/licenses/by-sa/4.0/ Creative Commons Attribution-ShareAlike 4.0 International] license.', res.args.title)
    self:assertTrue(res.args.description:find('You must give appropriate credit to \'\'Canonical Ltd.\'\', provide a link', 1, true) ~= nil)
    self:assertEquals('Canonical Ltd.', res.args.attr)
end

function suite:testCCBYNC30Ported()
    local frame = self:getMockFrame({by = "1", nc = "1", version = "3.0", jurisdiction = "de"})
    local res = cclicense.main(frame)
    
    self:assertEquals('https://creativecommons.org/licenses/by-nc/3.0/de/', res.args.link)
    self:assertEquals('This file is licensed under the [https://creativecommons.org/licenses/by-nc/3.0/de/ Creative Commons Attribution-NonCommercial 3.0 De] license.', res.args.title)
    self:assertEquals('CC BY-NC 3.0 DE', res.args.shortname)
    self:assertTrue(res.args.icons:find('Cc-nc_white.svg|32px', 1, true) ~= nil)
    self:assertEquals('true', res.args.nonfree)
end

function suite:testSuppressedCategorization()
    local frame = self:getMockFrame({by = "1", sa = "1", version = "4.0", nocat = "true"})
    local res = cclicense.main(frame)
    
    self:assertTrue(res.args.description:find('Category:Creative Commons', 1, true) == nil)
end

return suite