public function testUsersInsert_WithAlias() { $fixturesClass = new GoogleFixtures($this->dataFile); $fixturesClass->removeAllFixtures(); $newUser = new Google_Service_Directory_User(); $newUser->changePasswordAtNextLogin = false; // bool $newUser->hashFunction = "SHA-1"; // string $newUser->id = 999991; // int??? $newUser->password = '******'; // string $newUser->primaryEmail = '*****@*****.**'; // string email $newUser->suspended = false; // bool // $newUser->$suspensionReason = ''; // string $newAliases = new Google_Service_Directory_Aliases(); $newAlias = new Google_Service_Directory_Alias(); $newAlias->alias = '*****@*****.**'; $newAlias->setKind("personal"); $newAlias->primaryEmail = $newUser->primaryEmail; $newAliases->setAliases(array($newAlias)); $newUser->aliases = $newAliases; // bool $newDir = new Directory('anyclient', $this->dataFile); $newUser = $newDir->users->insert($newUser); $results = $this->getProperties($newUser); $expected = array("changePasswordAtNextLogin" => false, "hashFunction" => "SHA-1", "id" => 999991, "password" => "testP4ss", "primaryEmail" => "*****@*****.**", "suspended" => false, "aliases" => array('etag' => null, 'kind' => null, 'aliases' => array(array('alias' => "*****@*****.**", 'etag' => null, 'id' => null, 'kind' => 'personal', 'primaryEmail' => '*****@*****.**')))); $msg = " *** Bad returned user"; $this->assertEquals($expected, $results, $msg); $sqliteClass = new SqliteUtils($this->dataFile); $sqliteData = $sqliteClass->getData('', ''); $sqliteDataValues = array_values($sqliteData); $lastDataEntry = end($sqliteDataValues); $lastAliases = json_decode($lastDataEntry['data'], true); $results = $lastAliases['aliases']['aliases']; $expected = array(array("alias" => "*****@*****.**", "kind" => "personal", "primaryEmail" => "*****@*****.**", 'etag' => null, 'id' => null)); $msg = " *** Bad data from sqlite database"; $this->assertEquals($expected, $results, $msg); }
/** * Gets a Google_Service_Directory_Aliases instance with its * aliases property populated with Google_Service_Directory_Alias * instances for that user * * @param string $keyType - "Email" or "Id" * @param string $userKey - The Email or immutable Id of the user * @return null|a real Google_Service_Directory_Aliases instance */ public function fetchAliasesByUser($keyType, $userKey) { $sqliteUtils = new SqliteUtils($this->_dbFile); $aliases = $sqliteUtils->getAllRecordsByDataKey($this->_dataType, $this->_dataClass, $keyType, $userKey); if (!$aliases) { return null; } $foundAliases = array(); foreach ($aliases as $nextAlias) { $newAlias = new \Google_Service_Directory_Alias(); ObjectUtils::initialize($newAlias, json_decode($nextAlias['data'], true)); $foundAliases[] = $newAlias; } $newUsersAliases = new \Google_Service_Directory_Aliases(); $newUsersAliases->setAliases($foundAliases); return $newUsersAliases; }