Skip to content

Commit

Permalink
Renaming methods for codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Jan 10, 2025
1 parent e47f340 commit a371c26
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 111 deletions.
50 changes: 25 additions & 25 deletions Tests/Unit/Validation/AbstractDomDocumentValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function setUp(): void
*/
public function testDocument()
{
$this->assertNoError();
$this->hasNoError();
}

/**
Expand Down Expand Up @@ -206,20 +206,20 @@ protected function getDomDocument(): DOMDocument
*
* @return void
*/
protected function assertNoError(): void
protected function hasNoError(): void
{
$result = $this->validate();
$this->assertFalse($result->hasErrors());
}

/**
* Assert validation error has any.
* Assert error of has any validation.
*
* @param string $expression The expression in error message
* @param string $context The context in error message
* @return void
*/
protected function assertErrorHasAny(string $expression, string $context=''): void
protected function hasErrorAny(string $expression, string $context=''): void
{
$message = 'There must be at least one element that matches the XPath expression "' . $expression . '"';
if ($context != '') {
Expand All @@ -229,13 +229,13 @@ protected function assertErrorHasAny(string $expression, string $context=''): vo
}

/**
* Assert validation error has one.
* Assert error of has one validation.
*
* @param string $expression The expression in error message
* @param string $context The context in error message
* @return void
*/
protected function assertErrorHasOne(string $expression, string $context=''): void
protected function hasErrorOne(string $expression, string $context=''): void
{
$message = 'There must be an element that matches the XPath expression "' . $expression . '"';
if ($context != '') {
Expand All @@ -245,13 +245,13 @@ protected function assertErrorHasOne(string $expression, string $context=''): vo
}

/**
* Assert validation error has none or one.
* Assert error of has none or one validation.
*
* @param string $expression The expression in error message
* @param string $context The context in error message
* @return void
*/
protected function assertErrorHasNoneOrOne(string $expression, string $context=''): void
protected function hasErrorNoneOrOne(string $expression, string $context=''): void
{
$message = 'There must be no more than one element that matches the XPath expression "' . $expression . '"';
if ($context != '') {
Expand All @@ -261,102 +261,102 @@ protected function assertErrorHasNoneOrOne(string $expression, string $context='
}

/**
* Assert validation error has attribute.
* Assert error of has attribute validation.
*
* @param string $expression The expression in error message
* @param string $name The attribute name
* @return void
*/
protected function assertErrorHasAttribute(string $expression, string $name): void
protected function hasErrorAttribute(string $expression, string $name): void
{
$this->validateAndAssertEquals('Mandatory "' . $name . '" attribute of "' . $expression . '" is missing.');
}

/**
* Assert validation error has attribute with value.
* Assert error of has attribute with value validation.
*
* @param string $expression The expression in error message
* @param string $name The attribute name
* @param string $value The attribute value
* @return void
*/
protected function assertErrorHasAttributeWithValue(string $expression, string $name, string $value): void
protected function hasErrorAttributeWithValue(string $expression, string $name, string $value): void
{
$this->validateAndAssertEquals('Value "' . $value . '" in the "' . $name . '" attribute of "' . $expression . '" is not permissible.');
}

/**
* Assert validation error has attribute with URL value.
* Assert error of has attribute with URL value validation.
*
* @param string $expression The expression in error message
* @param string $name The attribute name
* @param string $value The attribute value
* @return void
*/
protected function assertErrorHasAttributeWithUrl(string $expression, string $name, string $value): void
protected function hasErrorAttributeWithUrl(string $expression, string $name, string $value): void
{
$this->validateAndAssertEquals('URL "' . $value . '" in the "' . $name . '" attribute of "' . $expression . '" is not valid.');
}

/**
* Assert validation error has content with Email.
* Assert error of has attribute reference to one validation.
*
* @param string $expression The expression in error message
* @param string $name The attribute name
* @param string $value The attribute value
* @param string $targetExpression The target context expression
* @return void
*/
protected function assertErrorHasAttributeRefToOne(string $expression, string $name, string $value, string $targetExpression): void
protected function hasErrorAttributeRefToOne(string $expression, string $name, string $value, string $targetExpression): void
{
$this->validateAndAssertEquals('Value "' . $value . '" in the "' . $name . '" attribute of "' . $expression . '" must reference one element under XPath expression "' . $targetExpression);
}

/**
* Assert validation error has content with Email.
* Assert error of has content with Email validation.
*
* @param string $expression The expression in error message
* @param string $value The content value
* @return void
*/
protected function assertErrorHasContentWithEmail(string $expression, string $value): void
protected function hasErrorContentWithEmail(string $expression, string $value): void
{
$this->validateAndAssertEquals('Email "' . $value . '" in the content of "' . $expression . '" is not valid.');
}

/**
* Assert validation error has content with URL.
* Assert error of has content with URL.
*
* @param string $expression The expression in error message
* @param string $value The content value
* @return void
*/
protected function assertErrorHasContentWithUrl(string $expression, string $value): void
protected function hasErrorContentWithUrl(string $expression, string $value): void
{
$this->validateAndAssertEquals('URL "' . $value . '" in the content of "' . $expression . '" is not valid.');
}

/**
* Assert validation error has unique identifier.
* Assert error of has unique identifier.
*
* @param string $expression The expression in error message
* @param string $value The attribute value
* @return void
*/
protected function assertErrorHasUniqueId(string $expression, string $value): void
protected function hasErrorUniqueId(string $expression, string $value): void
{
$this->assertErrorHasUniqueAttribute($expression, 'ID', $value);
$this->hasErrorUniqueAttribute($expression, 'ID', $value);
}

/**
* Assert validation error has unique attribute with value.
* Assert error of has unique attribute with value.
*
* @param string $expression The expression in error message
* @param string $name The attribute name
* @param string $value The attribute value
* @return void
*/
protected function assertErrorHasUniqueAttribute(string $expression, string $name, string $value): void
protected function hasErrorUniqueAttribute(string $expression, string $name, string $value): void
{
$this->validateAndAssertEquals('"' . $name . '" attribute with value "' . $value . '" of "' . $expression . '" already exists.');
}
Expand Down
36 changes: 18 additions & 18 deletions Tests/Unit/Validation/DvMetadataValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DvMetadataValidatorTest extends AbstractDomDocumentValidatorTest
public function testDvRights(): void
{
$this->removeNodes(VH::XPATH_DVRIGHTS);
$this->assertErrorHasOne(VH::XPATH_DVRIGHTS);
$this->hasErrorOne(VH::XPATH_DVRIGHTS);
}

/**
Expand All @@ -51,30 +51,30 @@ public function testDvRights(): void
public function testDvRightsSubelements(): void
{
$this->removeNodes(VH::XPATH_DVRIGHTS . '/dv:owner');
$this->assertErrorHasOne(VH::XPATH_DVRIGHTS . '/dv:owner');
$this->hasErrorOne(VH::XPATH_DVRIGHTS . '/dv:owner');
$this->resetDocument();

$this->assertNodeContent(VH::XPATH_DVRIGHTS . '/dv:ownerLogo', VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:ownerLogo');
$this->assertNodeContent(VH::XPATH_DVRIGHTS . '/dv:ownerSiteURL', VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:ownerSiteURL');
$this->assertNodeContent(VH::XPATH_DVRIGHTS . '/dv:ownerContact', VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:ownerContact');
$this->setContentValue(VH::XPATH_DVRIGHTS . '/dv:ownerContact', 'mailto:Test');
$this->assertErrorHasContentWithEmail(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:ownerContact', 'mailto:Test');
$this->hasErrorContentWithEmail(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:ownerContact', 'mailto:Test');
$this->resetDocument();

$this->addChildNodeWithNamespace(VH::XPATH_DVRIGHTS, VH::NAMESPACE_DV, 'dv:aggregator');
$this->assertErrorHasNoneOrOne(VH::XPATH_DVRIGHTS . '/dv:aggregator');
$this->hasErrorNoneOrOne(VH::XPATH_DVRIGHTS . '/dv:aggregator');
$this->resetDocument();
$this->assertOptionalNodeContent(VH::XPATH_DVRIGHTS, 'dv:aggregatorLogo', VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:aggregatorLogo');
$this->assertOptionalNodeContent(VH::XPATH_DVRIGHTS, 'dv:aggregatorSiteURL', VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:aggregatorSiteURL');

$this->addChildNodeWithNamespace(VH::XPATH_DVRIGHTS, VH::NAMESPACE_DV, 'dv:sponsor');
$this->assertErrorHasNoneOrOne(VH::XPATH_DVRIGHTS . '/dv:sponsor');
$this->hasErrorNoneOrOne(VH::XPATH_DVRIGHTS . '/dv:sponsor');
$this->resetDocument();
$this->assertOptionalNodeContent(VH::XPATH_DVRIGHTS, 'dv:sponsorLogo', VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:sponsorLogo');
$this->assertOptionalNodeContent(VH::XPATH_DVRIGHTS, 'dv:sponsorSiteURL', VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:sponsorSiteURL');

$this->setContentValue(VH::XPATH_DVRIGHTS . '/dv:license', 'Test');
$this->assertErrorHasContentWithUrl(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:license', 'Test');
$this->hasErrorContentWithUrl(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_RIGHTS_METADATA) . '/mets:mdWrap/mets:xmlData/dv:rights/dv:license', 'Test');
}

/**
Expand All @@ -85,7 +85,7 @@ public function testDvRightsSubelements(): void
public function testDvLinks(): void
{
$this->removeNodes(VH::XPATH_DVLINKS);
$this->assertErrorHasOne(VH::XPATH_DVLINKS);
$this->hasErrorOne(VH::XPATH_DVLINKS);
}

/**
Expand All @@ -97,53 +97,53 @@ public function testDvLinks(): void
public function testDvLinksSubelements(): void
{
$this->removeNodes(VH::XPATH_DVLINKS . '/dv:reference');
$this->assertErrorHasAny(VH::XPATH_DVLINKS . '/dv:reference');
$this->hasErrorAny(VH::XPATH_DVLINKS . '/dv:reference');
$this->resetDocument();

// if there are multiple `dv:references`, the `linktext` attribute must be present.
$this->addChildNodeWithNamespace(VH::XPATH_DVLINKS, VH::NAMESPACE_DV, 'dv:reference');
$this->assertErrorHasAttribute(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_DIGIPROV_METADATA) . '/mets:mdWrap/mets:xmlData/dv:links/dv:reference[1]', 'linktext');
$this->hasErrorAttribute(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_DIGIPROV_METADATA) . '/mets:mdWrap/mets:xmlData/dv:links/dv:reference[1]', 'linktext');
$this->resetDocument();

$this->addChildNodeWithNamespace(VH::XPATH_DVLINKS, VH::NAMESPACE_DV, 'dv:presentation');
$this->assertErrorHasNoneOrOne(VH::XPATH_DVLINKS . '/dv:presentation');
$this->hasErrorNoneOrOne(VH::XPATH_DVLINKS . '/dv:presentation');
$this->resetDocument();

$this->addChildNodeWithNamespace(VH::XPATH_DVLINKS, VH::NAMESPACE_DV, 'dv:sru');
$this->assertErrorHasNoneOrOne(VH::XPATH_DVLINKS . '/dv:sru');
$this->hasErrorNoneOrOne(VH::XPATH_DVLINKS . '/dv:sru');
$this->resetDocument();

$this->setContentValue(VH::XPATH_DVLINKS . '/dv:sru', 'Test');
$this->assertErrorHasContentWithUrl(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_DIGIPROV_METADATA) . '/mets:mdWrap/mets:xmlData/dv:links/dv:sru', 'Test');
$this->hasErrorContentWithUrl(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_DIGIPROV_METADATA) . '/mets:mdWrap/mets:xmlData/dv:links/dv:sru', 'Test');
$this->resetDocument();

$this->addChildNodeWithNamespace(VH::XPATH_DVLINKS, VH::NAMESPACE_DV, 'dv:iiif');
$this->assertErrorHasNoneOrOne(VH::XPATH_DVLINKS . '/dv:iiif');
$this->hasErrorNoneOrOne(VH::XPATH_DVLINKS . '/dv:iiif');
$this->resetDocument();

$this->setContentValue(VH::XPATH_DVLINKS . '/dv:iiif', 'Test');
$this->assertErrorHasContentWithUrl(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_DIGIPROV_METADATA) . '/mets:mdWrap/mets:xmlData/dv:links/dv:iiif', 'Test');
$this->hasErrorContentWithUrl(VH::trimDoubleSlash(VH::XPATH_ADMINISTRATIVE_DIGIPROV_METADATA) . '/mets:mdWrap/mets:xmlData/dv:links/dv:iiif', 'Test');
}

protected function assertNodeContent(string $expression, string $expectedExpression): void
{
$this->removeNodes($expression);
$this->assertErrorHasOne($expression);
$this->hasErrorOne($expression);
$this->resetDocument();

$this->setContentValue($expression, 'Test');
$this->assertErrorHasContentWithUrl($expectedExpression, 'Test');
$this->hasErrorContentWithUrl($expectedExpression, 'Test');
$this->resetDocument();
}

protected function assertOptionalNodeContent(string $expression, string $name, string $expectedExpression): void
{
$this->addChildNodeWithNamespace($expression, VH::NAMESPACE_DV, $name);
$this->assertErrorHasNoneOrOne($expression . '/' . $name);
$this->hasErrorNoneOrOne($expression . '/' . $name);
$this->resetDocument();

$this->setContentValue($expression . '/' . $name, 'Test');
$this->assertErrorHasContentWithUrl($expectedExpression, 'Test');
$this->hasErrorContentWithUrl($expectedExpression, 'Test');
$this->resetDocument();
}

Expand Down
Loading

0 comments on commit a371c26

Please sign in to comment.