Skip to content
Snippets Groups Projects
Commit 9047384a authored by Jeff Krug's avatar Jeff Krug Committed by Thijs Kinkhorst
Browse files

Updated documentation for attribute alter to include an example of setting an attribute

to a default value and then executing a test to change it.

Added some very basic tests for the AttributeAlter module.
parent 44b3141c
No related branches found
No related tags found
No related merge requests found
......@@ -90,6 +90,17 @@ Get the domain of the email and put it in a separate attribute:
'%replace',
),
Defaulting an attribute to one value (Add it with the default before altering) unless another attribute meets a condition:
10 => array ('class' => 'core:AttributeAdd',
'myAttribute' => 'default-value'),
11 => array ('class' => 'core:AttributeAlter',
'subject' => 'entitlement',
'pattern' => '/faculty/',
'target' => 'myAttribute',
'%replace',
),
Remove internal, private values from eduPersonEntitlement:
10 => array(
......@@ -117,4 +128,4 @@ Set a value to be NULL (which will be sent as a NULL value):
'pattern' => '/NULL/',
'replacement' => null,
'%replace',
),
\ No newline at end of file
),
<?php
/**
* Test for the core:AttributeAlter filter.
*/
class Test_Core_Auth_Process_AttributeAlter extends PHPUnit_Framework_TestCase
{
/**
* Helper function to run the filter with a given configuration.
*
* @param array $config The filter configuration.
* @param array $request The request state.
* @return array The state array after processing.
*/
private static function processFilter(array $config, array $request)
{
$filter = new sspmod_core_Auth_Process_AttributeAlter($config, NULL);
$filter->process($request);
return $request;
}
/**
* Test the most basic functionality.
*/
public function testBasic()
{
$config = array(
'subject' => 'test',
'pattern' => '/wrong/',
'replacement' => 'right',
);
$request = array(
'Attributes' => array(
'test' => array('wrong'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertArrayHasKey('test', $attributes);
$this->assertEquals($attributes['test'], array('right'));
}
/**
* Test replacing attribute value.
*/
public function testReplaceMatch()
{
$config = array(
'subject' => 'source',
'pattern' => '/wrong/',
'replacement' => 'right',
'target' => 'test',
'%replace',
);
$request = array(
'Attributes' => array(
'source' => array('wrong'),
'test' => array('wrong'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertEquals($attributes['test'], array('right'));
}
/**
* Test replacing attribute values.
*/
public function testReplaceNoMatch()
{
$config = array(
'subject' => 'test',
'pattern' => '/doink/',
'replacement' => 'wrong',
'target' => 'test',
'%replace',
);
$request = array(
'Attributes' => array(
'source' => array('wrong'),
'test' => array('right'),
),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertEquals($attributes['test'], array('right'));
}
}
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