class CasPropertyBagTest in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/CasPropertyBagTest.php \Drupal\Tests\cas\Unit\CasPropertyBagTest
CasPropertyBag unit tests.
@group cas
@coversDefaultClass \Drupal\cas\CasPropertyBag
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\cas\Unit\CasPropertyBagTest
Expanded class hierarchy of CasPropertyBagTest
File
- tests/
src/ Unit/ CasPropertyBagTest.php, line 16
Namespace
Drupal\Tests\cas\UnitView source
class CasPropertyBagTest extends UnitTestCase {
/**
* Test constructing a bag with a username.
*
* @covers ::__construct
*/
public function testConstruct() {
$name = $this
->randomMachineName(8);
$bag = new CasPropertyBag($name);
$this
->assertEquals($name, $bag
->getUsername());
$this
->assertEquals($name, $bag
->getOriginalUsername());
}
/**
* Test setting a username.
*
* @covers ::setUsername
*/
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());
}
/**
* Test setting a proxy granting ticket.
*
* @covers ::setPgt
*/
public function testSetPgt() {
$bag = new CasPropertyBag($this
->randomMachineName(8));
$pgt = $this
->randomMachineName(24);
$bag
->setPgt($pgt);
$this
->assertEquals($pgt, $bag
->getPgt());
}
/**
* Test setting the attributes array.
*
* @covers ::setAttributes
*/
public function testSetAttributes() {
$bag = new CasPropertyBag($this
->randomMachineName(8));
$attributes = [
'foo' => [
'bar',
],
'baz' => [
'quux, foobar',
],
];
$bag
->setAttributes($attributes);
$this
->assertEquals($attributes, $bag
->getAttributes());
}
/**
* Test getting the username.
*
* @covers ::getUsername
*/
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());
}
/**
* Test getting the proxy granting ticket.
*
* @covers ::getPgt
*/
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());
}
/**
* Test getting the attributes.
*
* @covers ::getAttributes
*/
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());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CasPropertyBagTest:: |
public | function | Test constructing a bag with a username. | |
CasPropertyBagTest:: |
public | function | Test getting the attributes. | |
CasPropertyBagTest:: |
public | function | Test getting the proxy granting ticket. | |
CasPropertyBagTest:: |
public | function | Test getting the username. | |
CasPropertyBagTest:: |
public | function | Test setting the attributes array. | |
CasPropertyBagTest:: |
public | function | Test setting a proxy granting ticket. | |
CasPropertyBagTest:: |
public | function | Test setting a username. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |