CasPropertyBagTest.php in CAS 2.x
File
tests/src/Unit/CasPropertyBagTest.php
View source
<?php
namespace Drupal\Tests\cas\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\cas\CasPropertyBag;
class CasPropertyBagTest extends UnitTestCase {
public function testConstruct() {
$name = $this
->randomMachineName(8);
$bag = new CasPropertyBag($name);
$this
->assertEquals($name, $bag
->getUsername());
$this
->assertEquals($name, $bag
->getOriginalUsername());
}
public function testSetUsername() {
$name = $this
->randomMachineName(8);
$bag = new CasPropertyBag($name);
$new_name = $this
->randomMachineName(8);
$bag
->setUsername($new_name);
$this
->assertEquals($new_name, $bag
->getUsername());
$this
->assertEquals($name, $bag
->getOriginalUsername());
}
public function testSetPgt() {
$bag = new CasPropertyBag($this
->randomMachineName(8));
$pgt = $this
->randomMachineName(24);
$bag
->setPgt($pgt);
$this
->assertEquals($pgt, $bag
->getPgt());
}
public function testSetAttributes() {
$bag = new CasPropertyBag($this
->randomMachineName(8));
$attributes = [
'foo' => [
'bar',
],
'baz' => [
'quux, foobar',
],
];
$bag
->setAttributes($attributes);
$this
->assertEquals($attributes, $bag
->getAttributes());
}
public function testGetUsername() {
$name = $this
->randomMachineName(8);
$bag = new CasPropertyBag($name);
$reflection = new \ReflectionClass($bag);
$property = $reflection
->getProperty('username');
$property
->setAccessible(TRUE);
$new_name = $this
->randomMachineName(8);
$property
->setValue($bag, $new_name);
$this
->assertEquals($new_name, $bag
->getUsername());
$this
->assertEquals($name, $bag
->getOriginalUsername());
}
public function testGetPgt() {
$bag = new CasPropertyBag($this
->randomMachineName(8));
$reflection = new \ReflectionClass($bag);
$property = $reflection
->getProperty('pgt');
$property
->setAccessible(TRUE);
$pgt = $this
->randomMachineName(24);
$property
->setValue($bag, $pgt);
$this
->assertEquals($pgt, $bag
->getPgt());
}
public function testGetAttributes() {
$bag = new CasPropertyBag($this
->randomMachineName(8));
$reflection = new \ReflectionClass($bag);
$property = $reflection
->getProperty('attributes');
$property
->setAccessible(TRUE);
$attributes = [
'foo' => [
'bar',
],
'baz' => [
'quux',
'foobar',
],
];
$property
->setValue($bag, $attributes);
$this
->assertEquals($attributes, $bag
->getAttributes());
}
}