Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lua/spec/player_ext_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--- Triple Comment to Enable our LLS Plugin
describe('PlayerExt', function()
local PlayerExt = require('Module:Player/Ext')

describe('is party', function()
local mockLpdb = require('Module:Mock/Lpdb')

---@param pageName string
---@return player
local getDataFor = function(pageName)
mockLpdb.setUp()
local data = mw.ext.LiquipediaDB.lpdb('player', {
limit = 1,
conditions = '[[pagename::' .. pageName .. ']]',
})[1]
mockLpdb.tearDown()
return data
end

it('check', function()
assert.is_nil(PlayerExt.fromLpdbPlayerRecord())
assert.is_nil(PlayerExt.fromLpdbPlayerRecord{})

assert.are_same({
pageName = 'Supr',
displayName = 'supr',
flag = 'United States',
faction = nil,
team = 'soniqs 2021',
extradata = {
role = 'In-game leader',
role2 = 'Support',
signatureOperator1 = 'smoke',
signatureOperator2 = 'gridlock',
},
pageIsResolved = true,
apiId = nil,
}, PlayerExt.fromLpdbPlayerRecord(getDataFor('Supr')))

assert.are_same({
pageName = 'Clem',
displayName = 'Clem',
flag = 'France',
faction = 'Terran',
team = 'team liquid 2024',
extradata = {
firstname = 'Clément',
faction = 'Terran',
lastname = 'Desplanches',
roles = {},
},
pageIsResolved = true,
apiId = nil,
}, PlayerExt.fromLpdbPlayerRecord(getDataFor('Clem')))
end)
end)
end)
101 changes: 75 additions & 26 deletions lua/test_assets/lpdb_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ return {
{
['alternateid'] = 'suprmane, supr2turnt, suprSayian, suprWRLD',
['birthdate'] = '1989-03-16',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '74410',
['earningsbyyear'] = {
[2017] = 900,
Expand Down Expand Up @@ -55,7 +55,7 @@ return {
{
['alternateid'] = '',
['birthdate'] = '1993-05-07',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '18038',
['earningsbyyear'] = {
[2017] = 10988,
Expand Down Expand Up @@ -94,7 +94,7 @@ return {
{
['alternateid'] = '',
['birthdate'] = '1999-08-03',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '225491',
['earningsbyyear'] = {
[2017] = 1352,
Expand Down Expand Up @@ -139,7 +139,7 @@ return {
{
['alternateid'] = '',
['birthdate'] = '1999-05-08',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '222124',
['earningsbyyear'] = {
[2017] = 3524,
Expand Down Expand Up @@ -187,7 +187,7 @@ return {
{
['alternateid'] = 'BBooAF',
['birthdate'] = '1997-02-21',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '56737',
['earningsbyyear'] = {
[2016] = 4750,
Expand Down Expand Up @@ -232,7 +232,7 @@ return {
{
['alternateid'] = '',
['birthdate'] = '1995-05-09',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '354870',
['earningsbyyear'] = {
[2016] = 1750,
Expand Down Expand Up @@ -277,7 +277,7 @@ return {
{
['alternateid'] = 'Psycho0',
['birthdate'] = '1999-02-02',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '392682',
['earningsbyyear'] = {
[2017] = 12481,
Expand Down Expand Up @@ -325,8 +325,8 @@ return {
},
{
['alternateid'] = '',
['birthdate'] = '1970-01-01',
['deathdate'] = '1970-01-01',
['birthdate'] = '0000-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '39346',
['earningsbyyear'] = {
[2017] = 12481,
Expand Down Expand Up @@ -367,8 +367,8 @@ return {
},
{
['alternateid'] = 'wagao, waaaaaaaag',
['birthdate'] = '1970-01-01',
['deathdate'] = '1970-01-01',
['birthdate'] = '0000-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '39316',
['earningsbyyear'] = {
[2017] = 9618,
Expand Down Expand Up @@ -408,8 +408,8 @@ return {
},
{
['alternateid'] = '',
['birthdate'] = '1970-01-01',
['deathdate'] = '1970-01-01',
['birthdate'] = '0000-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '5645',
['earningsbyyear'] = {
[2017] = 5645,
Expand Down Expand Up @@ -443,8 +443,8 @@ return {
},
{
['alternateid'] = '',
['birthdate'] = '1970-01-01',
['deathdate'] = '1970-01-01',
['birthdate'] = '0000-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '9796',
['earningsbyyear'] = {
[2017] = 3446,
Expand Down Expand Up @@ -484,7 +484,7 @@ return {
{
['alternateid'] = '',
['birthdate'] = '1997-11-22',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '261091',
['earningsbyyear'] = {
[2016] = 4750,
Expand Down Expand Up @@ -529,8 +529,8 @@ return {
},
{
['alternateid'] = '',
['birthdate'] = '1970-01-01',
['deathdate'] = '1970-01-01',
['birthdate'] = '0000-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '23573',
['earningsbyyear'] = {
[2016] = 4750,
Expand Down Expand Up @@ -570,7 +570,7 @@ return {
{
['alternateid'] = '',
['birthdate'] = '1995-04-01',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '31509',
['earningsbyyear'] = {
[2016] = 3000,
Expand Down Expand Up @@ -609,7 +609,7 @@ return {
{
['alternateid'] = '',
['birthdate'] = '1994-02-19',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '19179',
['earningsbyyear'] = {
[2017] = 2416,
Expand Down Expand Up @@ -651,8 +651,8 @@ return {
},
{
['alternateid'] = '',
['birthdate'] = '1970-01-01',
['deathdate'] = '1970-01-01',
['birthdate'] = '0000-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '9661',
['earningsbyyear'] = {
[2017] = 2111,
Expand Down Expand Up @@ -690,7 +690,7 @@ return {
{
['alternateid'] = 'Faker, fk',
['birthdate'] = '1998-11-28',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '8861',
['earningsbyyear'] = {
[2017] = 2361,
Expand Down Expand Up @@ -727,7 +727,7 @@ return {
{
['alternateid'] = 'geoolicious, geoo, sleepygeo, senpapigeo, geoometrics, geonidas',
['birthdate'] = '1995-08-10',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '396760',
['earningsbyyear'] = {
[2017] = 2500,
Expand Down Expand Up @@ -772,7 +772,7 @@ return {
{
['alternateid'] = 'ShuttleAK, ShuttleMK, Shutt',
['birthdate'] = '1999-06-11',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '74140',
['earningsbyyear'] = {
[2017] = 6900,
Expand Down Expand Up @@ -813,7 +813,7 @@ return {
{
['alternateid'] = 'Whiteshark, Wshark',
['birthdate'] = '1994-08-30',
['deathdate'] = '1970-01-01',
['deathdate'] = '0000-01-01',
['earnings'] = '7095',
['earningsbyyear'] = {
[2017] = 116,
Expand Down Expand Up @@ -851,4 +851,53 @@ return {
['teamtemplate'] = '',
['type'] = 'player',
},
{
['alternateid'] = 'Xavier',
['birthdate'] = '2002-04-08',
['deathdate'] = '0000-01-01',
['earnings'] = '945973',
['earningsbyyear'] = {
[2016] = 887,
[2017] = 510,
[2018] = 9461,
[2019] = 18224,
[2020] = 63378,
[2021] = 81181,
[2022] = 66171,
[2023] = 90202,
[2024] = 520388,
[2025] = 77691,
[2026] = 17880,
},
['extradata'] = {
['firstname'] = 'Clément',
['faction'] = 'Terran',
['lastname'] = 'Desplanches',
['roles'] = {},
},
['id'] = 'Clem',
['image'] = 'Liquid Clem at the 2025 Esports World Cup.jpg',
['imageurl'] = 'https://liquipedia.net/commons/images/thumb/2/2f/Liquid_Clem_at_the_2025_Esports_World_Cup.jpg/400px-Liquid_Clem_at_the_2025_Esports_World_Cup.jpg',
['links'] = {
['aligulac'] = 'https://aligulac.com/players/5878',
['twitter'] = 'https://twitter.com/Clem_sc2',
['twitch'] = 'https://www.twitch.tv/liquidclem',
},
['localizedname'] = '',
['name'] = 'Clément Desplanches',
['namespace'] = '0',
['nationality'] = 'France',
['nationality2'] = '',
['nationality3'] = '',
['objectname'] = '65124_player_Clem',
['pageid'] = '65124',
['pagename'] = 'Clem',
['region'] = '',
['romanizedname'] = 'Clément Desplanches',
['status'] = 'Active',
['team'] = 'Team Liquid',
['teampagename'] = 'Team_Liquid',
['teamtemplate'] = 'team liquid 2024',
['type'] = 'player',
},
}
2 changes: 1 addition & 1 deletion lua/wikis/commons/Mock/Lpdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ end
---@param dbTable string
---@return table
function mockLpdb._getMockData(dbTable)
local data = Lua.import('Module:TestAssets/Lpdb/' .. dbTable)
local data = Lua.import('Module:test_assets/lpdb_' .. dbTable)

if not data then
error(mw.message.new('liquipediadb-error-invalid-datatype'))
Expand Down
25 changes: 24 additions & 1 deletion lua/wikis/commons/Player/Ext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ function PlayerExt.syncTeam(pageName, template, options)

if entry and not entry.isResolved then
entry.raw = entry.template
entry.template = entry.template and TeamTemplate.resolve(entry.template, options.date --[[@as string|number?]])
entry.template = entry.template
and TeamTemplate.resolve(entry.template, options.date --[[@as string|number?]]) --[[@as string]]
entry.isResolved = true
end

Expand Down Expand Up @@ -398,4 +399,26 @@ function PlayerExt.TemplateStorePlayerLink(frame)
}, {overwritePageVars = true})
end

---@param record player
---@return standardPlayer
---@overload fun(record: {}?): nil
function PlayerExt.fromLpdbPlayerRecord(record)
if Logic.isEmpty(record) then
return
end

local extradata = record.extradata or {}

return {
pageName = record.pagename,
displayName = record.id,
flag = record.nationality,
faction = extradata.faction,
team = record.teamtemplate,
extradata = extradata,
pageIsResolved = true,
apiId = extradata.playerid, -- dota appid is stored that way
}
end

return PlayerExt
Loading