1+ using Refresh . Common . Constants ;
2+ using Refresh . Database ;
3+ using Refresh . Database . Models ;
4+ using Refresh . Database . Models . Authentication ;
5+ using Refresh . Database . Models . Playlists ;
6+ using Refresh . Database . Models . Users ;
7+ using Refresh . Interfaces . Game . Types . Playlists ;
8+ using RefreshTests . GameServer . Extensions ;
9+
10+ namespace RefreshTests . GameServer . Tests . Playlists ;
11+
12+ public class PlaylistUploadTests : GameServerTest
13+ {
14+ private const string ValidIconGuid = "g18451" ; // star sticker
15+ private const string InvalidIconGuid = "g1087" ; // sackboy model
16+ private const string IconHash = "9488801db61c5313db3bb15db7d66fd26df7e789" ; // hash of "TEX "
17+
18+ [ Test ]
19+ public void CreateAndUpdateLbp1Playlist ( )
20+ {
21+ using TestContext context = this . GetServer ( ) ;
22+ GameUser user = context . CreateUser ( ) ;
23+
24+ HttpClient client = context . GetAuthenticatedClient ( TokenType . Game , TokenGame . LittleBigPlanet1 , TokenPlatform . PS3 , user ) ;
25+
26+ // create root playlist
27+ SerializedLbp1Playlist request = new ( )
28+ {
29+ Name = "root" ,
30+ Icon = ValidIconGuid ,
31+ Description = "DESCRIPTION" ,
32+ Location = new GameLocation ( ) ,
33+ } ;
34+
35+ HttpResponseMessage message = client . PostAsync ( "/lbp/createPlaylist" , new StringContent ( request . AsXML ( ) ) ) . Result ;
36+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
37+
38+ SerializedLbp1Playlist rootResponse = message . Content . ReadAsXML < SerializedLbp1Playlist > ( ) ;
39+ Assert . That ( rootResponse . Name , Is . EqualTo ( "root" ) ) ;
40+
41+ // create actual playlist
42+ request = new ( )
43+ {
44+ Name = "real" ,
45+ Icon = ValidIconGuid ,
46+ Description = "DESCRIPTION" ,
47+ Location = new GameLocation ( ) ,
48+ } ;
49+
50+ message = client . PostAsync ( $ "/lbp/createPlaylist?parent_id={ rootResponse . Id } ", new StringContent ( request . AsXML ( ) ) ) . Result ;
51+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
52+
53+ SerializedLbp1Playlist subResponse = message . Content . ReadAsXML < SerializedLbp1Playlist > ( ) ;
54+ Assert . That ( subResponse . Name , Is . EqualTo ( "real" ) ) ;
55+
56+ // Ensure the playlists are properly fetchable
57+ GamePlaylist ? root = context . Database . GetUserRootPlaylist ( user ) ;
58+ Assert . That ( root , Is . Not . Null ) ;
59+ Assert . That ( root ! . PlaylistId , Is . EqualTo ( rootResponse . Id ) ) ;
60+ Assert . That ( root ! . PublisherId , Is . EqualTo ( user . UserId ) ) ;
61+
62+ DatabaseList < GamePlaylist > playlists = context . Database . GetPlaylistsByAuthor ( user , 0 , 10 ) ;
63+ Assert . That ( playlists . Items . Count , Is . EqualTo ( 1 ) ) ;
64+
65+ playlists = context . Database . GetPlaylistsInPlaylist ( root , 0 , 10 ) ;
66+ Assert . That ( playlists . Items . Count , Is . EqualTo ( 1 ) ) ;
67+
68+ // Now update
69+ request = new ( )
70+ {
71+ Name = "legit" ,
72+ Icon = ValidIconGuid ,
73+ Description = "DESCRIPTION" ,
74+ Location = new GameLocation ( ) ,
75+ } ;
76+
77+ message = client . PostAsync ( $ "/lbp/setPlaylistMetaData/{ subResponse . Id } ", new StringContent ( request . AsXML ( ) ) ) . Result ;
78+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
79+
80+ context . Database . Refresh ( ) ;
81+
82+ GamePlaylist ? updated = context . Database . GetPlaylistById ( subResponse . Id ) ;
83+ Assert . That ( updated , Is . Not . Null ) ;
84+ Assert . That ( updated ! . Name , Is . EqualTo ( "legit" ) ) ;
85+ }
86+
87+ [ Test ]
88+ public void CreateAndUpdateLbp3Playlist ( )
89+ {
90+ using TestContext context = this . GetServer ( ) ;
91+ GameUser user = context . CreateUser ( ) ;
92+
93+ HttpClient client = context . GetAuthenticatedClient ( TokenType . Game , TokenGame . LittleBigPlanet3 , TokenPlatform . PS3 , user ) ;
94+
95+ // create playlist
96+ SerializedLbp3Playlist request = new ( )
97+ {
98+ Name = "real" ,
99+ } ;
100+
101+ HttpResponseMessage message = client . PostAsync ( $ "/lbp/playlists", new StringContent ( request . AsXML ( ) ) ) . Result ;
102+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
103+
104+ SerializedLbp3Playlist response = message . Content . ReadAsXML < SerializedLbp3Playlist > ( ) ;
105+ Assert . That ( response . Name , Is . EqualTo ( "real" ) ) ;
106+ Assert . That ( response . Description , Is . EqualTo ( "" ) ) ;
107+
108+ // Ensure a root playlist was automatically created, and the actual playlist is in that root playlist
109+ GamePlaylist ? root = context . Database . GetUserRootPlaylist ( user ) ;
110+ Assert . That ( root , Is . Not . Null ) ;
111+ Assert . That ( root ! . PlaylistId , Is . Not . EqualTo ( response . Id ) ) ;
112+ Assert . That ( root ! . PublisherId , Is . EqualTo ( user . UserId ) ) ;
113+
114+ DatabaseList < GamePlaylist > playlists = context . Database . GetPlaylistsByAuthor ( user , 0 , 10 ) ;
115+ Assert . That ( playlists . Items . Count , Is . EqualTo ( 1 ) ) ;
116+
117+ playlists = context . Database . GetPlaylistsInPlaylist ( root , 0 , 10 ) ;
118+ Assert . That ( playlists . Items . Count , Is . EqualTo ( 1 ) ) ;
119+
120+ // Now update
121+ request = new ( )
122+ {
123+ Description = "DESCRIPTION" ,
124+ } ;
125+
126+ message = client . PostAsync ( $ "/lbp/playlists/{ response . Id } ", new StringContent ( request . AsXML ( ) ) ) . Result ;
127+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
128+
129+ response = message . Content . ReadAsXML < SerializedLbp3Playlist > ( ) ;
130+ Assert . That ( response . Name , Is . EqualTo ( "real" ) ) ;
131+ Assert . That ( response . Description , Is . EqualTo ( "DESCRIPTION" ) ) ;
132+ }
133+
134+ [ Test ]
135+ public void TrimLbp1PlaylistStrings ( )
136+ {
137+ using TestContext context = this . GetServer ( ) ;
138+ GameUser user = context . CreateUser ( ) ;
139+
140+ HttpClient client = context . GetAuthenticatedClient ( TokenType . Game , TokenGame . LittleBigPlanet1 , TokenPlatform . PS3 , user ) ;
141+
142+ // create root playlist
143+ SerializedLbp1Playlist request = new ( )
144+ {
145+ Name = new string ( '*' , UgcLimits . TitleLimit * 2 ) ,
146+ Icon = ValidIconGuid ,
147+ Description = new string ( '*' , UgcLimits . DescriptionLimit * 2 ) ,
148+ Location = new GameLocation ( ) ,
149+ } ;
150+
151+ HttpResponseMessage message = client . PostAsync ( "/lbp/createPlaylist" , new StringContent ( request . AsXML ( ) ) ) . Result ;
152+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
153+
154+ SerializedLbp1Playlist response = message . Content . ReadAsXML < SerializedLbp1Playlist > ( ) ;
155+ Assert . That ( response . Name . Length , Is . EqualTo ( UgcLimits . TitleLimit ) ) ;
156+ Assert . That ( response . Description . Length , Is . EqualTo ( UgcLimits . DescriptionLimit ) ) ;
157+
158+ // Now update
159+ request = new ( )
160+ {
161+ Name = new string ( 'd' , UgcLimits . TitleLimit * 2 ) ,
162+ Icon = ValidIconGuid ,
163+ Description = new string ( 'd' , UgcLimits . DescriptionLimit * 2 ) ,
164+ Location = new GameLocation ( ) ,
165+ } ;
166+ message = client . PostAsync ( $ "/lbp/setPlaylistMetaData/{ response . Id } ", new StringContent ( request . AsXML ( ) ) ) . Result ;
167+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
168+
169+ GamePlaylist ? updated = context . Database . GetPlaylistById ( response . Id ) ;
170+ Assert . That ( updated , Is . Not . Null ) ;
171+ Assert . That ( updated ! . Name . Length , Is . EqualTo ( UgcLimits . TitleLimit ) ) ;
172+ Assert . That ( updated ! . Description . Length , Is . EqualTo ( UgcLimits . DescriptionLimit ) ) ;
173+ }
174+
175+ [ Test ]
176+ public void TrimLbp3PlaylistStrings ( )
177+ {
178+ using TestContext context = this . GetServer ( ) ;
179+ GameUser user = context . CreateUser ( ) ;
180+
181+ HttpClient client = context . GetAuthenticatedClient ( TokenType . Game , TokenGame . LittleBigPlanet3 , TokenPlatform . PS3 , user ) ;
182+
183+ // create root playlist
184+ SerializedLbp3Playlist request = new ( )
185+ {
186+ Name = new string ( '*' , UgcLimits . TitleLimit * 2 ) ,
187+ Description = new string ( '*' , UgcLimits . DescriptionLimit * 2 ) ,
188+ } ;
189+
190+ HttpResponseMessage message = client . PostAsync ( "/lbp/playlists" , new StringContent ( request . AsXML ( ) ) ) . Result ;
191+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
192+
193+ SerializedLbp3Playlist response = message . Content . ReadAsXML < SerializedLbp3Playlist > ( ) ;
194+ Assert . That ( response . Name , Is . Not . Null ) ;
195+ Assert . That ( response . Description , Is . Not . Null ) ;
196+ Assert . That ( response . Name ! . Length , Is . EqualTo ( UgcLimits . TitleLimit ) ) ;
197+ Assert . That ( response . Description ! . Length , Is . EqualTo ( UgcLimits . DescriptionLimit ) ) ;
198+
199+ // Now update
200+ request = new ( )
201+ {
202+ Name = new string ( 'd' , UgcLimits . TitleLimit * 2 ) ,
203+ Description = new string ( 'd' , UgcLimits . DescriptionLimit * 2 ) ,
204+ } ;
205+ message = client . PostAsync ( $ "/lbp/playlists/{ response . Id } ", new StringContent ( request . AsXML ( ) ) ) . Result ;
206+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
207+
208+ context . Database . Refresh ( ) ;
209+
210+ response = message . Content . ReadAsXML < SerializedLbp3Playlist > ( ) ;
211+ Assert . That ( response . Name , Is . Not . Null ) ;
212+ Assert . That ( response . Description , Is . Not . Null ) ;
213+ Assert . That ( response . Name ! . Length , Is . EqualTo ( UgcLimits . TitleLimit ) ) ;
214+ Assert . That ( response . Description ! . Length , Is . EqualTo ( UgcLimits . DescriptionLimit ) ) ;
215+ }
216+
217+ [ Test ]
218+ [ TestCase ( "" , true , false ) ]
219+ [ TestCase ( "0" , true , false ) ]
220+ [ TestCase ( ValidIconGuid , true , false ) ]
221+ [ TestCase ( InvalidIconGuid , false , false ) ]
222+ [ TestCase ( "hi" , false , false ) ]
223+ [ TestCase ( IconHash , false , false ) ]
224+ [ TestCase ( IconHash , true , true ) ]
225+ public void ValidatePlaylistIcon ( string iconHash , bool isValid , bool uploadAsset )
226+ {
227+ using TestContext context = this . GetServer ( ) ;
228+ GameUser user = context . CreateUser ( ) ;
229+
230+ HttpClient client = context . GetAuthenticatedClient ( TokenType . Game , TokenGame . LittleBigPlanet1 , TokenPlatform . PS3 , user ) ;
231+
232+ // If this is a server asset, upload it
233+ if ( uploadAsset )
234+ {
235+ HttpResponseMessage assetMessage = client . PostAsync ( $ "/lbp/upload/{ iconHash } ", new ReadOnlyMemoryContent ( "TEX "u8 . ToArray ( ) ) ) . Result ;
236+ Assert . That ( assetMessage . StatusCode , Is . EqualTo ( OK ) ) ;
237+ }
238+
239+ // create playlist
240+ SerializedLbp1Playlist request = new ( )
241+ {
242+ Name = "" ,
243+ Icon = iconHash ,
244+ Description = "" ,
245+ Location = new GameLocation ( ) ,
246+ } ;
247+
248+ HttpResponseMessage message = client . PostAsync ( "/lbp/createPlaylist" , new StringContent ( request . AsXML ( ) ) ) . Result ;
249+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
250+
251+ SerializedLbp1Playlist response = message . Content . ReadAsXML < SerializedLbp1Playlist > ( ) ;
252+ Assert . That ( response . Icon , Is . EqualTo ( isValid ? iconHash : "0" ) ) ;
253+
254+ // Now update
255+ message = client . PostAsync ( $ "/lbp/setPlaylistMetaData/{ response . Id } ", new StringContent ( request . AsXML ( ) ) ) . Result ;
256+ Assert . That ( message . StatusCode , Is . EqualTo ( OK ) ) ;
257+
258+ GamePlaylist ? updated = context . Database . GetPlaylistById ( response . Id ) ;
259+ Assert . That ( updated , Is . Not . Null ) ;
260+ Assert . That ( updated ! . IconHash , Is . EqualTo ( isValid ? iconHash : "0" ) ) ;
261+ }
262+ }
0 commit comments