'', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ]; public function testConstructor() { $channel = [ 'channel_allow_cid' => '', 'channel_allow_gid' => '', 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]; $accessList = new AccessList($channel); $this->assertEquals($this->expectedResult, $accessList->get()); $this->assertFalse($accessList->get_explicit()); } /** * AccessList constructor should throw an exception if input is not * an array. */ public function testConstructorThrowsOnInvalidInputType() { $this->expectException("TypeError"); $accessList = new AccessList('invalid'); } /** * AccessList constructor should throw an exception on * invalid input. */ public function testConstructorThrowsOnMissingKeysInArray() { $this->expectException("Exception"); $this->expectExceptionMessage("Invalid AccessList object"); $accessList = new AccessList(['something_else' => 'should_this_fail?']); } /** * Test that the defaults are as expected when constructed with * an empty array. */ public function testDefaults() { $accessList = new AccessList([]); $this->assertFalse($accessList->get_explicit()); $this->assertFalse($accessList->is_private()); $expected = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ]; $this->assertEquals($expected, $accessList->get()); } public function testSet() { $arr = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ]; $accessList = new AccessList([]); // default explicit true $accessList->set($arr); $this->assertEquals($this->expectedResult, $accessList->get()); $this->assertTrue($accessList->get_explicit()); // set explicit false $accessList->set($arr, false); $this->assertEquals($this->expectedResult, $accessList->get()); $this->assertFalse($accessList->get_explicit()); } /** * The set method should throw an exception if input is not an array. */ public function testSetThrowsOnInvalidInputType() { $this->expectException('TypeError'); $accessList = new AccessList([]); $accessList->set('invalid'); } public function testSetThrowsOnMissingKeysInArray() { $this->expectException('Exception'); $this->expectExceptionMessage('Invalid AccessList object'); $accessList = new AccessList([]); $accessList->set(['something_else' => 'should_this_fail?']); } /** * The set_from_array() function calls some other functions, too which are * not yet unit tested. * * @uses ::perms2str * @uses ::sanitise_acl * @uses ::notags */ public function testSetFromArray() { // array $arraySetFromArray = [ 'contact_allow' => ['acid', 'acid2'], 'group_allow' => ['agid'], 'contact_deny' => [], 'group_deny' => ['dgid', 'dgid2'] ]; $accessList = new AccessList([]); $accessList->set_from_array($arraySetFromArray); $this->assertEquals($this->expectedResult, $accessList->get()); $this->assertTrue($accessList->get_explicit()); // string $stringSetFromArray = [ 'contact_allow' => 'acid,acid2', 'group_allow' => 'agid', 'contact_deny' => '', 'group_deny' => 'dgid, dgid2' ]; $accessList2 = new AccessList([]); $accessList2->set_from_array($stringSetFromArray, false); $this->assertEquals($this->expectedResult, $accessList2->get()); $this->assertFalse($accessList2->get_explicit()); } /** * The AccessList should be private if any of the fields are set, * * @dataProvider isprivateProvider */ public function testIsPrivate($channel) { $accessListPrivate = new AccessList($channel); $this->assertTrue($accessListPrivate->is_private()); } public static function isprivateProvider() { return [ 'all set' => [[ 'channel_allow_cid' => '', 'channel_allow_gid' => '', 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]], 'only allow_cid set' => [[ 'channel_allow_cid' => '', 'channel_allow_gid' => '', 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]], 'only allow_gid set' => [[ 'channel_allow_cid' => '', 'channel_allow_gid' => '', 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]], 'only deny_cid set' => [[ 'channel_allow_cid' => '', 'channel_allow_gid' => '', 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]], 'only deny_gid set' => [[ 'channel_allow_cid' => '', 'channel_allow_gid' => '', 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]], 'acid+null' => [[ 'channel_allow_cid' => '', 'channel_allow_gid' => null, 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]] ]; } }