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'][] = '*****@*****.**';
     $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" => "*****@*****.**", "group-id" => "*****@*****.**")));
     $testController->configureOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", array("group-name" => "West Seneschal", "group-email" => "*****@*****.**", "group-id" => "*****@*****.**")));
     $testController->verifyOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", array("group-name" => "West Seneschal", "group-email" => "*****@*****.**", "group-id" => "*****@*****.**")));
     $testController->verifyOfficeConfiguration()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", array("group-name" => "West Seneschal", "group-email" => "*****@*****.**", "group-id" => "*****@*****.**")));
     $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", "*****@*****.**", "*****@*****.**"));
     $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "west", "seneschal", "*****@*****.**", "*****@*****.**"));
     $testController->insertOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "*****@*****.**", "group-id" => "*****@*****.**", 'alternate-addresses' => array('*****@*****.**'))));
     $testController->configureOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "*****@*****.**", "group-id" => "*****@*****.**", 'alternate-addresses' => array('*****@*****.**'))));
     $testController->verifyOfficeConfiguration()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "*****@*****.**", "group-id" => "*****@*****.**", 'alternate-addresses' => array('*****@*****.**'))));
     $testController->verifyOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", array("group-name" => "West Officers", "group-email" => "*****@*****.**", "group-id" => "*****@*****.**", 'alternate-addresses' => array('*****@*****.**'))));
     $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "*****@*****.**", "*****@*****.**"));
     $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "*****@*****.**", "*****@*****.**"));
     $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "*****@*****.**", "*****@*****.**"));
     $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "*****@*****.**", "*****@*****.**"));
     //    $testController->insertOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "*****@*****.**", "group-name" => "All Seneschals", "group-email" => "*****@*****.**")));
     //    $testController->configureOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "*****@*****.**", "group-name" => "All Seneschals", "group-email" => "*****@*****.**")));
     //    $testController->verifyOffice()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "*****@*****.**", "group-name" => "All Seneschals", "group-email" => "*****@*****.**")));
     //    $testController->verifyOfficeConfiguration()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", array("group-id" => "*****@*****.**", "group-name" => "All Seneschals", "group-email" => "*****@*****.**")));
     //    $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", "*****@*****.**", "*****@*****.**"));
     //    $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "all-seneschals", "*****@*****.**", "*****@*****.**"));
     //    $testController->insertMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "*****@*****.**", "*****@*****.**"));
     //    $testController->verifyMember()->shouldBeCalled()->withArguments(array(new AnyValueToken(), "_aggregated", "west-officers", "*****@*****.**", "*****@*****.**"));
     $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));
 }