Skip to content
Snippets Groups Projects
Commit 2e229475 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Fix tests for SimpleSAML\Utils\Attributes::getExpectedAttribute().

parent 53bbb493
No related branches found
No related tags found
No related merge requests found
...@@ -10,9 +10,9 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase ...@@ -10,9 +10,9 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase
{ {
/** /**
* Test the getExpectedAttribute() function with invalid input. * Test the getExpectedAttribute() method with invalid attributes array.
*/ */
public function testGetExpectedAttributeInvalidInput() public function testGetExpectedAttributeInvalidAttributesArray()
{ {
// check with empty array as input // check with empty array as input
$attributes = 'string'; $attributes = 'string';
...@@ -22,7 +22,14 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase ...@@ -22,7 +22,14 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase
'The attributes array is not an array, it is: '.print_r($attributes, true).'.' 'The attributes array is not an array, it is: '.print_r($attributes, true).'.'
); );
\SimpleSAML\Utils\Attributes::getExpectedAttribute($attributes, $expected); \SimpleSAML\Utils\Attributes::getExpectedAttribute($attributes, $expected);
}
/**
* Test the getExpectedAttributeMethod() method with invalid expected attribute parameter.
*/
public function testGetExpectedAttributeInvalidAttributeName()
{
// check with invalid attribute name // check with invalid attribute name
$attributes = array(); $attributes = array();
$expected = false; $expected = false;
...@@ -31,7 +38,14 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase ...@@ -31,7 +38,14 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase
'The expected attribute is not a string, it is: '.print_r($expected, true).'.' 'The expected attribute is not a string, it is: '.print_r($expected, true).'.'
); );
\SimpleSAML\Utils\Attributes::getExpectedAttribute($attributes, $expected); \SimpleSAML\Utils\Attributes::getExpectedAttribute($attributes, $expected);
}
/**
* Test the getExpectedAttributeMethod() method with a non-normalized attributes array.
*/
public function testGetExpectedAttributeNonNormalizedArray()
{
// check with non-normalized attributes array // check with non-normalized attributes array
$attributes = array( $attributes = array(
'attribute' => 'value', 'attribute' => 'value',
...@@ -46,9 +60,9 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase ...@@ -46,9 +60,9 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase
/** /**
* Test the getExpectedAttribute() with valid input that raises exceptions. * Test the getExpectedAttribute() method with valid input but missing expected attribute.
*/ */
public function testGetExpectedAttributeErrorConditions() public function testGetExpectedAttributeMissingAttribute()
{ {
// check missing attribute // check missing attribute
$attributes = array( $attributes = array(
...@@ -60,7 +74,32 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase ...@@ -60,7 +74,32 @@ class Utils_AttributesTest extends PHPUnit_Framework_TestCase
"No such attribute '".$expected."' found." "No such attribute '".$expected."' found."
); );
\SimpleSAML\Utils\Attributes::getExpectedAttribute($attributes, $expected); \SimpleSAML\Utils\Attributes::getExpectedAttribute($attributes, $expected);
}
/**
* Test the getExpectedAttribute() method with an empty attribute.
*/
public function testGetExpectedAttributeEmptyAttribute()
{
// check empty attribute
$attributes = array(
'attribute' => array(),
);
$expected = 'attribute';
$this->setExpectedException(
'SimpleSAML_Error_Exception',
"Empty attribute '".$expected."'.'"
);
\SimpleSAML\Utils\Attributes::getExpectedAttribute($attributes, $expected);
}
/**
* Test the getExpectedAttributeMethod() method with multiple values (not being allowed).
*/
public function testGetExpectedAttributeMultipleValues()
{
// check attribute with more than value, that being not allowed // check attribute with more than value, that being not allowed
$attributes = array( $attributes = array(
'attribute' => array( 'attribute' => array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment