function insertOffice($branch, $officename, $officeData)
 {
     $this->journal->insertOffice($branch, $officename, $officeData['properties']);
     $this->updateOfficeMembers($branch, $officename, $officeData['properties']['group-id'], $officeData['members'], array());
     $newAlternateAddresses = GroupsManager::getAlternateAddresses($branch, $officename, $officeData['properties']['group-id'], $officeData);
     $this->updateOfficeAlternateAddresses($branch, $officename, $officeData['properties']['group-id'], $newAlternateAddresses, array());
 }
 public function testInsertOffice()
 {
     // Create a new state object by copying our existing state and adding
     // a member to the "west-webminister" group.
     $newState = $this->initialState;
     $newState['west']['lists']['seneschal']['members'][] = 'anne@kingdom.org';
     $newState['west']['lists']['seneschal']['properties']['group-name'] = 'West Seneschal';
     // Create a new test controller prophecy, and reveal it to the
     // Groups object we are going to test.
     $testController = $this->prophesize('Westkingdom\\HierarchicalGroupEmail\\GroupsController');
     $revealedController = $testController->reveal();
     $journal = new Journal($revealedController, $this->initialState);
     $groupManager = new GroupsManager($revealedController, $this->policy, $this->initialState, $journal);
     // Prophesize that the new user will be added to the west webministers group.
     $testController->begin()->shouldBeCalled();
     $testController->insertOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", array("group-name" => "West Seneschal", "group-email" => "west-seneschal@testdomain.org", "group-id" => "west-seneschal@testdomain.org")));
     $testController->configureOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", array("group-name" => "West Seneschal", "group-email" => "west-seneschal@testdomain.org", "group-id" => "west-seneschal@testdomain.org")));
     $testController->verifyOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", array("group-name" => "West Seneschal", "group-email" => "west-seneschal@testdomain.org", "group-id" => "west-seneschal@testdomain.org")));
     $testController->verifyOfficeConfiguration()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", array("group-name" => "West Seneschal", "group-email" => "west-seneschal@testdomain.org", "group-id" => "west-seneschal@testdomain.org")));
     $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", "west-seneschal@testdomain.org", "anne@kingdom.org"));
     $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", "west-seneschal@testdomain.org", "anne@kingdom.org"));
     $testController->insertOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "west-officers@testdomain.org", "group-id" => "west-officers@testdomain.org", 'alternate-addresses' => array('officers@west.testdomain.org'))));
     $testController->configureOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "west-officers@testdomain.org", "group-id" => "west-officers@testdomain.org", 'alternate-addresses' => array('officers@west.testdomain.org'))));
     $testController->verifyOfficeConfiguration()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "west-officers@testdomain.org", "group-id" => "west-officers@testdomain.org", 'alternate-addresses' => array('officers@west.testdomain.org'))));
     $testController->verifyOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "west-officers@testdomain.org", "group-id" => "west-officers@testdomain.org", 'alternate-addresses' => array('officers@west.testdomain.org'))));
     $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "west-officers@testdomain.org", "west-webminister@testdomain.org"));
     $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "west-officers@testdomain.org", "west-seneschal@testdomain.org"));
     $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "west-officers@testdomain.org", "west-webminister@testdomain.org"));
     $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "west-officers@testdomain.org", "west-seneschal@testdomain.org"));
     //    $testController->insertOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "all-seneschals@testdomain.org", "group-name" => "All Seneschals", "group-email" => "all-seneschals@testdomain.org")));
     //    $testController->configureOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "all-seneschals@testdomain.org", "group-name" => "All Seneschals", "group-email" => "all-seneschals@testdomain.org")));
     //    $testController->verifyOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "all-seneschals@testdomain.org", "group-name" => "All Seneschals", "group-email" => "all-seneschals@testdomain.org")));
     //    $testController->verifyOfficeConfiguration()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "all-seneschals@testdomain.org", "group-name" => "All Seneschals", "group-email" => "all-seneschals@testdomain.org")));
     //    $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", "all-seneschals@testdomain.org", "west-seneschal@testdomain.org"));
     //    $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", "all-seneschals@testdomain.org", "west-seneschal@testdomain.org"));
     //    $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "west-officers@testdomain.org", "west-seneschal@testdomain.org"));
     //    $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "west-officers@testdomain.org", "west-seneschal@testdomain.org"));
     $testController->complete()->shouldBeCalled()->withArguments(array(TRUE));
     // Update the group.  The prophecies are checked against actual
     // behavior during teardown.
     $groupManager->update($newState);
     $groupManager->execute();
     // Force the call to insertOfficeVerified, so we can test the generation
     // of aggregated groups.
     $journal->insertOfficeVerified(array(), 'west', 'seneschal', $newState['west']['lists']['seneschal']['properties']);
     // Call 'execute' again, to insure that updateAggregated() is called.
     $groupManager->execute();
     // We don't see the aggregated group here, because the verify functions
     // are never called (due to the mocked controller), so the verified()
     // functions are never called, and these are what update the state.
     $expectedFinalState = "\nwest:\n  lists:\n    seneschal:\n      properties:\n        group-name: 'West Seneschal'\n    webminister:\n      members:\n        - deputy@sca.org\n        - minister@sca.org\n      properties:\n        group-name: 'West Kingdom Web Minister'";
     $state = $groupManager->export();
     unset($state['#queues']);
     $this->assertEquals(trim($expectedFinalState), $this->arrayToYaml($state));
 }