php-8.3.3-mac/lib/php/pear/test/XML_Util/tests/IsValidNameTests.php

63 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2024-03-11 14:31:54 +03:00
<?php
class IsValidNameTests extends AbstractUnitTests
{
/**
* @covers XML_Util::isValidName()
*/
public function testIsValidNameForTagNameThatIsValid()
{
$tagName = "alpha-x_y_z.123";
$result = XML_Util::isValidName($tagName);
$this->assertTrue($result);
}
/**
* @covers XML_Util::isValidName()
*/
public function testIsValidNameForTagNameWithInvalidCharacter()
{
$tagName = "invalidTag?";
$result = XML_Util::isValidName($tagName);
$this->assertInstanceOf('PEAR_Error', $result);
$expectedError = "XML names may only contain alphanumeric chars, period, hyphen, colon and underscores";
$this->assertEquals($expectedError, $result->getMessage());
}
/**
* @covers XML_Util::isValidName()
*/
public function testIsValidNameForTagNameWithInvalidStartingCharacter()
{
$tagName = "1234five";
$result = XML_Util::isValidName($tagName);
$this->assertInstanceOf('PEAR_Error', $result);
$expectedError = "XML names may only start with letter or underscore";
$this->assertEquals($expectedError, $result->getMessage());
}
/**
* @covers XML_Util::isValidName()
*/
public function testIsValidNameForInt()
{
$tagName = 1;
$result = XML_Util::isValidName($tagName);
$this->assertInstanceOf('PEAR_Error', $result);
$expectedError = "XML names may only start with letter or underscore";
$this->assertEquals($expectedError, $result->getMessage());
}
/**
* @covers XML_Util::isValidName()
*/
public function testIsValidNameForEmptyString()
{
$tagName = '';
$result = XML_Util::isValidName($tagName);
$this->assertInstanceOf('PEAR_Error', $result);
$expectedError = "XML names may only start with letter or underscore";
$this->assertEquals($expectedError, $result->getMessage());
}
}