function testGroupsController() { // Use a batch standin, which acts like a Google_Http_Batch, but // merely accumulates the requests added to it, and returns them // to us when requested. $batch = new BatchWrapper(); // Create a new Google Apps group controller, and add some users // and groups to it. $controller = new GoogleAppsGroupsController($this->client, $batch); $presidentProperties = array('group-email' => '*****@*****.**', 'group-id' => '*****@*****.**', 'group-name' => 'North President'); $vicePresidentProperties = array('group-email' => '*****@*****.**', 'group-id' => '*****@*****.**', 'group-name' => 'North Vice-President'); $op = new Operation('placeholderOperation', array()); $controller->insertOffice($op, 'north', 'president', $presidentProperties); $controller->configureOffice($op, 'north', 'president', $presidentProperties); $controller->insertMember($op, 'north', 'president', $presidentProperties['group-id'], '*****@*****.**'); $controller->insertGroupAlternateAddress($op, 'north', 'president', $presidentProperties['group-id'], '*****@*****.**'); $controller->removeMember($op, 'north', 'president', $presidentProperties['group-id'], '*****@*****.**'); $controller->removeGroupAlternateAddress($op, 'north', 'president', $presidentProperties['group-id'], '*****@*****.**'); $controller->insertMember($op, 'north', 'vice-president', $vicePresidentProperties['group-id'], '*****@*****.**'); $controller->removeMember($op, 'north', 'vice-president', $vicePresidentProperties['group-id'], '*****@*****.**'); $controller->deleteOffice($op, 'north', 'president', $presidentProperties); // The expected list of requests corresponding to the calls above: $expected = <<<EOT - requestMethod: POST url: /admin/directory/v1/groups email: north-president@testdomain.org name: 'North President' - requestMethod: PATCH url: /groups/v1/groups/north-president%40testdomain.org isArchived: true whoCanJoin: INVITED_CAN_JOIN whoCanPostMessage: ANYONE_CAN_POST - requestMethod: POST url: /admin/directory/v1/groups/north-president%40testdomain.org/members email: franklin@testdomain.org role: MEMBER type: USER - requestMethod: POST url: /admin/directory/v1/groups/north-president%40testdomain.org/aliases alias: elpresidente@testdomain.org - requestMethod: DELETE url: /admin/directory/v1/groups/north-president%40testdomain.org/members/franklin%40testdomain.org - requestMethod: DELETE url: /admin/directory/v1/groups/north-president%40testdomain.org/aliases/elpresidente%40testdomain.org - requestMethod: POST url: /admin/directory/v1/groups/north-vicepresident%40testdomain.org/members email: garner@testdomain.org role: MEMBER type: USER - requestMethod: DELETE url: /admin/directory/v1/groups/north-vicepresident%40testdomain.org/members/garner%40testdomain.org - requestMethod: DELETE url: /admin/directory/v1/groups/north-president%40testdomain.org EOT; $requests = $batch->getSimplifiedRequests(); $this->assertEquals(trim($expected), $this->arrayToYaml($requests)); }
exit(1); } print "authenticated\n"; /* // Get info about a user $service = new Google_Service_Directory($client); $data = $service->users->get("*****@*****.**"); var_export($data); print("\n"); exit(0); */ $policy = new StandardGroupPolicy('westkingdom.org'); $batch = new \Google_Http_Batch($client); $batchWrapper = new BatchWrapper($batch); $controller = new GoogleAppsGroupsController($client, $batchWrapper); if (!file_exists('currentstate.westkingdom.org.yaml')) { print "about to fetch\n"; $existing = $controller->fetch('westkingdom.org'); $dumper = new Dumper(); $dumper->setIndentation(2); $existingAsYaml = trim($dumper->dump($existing, PHP_INT_MAX)); file_put_contents('currentstate.westkingdom.org.yaml', $existingAsYaml); exit(0); } $groupData = file_get_contents(dirname(__FILE__) . "/currentstate.westkingdom.org.yaml"); $currentState = Yaml::parse($groupData); $groupManager = new Westkingdom\HierarchicalGroupEmail\GroupsManager($controller, $policy, $currentState); $groupManager->update($newState); $dumper = new Dumper(); $dumper->setIndentation(2);