'', '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()); } /** * @expectedException PHPUnit\Framework\Error\Error */ /* public function testPHPErrorOnInvalidConstructor() { $accessList = new AccessList('invalid'); // Causes: "Illegal string offset 'channel_allow_cid'" } */ /** * 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()); } /** * @expectedException PHPUnit\Framework\Error\Error */ /* public function testPHPErrorOnInvalidSet() { $accessList = new AccessList([]); $accessList->set('invalid'); // Causes: "Illegal string offset 'allow_cid'" } */ /** * 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()); } /** * @dataProvider isprivateProvider */ public function testIsPrivate($channel) { $accessListPrivate = new AccessList($channel); $this->assertTrue($accessListPrivate->is_private()); } public function isprivateProvider() { return [ 'all set' => [[ 'channel_allow_cid' => '', 'channel_allow_gid' => '', 'channel_deny_cid' => '', 'channel_deny_gid' => '' ]], 'only one 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' => '' ]] ]; } }