99
1010namespace OCA \Github \Tests \Integration ;
1111
12+ require_once __DIR__ . '/WorkflowTokenTrait.php ' ;
13+
1214use OCA \Github \Reference \GithubCodeReferenceProvider ;
1315use OCA \Github \Service \SecretService ;
1416use OCP \Collaboration \Reference \IReference ;
1517use OCP \Server ;
16- use PHPUnit \Framework \Attributes \DependsExternal ;
1718use PHPUnit \Framework \Attributes \Group ;
1819use Test \TestCase ;
1920
2021#[Group('DB ' )]
2122class GitHubCodeReferenceIntegrationTest extends TestCase {
23+ use WorkflowTokenTrait;
24+
2225 private GithubCodeReferenceProvider $ referenceProvider ;
2326 private SecretService $ secretService ;
2427
2528 protected function setUp (): void {
2629 parent ::setUp ();
2730
31+ $ this ->useWorkflowToken ();
2832 $ this ->referenceProvider = Server::get (GithubCodeReferenceProvider::class);
2933 $ this ->secretService = Server::get (SecretService::class);
3034 }
3135
32- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
33- public function testResolveSingleLineCodeReference (array $ oauthData ): void {
34- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
35- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
36- $ userId = $ oauthData ['userId ' ];
36+ protected function tearDown (): void {
37+ $ this ->restorePreviousToken ();
38+ parent ::tearDown ();
39+ }
40+
41+ public function testResolveSingleLineCodeReference (): void {
42+ $ userId = $ this ->userId ;
3743
3844 $ token = $ this ->secretService ->getEncryptedUserValue ($ userId , 'token ' );
39- $ this ->assertNotSame ('' , $ token , 'Token should be stored after OAuth flow ' );
45+ $ this ->assertNotSame ('' , $ token , 'The workflow token should be stored for the test user ' );
4046
4147 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1 ' ;
4248 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
@@ -79,11 +85,7 @@ private function assertCodeRichObjectStructure(array $richObject): void {
7985 $ this ->assertStringContainsString ('github.com ' , $ richObject ['link ' ], 'link should contain github.com ' );
8086 }
8187
82- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
83- public function testResolveMultiLineCodeReference (array $ oauthData ): void {
84- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
85- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
86-
88+ public function testResolveMultiLineCodeReference (): void {
8789 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1-L5 ' ;
8890 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
8991
@@ -103,10 +105,7 @@ public function testResolveMultiLineCodeReference(array $oauthData): void {
103105 $ this ->assertCount ($ expectedLineCount , $ richObject ['lines ' ], 'lines array should have correct count ' );
104106 }
105107
106- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
107- public function testMatchReference (array $ oauthData ): void {
108- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
109-
108+ public function testMatchReference (): void {
110109 $ validSingleLine = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1 ' ;
111110 $ validMultiLine = 'https://github.com/nextcloud/server/blob/abc123/lib/base.php#L1-L10 ' ;
112111 $ invalidNoLine = 'https://github.com/nextcloud/server/blob/master/lib/base.php ' ;
@@ -118,11 +117,7 @@ public function testMatchReference(array $oauthData): void {
118117 $ this ->assertFalse ($ this ->referenceProvider ->matchReference ($ invalidWrongUrl ), 'Should not match non-blob URL ' );
119118 }
120119
121- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
122- public function testReferenceTitle (array $ oauthData ): void {
123- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
124- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
125-
120+ public function testReferenceTitle (): void {
126121 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1 ' ;
127122 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
128123
@@ -133,11 +128,7 @@ public function testReferenceTitle(array $oauthData): void {
133128 $ this ->assertStringContainsString ('permalink ' , strtolower ($ title ), 'Title should mention permalink ' );
134129 }
135130
136- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
137- public function testReferenceDescription (array $ oauthData ): void {
138- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
139- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
140-
131+ public function testReferenceDescription (): void {
141132 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1 ' ;
142133 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
143134
@@ -151,11 +142,7 @@ public function testReferenceDescription(array $oauthData): void {
151142 }
152143 }
153144
154- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
155- public function testShortRefFormat (array $ oauthData ): void {
156- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
157- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
158-
145+ public function testShortRefFormat (): void {
159146 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1 ' ;
160147 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
161148
@@ -174,11 +161,7 @@ public function testShortRefFormat(array $oauthData): void {
174161 }
175162 }
176163
177- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
178- public function testVcsCodePermalinkStructure (array $ oauthData ): void {
179- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
180- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
181-
164+ public function testVcsCodePermalinkStructure (): void {
182165 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1 ' ;
183166 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
184167
@@ -204,11 +187,7 @@ public function testVcsCodePermalinkStructure(array $oauthData): void {
204187 }
205188 }
206189
207- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
208- public function testCodeLinesContent (array $ oauthData ): void {
209- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
210- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
211-
190+ public function testCodeLinesContent (): void {
212191 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1-L3 ' ;
213192 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
214193
@@ -226,11 +205,7 @@ public function testCodeLinesContent(array $oauthData): void {
226205 }
227206 }
228207
229- #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin ' )]
230- public function testFilePathExtraction (array $ oauthData ): void {
231- $ this ->assertIsArray ($ oauthData , 'oauthData should be an array from OAuth test ' );
232- $ this ->assertArrayHasKey ('userId ' , $ oauthData , 'oauthData must contain userId ' );
233-
208+ public function testFilePathExtraction (): void {
234209 $ referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1 ' ;
235210 $ reference = $ this ->referenceProvider ->resolveReference ($ referenceUrl );
236211
0 commit comments