Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ on:
- templates/**
- tests/**

permissions:
contents: read

env:
APP_NAME: integration_github

Expand Down Expand Up @@ -86,6 +89,7 @@ jobs:
CI_USER_LOGIN: ${{ secrets.CI_USER_LOGIN }}
CI_USER_PASSWORD: ${{ secrets.CI_USER_PASSWORD }}
CI_TOTP_SECRET: ${{ secrets.CI_TOTP_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: composer run test:integration

- name: Upload Nextcloud log on failure
Expand Down
67 changes: 21 additions & 46 deletions tests/integration/GitHubCodeReferenceIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,40 @@

namespace OCA\Github\Tests\Integration;

require_once __DIR__ . '/WorkflowTokenTrait.php';

use OCA\Github\Reference\GithubCodeReferenceProvider;
use OCA\Github\Service\SecretService;
use OCP\Collaboration\Reference\IReference;
use OCP\Server;
use PHPUnit\Framework\Attributes\DependsExternal;
use PHPUnit\Framework\Attributes\Group;
use Test\TestCase;

#[Group('DB')]
class GitHubCodeReferenceIntegrationTest extends TestCase {
use WorkflowTokenTrait;

private GithubCodeReferenceProvider $referenceProvider;
private SecretService $secretService;

protected function setUp(): void {
parent::setUp();

$this->useWorkflowToken();
$this->referenceProvider = Server::get(GithubCodeReferenceProvider::class);
$this->secretService = Server::get(SecretService::class);
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testResolveSingleLineCodeReference(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');
$userId = $oauthData['userId'];
protected function tearDown(): void {
$this->restorePreviousToken();
parent::tearDown();
}

public function testResolveSingleLineCodeReference(): void {
$userId = $this->userId;

$token = $this->secretService->getEncryptedUserValue($userId, 'token');
$this->assertNotSame('', $token, 'Token should be stored after OAuth flow');
$this->assertNotSame('', $token, 'The workflow token should be stored for the test user');

$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);
Expand Down Expand Up @@ -79,11 +85,7 @@ private function assertCodeRichObjectStructure(array $richObject): void {
$this->assertStringContainsString('github.com', $richObject['link'], 'link should contain github.com');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testResolveMultiLineCodeReference(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testResolveMultiLineCodeReference(): void {
$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1-L5';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -103,10 +105,7 @@ public function testResolveMultiLineCodeReference(array $oauthData): void {
$this->assertCount($expectedLineCount, $richObject['lines'], 'lines array should have correct count');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testMatchReference(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');

public function testMatchReference(): void {
$validSingleLine = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1';
$validMultiLine = 'https://github.com/nextcloud/server/blob/abc123/lib/base.php#L1-L10';
$invalidNoLine = 'https://github.com/nextcloud/server/blob/master/lib/base.php';
Expand All @@ -118,11 +117,7 @@ public function testMatchReference(array $oauthData): void {
$this->assertFalse($this->referenceProvider->matchReference($invalidWrongUrl), 'Should not match non-blob URL');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testReferenceTitle(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testReferenceTitle(): void {
$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -133,11 +128,7 @@ public function testReferenceTitle(array $oauthData): void {
$this->assertStringContainsString('permalink', strtolower($title), 'Title should mention permalink');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testReferenceDescription(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testReferenceDescription(): void {
$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -151,11 +142,7 @@ public function testReferenceDescription(array $oauthData): void {
}
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testShortRefFormat(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testShortRefFormat(): void {
$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -174,11 +161,7 @@ public function testShortRefFormat(array $oauthData): void {
}
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testVcsCodePermalinkStructure(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testVcsCodePermalinkStructure(): void {
$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -204,11 +187,7 @@ public function testVcsCodePermalinkStructure(array $oauthData): void {
}
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testCodeLinesContent(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testCodeLinesContent(): void {
$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1-L3';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -226,11 +205,7 @@ public function testCodeLinesContent(array $oauthData): void {
}
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testFilePathExtraction(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testFilePathExtraction(): void {
$referenceUrl = 'https://github.com/nextcloud/server/blob/master/lib/base.php#L1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand Down
61 changes: 23 additions & 38 deletions tests/integration/GitHubIssuePrReferenceIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,40 @@

namespace OCA\Github\Tests\Integration;

require_once __DIR__ . '/WorkflowTokenTrait.php';

use OCA\Github\Reference\GithubIssuePrReferenceProvider;
use OCA\Github\Service\SecretService;
use OCP\Collaboration\Reference\IReference;
use OCP\Server;
use PHPUnit\Framework\Attributes\DependsExternal;
use PHPUnit\Framework\Attributes\Group;
use Test\TestCase;

#[Group('DB')]
class GitHubIssuePrReferenceIntegrationTest extends TestCase {
use WorkflowTokenTrait;

private GithubIssuePrReferenceProvider $referenceProvider;
private SecretService $secretService;

protected function setUp(): void {
parent::setUp();

$this->useWorkflowToken();
$this->referenceProvider = Server::get(GithubIssuePrReferenceProvider::class);
$this->secretService = Server::get(SecretService::class);
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testResolveIssueReference(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');
$userId = $oauthData['userId'];
protected function tearDown(): void {
$this->restorePreviousToken();
parent::tearDown();
}

public function testResolveIssueReference(): void {
$userId = $this->userId;

$token = $this->secretService->getEncryptedUserValue($userId, 'token');
$this->assertNotSame('', $token, 'Token should be stored after OAuth flow');
$this->assertNotSame('', $token, 'The workflow token should be stored for the test user');

$referenceUrl = 'https://github.com/nextcloud/server/issues/1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);
Expand Down Expand Up @@ -96,14 +102,11 @@ private function assertIssueRichObjectStructure(array $richObject): void {
}
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testResolvePullRequestReference(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');
$userId = $oauthData['userId'];
public function testResolvePullRequestReference(): void {
$userId = $this->userId;

$token = $this->secretService->getEncryptedUserValue($userId, 'token');
$this->assertNotSame('', $token, 'Token should be stored after OAuth flow');
$this->assertNotSame('', $token, 'The workflow token should be stored for the test user');

$referenceUrl = 'https://github.com/nextcloud/server/pull/1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);
Expand Down Expand Up @@ -156,14 +159,11 @@ private function assertPullRequestRichObjectStructure(array $richObject): void {
$this->assertValidDateString($richObject['created_at'], 'created_at should be a valid date string');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testResolveIssueWithCommentReference(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');
$userId = $oauthData['userId'];
public function testResolveIssueWithCommentReference(): void {
$userId = $this->userId;

$token = $this->secretService->getEncryptedUserValue($userId, 'token');
$this->assertNotSame('', $token, 'Token should be stored after OAuth flow');
$this->assertNotSame('', $token, 'The workflow token should be stored for the test user');

$referenceUrl = 'https://github.com/nextcloud/server/issues/1#issuecomment-223229268';
$reference = $this->referenceProvider->resolveReference($referenceUrl);
Expand Down Expand Up @@ -193,10 +193,7 @@ private function assertCommentStructure(array $comment): void {
$this->assertValidDateString($comment['updated_at'], 'Comment updated_at should be a valid date string');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testMatchReference(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');

public function testMatchReference(): void {
$validIssueUrl = 'https://github.com/nextcloud/server/issues/123';
$validPrUrl = 'https://github.com/nextcloud/server/pull/456';
$invalidUrl = 'https://github.com/nextcloud/server';
Expand All @@ -206,11 +203,7 @@ public function testMatchReference(array $oauthData): void {
$this->assertFalse($this->referenceProvider->matchReference($invalidUrl), 'Should not match repo URL');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testReferenceTitle(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testReferenceTitle(): void {
$referenceUrl = 'https://github.com/nextcloud/server/issues/1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -222,11 +215,7 @@ public function testReferenceTitle(array $oauthData): void {
$this->assertStringContainsString('nextcloud/server', $title, 'Title should contain repo name');
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testReferenceMilestone(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testReferenceMilestone(): void {
$referenceUrl = 'https://github.com/nextcloud/server/issues/1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand All @@ -240,11 +229,7 @@ public function testReferenceMilestone(array $oauthData): void {
}
}

#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
public function testReferenceReactions(array $oauthData): void {
$this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test');
$this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId');

public function testReferenceReactions(): void {
$referenceUrl = 'https://github.com/nextcloud/server/issues/1';
$reference = $this->referenceProvider->resolveReference($referenceUrl);

Expand Down
Loading
Loading