33namespace Tests \Unit \TUF ;
44
55use App \TUF \EloquentModelStorage ;
6+ use App \TUF \ReleaseData ;
67use App \TUF \TufFetcher ;
78use Illuminate \Support \Facades \App ;
89use Tests \TestCase ;
@@ -24,13 +25,15 @@ public function testGetReleasesConvertsLegitResponse()
2425 "Joomla_5.1.2-Stable-Upgrade_Package.zip " => [
2526 "custom " => [
2627 "description " => "Joomla! 5.1.2 Release " ,
27- "version " => "5.1.2 "
28+ "version " => "5.1.2 " ,
29+ "stability " => "stable " ,
2830 ]
2931 ],
3032 "Joomla_5.2.1-Stable-Upgrade_Package.zip " => [
3133 "custom " => [
3234 "description " => "Joomla! 5.2.1 Release " ,
33- "version " => "5.2.1 "
35+ "version " => "5.2.1 " ,
36+ "stability " => "stable " ,
3437 ]
3538 ]
3639 ]));
@@ -39,14 +42,16 @@ public function testGetReleasesConvertsLegitResponse()
3942 $ result = $ object ->getReleases ();
4043
4144 $ this ->assertEquals ([
42- "5.1.2 " => [
45+ "5.1.2 " => ReleaseData:: from ( [
4346 "description " => "Joomla! 5.1.2 Release " ,
44- "version " => "5.1.2 "
45- ],
46- "5.2.1 " => [
47+ "version " => "5.1.2 " ,
48+ "stability " => "stable " ,
49+ ]),
50+ "5.2.1 " => ReleaseData::from ([
4751 "description " => "Joomla! 5.2.1 Release " ,
48- "version " => "5.2.1 "
49- ],
52+ "version " => "5.2.1 " ,
53+ "stability " => "stable " ,
54+ ]),
5055 ], $ result ->toArray ());
5156 }
5257
@@ -74,6 +79,81 @@ public function testGetReleasesThrowsExceptionOnMissingCustom()
7479 $ object ->getReleases ();
7580 }
7681
82+ public function testGetLatestVersionForBranchReturnsNullForMissingBranch ()
83+ {
84+ App::bind (StorageInterface::class, fn () => $ this ->getStorageMock ([
85+ "Joomla_5.2.1-Stable-Upgrade_Package.zip " => [
86+ "custom " => [
87+ "description " => "Joomla! 5.2.1 Release " ,
88+ "version " => "5.2.1 " ,
89+ "stability " => "stable " ,
90+ ]
91+ ]
92+ ]));
93+
94+ $ object = new TufFetcher ();
95+ $ result = $ object ->getLatestVersionForBranch (6 );
96+
97+ $ this ->assertNull ($ result );
98+ }
99+
100+ public function testGetLatestVersionForBranchChecksBranch ()
101+ {
102+ App::bind (StorageInterface::class, fn () => $ this ->getStorageMock ([
103+ "Joomla_5.2.1-Stable-Upgrade_Package.zip " => [
104+ "custom " => [
105+ "description " => "Joomla! 5.2.1 Release " ,
106+ "version " => "5.2.1 " ,
107+ "stability " => "stable " ,
108+ ]
109+ ],
110+ "Joomla_4.2.1-Stable-Upgrade_Package.zip " => [
111+ "custom " => [
112+ "description " => "Joomla! 4.2.1 Release " ,
113+ "version " => "4.1.2 " ,
114+ "stability " => "stable " ,
115+ ]
116+ ]
117+ ]));
118+
119+ $ object = new TufFetcher ();
120+ $ result = $ object ->getLatestVersionForBranch (4 );
121+
122+ $ this ->assertEquals ("4.1.2 " , $ result );
123+ }
124+
125+ public function testGetLatestVersionForBranchChecksOrdering ()
126+ {
127+ App::bind (StorageInterface::class, fn () => $ this ->getStorageMock ([
128+ "Joomla_5.2.3-Stable-Upgrade_Package.zip " => [
129+ "custom " => [
130+ "description " => "Joomla! 5.2.3 Release " ,
131+ "version " => "5.2.3 " ,
132+ "stability " => "stable " ,
133+ ]
134+ ],
135+ "Joomla_5.2.1-Stable-Upgrade_Package.zip " => [
136+ "custom " => [
137+ "description " => "Joomla! 5.2.1 Release " ,
138+ "version " => "5.2.1 " ,
139+ "stability " => "stable " ,
140+ ]
141+ ],
142+ "Joomla_5.2.2-Stable-Upgrade_Package.zip " => [
143+ "custom " => [
144+ "description " => "Joomla! 5.2.2 Release " ,
145+ "version " => "5.2.2 " ,
146+ "stability " => "stable " ,
147+ ]
148+ ]
149+ ]));
150+
151+ $ object = new TufFetcher ();
152+ $ result = $ object ->getLatestVersionForBranch (5 );
153+
154+ $ this ->assertEquals ("5.2.3 " , $ result );
155+ }
156+
77157 protected function getStorageMock (array $ targets )
78158 {
79159 $ targetsMock = $ this ->getMockBuilder (TargetsMetadata::class)
0 commit comments