Skip to content
Snippets Groups Projects
Commit 2d06c575 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Add more tests.

parent 2d6cf6ed
No related branches found
No related tags found
No related merge requests found
......@@ -33,20 +33,92 @@ class Test_Core_Auth_Process_AttributeAlter extends PHPUnit_Framework_TestCase
$request = array(
'Attributes' => array(
'test' => array('wrong'),
'test' => array('somethingiswrong'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertArrayHasKey('test', $attributes);
$this->assertEquals($attributes['test'], array('right'));
$this->assertEquals($attributes['test'], array('somethingisright'));
}
/**
* Test the most basic functionality.
*/
public function testWithTarget()
{
$config = array(
'subject' => 'test',
'target' => 'test2',
'pattern' => '/wrong/',
'replacement' => 'right',
);
$request = array(
'Attributes' => array(
'something' => array('somethingelse'),
'test' => array('wrong'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertArrayHasKey('test2', $attributes);
$this->assertEquals($attributes['test'], array('wrong'));
$this->assertEquals($attributes['test2'], array('right'));
}
/**
* Module is a no op if subject attribute is not present.
*/
public function testNomatch()
{
$config = array(
'subject' => 'test',
'pattern' => '/wrong/',
'replacement' => 'right',
);
$request = array(
'Attributes' => array(
'something' => array('somevalue'),
'somethingelse' => array('someothervalue'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertEquals($attributes,
array('something' => array('somevalue'),
'somethingelse' => array('someothervalue')));
}
/**
* Test replacing attribute value.
*/
public function testReplaceMatch()
{
$config = array(
'subject' => 'source',
'pattern' => '/wrong/',
'replacement' => 'right',
'%replace',
);
$request = array(
'Attributes' => array(
'source' => array('wrongthing'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertEquals($attributes['source'], array('right'));
}
/**
* Test replacing attribute value.
*/
public function testReplaceMatchWithTarget()
{
$config = array(
'subject' => 'source',
......@@ -89,5 +161,197 @@ class Test_Core_Auth_Process_AttributeAlter extends PHPUnit_Framework_TestCase
$this->assertEquals($attributes['test'], array('right'));
}
/**
* Test removing attribute values.
* Note that removing a value does not renumber the attributes array.
* Also ensure unrelated attributes are not touched.
*/
public function testRemoveMatch()
{
$config = array(
'subject' => 'eduPersonAffiliation',
'pattern' => '/^emper/',
'%remove',
);
$request = array(
'Attributes' => array(
'displayName' => array('emperor kuzco'),
'eduPersonAffiliation' => array('member', 'emperor', 'staff'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertEquals($attributes['displayName'], array('emperor kuzco'));
$this->assertEquals($attributes['eduPersonAffiliation'], array(0 => 'member', 2 => 'staff'));
}
/**
* Test removing attribute values, resulting in an empty attribute.
*/
public function testRemoveMatchAll()
{
$config = array(
'subject' => 'eduPersonAffiliation',
'pattern' => '/^emper/',
'%remove',
);
$request = array(
'Attributes' => array(
'displayName' => array('emperor kuzco'),
'eduPersonAffiliation' => array('emperess', 'emperor'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertArrayNotHasKey('eduPersonAffiliation', $attributes);
}
/**
* Test for exception with illegal config.
*
* @expectedException Exception
*/
public function testWrongConfig()
{
$config = array(
'subject' => 'eduPersonAffiliation',
'pattern' => '/^emper/',
'%dwiw',
);
$request = array(
'Attributes' => array(
'eduPersonAffiliation' => array('emperess', 'emperor'),
),
);
$result = self::processFilter($config, $request);
}
/**
* Test for exception with illegal config.
*
* @expectedException Exception
*/
public function testIncompleteConfig()
{
$config = array(
'subject' => 'eduPersonAffiliation',
);
$request = array(
'Attributes' => array(
'eduPersonAffiliation' => array('emperess', 'emperor'),
),
);
$result = self::processFilter($config, $request);
}
/**
* Test for exception with illegal config.
*
* @expectedException Exception
*/
public function testIncompleteConfig2()
{
$config = array(
'subject' => 'test',
'pattern' => '/wrong/',
);
$request = array(
'Attributes' => array(
'test' => array('somethingiswrong'),
),
);
$request = array(
'Attributes' => array(
'eduPersonAffiliation' => array('emperess', 'emperor'),
),
);
$result = self::processFilter($config, $request);
}
/**
* Test for exception with illegal config.
*
* @expectedException Exception
*/
public function testIncompleteConfig3()
{
$config = array(
'subject' => 'test',
'pattern' => '/wrong/',
'%replace',
'%remove',
);
$request = array(
'Attributes' => array(
'test' => array('somethingiswrong'),
),
);
$request = array(
'Attributes' => array(
'eduPersonAffiliation' => array('emperess', 'emperor'),
),
);
$result = self::processFilter($config, $request);
}
/**
* Test for exception with illegal config.
*
* @expectedException Exception
*/
public function testIncompleteConfig4()
{
$config = array(
'subject' => 'test',
'pattern' => '/wrong/',
'target' => 'test2',
'%remove',
);
$request = array(
'Attributes' => array(
'test' => array('somethingiswrong'),
),
);
$request = array(
'Attributes' => array(
'eduPersonAffiliation' => array('emperess', 'emperor'),
),
);
$result = self::processFilter($config, $request);
}
/**
* Test for exception with illegal config.
*
* @expectedException Exception
*/
public function testIncompleteConfig5()
{
$config = array(
'subject' => 'test',
'pattern' => '/wrong/',
'replacement' => null,
);
$request = array(
'Attributes' => array(
'test' => array('somethingiswrong'),
),
);
$request = array(
'Attributes' => array(
'eduPersonAffiliation' => array('emperess', 'emperor'),
),
);
$result = self::processFilter($config, $request);
}
}
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