/** @return UsersToBeImportedCollection */
 public function build(SimpleXMLElement $xml)
 {
     $collection = new UsersToBeImportedCollection();
     foreach ($xml as $user) {
         $to_be_imported_user = $this->instantiateUserToBeImported($user);
         $collection->add($to_be_imported_user);
     }
     return $collection;
 }
 public function itDoesNotIndexByLdapIdWhenNoLdapId()
 {
     $user = mock('User\\XML\\Import\\ReadyToBeImportedUser');
     $id = 108;
     $username = '******';
     $ldap_id = '';
     $this->collection->add($user, $id, $username, $ldap_id);
     $this->expectException('User\\XML\\Import\\UserNotFoundException');
     $this->collection->getUserByLdapId($ldap_id);
 }
 /** @return User\XML\Import\ReadyToBeImportedUsersCollection */
 public function transform(UsersToBeImportedCollection $collection_from_archive, $filename)
 {
     $csv_lines = $this->parseCSVFile($filename);
     $collection_for_import = new ReadyToBeImportedUsersCollection();
     foreach ($collection_from_archive->toArray() as $username => $to_be_imported_user) {
         if (isset($csv_lines[$username])) {
             $action = $csv_lines[$username];
             $collection_for_import->add($this->transformUser($collection_from_archive, $username, $action, $to_be_imported_user), $to_be_imported_user->getOriginalUserId(), $to_be_imported_user->getUserName(), $to_be_imported_user->getOriginalLdapId());
         } else {
             if ($to_be_imported_user instanceof AlreadyExistingUser) {
                 $collection_for_import->add($to_be_imported_user, $to_be_imported_user->getOriginalUserId(), $to_be_imported_user->getUserName(), $to_be_imported_user->getOriginalLdapId());
             } else {
                 throw new MissingEntryInMappingFileException("user {$username} should be in the mapping file");
             }
         }
     }
     return $collection_for_import;
 }
 public function itDumpsToBeMappedUser()
 {
     $user1 = mock('PFUser');
     stub($user1)->getUserName()->returns('john');
     stub($user1)->getRealName()->returns('John Doe');
     stub($user1)->getEmail()->returns('*****@*****.**');
     stub($user1)->getStatus()->returns('A');
     $user2 = mock('PFUser');
     stub($user2)->getUserName()->returns('admin_john');
     stub($user2)->getRealName()->returns('John Doe (admin)');
     stub($user2)->getEmail()->returns('*****@*****.**');
     stub($user2)->getStatus()->returns('A');
     $this->collection->add(new ToBeMappedUser('jdoe', 'John Doe', array($user1, $user2), 104, 'ldap1234'));
     $this->collection->toCSV($this->output_filename);
     $data = $this->getCSVFirstData();
     $this->assertEqual($data, array('jdoe', 'map:', 'User John Doe (jdoe) has the same email address than following users: John Doe (john) [A], John Doe (admin) (admin_john) [A].' . ' Use one of the following actions to confirm the mapping: "map:john", "map:admin_john".'));
 }
 protected function addToBeMappedUserToCollection()
 {
     $this->collection->add(new ToBeMappedUser('to.be.mapped', 'To Be Mapped', array(aUser()->withUserName('cstevens')->build()), 104, 'ldap1234'));
 }