1*e7339d5aSAndreas Gohr<?php 2*e7339d5aSAndreas Gohr 3*e7339d5aSAndreas Gohrnamespace dokuwiki\plugin\pureldap\test; 4*e7339d5aSAndreas Gohr 5*e7339d5aSAndreas Gohruse dokuwiki\plugin\pureldap\classes\ADClient; 6*e7339d5aSAndreas Gohruse dokuwiki\plugin\pureldap\classes\GroupHierarchyCache; 7*e7339d5aSAndreas Gohruse DokuWikiTest; 8*e7339d5aSAndreas Gohr 9*e7339d5aSAndreas Gohr/** 10*e7339d5aSAndreas Gohr * tests for the pureldap plugin 11*e7339d5aSAndreas Gohr * 12*e7339d5aSAndreas Gohr * @group plugin_pureldap 13*e7339d5aSAndreas Gohr * @group plugins 14*e7339d5aSAndreas Gohr */ 15*e7339d5aSAndreas Gohrclass GroupHierarchyCacheTest extends DokuWikiTest 16*e7339d5aSAndreas Gohr{ 17*e7339d5aSAndreas Gohr 18*e7339d5aSAndreas Gohr /** 19*e7339d5aSAndreas Gohr * Return an initialized GroupHierarchyCache 20*e7339d5aSAndreas Gohr * 21*e7339d5aSAndreas Gohr * Creates a client with default settings. Optionally allows to override configs. 22*e7339d5aSAndreas Gohr * 23*e7339d5aSAndreas Gohr * All tests assume to be running against https://github.com/splitbrain/vagrant-active-directory 24*e7339d5aSAndreas Gohr * 25*e7339d5aSAndreas Gohr * @param array $conf 26*e7339d5aSAndreas Gohr * @return GroupHierarchyCache|null 27*e7339d5aSAndreas Gohr */ 28*e7339d5aSAndreas Gohr protected function getClient($conf = []) 29*e7339d5aSAndreas Gohr { 30*e7339d5aSAndreas Gohr $client = new ADClient( 31*e7339d5aSAndreas Gohr array_merge( 32*e7339d5aSAndreas Gohr [ 33*e7339d5aSAndreas Gohr 'base_dn' => 'DC=example,DC=local', 34*e7339d5aSAndreas Gohr 'suffix' => 'example.local', 35*e7339d5aSAndreas Gohr 'servers' => ['localhost'], 36*e7339d5aSAndreas Gohr 'port' => 7636, 37*e7339d5aSAndreas Gohr 'admin_username' => 'vagrant', 38*e7339d5aSAndreas Gohr 'admin_password' => 'vagrant', 39*e7339d5aSAndreas Gohr 'encryption' => 'ssl', 40*e7339d5aSAndreas Gohr 'validate' => 'self', 41*e7339d5aSAndreas Gohr 'attributes' => ['mobile'], 42*e7339d5aSAndreas Gohr ], 43*e7339d5aSAndreas Gohr $conf 44*e7339d5aSAndreas Gohr ) 45*e7339d5aSAndreas Gohr ); 46*e7339d5aSAndreas Gohr 47*e7339d5aSAndreas Gohr return $client->getGroupHierarchyCache(); 48*e7339d5aSAndreas Gohr } 49*e7339d5aSAndreas Gohr 50*e7339d5aSAndreas Gohr public function testGetGroupList() 51*e7339d5aSAndreas Gohr { 52*e7339d5aSAndreas Gohr $ghc = $this->getClient(); 53*e7339d5aSAndreas Gohr $list = $this->callInaccessibleMethod($ghc, 'getGroupList', []); 54*e7339d5aSAndreas Gohr 55*e7339d5aSAndreas Gohr $this->assertGreaterThan(20, $list); 56*e7339d5aSAndreas Gohr $this->assertArrayHasKey('CN=Gamma Nested,CN=Users,DC=example,DC=local', $list); 57*e7339d5aSAndreas Gohr $this->assertArrayHasKey('parents', $list['CN=Gamma Nested,CN=Users,DC=example,DC=local']); 58*e7339d5aSAndreas Gohr $this->assertArrayHasKey('children', $list['CN=Gamma Nested,CN=Users,DC=example,DC=local']); 59*e7339d5aSAndreas Gohr } 60*e7339d5aSAndreas Gohr 61*e7339d5aSAndreas Gohr public function testGetParents() 62*e7339d5aSAndreas Gohr { 63*e7339d5aSAndreas Gohr $ghc = $this->getClient(); 64*e7339d5aSAndreas Gohr $this->assertEquals( 65*e7339d5aSAndreas Gohr [ 66*e7339d5aSAndreas Gohr 'CN=Gamma Nested,CN=Users,DC=example,DC=local', 67*e7339d5aSAndreas Gohr 'CN=beta,CN=Users,DC=example,DC=local', 68*e7339d5aSAndreas Gohr ], 69*e7339d5aSAndreas Gohr $ghc->getParents('CN=omega nested,CN=Users,DC=example,DC=local') 70*e7339d5aSAndreas Gohr ); 71*e7339d5aSAndreas Gohr } 72*e7339d5aSAndreas Gohr 73*e7339d5aSAndreas Gohr public function testGetChildren() 74*e7339d5aSAndreas Gohr { 75*e7339d5aSAndreas Gohr $ghc = $this->getClient(); 76*e7339d5aSAndreas Gohr $this->assertEquals( 77*e7339d5aSAndreas Gohr [ 78*e7339d5aSAndreas Gohr 'CN=Gamma Nested,CN=Users,DC=example,DC=local', 79*e7339d5aSAndreas Gohr 'CN=omega nested,CN=Users,DC=example,DC=local', 80*e7339d5aSAndreas Gohr ], 81*e7339d5aSAndreas Gohr $ghc->getChildren('CN=beta,CN=Users,DC=example,DC=local') 82*e7339d5aSAndreas Gohr ); 83*e7339d5aSAndreas Gohr } 84*e7339d5aSAndreas Gohr 85*e7339d5aSAndreas Gohr} 86