/** * @param mixed $src * @param mixed $expected * * @dataProvider addDeepEntityProvider */ public function testAddDeepEntity($src, $expected) { $tree = new OwnerTree(); foreach ($src as $item) { $tree->addDeepEntity($item[0], $item[1]); } $tree->buildTree(); foreach ($expected as $buId => $sBuIds) { $this->assertEquals($sBuIds, $tree->getSubordinateBusinessUnitIds($buId), sprintf('Failed for %s', $buId)); } }
private function buildTestTree() { /** * org1 org2 org3 org4 * | | * bu1 bu2 +-bu3 +-bu4 * | | | | * | | +-bu31 | * | | | | | * | | | +-user31 | * | | | | * user1 +-user2 | +-user3 +-user4 * | | * +-bu3a +-bu3 * | +-bu4 * +-bu3a1 | * +-bu41 * | * +-bu411 * | * +-user411 * * user1 user2 user3 user31 user4 user411 * * org1 org2 org3 org3 org4 org4 * org2 org2 * * bu1 bu2 bu3 bu31 bu4 bu411 * bu2 bu2 * */ $this->tree->addBusinessUnit('bu1', null); $this->tree->addBusinessUnit('bu2', null); $this->tree->addBusinessUnit('bu3', 'org3'); $this->tree->addBusinessUnit('bu31', 'org3'); $this->tree->addBusinessUnit('bu3a', 'org3'); $this->tree->addBusinessUnit('bu3a1', 'org3'); $this->tree->addBusinessUnit('bu4', 'org4'); $this->tree->addBusinessUnit('bu41', 'org4'); $this->tree->addBusinessUnit('bu411', 'org4'); $this->tree->addBusinessUnitRelation('bu1', null); $this->tree->addBusinessUnitRelation('bu2', null); $this->tree->addBusinessUnitRelation('bu3', null); $this->tree->addBusinessUnitRelation('bu31', 'bu3'); $this->tree->addBusinessUnitRelation('bu3a', null); $this->tree->addBusinessUnitRelation('bu3a1', 'bu3a'); $this->tree->addBusinessUnitRelation('bu4', null); $this->tree->addBusinessUnitRelation('bu41', 'bu4'); $this->tree->addBusinessUnitRelation('bu411', 'bu41'); $this->tree->addUser('user1', null); $this->tree->addUser('user2', 'bu2'); $this->tree->addUser('user3', 'bu3'); $this->tree->addUser('user31', 'bu31'); $this->tree->addUser('user4', 'bu4'); $this->tree->addUser('user41', 'bu41'); $this->tree->addUser('user411', 'bu411'); $this->tree->addUserOrganization('user1', 'org1'); $this->tree->addUserOrganization('user1', 'org2'); $this->tree->addUserOrganization('user2', 'org2'); $this->tree->addUserOrganization('user3', 'org2'); $this->tree->addUserOrganization('user3', 'org3'); $this->tree->addUserOrganization('user31', 'org3'); $this->tree->addUserOrganization('user4', 'org4'); $this->tree->addUserOrganization('user411', 'org4'); $this->tree->addUserBusinessUnit('user1', 'org1', 'bu1'); $this->tree->addUserBusinessUnit('user1', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user2', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user3', 'org3', 'bu3'); $this->tree->addUserBusinessUnit('user3', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user31', 'org3', 'bu31'); $this->tree->addUserBusinessUnit('user4', 'org4', 'bu4'); $this->tree->addUserBusinessUnit('user411', 'org4', 'bu411'); $this->tree->buildTree(); }
protected function buildTestTree() { /** * org1 org2 org3 org4 * | | * bu1 bu2 +-bu3 +-bu4 * | | | | * | | +-bu31 | * | | | | | * | | | +-user31 | * | | | | * user1 +-user2 | +-user3 +-user4 * | | * +-bu3a +-bu3 * | +-bu4 * +-bu3a1 | * +-bu41 * | * +-bu411 * | * +-user411 * * user1 user2 user3 user31 user4 user411 * * org1 org2 org3 org3 org4 org4 * org2 org2 * * bu1 bu2 bu3 bu31 bu4 bu411 * bu2 bu2 */ $this->org1 = new Organization('org1'); $this->org2 = new Organization('org2'); $this->org3 = new Organization('org3'); $this->org4 = new Organization('org4'); $this->bu1 = new BusinessUnit('bu1'); $this->bu2 = new BusinessUnit('bu2'); $this->bu3 = new BusinessUnit('bu3'); $this->bu31 = new BusinessUnit('bu31', $this->bu3); $this->bu4 = new BusinessUnit('bu4'); $this->bu41 = new BusinessUnit('bu41', $this->bu4); $this->bu411 = new BusinessUnit('bu411', $this->bu41); $this->user1 = new User('user1', null, $this->org1); $this->user2 = new User('user2', $this->bu2, $this->org2); $this->user3 = new User('user3', $this->bu3, $this->org3); $this->user31 = new User('user31', $this->bu31, $this->org3); $this->user4 = new User('user4', $this->bu4, $this->org4); $this->user411 = new User('user411', $this->bu411, $this->org4); $this->tree->addBusinessUnit('bu1', null); $this->tree->addBusinessUnit('bu2', null); $this->tree->addBusinessUnit('bu3', 'org3'); $this->tree->addBusinessUnit('bu31', 'org3'); $this->tree->addBusinessUnit('bu3a', 'org3'); $this->tree->addBusinessUnit('bu3a1', 'org3'); $this->tree->addBusinessUnit('bu4', 'org4'); $this->tree->addBusinessUnit('bu41', 'org4'); $this->tree->addBusinessUnit('bu411', 'org4'); $this->tree->addBusinessUnitRelation('bu1', null); $this->tree->addBusinessUnitRelation('bu2', null); $this->tree->addBusinessUnitRelation('bu3', null); $this->tree->addBusinessUnitRelation('bu31', 'bu3'); $this->tree->addBusinessUnitRelation('bu3a', null); $this->tree->addBusinessUnitRelation('bu3a1', 'bu3a'); $this->tree->addBusinessUnitRelation('bu4', null); $this->tree->addBusinessUnitRelation('bu41', 'bu4'); $this->tree->addBusinessUnitRelation('bu411', 'bu41'); $this->tree->buildTree(); $this->tree->addUser('user1', null); $this->tree->addUser('user2', 'bu2'); $this->tree->addUser('user3', 'bu3'); $this->tree->addUser('user31', 'bu31'); $this->tree->addUser('user4', 'bu4'); $this->tree->addUser('user41', 'bu41'); $this->tree->addUser('user411', 'bu411'); $this->tree->addUserOrganization('user1', 'org1'); $this->tree->addUserOrganization('user1', 'org2'); $this->tree->addUserOrganization('user2', 'org2'); $this->tree->addUserOrganization('user3', 'org2'); $this->tree->addUserOrganization('user3', 'org3'); $this->tree->addUserOrganization('user31', 'org3'); $this->tree->addUserOrganization('user4', 'org4'); $this->tree->addUserOrganization('user411', 'org4'); $this->tree->addUserBusinessUnit('user1', 'org1', 'bu1'); $this->tree->addUserBusinessUnit('user1', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user2', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user3', 'org3', 'bu3'); $this->tree->addUserBusinessUnit('user3', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user31', 'org3', 'bu31'); $this->tree->addUserBusinessUnit('user4', 'org4', 'bu4'); $this->tree->addUserBusinessUnit('user411', 'org4', 'bu411'); }