Skip to content

Commit

Permalink
Call statically static assert methods
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Oct 30, 2023
1 parent 4362a7f commit 1ed0636
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 210 deletions.
52 changes: 26 additions & 26 deletions Tests/Functional/Api/OaiPmhTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ public function correctlyRespondsOnBadVerb()
]);
$xml = new SimpleXMLElement((string) $response->getBody());

$this->assertEquals('badVerb', (string) $xml->error['code']);
self::assertEquals('badVerb', (string) $xml->error['code']);

// The base URL may be different from the one used that we actually used,
// but it shouldn't contain the verb argument
$this->assertStringNotContainsString('nastyVerb', (string) $xml->request);
self::assertStringNotContainsString('nastyVerb', (string) $xml->request);

// For bad verbs, the <request> element must not contain any attributes
// - http://www.openarchives.org/OAI/openarchivesprotocol.html#XMLResponse
// - http://www.openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions
$this->assertEmpty($xml->request->attributes());
self::assertEmpty($xml->request->attributes());
}

/**
Expand All @@ -108,10 +108,10 @@ public function canIdentify()
$oai = Endpoint::build($this->oaiUrl);
$identity = $oai->identify();

$this->assertEquals('Identify', (string) $identity->request['verb']);
$this->assertEquals('Default Library - OAI Repository', (string) $identity->Identify->repositoryName);
$this->assertUtcDateString((string) $identity->Identify->earliestDatestamp);
$this->assertEquals('default-library@example.com', (string) $identity->Identify->adminEmail);
self::assertEquals('Identify', (string) $identity->request['verb']);
self::assertEquals('Default Library - OAI Repository', (string) $identity->Identify->repositoryName);
self::assertUtcDateString((string) $identity->Identify->earliestDatestamp);
self::assertEquals('default-library@example.com', (string) $identity->Identify->adminEmail);
}

/**
Expand All @@ -122,7 +122,7 @@ public function identifyGivesFallbackDatestampWhenNoDocuments()
$oai = Endpoint::build($this->oaiUrlNoStoragePid);
$identity = $oai->identify();

$this->assertUtcDateString((string) $identity->Identify->earliestDatestamp);
self::assertUtcDateString((string) $identity->Identify->earliestDatestamp);
}

/**
Expand All @@ -138,7 +138,7 @@ public function canListMetadataFormats()
$formatMap[(string) $format->metadataPrefix] = $format;
}

$this->assertEquals('http://www.loc.gov/METS/', (string) $formatMap['mets']->metadataNamespace);
self::assertEquals('http://www.loc.gov/METS/', (string) $formatMap['mets']->metadataNamespace);
}

/**
Expand All @@ -151,8 +151,8 @@ public function canListRecords()

$record = $result->current();
$metsRoot = $record->metadata->children('http://www.loc.gov/METS/')[0];
$this->assertNotNull($metsRoot);
$this->assertEquals('mets', $metsRoot->getName());
self::assertNotNull($metsRoot);
self::assertEquals('mets', $metsRoot->getName());
}

/**
Expand Down Expand Up @@ -192,13 +192,13 @@ public function canUseResumptionToken()
$xml = new SimpleXMLElement((string) $response->getBody());

$resumptionToken = $xml->$verb->resumptionToken;
$this->assertEquals('0', (string) $resumptionToken['cursor']);
$this->assertInFuture((string) $resumptionToken['expirationDate']);
$this->assertNotEmpty((string) $resumptionToken);
self::assertEquals('0', (string) $resumptionToken['cursor']);
self::assertInFuture((string) $resumptionToken['expirationDate']);
self::assertNotEmpty((string) $resumptionToken);

// Store list size to check that it remains constant (and check its sanity)
$completeListSize = (int) $resumptionToken['completeListSize'];
$this->assertGreaterThan(2, $completeListSize); // we have more than two documents in document set
self::assertGreaterThan(2, $completeListSize); // we have more than two documents in document set

// Check that we can resume and get a proper cursor value
$cursor = 1;
Expand All @@ -215,13 +215,13 @@ public function canUseResumptionToken()
$resumptionToken = $xml->$verb->resumptionToken;
$tokenStr = (string) $resumptionToken;

$this->assertEquals($cursor, (string) $resumptionToken['cursor']); // settings.limit = 1
$this->assertEquals($completeListSize, (string) $resumptionToken['completeListSize']);
self::assertEquals($cursor, (string) $resumptionToken['cursor']); // settings.limit = 1
self::assertEquals($completeListSize, (string) $resumptionToken['completeListSize']);

// The last resumptionToken is empty and doesn't have expirationDate
$isLastBatch = $cursor + 1 >= $completeListSize;
$this->assertEquals($isLastBatch, empty((string) $resumptionToken['expirationDate']));
$this->assertEquals($isLastBatch, empty($tokenStr));
self::assertEquals($isLastBatch, empty((string) $resumptionToken['expirationDate']));
self::assertEquals($isLastBatch, empty($tokenStr));

$cursor++;
} while ($tokenStr);
Expand All @@ -246,8 +246,8 @@ public function noResumptionTokenForCompleteList()
]);
$xml = new SimpleXMLElement((string) $response->getBody());

$this->assertEquals(1, count($xml->$verb->children()));
$this->assertEmpty($xml->$verb->resumptionToken);
self::assertEquals(1, count($xml->$verb->children()));
self::assertEmpty($xml->$verb->resumptionToken);
}
}

Expand All @@ -260,12 +260,12 @@ public function canListAndResumeIdentifiers()
$result = $oai->listIdentifiers('mets');

$record = $result->current();
$this->assertEquals('oai:de:slub-dresden:db:id-476251419', $record->identifier);
$this->assertEquals(['collection-with-single-document', 'music'], (array) $record->setSpec);
self::assertEquals('oai:de:slub-dresden:db:id-476251419', $record->identifier);
self::assertEquals(['collection-with-single-document', 'music'], (array) $record->setSpec);

// This should use a resumption token because settings.limit is 1
$record = $result->next();
$this->assertEquals('oai:de:slub-dresden:db:id-476248086', $record->identifier);
self::assertEquals('oai:de:slub-dresden:db:id-476248086', $record->identifier);
}

protected function parseUtc(string $dateTime)
Expand All @@ -275,11 +275,11 @@ protected function parseUtc(string $dateTime)

protected function assertUtcDateString(string $dateTime)
{
$this->assertInstanceOf(DateTime::class, $this->parseUtc($dateTime));
self::assertInstanceOf(DateTime::class, $this->parseUtc($dateTime));
}

protected function assertInFuture(string $dateTime)
{
$this->assertGreaterThan(new DateTime(), $this->parseUtc($dateTime));
self::assertGreaterThan(new DateTime(), $this->parseUtc($dateTime));
}
}
2 changes: 1 addition & 1 deletion Tests/Functional/Api/PageViewProxyDisabledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function cannotAccessPageWhenProxyIsDisabled(): void
'uHash' => $uHash,
]);

$this->assertEquals(404, $response->getStatusCode());
self::assertEquals(404, $response->getStatusCode());
}
}
22 changes: 11 additions & 11 deletions Tests/Functional/Api/PageViewProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function cannotAccessFileUrl(): void
'url' => 'file:///etc/passwd',
]);

$this->assertEquals(400, $response->getStatusCode());
self::assertEquals(400, $response->getStatusCode());
}

/**
Expand All @@ -47,7 +47,7 @@ public function cannotAccessUrlWithoutUrlHash(): void
'url' => 'http://web:8001/Tests/Fixtures/PageViewProxy/test.txt',
]);

$this->assertEquals(401, $response->getStatusCode());
self::assertEquals(401, $response->getStatusCode());
}

/**
Expand All @@ -60,7 +60,7 @@ public function cannotAccessUrlWithInvalidUrlHash(): void
'uHash' => 'nottherealhash',
]);

$this->assertEquals(401, $response->getStatusCode());
self::assertEquals(401, $response->getStatusCode());
}

/**
Expand All @@ -76,8 +76,8 @@ public function canAccessPageWithUrlHash(): void
'uHash' => $uHash,
]);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('This is some plain text test file.' . "\n", (string) $response->getBody());
self::assertEquals(200, $response->getStatusCode());
self::assertEquals('This is some plain text test file.' . "\n", (string) $response->getBody());
}

/**
Expand All @@ -93,7 +93,7 @@ public function cannotSendPostRequest(): void
'uHash' => $uHash,
], 'POST');

$this->assertEquals(405, $response->getStatusCode());
self::assertEquals(405, $response->getStatusCode());
}

/**
Expand All @@ -109,8 +109,8 @@ public function sendsUserAgentToTarget(): void
'uHash' => $uHash,
]);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Kitodo.Presentation Proxy', (string) $response->getBody());
self::assertEquals(200, $response->getStatusCode());
self::assertEquals('Kitodo.Presentation Proxy', (string) $response->getBody());
}

/**
Expand All @@ -120,9 +120,9 @@ public function canQueryOptions(): void
{
$response = $this->queryProxy([], 'OPTIONS');

$this->assertGreaterThanOrEqual(200, $response->getStatusCode());
$this->assertLessThan(300, $response->getStatusCode());
self::assertGreaterThanOrEqual(200, $response->getStatusCode());
self::assertLessThan(300, $response->getStatusCode());

$this->assertNotEmpty($response->getHeader('Access-Control-Allow-Methods'));
self::assertNotEmpty($response->getHeader('Access-Control-Allow-Methods'));
}
}
32 changes: 16 additions & 16 deletions Tests/Functional/Common/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,41 @@ public function canGetIndexNameFromUid()
// Repeat to make sure caching isn't broken
for ($n = 0; $n < 2; $n++) {
// Good UID, no PID
$this->assertEquals(
self::assertEquals(
'default',
Helper::getIndexNameFromUid(10001, 'tx_dlf_libraries')
);
$this->assertEquals(
self::assertEquals(
'title',
Helper::getIndexNameFromUid(5001, 'tx_dlf_metadata')
);
$this->assertEquals(
self::assertEquals(
'collection',
Helper::getIndexNameFromUid(5002, 'tx_dlf_metadata')
);

// Good UID, good PID
$this->assertEquals(
self::assertEquals(
'default',
Helper::getIndexNameFromUid(10001, 'tx_dlf_libraries', 20000)
);
$this->assertEquals(
self::assertEquals(
'title',
Helper::getIndexNameFromUid(5001, 'tx_dlf_metadata', 20000)
);
$this->assertEquals(
self::assertEquals(
'collection',
Helper::getIndexNameFromUid(5002, 'tx_dlf_metadata', 20000)
);

// Good UID, bad PID
$this->assertEquals(
self::assertEquals(
'',
Helper::getIndexNameFromUid(10001, 'tx_dlf_libraries', 123456)
);

// Bad UID, no PID
$this->assertEquals(
self::assertEquals(
'',
Helper::getIndexNameFromUid(123456, 'tx_dlf_libraries')
);
Expand All @@ -73,10 +73,10 @@ public function canTranslateLanguageNameToEnglish()
// NOTE: This only tests in BE mode

$this->initLanguageService('default');
$this->assertEquals('German', Helper::getLanguageName('de')); // ISO 639-1
$this->assertEquals('German', Helper::getLanguageName('ger')); // ISO 639-2
$this->assertEquals('abcde', Helper::getLanguageName('abcde')); // doesn't match ISO code regex
$this->assertEquals('abc', Helper::getLanguageName('abc')); // matches ISO code regex, but not an ISO code
self::assertEquals('German', Helper::getLanguageName('de')); // ISO 639-1
self::assertEquals('German', Helper::getLanguageName('ger')); // ISO 639-2
self::assertEquals('abcde', Helper::getLanguageName('abcde')); // doesn't match ISO code regex
self::assertEquals('abc', Helper::getLanguageName('abc')); // matches ISO code regex, but not an ISO code
}

/**
Expand All @@ -88,9 +88,9 @@ public function canTranslateLanguageNameToGerman()
// NOTE: This only tests in BE mode

$this->initLanguageService('de');
$this->assertEquals('Deutsch', Helper::getLanguageName('de')); // ISO 639-1
$this->assertEquals('Deutsch', Helper::getLanguageName('ger')); // ISO 639-2
$this->assertEquals('abcde', Helper::getLanguageName('abcde')); // doesn't match ISO code regex
$this->assertEquals('abc', Helper::getLanguageName('abc')); // matches ISO code regex, but not an ISO code
self::assertEquals('Deutsch', Helper::getLanguageName('de')); // ISO 639-1
self::assertEquals('Deutsch', Helper::getLanguageName('ger')); // ISO 639-2
self::assertEquals('abcde', Helper::getLanguageName('abcde')); // doesn't match ISO code regex
self::assertEquals('abc', Helper::getLanguageName('abc')); // matches ISO code regex, but not an ISO code
}
}
4 changes: 2 additions & 2 deletions Tests/Functional/Common/IiifUrlReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function getContentCheck()

$correctUrl = 'http://web:8001/Tests/Fixtures/Common/correct.txt';
$expected = "Correct result\n";
$this->assertSame($expected, $iiifUrlReader->getContent($correctUrl));
self::assertSame($expected, $iiifUrlReader->getContent($correctUrl));

$incorrectUrl = 'http://web:8001/incorrectPath';
$this->assertSame('', $iiifUrlReader->getContent($incorrectUrl));
self::assertSame('', $iiifUrlReader->getContent($incorrectUrl));
}
}
Loading

0 comments on commit 1ed0636

Please sign in to comment.