/** * @covers AdsUser::GetClientLibraryUserAgent */ public function testGetClientLibraryUserAgentReturnsCorrectlyFormattedUserAgent() { $USER_AGENT = 'AdWordsApiPhpClient-test'; $LIB_NAME = 'AwApi-PHP'; $COMMON_NAME = 'Common-PHP'; $VERSION_REGEX = '\\d{1,2}\\.\\d{1,2}\\.\\d{1,2}'; $user = new AdWordsUser($this->authIniFilePath, 'devToken', $USER_AGENT, null, null, $this->mockOAuth2Credential); // Example: "AdWordsApiPhpClient-test (AwApi-PHP/4.1.1, Common-PHP/5.0.0, // PHP/5.4.8)" $search = sprintf('/^%s \\(%s\\/%s, %s\\/%s, PHP\\/%s\\)$/', preg_quote($user->GetUserAgent()), preg_quote($LIB_NAME), $VERSION_REGEX, preg_quote($COMMON_NAME), $VERSION_REGEX, preg_quote(PHP_VERSION)); $this->assertRegExp($search, $user->GetClientLibraryUserAgent()); }
/** * Tests that the user agent header is properly set for this client library. * * @covers AdsUser::GetClientLibraryUserAgent */ public function testGetClientLibraryUserAgent() { $USER_AGENT = 'AdWordsApiPhpClient-test'; $LIB_NAME = 'AwApi-PHP'; $COMMON_NAME = 'Common-PHP'; $VERSION_REGEX = '\\d{1,2}\\.\\d{1,2}\\.\\d{1,2}'; $authIniFilePath = tempnam(sys_get_temp_dir(), 'auth.ini.'); $settingsIniFilePath = tempnam(sys_get_temp_dir(), 'settings.ini.'); $user = new AdWordsUser($authIniFilePath, NULL, NULL, NULL, NULL, $USER_AGENT, NULL, $settingsIniFilePath); // Example: "testApplication (AwApi-PHP/4.1.1, Common-PHP/5.0.0, PHP/5.4.8)" $search = sprintf('/^%s \\(%s\\/%s, %s\\/%s, PHP\\/%s\\)$/', preg_quote($user->GetUserAgent()), preg_quote($LIB_NAME), $VERSION_REGEX, preg_quote($COMMON_NAME), $VERSION_REGEX, preg_quote(PHP_VERSION)); $this->assertRegExp($search, $user->GetClientLibraryUserAgent()); }
/** * Tests if the user agent doesn't include any usages of ads utilities when * isIncludeUtilitiesInUserAgent is false. * * @covers AdsUser::setIncludeUtilitiesInUserAgent * @covers AdsUser::updateClientLibraryUserAgent * @covers AdWordsUser::__construct */ public function testUpdateClientLibraryUserAgent_isIncludeUtilitiesInUserAgent_false() { $USER_AGENT = 'AdWordsApiPhpClient-test'; $LIB_NAME = 'AwApi-PHP'; $COMMON_NAME = 'Common-PHP'; $VERSION_REGEX = '\\d{1,2}\\.\\d{1,2}\\.\\d{1,2}'; $user = new AdWordsUser($this->authIniFilePath, 'devToken', $USER_AGENT, null, null, $this->mockOAuth2Credential); $user->setIncludeUtilitiesInUserAgent('false'); AdsUtilityRegistry::getInstance()->addUtility('BatchJobHelper'); $user->updateClientLibraryUserAgent($user->GetUserAgent()); // Example: "AdWordsApiPhpClient-test (AwApi-PHP/9.0.0, Common-PHP/9.0.0, // PHP/5.4.8)" $expectedUserAgents = sprintf('/^%s \\(%s\\/%s, %s\\/%s, PHP\\/%s\\)$/', preg_quote($user->GetUserAgent()), preg_quote($LIB_NAME), $VERSION_REGEX, preg_quote($COMMON_NAME), $VERSION_REGEX, preg_quote(PHP_VERSION)); $this->assertRegExp($expectedUserAgents, $user->GetClientLibraryUserAgent()); }