first commit
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest;
|
||||
|
||||
use FacebookAds\Api;
|
||||
use FacebookAds\Http\Adapter\CurlAdapter;
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAds\Http\Exception\RequestException;
|
||||
use FacebookAds\Logger\CurlLogger;
|
||||
use FacebookAds\Logger\LoggerInterface;
|
||||
use FacebookAds\Logger\NullLogger;
|
||||
use FacebookAds\Session;
|
||||
use FacebookAdsTest\Exception\PHPUnitRequestExceptionWrapper;
|
||||
|
||||
/**
|
||||
* Base class for the integration test cases.
|
||||
* Provide Network services.
|
||||
*/
|
||||
class AbstractIntegrationTestCase extends AbstractTestCase {
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
protected $httpClient;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* @var Api
|
||||
*/
|
||||
protected $api;
|
||||
|
||||
/**
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
public function getLogger() {
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function getSession() {
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Client
|
||||
*/
|
||||
public function getHttpClient() {
|
||||
return $this->httpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Api
|
||||
*/
|
||||
public function getApi() {
|
||||
return $this->api;
|
||||
}
|
||||
|
||||
protected function setupSession() {
|
||||
$this->session = new Session(
|
||||
$this->getConfig()->appId,
|
||||
$this->getConfig()->appSecret,
|
||||
$this->getConfig()->accessToken);
|
||||
}
|
||||
|
||||
protected function setupHttpClient() {
|
||||
$this->httpClient = new Client();
|
||||
if ($this->getConfig()->graphBaseDomain) {
|
||||
$this->httpClient->setDefaultGraphBaseDomain(
|
||||
$this->getConfig()->graphBaseDomain);
|
||||
}
|
||||
if ($this->getConfig()->skipSslVerification) {
|
||||
/** @var CurlAdapter $adapter */
|
||||
$adapter = $this->httpClient->getAdapter();
|
||||
$adapter->getOpts()->offsetSet(CURLOPT_SSL_VERIFYHOST, false);
|
||||
$adapter->getOpts()->offsetSet(CURLOPT_SSL_VERIFYPEER, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setupLogger() {
|
||||
$this->logger = $this->getConfig()->curlLogger
|
||||
? new CurlLogger(fopen($this->getConfig()->curlLogger, "a"))
|
||||
: new NullLogger();
|
||||
}
|
||||
|
||||
protected function setupApi() {
|
||||
$this->api = new Api(
|
||||
$this->getHttpClient(),
|
||||
$this->getSession());
|
||||
|
||||
$this->api->setLogger($this->getLogger());
|
||||
|
||||
Api::setInstance($this->api);
|
||||
}
|
||||
|
||||
public function setup() : void {
|
||||
parent::setup();
|
||||
|
||||
$this->getSkippableFeaturesManager()->enforceSkipTest($this);
|
||||
|
||||
$this->setupLogger();
|
||||
$this->setupSession();
|
||||
$this->setupHttpClient();
|
||||
$this->setupApi();
|
||||
}
|
||||
|
||||
public function tearDown() : void {
|
||||
$this->api = null;
|
||||
$this->httpClient = null;
|
||||
$this->session = null;
|
||||
$this->logger = null;
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a test method did not execute successfully.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @throws \Throwable
|
||||
*/
|
||||
protected function onNotSuccessfulTest(\Throwable $e) : void {
|
||||
if ($e instanceof RequestException) {
|
||||
throw new PHPUnitRequestExceptionWrapper($e);
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
132
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/AbstractTestCase.php
vendored
Normal file
132
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/AbstractTestCase.php
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest;
|
||||
|
||||
use FacebookAdsTest\Config\Config;
|
||||
use FacebookAdsTest\Config\SkippableFeaturesManager;
|
||||
use \PHPUnit_Framework_MockObject_Builder_InvocationMocker as Mock;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Base class for the unit test cases, providing the functions for AdsAPI
|
||||
* initialization etc.
|
||||
*/
|
||||
class AbstractTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* @return SkippableFeaturesManager
|
||||
*/
|
||||
public function getSkippableFeaturesManager() {
|
||||
return SkippableFeaturesManager::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldSkipTest($key) {
|
||||
return $this->getSkippableFeaturesManager()->isSkipKey($key);
|
||||
}
|
||||
|
||||
public function skipIf($key) {
|
||||
if ($this->shouldSkipTest($key)) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function getConfig() {
|
||||
return Config::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated use getConfig()
|
||||
*/
|
||||
public function getTestRunId() {
|
||||
return $this->getConfig()->testRunId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated use getConfig()
|
||||
*/
|
||||
public function getTestImagePath() {
|
||||
return $this->getConfig()->testImagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated use getConfig()
|
||||
*/
|
||||
public function getTestZippedImagesPath() {
|
||||
return $this->getConfig()->testZippedImagesPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated use getConfig()
|
||||
*/
|
||||
public function getTestVideoPath() {
|
||||
return $this->getConfig()->testVideoPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mock
|
||||
* @param array $data
|
||||
*/
|
||||
protected function makeMockIterable(
|
||||
$mock, array $data = array()) {
|
||||
|
||||
/** @var Mock $mock */
|
||||
$mock->method('count')->willReturn(count($data));
|
||||
$mock->method('getIterator')->willReturn(new \ArrayIterator($data));
|
||||
$mock->method('getArrayCopy')->willReturn($data);
|
||||
$mock->method('export')->willReturn($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Closure $closure
|
||||
* @param string $fqn
|
||||
*/
|
||||
protected function assertWillThrow(
|
||||
\Closure $closure,
|
||||
$fqn = 'Exception') {
|
||||
|
||||
try {
|
||||
call_user_func($closure);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue(
|
||||
is_a($e, $fqn),
|
||||
'Expected exception of type '.$fqn.': '.get_class($e).' received');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fail('Expected exception didn\'t throw: '.$fqn);
|
||||
}
|
||||
}
|
||||
185
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/AbstractUnitTestCase.php
vendored
Normal file
185
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/AbstractUnitTestCase.php
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest;
|
||||
|
||||
use FacebookAds\Http\Adapter\AdapterInterface;
|
||||
use FacebookAds\Http\Adapter\Curl\CurlInterface;
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAds\Http\Headers;
|
||||
use FacebookAds\Http\Parameters;
|
||||
use FacebookAds\Http\RequestInterface;
|
||||
use FacebookAds\Http\ResponseInterface;
|
||||
use FacebookAds\Logger\LoggerInterface;
|
||||
use FacebookAds\Session;
|
||||
use PHPUnit_Framework_MockObject_Builder_InvocationMocker as Mocker;
|
||||
use PHPUnit_Framework_MockObject_MockObject as Mock;
|
||||
|
||||
/**
|
||||
* @method Mocker|Mock getMock($fqn, $methods = array(), $arguments = array())
|
||||
*/
|
||||
abstract class AbstractUnitTestCase extends AbstractTestCase {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_ADAPTER_INTERFACE = '\FacebookAds\Http\Adapter\AdapterInterface';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_CLIENT = '\FacebookAds\Http\Client';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_CURL_INTERFACE = '\FacebookAds\Http\Adapter\Curl\CurlInterface';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_HEADERS = '\FacebookAds\Http\Headers';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_LOGGER_INTERFACE = '\FacebookAds\Logger\LoggerInterface';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_PARAMETERS = '\FacebookAds\Http\Parameters';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_JSON_AWARE_PARAMETERS
|
||||
= '\FacebookAds\Logger\CurlLogger\JsonAwareParameters';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_REQUEST_INTERFACE = '\FacebookAds\Http\RequestInterface';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_RESPONSE_INTERFACE = '\FacebookAds\Http\ResponseInterface';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FQN_SESSION = '\FacebookAds\Session';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const VALUE_SESSION_APP_ID = '<APP_ID>';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const VALUE_SESSION_APP_SECRET = '<APP_SECRET>';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const VALUE_SESSION_ACCESS_TOKEN = '<ACCESS_TOKEN>';
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|ResponseInterface
|
||||
*/
|
||||
protected function createResponseMock() {
|
||||
return $this->createMock(static::FQN_RESPONSE_INTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|Client
|
||||
*/
|
||||
protected function createClientMock() {
|
||||
return $this->createMock(static::FQN_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|CurlInterface
|
||||
*/
|
||||
protected function createCurlMock() {
|
||||
return $this->createMock(static::FQN_CURL_INTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|Headers
|
||||
*/
|
||||
protected function createHeadersMock() {
|
||||
return $this->createMock(static::FQN_HEADERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|LoggerInterface
|
||||
*/
|
||||
protected function createLoggerMock() {
|
||||
return $this->createMock(static::FQN_LOGGER_INTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|Parameters
|
||||
*/
|
||||
protected function createParametersMock() {
|
||||
return $this->createMock(static::FQN_PARAMETERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|Parameters
|
||||
*/
|
||||
protected function createJsonAwareParametersMock() {
|
||||
return $this->createMock(static::FQN_JSON_AWARE_PARAMETERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|RequestInterface
|
||||
*/
|
||||
protected function createRequestMock() {
|
||||
return $this->createMock(static::FQN_REQUEST_INTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|AdapterInterface
|
||||
*/
|
||||
protected function createAdapterMock() {
|
||||
return $this->createMock(static::FQN_ADAPTER_INTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mocker|Mock|Session
|
||||
*/
|
||||
protected function createSessionMock() {
|
||||
return $this->getMockBuilder(static::FQN_SESSION)
|
||||
->setConstructorArgs(array(
|
||||
static::VALUE_SESSION_APP_ID,
|
||||
static::VALUE_SESSION_APP_SECRET,
|
||||
static::VALUE_SESSION_ACCESS_TOKEN,
|
||||
))
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
148
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/ApiTest.php
vendored
Normal file
148
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/ApiTest.php
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest;
|
||||
|
||||
use FacebookAds\Api;
|
||||
use FacebookAds\Http\RequestInterface;
|
||||
use FacebookAds\Http\ResponseInterface;
|
||||
use FacebookAds\Logger\NullLogger;
|
||||
|
||||
class ApiTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @return Api
|
||||
*/
|
||||
protected function createApi() {
|
||||
return new Api($this->createClientMock(), $this->createSessionMock());
|
||||
}
|
||||
|
||||
public function testInstance() {
|
||||
$this->assertNull(Api::instance());
|
||||
|
||||
$api = $this->createApi();
|
||||
Api::setInstance($api);
|
||||
$this->assertTrue($api === Api::instance());
|
||||
|
||||
$newApi = $this->createApi();
|
||||
Api::setInstance($newApi);
|
||||
$this->assertTrue($newApi === Api::instance());
|
||||
$this->assertFalse($api === Api::instance());
|
||||
}
|
||||
|
||||
public function testInit() {
|
||||
$api = Api::init(
|
||||
static::VALUE_SESSION_APP_ID,
|
||||
static::VALUE_SESSION_APP_SECRET,
|
||||
static::VALUE_SESSION_ACCESS_TOKEN,
|
||||
false
|
||||
);
|
||||
$this->assertTrue($api instanceof Api);
|
||||
$this->assertTrue($api === Api::instance());
|
||||
$this->assertEquals(
|
||||
static::VALUE_SESSION_APP_ID, $api->getSession()->getAppId());
|
||||
$this->assertEquals(
|
||||
static::VALUE_SESSION_APP_SECRET, $api->getSession()->getAppSecret());
|
||||
$this->assertEquals(
|
||||
static::VALUE_SESSION_ACCESS_TOKEN, $api->getSession()->getAccessToken());
|
||||
}
|
||||
|
||||
public function testGetters() {
|
||||
$client = $this->createClientMock();
|
||||
$session = $this->createSessionMock();
|
||||
$api = new Api($client, $session);
|
||||
$this->assertTrue($api->getHttpClient() === $client);
|
||||
$this->assertTrue($api->getSession() === $session);
|
||||
}
|
||||
|
||||
public function testLogger() {
|
||||
$api = $this->createApi();
|
||||
$logger = $this->createLoggerMock();
|
||||
$api->setLogger($logger);
|
||||
$this->assertTrue($logger === $api->getLogger());
|
||||
|
||||
// Test default
|
||||
$api = $this->createApi();
|
||||
$this->assertTrue($api->getLogger() instanceof NullLogger);
|
||||
}
|
||||
|
||||
public function testDefaultGraphVersion() {
|
||||
$api = $this->createApi();
|
||||
$api->setDefaultGraphVersion('<VERSION>');
|
||||
$this->assertEquals('<VERSION>', $api->getDefaultGraphVersion());
|
||||
|
||||
// Test default
|
||||
$api = $this->createApi();
|
||||
$this->assertTrue(is_string($api->getDefaultGraphVersion()));
|
||||
$this->assertRegExp('/^\d+\.\d+$/', $api->getDefaultGraphVersion());
|
||||
}
|
||||
|
||||
public function testCall() {
|
||||
$request = $this->createRequestMock();
|
||||
$request->method('execute')->willReturn($this->createResponseMock());
|
||||
$request->method('getQueryParams')
|
||||
->willReturn($this->createParametersMock());
|
||||
$request->method('getBodyParams')
|
||||
->willReturn($this->createParametersMock());
|
||||
$request->expects($this->exactly(2))->method('setMethod')
|
||||
->with($this->logicalOr(
|
||||
RequestInterface::METHOD_GET,
|
||||
RequestInterface::METHOD_POST));
|
||||
$request->expects($this->exactly(2))->method('setGraphVersion')
|
||||
->with($this->equalTo($this->createApi()->getDefaultGraphVersion()));
|
||||
$request->expects($this->exactly(2))->method('setPath')
|
||||
->with($this->equalTo('/<PATH>'));
|
||||
|
||||
$client = $this->createClientMock();
|
||||
$client->method('createRequest')->willReturn($request);
|
||||
|
||||
$session = $this->createSessionMock();
|
||||
$session->method('getAppSecretProof')->willReturn('<APP_SECRET_PROOF>');
|
||||
$session->method('getRequestParameters')->willReturn([]);
|
||||
|
||||
$logger = $this->createLoggerMock();
|
||||
$logger->expects($this->exactly(2))->method('logRequest');
|
||||
$logger->expects($this->exactly(2))->method('logResponse');
|
||||
|
||||
$api = new Api($client, $session);
|
||||
$api->setLogger($logger);
|
||||
|
||||
// HTTP GET request
|
||||
$request->expects($this->exactly(1))->method('getQueryParams');
|
||||
|
||||
$response = $api->call('/<PATH>');
|
||||
$this->assertTrue($response instanceof ResponseInterface);
|
||||
|
||||
// HTTP POST request
|
||||
$request->expects($this->exactly(1))->method('getBodyParams');
|
||||
|
||||
$api->call(
|
||||
'/<PATH>', RequestInterface::METHOD_POST, array('param' => 'value'));
|
||||
$this->assertTrue($response instanceof ResponseInterface);
|
||||
}
|
||||
|
||||
public function testBase64UrlEncode() {
|
||||
$this->assertEquals('MTIzNDU', Api::base64UrlEncode('12345'));
|
||||
}
|
||||
}
|
||||
149
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Bootstrap/Bootstrap.php
vendored
Normal file
149
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Bootstrap/Bootstrap.php
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Bootstrap;
|
||||
|
||||
use FacebookAdsTest\Config\Config;
|
||||
|
||||
class Bootstrap {
|
||||
|
||||
/**
|
||||
* @var self
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isIntialized = false;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $configData;
|
||||
|
||||
/**
|
||||
* @var Config|null
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $autoloader;
|
||||
|
||||
/**
|
||||
* @throws \LogicException
|
||||
*/
|
||||
final public function __construct() {
|
||||
if (self::$instance !== null) {
|
||||
throw new \LogicException("Bootstrap already instanciated");
|
||||
}
|
||||
|
||||
self::$instance = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getComposerAutoloadPath() {
|
||||
return __DIR__.'/../../../vendor/autoload.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAutoloader() {
|
||||
if ($this->autoloader === null) {
|
||||
$autoload_path = $this->getComposerAutoloadPath();
|
||||
if (!is_readable($autoload_path)) {
|
||||
throw new \RuntimeException("Could not read ".$autoload_path);
|
||||
}
|
||||
$this->autoloader = include $autoload_path;
|
||||
$this->autoloader->addPsr4('FacebookAdsTest\\', __DIR__.'/../');
|
||||
}
|
||||
|
||||
return $this->autoloader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplifies the common pattern of checking for an index in an array
|
||||
* and selecting a default value if it does not exist
|
||||
*
|
||||
* @param array $array
|
||||
* @param string|int $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
protected function idx(array $array, $key, $default = null) {
|
||||
return array_key_exists($key, $array) && $array[$key] !== ''
|
||||
? $array[$key]
|
||||
: $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplifies the common pattern of checking for an index in an array
|
||||
* and throw an exception if not
|
||||
*
|
||||
* @param array $array
|
||||
* @param string|int $key
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function idxt(array $array, $key) {
|
||||
if (!array_key_exists($key, $array) || !$array[$key]) {
|
||||
throw new \Exception("Missing mandatory config '{$key}'");
|
||||
}
|
||||
|
||||
return $array[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function getConfig() {
|
||||
if ($this->config === null) {
|
||||
$this->config = new Config();
|
||||
$this->config->testRunId
|
||||
= md5($this->idx($_SERVER, 'LOGNAME', uniqid(true)).microtime(true));
|
||||
$this->config->testImagePath = __DIR__.'/../../misc/image.png';
|
||||
$this->config->testZippedImagesPath = __DIR__.'/../../misc/images.zip';
|
||||
$this->config->testVideoPath = __DIR__.'/../../misc/video.mp4';
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function init() {
|
||||
if ($this->isIntialized) {
|
||||
throw new \LogicException("Bootstrap already initialized");
|
||||
}
|
||||
|
||||
$this->getAutoloader();
|
||||
Config::setInstance($this->getConfig());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Bootstrap;
|
||||
|
||||
use FacebookAdsTest\Config\Config;
|
||||
use FacebookAdsTest\Config\SkippableFeaturesManager;
|
||||
|
||||
class IntegrationBootstrap extends Bootstrap {
|
||||
|
||||
/**
|
||||
* @param string $file_path
|
||||
* @return array
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function loadConfigData($file_path) {
|
||||
if (!is_readable($file_path)) {
|
||||
throw new \RuntimeException("Could not read {$file_path}");
|
||||
}
|
||||
|
||||
$data = require $file_path;
|
||||
if (!is_array($data)) {
|
||||
throw new \RuntimeException("Invalid config structure");
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfigData() {
|
||||
if ($this->configData === null) {
|
||||
$this->configData = $this->loadConfigData(__DIR__.'/../../config.php');
|
||||
}
|
||||
|
||||
return $this->configData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|int $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
protected function confx($key, $default = null) {
|
||||
return $this->idx($this->getConfigData(), $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|int $key
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function confxt($key) {
|
||||
return $this->idxt($this->getConfigData(), $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
protected function getUnitConfig() {
|
||||
return parent::getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function getConfig() {
|
||||
if ($this->config === null) {
|
||||
$this->config = parent::getConfig();
|
||||
$this->config->appId = $this->confx('app_id');
|
||||
$this->config->appSecret = $this->confx('app_secret');
|
||||
$this->config->accessToken = $this->confx('access_token');
|
||||
$this->config->accountId = $this->confx('act_id');
|
||||
$this->config->pageId = $this->confx('page_id');
|
||||
$this->config->appUrl = $this->confx('app_url');
|
||||
$this->config->businessId = $this->confx('business_id');
|
||||
$this->config->instagramActorId = $this->confx('instagram_actor_id');
|
||||
|
||||
// Optionals: Override unit config
|
||||
$this->config->testRunId = $this->confx(
|
||||
'test_run_id', $this->config->testRunId);
|
||||
$this->config->testImagePath = $this->confx(
|
||||
'test_image_path', $this->config->testImagePath);
|
||||
$this->config->testZippedImagesPath = $this->confx(
|
||||
'test_zipped_images_path', $this->config->testZippedImagesPath);
|
||||
$this->config->testVideoPath = $this->confx(
|
||||
'test_video_path', $this->config->testVideoPath);
|
||||
|
||||
// Optionals
|
||||
$this->config->secondaryBusinessId
|
||||
= $this->confx('secondary_business_id', '');
|
||||
$this->config->secondaryAccountId
|
||||
= $this->confx('secondary_account_id', '');
|
||||
$this->config->secondaryPageId = $this->confx('secondary_page_id', '');
|
||||
$this->config->secondaryAppId = $this->confx('secondary_app_id', '');
|
||||
$this->config->graphBaseDomain = $this->confx('graph_base_domain');
|
||||
$this->config->skipSslVerification
|
||||
= $this->confx('skip_ssl_verification', false);
|
||||
$this->config->curlLogger = $this->confx('curl_logger');
|
||||
|
||||
SkippableFeaturesManager::setInstance(
|
||||
new SkippableFeaturesManager($this->confx('skip_if', array())));
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
}
|
||||
150
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Config/Config.php
vendored
Normal file
150
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Config/Config.php
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Config;
|
||||
|
||||
final class Config {
|
||||
|
||||
/**
|
||||
* @var self
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $testRunId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $testImagePath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $testZippedImagesPath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $testVideoPath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $curlLogger;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $appId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $appSecret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $accessToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $businessId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $accountId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $pageId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $appUrl;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $instagramActorId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $secondaryBusinessId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $secondaryPageId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $secondaryAccountId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $secondaryAppId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $graphBaseDomain;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $skipSslVerification;
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public static function instance() {
|
||||
return self::$instance ?: (self::$instance = new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
*/
|
||||
public static function setInstance(Config $config) {
|
||||
self::$instance = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function __set($key, $value) {
|
||||
throw new \RuntimeException("Unsupported key: {$key}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Config;
|
||||
|
||||
interface SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny();
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Config;
|
||||
|
||||
use FacebookAdsTest\AbstractTestCase;
|
||||
|
||||
final class SkippableFeaturesManager {
|
||||
|
||||
/**
|
||||
* @var SkippableFeaturesManager
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* @return SkippableFeaturesManager
|
||||
*/
|
||||
public static function instance() {
|
||||
return self::$instance ?: (self::$instance = new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SkippableFeaturesManager $manager
|
||||
*/
|
||||
public static function setInstance(SkippableFeaturesManager $manager) {
|
||||
self::$instance = $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data = array()) {
|
||||
$this->setData($data);
|
||||
}
|
||||
|
||||
public function setData(array $data = array()) {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return bool
|
||||
*/
|
||||
public function isSkipKey($key) {
|
||||
return array_key_exists($key, $this->data) && $this->data[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractTestCase $test
|
||||
* @return bool
|
||||
*/
|
||||
public function enforceSkipTest(AbstractTestCase $test) {
|
||||
if ($test instanceof SkippableFeatureTestInterface) {
|
||||
foreach ($test->skipIfAny() as $key) {
|
||||
if ($this->isSkipKey($key)) {
|
||||
/** @var AbstractTestCase $test */
|
||||
$test->markTestSkipped("Reason: skipped by config '{$key}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest;
|
||||
|
||||
use FacebookAds\Cursor;
|
||||
|
||||
class CursorDegradationTest extends CursorTest {
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getUniquePageId() {
|
||||
return (string) (microtime(true) * 1000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function createSampleResponseContent() {
|
||||
$url_fmt = $this->createUnparameterizedUrl()
|
||||
.'?offset=%s';
|
||||
|
||||
$content = parent::createSampleResponseContent();
|
||||
$content['paging'] = array(
|
||||
'next' => sprintf($url_fmt, $this->getUniquePageId()),
|
||||
'previous' => sprintf($url_fmt, $this->getUniquePageId()),
|
||||
);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function testRequestParamReset() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$params = $cursor->getLastResponse()->getRequest()->getQueryParams();
|
||||
$params->offsetSet('offset', $this->getUniquePageId());
|
||||
|
||||
$cursor->fetchAfter();
|
||||
$params2 = $cursor->getLastResponse()->getRequest()->getQueryParams();
|
||||
|
||||
$this->assertNotEquals(
|
||||
$params->offsetGet('offset'), $params2->offsetGet('offset'));
|
||||
}
|
||||
|
||||
public function testGetters() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
|
||||
$this->assertTrue($response === $cursor->getResponse());
|
||||
$this->assertTrue($response === $cursor->getLastResponse());
|
||||
$this->assertNull($cursor->getAfter());
|
||||
$this->assertNull($cursor->getBefore());
|
||||
}
|
||||
}
|
||||
385
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/CursorTest.php
vendored
Normal file
385
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/CursorTest.php
vendored
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest;
|
||||
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAds\Http\Parameters;
|
||||
use FacebookAds\Http\Request;
|
||||
use FacebookAds\Http\RequestInterface;
|
||||
use FacebookAds\Http\ResponseInterface;
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
use FacebookAds\Object\AbstractObject;
|
||||
use FacebookAds\Cursor;
|
||||
use FacebookAdsTest\Object\EmptyObject;
|
||||
use \PHPUnit_Framework_MockObject_Builder_InvocationMocker as Mock;
|
||||
|
||||
class CursorTest extends AbstractUnitTestCase {
|
||||
/**
|
||||
* @var EmptyObject
|
||||
*/
|
||||
protected $objectPrototype;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function createEmptyResponseContent() {
|
||||
return array('data' => array());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getUniquePageId() {
|
||||
return uniqid();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function createSampleResponseContent() {
|
||||
$content = array(
|
||||
'paging' => array(
|
||||
'cursors' => array(
|
||||
'after' => $this->getUniquePageId(),
|
||||
'before' => $this->getUniquePageId(),
|
||||
),
|
||||
),
|
||||
) + $this->createEmptyResponseContent();
|
||||
|
||||
$count = rand(2, 5);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$content['data'][] = array(
|
||||
AbstractCrudObject::FIELD_ID => $i,
|
||||
);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function createUnparameterizedUrl() {
|
||||
return Request::PROTOCOL_HTTPS
|
||||
.Client::DEFAULT_LAST_LEVEL_DOMAIN
|
||||
.'.'.Client::DEFAULT_GRAPH_BASE_DOMAIN
|
||||
.'/node/edge';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $num_pages
|
||||
* @param RequestInterface|null $prev
|
||||
* @return Mock|ResponseInterface
|
||||
*/
|
||||
protected function createResponseChainMock(
|
||||
$num_pages, RequestInterface $prev = null) {
|
||||
|
||||
$query_params = $prev ? clone $prev->getQueryParams() : new Parameters();
|
||||
$sample_content = $this->createSampleResponseContent();
|
||||
|
||||
$request = $this->createRequestMock();
|
||||
$request->method('getMethod')->willReturn(RequestInterface::METHOD_GET);
|
||||
$request->method('getQueryParams')->willReturn($query_params);
|
||||
|
||||
$response = $this->createResponseMock();
|
||||
$response->method('getRequest')->willReturn($request);
|
||||
|
||||
$request->method('execute')->willReturn($response);
|
||||
|
||||
$callback = function() use ($num_pages, $sample_content) {
|
||||
return $num_pages > 0
|
||||
? $sample_content
|
||||
: $this->createEmptyResponseContent();
|
||||
};
|
||||
|
||||
$clone_callback = function() use ($num_pages, $request) {
|
||||
return $this->createResponseChainMock(
|
||||
$num_pages - 1, $request)->getRequest();
|
||||
};
|
||||
|
||||
$url_callback = function() use ($query_params) {
|
||||
return $this->createUnparameterizedUrl().'?'
|
||||
.http_build_query($query_params->getArrayCopy());
|
||||
};
|
||||
|
||||
$response->method('getContent')->willReturnCallback($callback);
|
||||
$request->method('createClone')->willReturnCallback($clone_callback);
|
||||
$request->method('getUrl')->willReturnCallback($url_callback);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Mock|ResponseInterface
|
||||
*/
|
||||
protected function createEmptyResponseMock() {
|
||||
$response = $this->createResponseMock();
|
||||
$response->method('getContent')->willReturn(array(
|
||||
'data' => array(),
|
||||
));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function setup(): void {
|
||||
parent::setup();
|
||||
$this->objectPrototype = new EmptyObject();
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
$this->objectPrototype = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testGetters() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
|
||||
$this->assertTrue($response === $cursor->getResponse());
|
||||
$this->assertTrue($response === $cursor->getLastResponse());
|
||||
$this->assertTrue(is_string($cursor->getAfter()));
|
||||
$this->assertTrue(is_string($cursor->getBefore()));
|
||||
$this->assertNotEquals($cursor->getBefore(), $cursor->getAfter());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function responseDataStructureProvider() {
|
||||
return array(
|
||||
array(array()),
|
||||
array(array('data' => null)),
|
||||
array(array('data' => 1)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider responseDataStructureProvider
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @param mixed $content
|
||||
*/
|
||||
public function testResponseDataStructure($content) {
|
||||
$response = $this->createResponseMock();
|
||||
$response->method('getContent')->willReturn($content);
|
||||
|
||||
new Cursor($response, $this->objectPrototype);
|
||||
}
|
||||
|
||||
public function testIterator() {
|
||||
$cursor = new Cursor(
|
||||
$this->createResponseChainMock(1), $this->objectPrototype);
|
||||
|
||||
$this->assertTrue($cursor instanceof \Iterator);
|
||||
|
||||
$k = 0;
|
||||
|
||||
foreach ($cursor as $key => $value) {
|
||||
if ($key != $k) {
|
||||
$this->fail('iteration count missmatch $key');
|
||||
}
|
||||
++$k;
|
||||
}
|
||||
|
||||
$this->assertEquals($k, count($cursor));
|
||||
|
||||
$cursor->rewind();
|
||||
|
||||
$this->assertEquals(0, $cursor->key());
|
||||
$cursor->next();
|
||||
$this->assertEquals(1, $cursor->key());
|
||||
$cursor->prev();
|
||||
$this->assertEquals(0, $cursor->key());
|
||||
|
||||
$this->assertEquals($cursor->getIndexLeft(), 0);
|
||||
$this->assertEquals($cursor->getIndexRight(), count($cursor) - 1);
|
||||
}
|
||||
|
||||
public function testCountable() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
|
||||
$this->assertTrue($cursor instanceof \Countable);
|
||||
$this->assertEquals($cursor->count(), count($cursor));
|
||||
$this->assertEquals(
|
||||
$cursor->count(), count($response->getContent()['data']));
|
||||
}
|
||||
|
||||
public function testArrayAccess() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$test_index = rand(1, count($response->getContent()) - 1);
|
||||
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
|
||||
$this->assertTrue($cursor instanceof \arrayaccess);
|
||||
|
||||
$subject = new EmptyObject();
|
||||
$subject->setData($response->getContent()['data'][$test_index]);
|
||||
|
||||
// Checking offsetGet
|
||||
$this->assertEquals($cursor[$test_index]->getData(), $subject->getData());
|
||||
// Checking offsetExists
|
||||
$this->assertFalse(isset($cursor[count($cursor)]));
|
||||
// Checking offsetUnset
|
||||
unset($cursor[$test_index]);
|
||||
$this->assertNull($cursor[$test_index]);
|
||||
// Checking offsetSet
|
||||
$cursor->offsetSet($test_index, $subject);
|
||||
$this->assertEquals($cursor[$test_index]->getData(), $subject->getData());
|
||||
// Checking offsetSet - append
|
||||
$count = count($cursor);
|
||||
$cursor->offsetSet(null, new EmptyObject());
|
||||
$this->assertEquals(count($cursor), $count + 1);
|
||||
}
|
||||
|
||||
public function testUnneededFetch() {
|
||||
$response = $this->createEmptyResponseMock();
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$this->assertNull($cursor->createBeforeRequest());
|
||||
$this->assertNull($cursor->createAfterRequest());
|
||||
|
||||
// Reset for proper fetching
|
||||
$response = $this->createEmptyResponseMock();
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$length = $cursor->count();
|
||||
$cursor->fetchBefore();
|
||||
$this->assertEquals($length, $cursor->count());
|
||||
$cursor->fetchAfter();
|
||||
$this->assertEquals($length, $cursor->count());
|
||||
}
|
||||
|
||||
public function testIterability() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
|
||||
$cursor->next();
|
||||
$cursor->rewind();
|
||||
$this->assertEquals($cursor->getIndexLeft(), $cursor->key());
|
||||
|
||||
$cursor->end();
|
||||
$this->assertEquals($cursor->getIndexRight(), $cursor->key());
|
||||
|
||||
$index = rand($cursor->getIndexLeft(), $cursor->getIndexRight());
|
||||
$cursor->seekTo($index);
|
||||
$this->assertEquals($index, $cursor->key());
|
||||
|
||||
// Fetch after
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$cursor->fetchAfter();
|
||||
$this->assertFalse($response === $cursor->getLastResponse());
|
||||
}
|
||||
|
||||
public function testRequestParamReset() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$params = $cursor->getLastResponse()->getRequest()->getQueryParams();
|
||||
$params->offsetSet('after', $this->getUniquePageId());
|
||||
$params->offsetSet('before', $this->getUniquePageId());
|
||||
|
||||
$cursor->fetchAfter();
|
||||
$params2 = $cursor->getLastResponse()->getRequest()->getQueryParams();
|
||||
$this->assertNotEquals(
|
||||
$params->offsetGet('after'), $params2->offsetGet('after'));
|
||||
}
|
||||
|
||||
public function testImplicitFetch() {
|
||||
// Test setters/getters
|
||||
$response = $this->createEmptyResponseMock();
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
|
||||
$this->assertFalse(Cursor::getDefaultUseImplicitFetch());
|
||||
$this->assertFalse($cursor->getUseImplicitFetch());
|
||||
$cursor->setUseImplicitFetch(true);
|
||||
$this->assertTrue($cursor->getUseImplicitFetch());
|
||||
|
||||
Cursor::setDefaultUseImplicitFetch(true);
|
||||
|
||||
$response = $this->createEmptyResponseMock();
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$this->assertTrue(Cursor::getDefaultUseImplicitFetch());
|
||||
$this->assertTrue($cursor->getUseImplicitFetch());
|
||||
|
||||
// Test ordered iteration
|
||||
// f() lower interval * min repetition > upper interval
|
||||
// Min repetition > upper interval / lower interval -> f(x): x > 5 / 2 -> 3
|
||||
$response = $this->createResponseChainMock(3);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
while ($cursor->valid()) {
|
||||
$cursor->next();
|
||||
}
|
||||
|
||||
// Min upper boundary = upper interval + 1 = 5 + 1 = 6
|
||||
$this->assertGreaterThanOrEqual(6, $cursor->count());
|
||||
|
||||
// Test rervese iteration
|
||||
// same f()
|
||||
$response = $this->createResponseChainMock(3);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
|
||||
$count = 0;
|
||||
while ($cursor->valid()) {
|
||||
$cursor->prev();
|
||||
}
|
||||
|
||||
$this->assertGreaterThanOrEqual(6, $cursor->count());
|
||||
|
||||
// Force the array out of boundaries
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$cursor->setUseImplicitFetch(false);
|
||||
$cursor->prev();
|
||||
|
||||
// Restore static behaviour
|
||||
Cursor::setDefaultUseImplicitFetch(false);
|
||||
}
|
||||
|
||||
public function testExportability() {
|
||||
$response = $this->createResponseChainMock(1);
|
||||
$cursor = new Cursor($response, $this->objectPrototype);
|
||||
$array_copy = $cursor->getArrayCopy();
|
||||
|
||||
$this->assertTrue(is_array($array_copy));
|
||||
$this->assertEquals($cursor->getArrayCopy(), $cursor->getObjects());
|
||||
$this->assertEquals(
|
||||
count($array_copy), count($response->getContent()['data']));
|
||||
|
||||
foreach ($array_copy as $object) {
|
||||
if (!$object instanceof AbstractObject) {
|
||||
$this->fail("Wrong instance in array copy");
|
||||
}
|
||||
}
|
||||
|
||||
$cursor->fetchAfter();
|
||||
$cursor->fetchBefore();
|
||||
|
||||
$index = $cursor->getIndexLeft();
|
||||
// Test in-memory order while exporting
|
||||
foreach ($cursor->getArrayCopy(true) as $key => $object) {
|
||||
if ($key < $index) {
|
||||
$this->fail("Wrong order in sorted array copy");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Enum/DummyEnum.php
vendored
Normal file
33
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Enum/DummyEnum.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Enum;
|
||||
|
||||
use FacebookAds\Enum\AbstractEnum;
|
||||
|
||||
class DummyEnum extends AbstractEnum {
|
||||
|
||||
const NAME_1 = 'VALUE_1';
|
||||
const NAME_2 = 'VALUE_2';
|
||||
}
|
||||
107
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Enum/EnumTest.php
vendored
Normal file
107
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Enum/EnumTest.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Enum;
|
||||
|
||||
use FacebookAds\Enum\EmptyEnum;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class EnumTest extends AbstractUnitTestCase {
|
||||
|
||||
public function testSingleton() {
|
||||
$this->assertTrue(DummyEnum::getInstance() === DummyEnum::getInstance());
|
||||
}
|
||||
|
||||
public function testAccess() {
|
||||
$this->assertEquals(DummyEnum::className(), get_class(new DummyEnum()));
|
||||
|
||||
$enum = DummyEnum::getInstance();
|
||||
$copy = $enum->getArrayCopy();
|
||||
$names = $enum->getNames();
|
||||
$values = $enum->getValues();
|
||||
$values_map = $enum->getValuesMap();
|
||||
|
||||
$this->assertEquals(2, count($copy));
|
||||
$this->assertArrayHasKey('NAME_1', $copy);
|
||||
$this->assertEquals(DummyEnum::NAME_1, $copy['NAME_1']);
|
||||
|
||||
$this->assertEquals(2, count($names));
|
||||
$this->assertTrue(in_array('NAME_1', $names));
|
||||
|
||||
$this->assertEquals(2, count($values));
|
||||
$this->assertTrue(in_array(DummyEnum::NAME_1, $values));
|
||||
|
||||
$this->assertEquals(2, count($values_map));
|
||||
$this->assertArrayHasKey(DummyEnum::NAME_1, $values_map);
|
||||
|
||||
$this->assertEquals(DummyEnum::NAME_1, $enum->getValueForName('NAME_1'));
|
||||
}
|
||||
|
||||
public function testLazyLoading() {
|
||||
$enum = DummyEnum::getInstance();
|
||||
|
||||
$this->assertTrue($enum->getArrayCopy() === $enum->getArrayCopy());
|
||||
$this->assertTrue($enum->getNames() === $enum->getNames());
|
||||
$this->assertTrue($enum->getValues() === $enum->getValues());
|
||||
$this->assertTrue($enum->getValuesMap() === $enum->getValuesMap());
|
||||
}
|
||||
|
||||
public function testValidation() {
|
||||
$enum = DummyEnum::getInstance();
|
||||
|
||||
$this->assertTrue($enum->isValid('NAME_1'));
|
||||
$this->assertFalse($enum->isValid('NAME_ND'));
|
||||
$this->assertTrue($enum->isValidValue(DummyEnum::NAME_1));
|
||||
$this->assertFalse($enum->isValidValue('VALUE_ND'));
|
||||
}
|
||||
|
||||
|
||||
public function testAssurance() {
|
||||
$enum = DummyEnum::getInstance();
|
||||
|
||||
$this->assertEquals(DummyEnum::NAME_1, $enum->assureValueForName('NAME_1'));
|
||||
$this->assertWillThrow(function() use ($enum) {
|
||||
$enum->assureValueForName('NAME_ND');
|
||||
}, 'InvalidArgumentException');
|
||||
|
||||
$enum->assureIsValid('NAME_1');
|
||||
$this->assertWillThrow(function() use ($enum) {
|
||||
$enum->assureIsValid('NAME_ND');
|
||||
}, 'InvalidArgumentException');
|
||||
|
||||
$enum->assureIsValidValue(DummyEnum::NAME_1);
|
||||
$this->assertWillThrow(function() use ($enum) {
|
||||
$enum->assureIsValidValue('VALUE_ND');
|
||||
}, 'InvalidArgumentException');
|
||||
}
|
||||
|
||||
public function testEmptyEnum() {
|
||||
$enum = EmptyEnum::getInstance();
|
||||
|
||||
$this->assertEquals(array(), $enum->getArrayCopy());
|
||||
$this->assertEquals(array(), $enum->getNames());
|
||||
$this->assertEquals(array(), $enum->getValues());
|
||||
$this->assertEquals(array(), $enum->getValuesMap());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Exception;
|
||||
|
||||
use FacebookAds\Http\Exception\RequestException;
|
||||
|
||||
class PHPUnitRequestExceptionWrapper
|
||||
extends \PHPUnit_Framework_ExceptionWrapper {
|
||||
|
||||
/**
|
||||
* @var RequestException
|
||||
*/
|
||||
protected $wrappedException;
|
||||
|
||||
/**
|
||||
* @param RequestException $e
|
||||
*/
|
||||
public function __construct(RequestException $e) {
|
||||
$this->wrappedException = $e;
|
||||
parent::__construct($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RequestException
|
||||
*/
|
||||
public function getWrappedException() {
|
||||
return $this->wrappedException;
|
||||
}
|
||||
|
||||
protected function requestToString(RequestException $e) {
|
||||
if ($e->getResponse() === null) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
$request = $e->getResponse()->getRequest();
|
||||
|
||||
return sprintf(
|
||||
"%s %s\n%s",
|
||||
$request->getMethod(),
|
||||
$request->getUrl(),
|
||||
" ".str_replace("\n", "\n ", json_encode(
|
||||
$request->getFileParams()->getArrayCopy()
|
||||
+ $request->getBodyParams()->getArrayCopy(),
|
||||
JSON_PRETTY_PRINT)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function blameFieldSpecsToString() {
|
||||
return implode(", ", array_map(function($value) {
|
||||
return $value[0];
|
||||
}, $this->getWrappedException()->getErrorBlameFieldSpecs()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
$string = \PHPUnit_Framework_TestFailure::exceptionToString($this);
|
||||
|
||||
$e = $this->getWrappedException();
|
||||
|
||||
$string .= "\n Request: ".$this->requestToString($e)."\n"
|
||||
." HTTP status Code: ".$e->getHttpStatusCode()."\n"
|
||||
." Is transient: ".($e->isTransient() ? 'true' : 'false')."\n"
|
||||
." Code: ".$e->getCode()."\n"
|
||||
." Error Subcode: ".$e->getErrorSubcode()."\n"
|
||||
." Error User Title: ".$e->getErrorUserTitle()."\n"
|
||||
." Error User Message: ".$e->getErrorUserMessage()."\n";
|
||||
|
||||
if ($e->getErrorBlameFieldSpecs()) {
|
||||
$string .= " Error Blame Fields: ".$this->blameFieldSpecsToString()."\n";
|
||||
}
|
||||
|
||||
if ($trace = \PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
|
||||
$string .= "\n" . $trace;
|
||||
}
|
||||
|
||||
if ($this->previous) {
|
||||
$string .= "\nCaused by\n" . $this->previous;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http\Adapter;
|
||||
|
||||
use FacebookAds\Http\Adapter\AdapterInterface;
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
abstract class AbstractAdapterTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
* @return AdapterInterface
|
||||
*/
|
||||
abstract protected function createAdapter($client = null);
|
||||
|
||||
public function testGetters() {
|
||||
$client = new Client();
|
||||
$adapter = $this->createAdapter($client);
|
||||
$this->assertTrue($client === $adapter->getClient());
|
||||
$this->assertEquals(
|
||||
$client->getCaBundlePath(), $adapter->getCaBundlePath());
|
||||
}
|
||||
|
||||
public function testOpts() {
|
||||
$adapter = $this->createAdapter();
|
||||
$opts = new \ArrayObject();
|
||||
$adapter->setOpts($opts);
|
||||
$this->assertTrue($opts === $adapter->getOpts());
|
||||
|
||||
// Default initialization
|
||||
$adapter = $this->createAdapter();
|
||||
$this->assertTrue($adapter->getOpts() instanceof \ArrayObject);
|
||||
}
|
||||
|
||||
abstract public function testRequest();
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http\Adapter;
|
||||
|
||||
use FacebookAds\Exception\Exception;
|
||||
use FacebookAds\Http\Adapter\Curl\CurlInterface;
|
||||
use FacebookAds\Http\Adapter\CurlAdapter;
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAds\Http\RequestInterface;
|
||||
use FacebookAds\Http\ResponseInterface;
|
||||
use \PHPUnit_Framework_MockObject_Builder_InvocationMocker as Mock;
|
||||
|
||||
class CurlAdapterTest extends AbstractAdapterTest {
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
* @return CurlAdapter
|
||||
*/
|
||||
protected function createAdapter($client = null) {
|
||||
return new CurlAdapter($client ?: new Client(), $this->createCurlMock());
|
||||
}
|
||||
|
||||
public function testGetters() {
|
||||
parent::testGetters();
|
||||
$this->assertTrue(
|
||||
$this->createAdapter()->getCurl() instanceof CurlInterface);
|
||||
}
|
||||
|
||||
public function testRequest() {
|
||||
$adapter = $this->createAdapter();
|
||||
|
||||
/** @var Mock|CurlInterface $curl */
|
||||
$curl = $adapter->getCurl();
|
||||
$curl->method('preparePostFileField')->willReturn('file');
|
||||
$curl->method('exec')->willReturn("HTTP/1.1 200 OK\nX-header: value");
|
||||
|
||||
$headers = $this->createHeadersMock();
|
||||
$this->makeMockIterable($headers, array(
|
||||
'X-custom-header' => 'header value',
|
||||
));
|
||||
|
||||
$query = $this->createParametersMock(array(
|
||||
'param' => 'value',
|
||||
));
|
||||
|
||||
// HTTP_GET
|
||||
$body = $this->createParametersMock();
|
||||
$this->makeMockIterable($body);
|
||||
|
||||
$files = $this->createParametersMock();
|
||||
$this->makeMockIterable($files);
|
||||
|
||||
$request = $this->createRequestMock();
|
||||
$request->method('getMethod')->willReturn(RequestInterface::METHOD_GET);
|
||||
$request->method('getHeaders')->willReturn($headers);
|
||||
$request->method('getQueryParams')->willReturn($query);
|
||||
$request->method('getBodyParams')->willReturn($body);
|
||||
$request->method('getFileParams')->willReturn($files);
|
||||
$response = $adapter->sendRequest($request);
|
||||
$this->assertTrue($response instanceof ResponseInterface);
|
||||
|
||||
// HTTP_POST with files
|
||||
$body = $this->createParametersMock();
|
||||
$this->makeMockIterable($body, array(
|
||||
'file' => './filepath',
|
||||
));
|
||||
|
||||
$files = $this->createParametersMock();
|
||||
$this->makeMockIterable($files, array(
|
||||
'field' => 'value',
|
||||
));
|
||||
|
||||
$request = $this->createRequestMock();
|
||||
$request->method('getMethod')->willReturn(RequestInterface::METHOD_POST);
|
||||
$request->method('getHeaders')->willReturn($headers);
|
||||
$request->method('getQueryParams')->willReturn($query);
|
||||
$request->method('getBodyParams')->willReturn($body);
|
||||
$request->method('getFileParams')->willReturn($files);
|
||||
|
||||
$response = $adapter->sendRequest($request);
|
||||
$this->assertTrue($response instanceof ResponseInterface);
|
||||
|
||||
// HTTP_DELETE
|
||||
$body = $this->createParametersMock();
|
||||
$this->makeMockIterable($body);
|
||||
|
||||
$files = $this->createParametersMock();
|
||||
$this->makeMockIterable($files);
|
||||
|
||||
$request = $this->createRequestMock();
|
||||
$request->method('getMethod')->willReturn(RequestInterface::METHOD_DELETE);
|
||||
$request->method('getHeaders')->willReturn($headers);
|
||||
$request->method('getQueryParams')->willReturn($query);
|
||||
$request->method('getBodyParams')->willReturn($body);
|
||||
$request->method('getFileParams')->willReturn($files);
|
||||
|
||||
$response = $adapter->sendRequest($request);
|
||||
$this->assertTrue($response instanceof ResponseInterface);
|
||||
|
||||
// Force Curl Error
|
||||
/** @var CurlInterface|Mock $curl */
|
||||
$curl = $adapter->getCurl();
|
||||
$curl->method('errno')->willReturn(CURLE_SSL_CONNECT_ERROR);
|
||||
$curl->method('error')->willReturn('Mocked Curl Error');
|
||||
$body = $this->createParametersMock();
|
||||
$this->makeMockIterable($body);
|
||||
|
||||
$files = $this->createParametersMock();
|
||||
$this->makeMockIterable($files);
|
||||
|
||||
$request = $this->createRequestMock();
|
||||
$request->method('getMethod')->willReturn(RequestInterface::METHOD_DELETE);
|
||||
$request->method('getHeaders')->willReturn($headers);
|
||||
$request->method('getQueryParams')->willReturn($query);
|
||||
$request->method('getBodyParams')->willReturn($body);
|
||||
$request->method('getFileParams')->willReturn($files);
|
||||
|
||||
$e = null;
|
||||
try {
|
||||
$adapter->sendRequest($request);
|
||||
} catch (Exception $e) {}
|
||||
$this->assertTrue($e !== null);
|
||||
}
|
||||
}
|
||||
176
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Http/ClientTest.php
vendored
Normal file
176
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Http/ClientTest.php
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http;
|
||||
|
||||
use FacebookAds\ApiConfig;
|
||||
use FacebookAds\Http\Adapter\AdapterInterface;
|
||||
use FacebookAds\Http\Adapter\CurlAdapter;
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAds\Http\Exception\EmptyResponseException;
|
||||
use FacebookAds\Http\Exception\RequestException;
|
||||
use FacebookAds\Http\Headers;
|
||||
use FacebookAds\Http\Request;
|
||||
use FacebookAds\Http\RequestInterface;
|
||||
use FacebookAds\Http\Response;
|
||||
use FacebookAds\Http\ResponseInterface;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use \PHPUnit_Framework_MockObject_Builder_InvocationMocker as Mock;
|
||||
|
||||
class ClientTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @param mixed $response_content
|
||||
* @return Mock|AdapterInterface
|
||||
*/
|
||||
protected function createMockChain($response_content) {
|
||||
$adapter = $this->createAdapterMock();
|
||||
$response = $this->createResponseMock();
|
||||
$response->method('getContent')->willReturn($response_content);
|
||||
$adapter->method('sendRequest')->willReturn($response);
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
|
||||
public function testPrototypes() {
|
||||
$client = new Client();
|
||||
|
||||
$request_proto = $this->createRequestMock();
|
||||
$request_proto->method('createClone')->willReturnSelf();
|
||||
$client->setRequestPrototype($request_proto);
|
||||
$this->assertTrue($request_proto === $client->getRequestPrototype());
|
||||
$this->assertTrue($client->createRequest() instanceof RequestInterface);
|
||||
|
||||
$response_proto = $this->createResponseMock();
|
||||
$client->setResponsePrototype($response_proto);
|
||||
$this->assertTrue($response_proto === $client->getResponsePrototype());
|
||||
$this->assertTrue($client->createResponse() instanceof ResponseInterface);
|
||||
|
||||
// Default initialization
|
||||
$client = new Client();
|
||||
$this->assertTrue($client->getRequestPrototype() instanceof Request);
|
||||
$this->assertTrue($client->getResponsePrototype() instanceof Response);
|
||||
}
|
||||
|
||||
public function testHeaders() {
|
||||
$headers = new Headers();
|
||||
$this->assertTrue($headers instanceof \IteratorAggregate);
|
||||
$this->assertTrue($headers instanceof \Traversable);
|
||||
$this->assertTrue($headers instanceof \ArrayAccess);
|
||||
$this->assertTrue($headers instanceof \Serializable);
|
||||
$this->assertTrue($headers instanceof \Countable);
|
||||
|
||||
$client = new Client();
|
||||
$client->setDefaultRequestHeaders($headers);
|
||||
$this->assertTrue($headers === $client->getDefaultRequestHeaderds());
|
||||
|
||||
// Default initialization
|
||||
$client = new Client();
|
||||
$headers = $client->getDefaultRequestHeaderds();
|
||||
$this->assertTrue($headers instanceof Headers);
|
||||
$this->assertTrue($headers === $client->getDefaultRequestHeaderds());
|
||||
$this->assertArrayHasKey('User-Agent', $headers);
|
||||
$this->assertEquals('fbbizsdk-php-v'.ApiConfig::SDKVersion, $headers['User-Agent']);
|
||||
}
|
||||
|
||||
public function testDomain() {
|
||||
$client = new Client();
|
||||
$this->assertEquals(
|
||||
Client::DEFAULT_GRAPH_BASE_DOMAIN, $client->getDefaultGraphBaseDomain());
|
||||
|
||||
$domain = 'not.facebook.com';
|
||||
$client->setDefaultGraphBaseDomain($domain);
|
||||
$this->assertEquals($domain, $client->getDefaultGraphBaseDomain());
|
||||
}
|
||||
|
||||
public function testAdapter() {
|
||||
$client = new Client();
|
||||
|
||||
$adapter = $this->createAdapterMock();
|
||||
$client->setAdapter($adapter);
|
||||
$this->assertTrue($client->getAdapter() instanceof AdapterInterface);
|
||||
$this->assertTrue($adapter === $client->getAdapter());
|
||||
|
||||
// Default initialization
|
||||
$client = new Client();
|
||||
$this->assertTrue($client->getAdapter() instanceof CurlAdapter);
|
||||
}
|
||||
|
||||
public function testCaBundlePath() {
|
||||
$client = new Client();
|
||||
$path = '/tmp/dont_care_if_exists';
|
||||
$client->setCaBundlePath($path);
|
||||
$this->assertEquals($path, $client->getCaBundlePath());
|
||||
|
||||
// Default initialization
|
||||
$client = new Client();
|
||||
$this->assertFalse(!$client->getCaBundlePath());
|
||||
$this->assertFileExists($client->getCaBundlePath());
|
||||
}
|
||||
|
||||
public function testSendRequest() {
|
||||
$client = new Client();
|
||||
|
||||
// Empty response > json_decode('') = null
|
||||
$client->setAdapter($this->createMockChain(null));
|
||||
|
||||
$exception_catched = false;
|
||||
try {
|
||||
$client->sendRequest($this->createRequestMock());
|
||||
} catch (EmptyResponseException $e) {
|
||||
$exception_catched = true;
|
||||
}
|
||||
$this->assertTrue($exception_catched);
|
||||
|
||||
// Error payload
|
||||
$client->setAdapter($this->createMockChain(array(
|
||||
'error' => array(
|
||||
'message' => 'Stub Server Error Message',
|
||||
'type' => 'FacebookApiException',
|
||||
'code' => 1,
|
||||
),
|
||||
)));
|
||||
|
||||
$exception_catched = false;
|
||||
try {
|
||||
$client->sendRequest($this->createRequestMock());
|
||||
} catch (EmptyResponseException $e) {
|
||||
$this->fail("Catched wrong RequestException");
|
||||
} catch (RequestException $e) {
|
||||
$exception_catched = true;
|
||||
}
|
||||
$this->assertTrue($exception_catched);
|
||||
|
||||
// Success
|
||||
$client->setAdapter($this->createMockChain(array(
|
||||
'id' => 4,
|
||||
)));
|
||||
|
||||
$response = $client->sendRequest($this->createRequestMock());
|
||||
$this->assertTrue($response instanceof ResponseInterface);
|
||||
$content = $response->getContent();
|
||||
$this->assertArrayHasKey('id', $content);
|
||||
$this->assertEquals($content['id'], 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http\Exception;
|
||||
|
||||
use FacebookAds\Http\Exception\RequestException;
|
||||
use FacebookAds\Http\Response;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class RequestExceptionTest extends AbstractUnitTestCase {
|
||||
|
||||
public function testGetters() {
|
||||
$data = array(
|
||||
'error' => array(
|
||||
'message' => 'Stub Server Error Message',
|
||||
'type' => 'FacebookApiException',
|
||||
'code' => 1,
|
||||
'error_data' => array(
|
||||
'blame_field_specs' => array(
|
||||
array('mandatory_field'),
|
||||
array('field_with_malformed_value'),
|
||||
),
|
||||
),
|
||||
'error_subcode' => 1,
|
||||
'is_transient' => false,
|
||||
'error_user_title' => 'Just a test',
|
||||
'error_user_msg' => 'Let\'s avoid alarmism',
|
||||
),
|
||||
);
|
||||
$status_code = 400;
|
||||
$response = new Response();
|
||||
$response->setBody(json_encode($data));
|
||||
$response->setStatusCode($status_code);
|
||||
$e = new RequestException($response);
|
||||
$this->assertEquals($status_code, $e->getHttpStatusCode());
|
||||
$this->assertEquals(
|
||||
$data['error']['error_subcode'], $e->getErrorSubcode());
|
||||
$this->assertEquals(
|
||||
$data['error']['error_user_title'], $e->getErrorUserTitle());
|
||||
$this->assertEquals(
|
||||
$data['error']['error_user_msg'], $e->getErrorUserMessage());
|
||||
$this->assertEquals(
|
||||
$data['error']['error_data']['blame_field_specs'],
|
||||
$e->getErrorBlameFieldSpecs());
|
||||
}
|
||||
|
||||
public function testGetFacebookTraceIdReturnsValueFromResponseErrorData() {
|
||||
$data = array(
|
||||
'error' => array(
|
||||
'fbtrace_id' => 'abc123',
|
||||
),
|
||||
);
|
||||
|
||||
$response = new Response();
|
||||
$response->setBody(json_encode($data));
|
||||
$e = new RequestException($response);
|
||||
|
||||
$this->assertSame('abc123', $e->getFacebookTraceId());
|
||||
}
|
||||
|
||||
public function testGetErrorBlameFieldSpecsReturnsNullWithNullErrorData() {
|
||||
$data = array(
|
||||
'error' => array(
|
||||
'error_data' => null,
|
||||
),
|
||||
);
|
||||
|
||||
$response = new Response();
|
||||
$response->setBody(json_encode($data));
|
||||
$e = new RequestException($response);
|
||||
|
||||
$this->assertNull($e->getErrorBlameFieldSpecs());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function createConcreteProvider() {
|
||||
return array(
|
||||
array(array('type' => 'OAuthException'), 'AuthorizationException'),
|
||||
array(array('code' => 1), 'ServerException'),
|
||||
array(array('code' => 4), 'ThrottleException'),
|
||||
array(array('code' => 506), 'ClientException'),
|
||||
array(array('code' => 10), 'PermissionException'),
|
||||
array(array(), 'RequestException'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $expected_class
|
||||
* @dataProvider createConcreteProvider
|
||||
*/
|
||||
public function testCreateConcrete($data, $expected_class) {
|
||||
$response = new Response();
|
||||
$response->setBody(json_encode(array('error' => $data)));
|
||||
$response->setStatusCode(400);
|
||||
$e = RequestException::create($response);
|
||||
$fqn = '\FacebookAds\Http\Exception\\'.$expected_class;
|
||||
$this->assertTrue(is_a($e, $fqn));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http;
|
||||
|
||||
use FacebookAds\Http\FileParameter;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class FileParameterTest extends AbstractUnitTestCase {
|
||||
|
||||
public function testGetters() {
|
||||
$path = 'PATH';
|
||||
$name = 'NAME';
|
||||
$mime_type = 'MIME_TYPE';
|
||||
$param = (new FileParameter($path))
|
||||
->setName($name)
|
||||
->setMimeType($mime_type);
|
||||
|
||||
$this->assertEquals($param->getPath(), $path);
|
||||
$this->assertEquals($param->getName(), $name);
|
||||
$this->assertEquals($param->getMimeType(), $mime_type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http;
|
||||
|
||||
use FacebookAds\Http\Parameters;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class ParametersTest extends AbstractUnitTestCase {
|
||||
|
||||
public function testInterfaces() {
|
||||
$parameters = new Parameters();
|
||||
$this->assertTrue($parameters instanceof \IteratorAggregate);
|
||||
$this->assertTrue($parameters instanceof \Traversable);
|
||||
$this->assertTrue($parameters instanceof \ArrayAccess);
|
||||
$this->assertTrue($parameters instanceof \Serializable);
|
||||
$this->assertTrue($parameters instanceof \Countable);
|
||||
}
|
||||
|
||||
public function testEnhance() {
|
||||
$parameters = new Parameters();
|
||||
$copy = $parameters->getArrayCopy();
|
||||
|
||||
$data = array(
|
||||
'foo' => 0,
|
||||
'bar' => 1,
|
||||
);
|
||||
|
||||
$copy = array_merge($copy, $data);
|
||||
$parameters->enhance($data);
|
||||
$this->assertEquals($copy, $parameters->getArrayCopy());
|
||||
|
||||
$data = array(
|
||||
'bar' => -1,
|
||||
'baz' => 2,
|
||||
);
|
||||
|
||||
$copy = array_merge($copy, $data);
|
||||
$parameters->enhance($data);
|
||||
$this->assertEquals($copy, $parameters->getArrayCopy());
|
||||
}
|
||||
|
||||
public function testExport() {
|
||||
$parameters = new Parameters();
|
||||
$parameters['scalar'] = 1;
|
||||
$parameters['non_scalar'] = array(0, '1', true);
|
||||
$data = $parameters->export();
|
||||
$this->assertArrayHasKey('scalar', $data);
|
||||
$this->assertEquals(1, $data['scalar']);
|
||||
$this->assertArrayHasKey('non_scalar', $data);
|
||||
$this->assertEquals('[0,"1",true]', $data['non_scalar']);
|
||||
}
|
||||
}
|
||||
236
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Http/RequestTest.php
vendored
Normal file
236
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Http/RequestTest.php
vendored
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http;
|
||||
|
||||
use FacebookAds\Api;
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAds\Http\Headers;
|
||||
use FacebookAds\Http\Parameters;
|
||||
use FacebookAds\Http\Request;
|
||||
use FacebookAds\Http\ResponseInterface;
|
||||
use FacebookAds\Http\Util;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class RequestTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @return Request
|
||||
*/
|
||||
protected function createRequest() {
|
||||
return new Request($this->createClientMock());
|
||||
}
|
||||
|
||||
public function testGetters() {
|
||||
$client = $this->createClientMock();
|
||||
$request = new Request($client);
|
||||
|
||||
$this->assertTrue($request->getClient() instanceof Client);
|
||||
$this->assertTrue($client === $request->getClient());
|
||||
}
|
||||
|
||||
public function testProtocol() {
|
||||
$request = $this->createRequest();
|
||||
$protocol = Request::PROTOCOL_HTTP;
|
||||
$request->setProtocol($protocol);
|
||||
$this->assertEquals($protocol, $request->getProtocol());
|
||||
}
|
||||
|
||||
public function testDomain() {
|
||||
$request = $this->createRequest();
|
||||
$domain = 'not.facebook.com';
|
||||
$request->setDomain($domain);
|
||||
$this->assertEquals($domain, $request->getDomain());
|
||||
|
||||
// Default initialization
|
||||
$client = $this->createClientMock();
|
||||
$client->method('getDefaultGraphBaseDomain')
|
||||
->willReturn('not.facebook.com');
|
||||
$request = new Request($client);
|
||||
$domain = $request->getDomain();
|
||||
$this->assertRegExp('/.+\.not\.facebook\.com/', $domain);
|
||||
$this->assertEquals($domain, $request->getDomain());
|
||||
|
||||
// Partially set
|
||||
$client = $this->createClientMock();
|
||||
$client->method('getDefaultGraphBaseDomain')
|
||||
->willReturn('probably.not.facebook.com');
|
||||
$request = new Request($client);
|
||||
$request->setLastLevelDomain('most');
|
||||
$domain = $request->getDomain();
|
||||
$this->assertEquals('most.probably.not.facebook.com', $domain);
|
||||
$this->assertEquals($domain, $request->getDomain());
|
||||
}
|
||||
|
||||
public function testHeaders() {
|
||||
$client = $this->createClientMock();
|
||||
$request = new Request($client);
|
||||
$headers = $this->createHeadersMock();
|
||||
$client->setDefaultRequestHeaders($headers);
|
||||
$request->setHeaders($headers);
|
||||
$headers_mirror = $request->getHeaders();
|
||||
$this->assertTrue($headers_mirror instanceof Headers);
|
||||
$this->assertTrue($headers_mirror === $request->getHeaders());
|
||||
|
||||
// Default initialization
|
||||
$headers = new Headers();
|
||||
$client = $this->createClientMock();
|
||||
$client->method('getDefaultRequestHeaderds')->willReturn($headers);
|
||||
$request = new Request($client);
|
||||
$headers_mirror = $request->getHeaders();
|
||||
$this->assertTrue($headers_mirror instanceof Headers);
|
||||
$this->assertFalse($headers === $request->getHeaders());
|
||||
$this->assertTrue($headers_mirror === $request->getHeaders());
|
||||
}
|
||||
|
||||
public function testMethod() {
|
||||
$request = $this->createRequest();
|
||||
$method = Request::METHOD_GET;
|
||||
$request->setMethod($method);
|
||||
$this->assertEquals($method, $request->getMethod());
|
||||
}
|
||||
|
||||
public function testPath() {
|
||||
$request = $this->createRequest();
|
||||
$path = '/node/edge';
|
||||
$request->setPath($path);
|
||||
$this->assertEquals($path, $request->getPath());
|
||||
}
|
||||
|
||||
public function testGraphVersion() {
|
||||
$request = $this->createRequest();
|
||||
$graph_version = Api::VERSION;
|
||||
$request->setGraphVersion($graph_version);
|
||||
$this->assertEquals($graph_version, $request->getGraphVersion());
|
||||
}
|
||||
|
||||
public function testQueryParams() {
|
||||
$request = $this->createRequest();
|
||||
$parameters = $this->createParametersMock();
|
||||
$request->setQueryParams($parameters);
|
||||
$this->assertTrue($request->getQueryParams() instanceof Parameters);
|
||||
$this->assertTrue($parameters === $request->getQueryParams());
|
||||
|
||||
// Default initialization
|
||||
$request = $this->createRequest();
|
||||
$parameters = $request->getQueryParams();
|
||||
$this->assertTrue($parameters instanceof Parameters);
|
||||
$this->assertTrue($parameters === $request->getQueryParams());
|
||||
}
|
||||
|
||||
public function testBodyParams() {
|
||||
$request = $this->createRequest();
|
||||
$parameters = $this->createParametersMock();
|
||||
$request->setBodyParams($parameters);
|
||||
$this->assertTrue($request->getBodyParams() instanceof Parameters);
|
||||
$this->assertTrue($parameters === $request->getBodyParams());
|
||||
|
||||
// Default initialization
|
||||
$request = $this->createRequest();
|
||||
$parameters = $request->getBodyParams();
|
||||
$this->assertTrue($parameters instanceof Parameters);
|
||||
$this->assertTrue($parameters === $request->getBodyParams());
|
||||
}
|
||||
|
||||
public function testFileParams() {
|
||||
$request = $this->createRequest();
|
||||
$parameters = $this->createParametersMock();
|
||||
$request->setFileParams($parameters);
|
||||
$this->assertTrue($request->getFileParams() instanceof Parameters);
|
||||
$this->assertTrue($parameters === $request->getFileParams());
|
||||
|
||||
// Default initialization
|
||||
$request = $this->createRequest();
|
||||
$parameters = $request->getFileParams();
|
||||
$this->assertTrue($parameters instanceof Parameters);
|
||||
$this->assertTrue($parameters === $request->getFileParams());
|
||||
}
|
||||
|
||||
public function testClone() {
|
||||
$request = $this->createRequest();
|
||||
$query_params = $this->createParametersMock();
|
||||
$request->setFileParams($query_params);
|
||||
$body_params = $this->createParametersMock();
|
||||
$request->setBodyParams($body_params);
|
||||
$file_params = $this->createParametersMock();
|
||||
$request->setFileParams($file_params);
|
||||
|
||||
$clone = $request->createClone();
|
||||
$this->assertFalse($query_params === $clone->getQueryParams());
|
||||
$this->assertFalse($body_params === $clone->getBodyParams());
|
||||
$this->assertFalse($file_params === $clone->getFileParams());
|
||||
}
|
||||
|
||||
public function testUrlCustomArgSeparator(){
|
||||
$separator = ini_get('arg_separator.output');
|
||||
ini_set('arg_separator.output', '&');
|
||||
$this->testUrl();
|
||||
ini_set('arg_separator.output', $separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testProtocol
|
||||
* @depends testDomain
|
||||
* @depends testGraphVersion
|
||||
* @depends testPath
|
||||
* @depends testQueryParams
|
||||
*/
|
||||
public function testUrl() {
|
||||
$client = $this->createClientMock();
|
||||
$client->method('getDefaultGraphBaseDomain')
|
||||
->willReturn(Client::DEFAULT_GRAPH_BASE_DOMAIN);
|
||||
$request = new Request($client);
|
||||
$request->setGraphVersion('2.2');
|
||||
$request->setPath('/node/edge');
|
||||
$url = $request->getUrl();
|
||||
$this->assertEquals(
|
||||
parse_url($url, PHP_URL_SCHEME).'://', $request->getProtocol());
|
||||
$this->assertEquals(parse_url($url, PHP_URL_HOST), $request->getDomain());
|
||||
$this->assertEquals(
|
||||
parse_url($url, PHP_URL_PATH),
|
||||
sprintf("/v%s%s", $request->getGraphVersion(), $request->getPath()));
|
||||
$this->assertNull(parse_url($url, PHP_URL_QUERY));
|
||||
|
||||
// With query
|
||||
$params = array(
|
||||
'sdk' => 'PHP',
|
||||
'names' => 'abc,def',
|
||||
);
|
||||
$request->setQueryParams(new Parameters($params));
|
||||
$url = $request->getUrl();
|
||||
$parsed_query = Util::parseUrlQuery(parse_url($url, PHP_URL_QUERY));
|
||||
$this->assertEquals(
|
||||
$parsed_query, $request->getQueryParams()->getArrayCopy());
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
$response = $this->createResponseMock();
|
||||
$client = $this->createClientMock();
|
||||
$client->method('sendRequest')->willReturn($response);
|
||||
$request = new Request($client);
|
||||
$response_mirror = $request->execute();
|
||||
$this->assertTrue($response_mirror instanceof ResponseInterface);
|
||||
$this->assertTrue($response_mirror === $response);
|
||||
}
|
||||
}
|
||||
78
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Http/ResponseTest.php
vendored
Normal file
78
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Http/ResponseTest.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Http;
|
||||
|
||||
use FacebookAds\Http\Headers;
|
||||
use FacebookAds\Http\RequestInterface;
|
||||
use FacebookAds\Http\Response;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class ResponseTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
protected function createResponse() {
|
||||
return new Response();
|
||||
}
|
||||
|
||||
public function testRequest() {
|
||||
$response = $this->createResponse();
|
||||
$request = $this->createRequestMock();
|
||||
$response->setRequest($request);
|
||||
$request_mirror = $response->getRequest();
|
||||
$this->assertTrue($request_mirror instanceof RequestInterface);
|
||||
$this->assertTrue($request_mirror === $request);
|
||||
}
|
||||
|
||||
public function testStatusCode() {
|
||||
$response = $this->createResponse();
|
||||
$response->setStatusCode(200);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testHeaders() {
|
||||
$response = $this->createResponse();
|
||||
$headers = $this->createHeadersMock();
|
||||
$response->setHeaders($headers);
|
||||
$headers_mirror = $response->getHeaders();
|
||||
$this->assertTrue($headers_mirror instanceof Headers);
|
||||
$this->assertTrue($headers_mirror === $response->getHeaders());
|
||||
|
||||
// Default initialization
|
||||
$response = $this->createResponse();
|
||||
$headers_mirror = $response->getHeaders();
|
||||
$this->assertTrue($headers instanceof Headers);
|
||||
$this->assertTrue($headers_mirror === $response->getHeaders());
|
||||
}
|
||||
|
||||
public function testBodyContent() {
|
||||
$response = $this->createResponse();
|
||||
$body = '{"data":[]}';
|
||||
$response->setBody($body);
|
||||
$this->assertEquals($body, $response->getBody());
|
||||
$this->assertEquals(array('data' => array()), $response->getContent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Logger;
|
||||
|
||||
use FacebookAds\Logger\LoggerInterface;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
abstract class AbstractLoggerTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const VALUE_LOG_LEVEL = '<LEVEL>';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const VALUE_LOG_MESSAGE = '<MESSAGE>';
|
||||
|
||||
/**
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
abstract protected function createLogger();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Logger\CurlLogger;
|
||||
|
||||
use FacebookAds\Logger\CurlLogger\JsonAwareParameters;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class JsonAwareParametersTest extends AbstractUnitTestCase {
|
||||
use JsonAwareTestTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider parameterProvider
|
||||
* @param mixed $param_data
|
||||
*/
|
||||
public function testExtract($param_data) {
|
||||
foreach ((new JsonAwareParameters($param_data))->export() as $param) {
|
||||
$this->assertTrue(is_scalar($param) || is_null($param));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Logger\CurlLogger;
|
||||
|
||||
use FacebookAds\Logger\CurlLogger\JsonNode;
|
||||
|
||||
trait JsonAwareTestTrait {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function parameterProvider() {
|
||||
$base = array(
|
||||
'appsecret_proof' => '<APPSECRET_PROOF>',
|
||||
'access_token' => '<ACCESS_TOKEN>',
|
||||
'query_field' => 'query_value',
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$base + array(
|
||||
'json_field' => array(
|
||||
'query_field' => 'query_value',
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
$base + array(
|
||||
'json_field' => array(
|
||||
'query_field' => 'query_value',
|
||||
'query_field_1' => 'query_value_1',
|
||||
'query_field_2' => 'query_value_2',
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
$base + array(
|
||||
'json_field' => array(
|
||||
'query_field' => str_repeat('x', JsonNode::EXPLOSION_THRESHOLD + 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
$base + array(
|
||||
'json_field' => array(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
$base + array(
|
||||
'json_field' => array(
|
||||
'vector_value_1',
|
||||
'vector_value_2',
|
||||
'vector_value_3',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
new \StdClass(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Logger\CurlLogger;
|
||||
|
||||
use FacebookAds\Logger\CurlLogger\JsonNode;
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
|
||||
class JsonNodeTest extends AbstractUnitTestCase {
|
||||
use JsonAwareTestTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider parameterProvider
|
||||
* @param mixed $param_data
|
||||
*/
|
||||
public function testEncoding($param_data) {
|
||||
JsonNode::factory($param_data)->encode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidType() {
|
||||
JsonNode::factory(fopen('php://memory', 'r'))->encode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the sanity check for behaviour on empty children list
|
||||
* which should never happen as this is protected method
|
||||
*/
|
||||
public function testGetLastChildKey() {
|
||||
$object = JsonNode::factory(array());
|
||||
$method = new \ReflectionMethod($object, 'getLastChildKey');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertNull($method->invoke($object));
|
||||
|
||||
$method->setAccessible(false);
|
||||
}
|
||||
}
|
||||
141
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Logger/CurlLoggerTest.php
vendored
Normal file
141
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Logger/CurlLoggerTest.php
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Logger;
|
||||
|
||||
use FacebookAds\Http\RequestInterface;
|
||||
use FacebookAds\Logger\CurlLogger;
|
||||
use FacebookAds\Logger\CurlLogger\JsonAwareParameters;
|
||||
|
||||
class CurlLoggerTest extends AbstractLoggerTest {
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $handle;
|
||||
|
||||
public function setup(): void {
|
||||
$this->handle = fopen('php://temp', 'w+');
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
fclose($this->handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
protected function getHandle() {
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CurlLogger
|
||||
*/
|
||||
protected function createLogger() {
|
||||
return new CurlLogger($this->getHandle());
|
||||
}
|
||||
|
||||
protected function createRequestMock() {
|
||||
$query = $this->createParametersMock();
|
||||
$query->method('export')->willReturn(array(
|
||||
'appsecret_proof' => '<APPSECRET_PROOF>',
|
||||
'access_token' => '<ACCESS_TOKEN>',
|
||||
'query_field' => 'query_value',
|
||||
));
|
||||
|
||||
$body = $this->createParametersMock();
|
||||
$body->method('export')->willReturn(array(
|
||||
'body_field' => 'body_value',
|
||||
));
|
||||
|
||||
$files = $this->createParametersMock();
|
||||
$files->method('export')->willReturn(array(
|
||||
'file_field' => 'filepath',
|
||||
));
|
||||
|
||||
$request = parent::createRequestMock();
|
||||
$request->method('getQueryParams')->willReturn($query);
|
||||
$request->method('getBodyParams')->willReturn($body);
|
||||
$request->method('getFileParams')->willReturn($files);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function testLog() {
|
||||
$this->createLogger()->log(
|
||||
static::VALUE_LOG_LEVEL, static::VALUE_LOG_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function logRequestProvider() {
|
||||
return array(
|
||||
array(RequestInterface::METHOD_GET),
|
||||
array(RequestInterface::METHOD_POST),
|
||||
array(RequestInterface::METHOD_PUT),
|
||||
array(RequestInterface::METHOD_DELETE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider logRequestProvider
|
||||
* @param string $http_method
|
||||
*/
|
||||
public function testLogRequest($http_method) {
|
||||
$request = $this->createRequestMock();
|
||||
$request->method('getMethod')->willReturn($http_method);
|
||||
|
||||
$logger = $this->createLogger();
|
||||
$logger->logRequest(static::VALUE_LOG_LEVEL, $request);
|
||||
}
|
||||
|
||||
public function testLogResponse() {
|
||||
$this->createLogger()->logResponse(
|
||||
static::VALUE_LOG_LEVEL, $this->createResponseMock());
|
||||
}
|
||||
|
||||
public function testJsonPrettyPrint() {
|
||||
$logger = $this->createLogger();
|
||||
$this->assertFalse($logger->isJsonPrettyPrint());
|
||||
$logger->setJsonPrettyPrint(true);
|
||||
$this->assertTrue($logger->isJsonPrettyPrint());
|
||||
|
||||
$query = new JsonAwareParameters(array(
|
||||
'json_field' => array_fill(0, 3, 'json_value'),
|
||||
));
|
||||
$body = $files = $this->createParametersMock();
|
||||
|
||||
$request = parent::createRequestMock();
|
||||
$request->method('getQueryParams')->willReturn($query);
|
||||
$request->method('getBodyParams')->willReturn($body);
|
||||
$request->method('getFileParams')->willReturn($files);
|
||||
|
||||
$logger->logRequest(static::VALUE_LOG_LEVEL, $request);
|
||||
|
||||
$logger->setJsonPrettyPrint(false);
|
||||
$this->assertFalse($logger->isJsonPrettyPrint());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Logger;
|
||||
|
||||
use FacebookAds\Logger\NullLogger;
|
||||
|
||||
class NullLoggerTest extends AbstractLoggerTest {
|
||||
|
||||
protected function createLogger() {
|
||||
return new NullLogger();
|
||||
}
|
||||
|
||||
public function testLog() {
|
||||
$this->createLogger()->log(
|
||||
static::VALUE_LOG_LEVEL, static::VALUE_LOG_MESSAGE);
|
||||
}
|
||||
|
||||
public function testLogRequest() {
|
||||
$this->createLogger()->logRequest(
|
||||
static::VALUE_LOG_LEVEL, $this->createRequestMock());
|
||||
}
|
||||
|
||||
public function testLogResponse() {
|
||||
$this->createLogger()->logResponse(
|
||||
static::VALUE_LOG_LEVEL, $this->createResponseMock());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
|
||||
abstract class AbstractAsyncJobTestCase extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_async_jobs');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $job
|
||||
* @param int $timeout
|
||||
* @param int $interval
|
||||
*/
|
||||
protected function waitTillJobComplete(
|
||||
AbstractCrudObject $job, $timeout = 60, $interval = 2) {
|
||||
|
||||
$end = time() + $timeout;
|
||||
do {
|
||||
if ($job->getSelf()->isComplete()) {
|
||||
return;
|
||||
}
|
||||
sleep($interval);
|
||||
} while (time() <= $end);
|
||||
|
||||
$this->markTestSkipped(
|
||||
"Async Job timed out. Timeout: {$timeout}, Interval: {$interval}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAdsTest\Object\EmptyCrudObject;
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
|
||||
class AbstractCrudObjectTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCreationWithNull() {
|
||||
$this->checkCreationSuccessWithID(null);
|
||||
}
|
||||
|
||||
public function testCreationWithNegativeId() {
|
||||
$this->checkCreationFailureWithID(-1234123);
|
||||
}
|
||||
|
||||
public function testCreationWithPositiveId() {
|
||||
$this->checkCreationSuccessWithID(100007309086878);
|
||||
}
|
||||
|
||||
public function testCreationWithCorrectStringId() {
|
||||
$this->checkCreationSuccessWithID('100007309086878');
|
||||
}
|
||||
|
||||
public function testCreationWithIncorrectNegativeStringId() {
|
||||
$this->checkCreationFailureWithID('-1234123');
|
||||
}
|
||||
|
||||
public function testCreationWithIncorrectStringId() {
|
||||
$this->checkCreationFailureWithID('1.234e10');
|
||||
}
|
||||
|
||||
public function testCreationSuccessWithAct_() {
|
||||
$this->checkCreationSuccessWithID('act_12341521352312');
|
||||
}
|
||||
|
||||
public function testCreationFailureWithAct_() {
|
||||
$this->checkCreationFailureWithID('act_1.1234e10');
|
||||
}
|
||||
|
||||
public function testCreationWithOverFlowInt() {
|
||||
$this->checkCreationFailureWithID(PHP_INT_MAX+1);
|
||||
}
|
||||
private function checkCreationSuccessWithID($id) {
|
||||
new EmptyCrudObject($id);
|
||||
}
|
||||
|
||||
private function checkCreationFailureWithID($id) {
|
||||
$this->assertInvalidArgumentException($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function assertInvalidArgumentException(mixed $id) {
|
||||
$has_throw_exception = false;
|
||||
try {
|
||||
new EmptyCrudObject($id);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$has_throw_exception = true;
|
||||
}
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Cursor;
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
use FacebookAds\Object\AbstractObject;
|
||||
use FacebookAds\Object\AbstractArchivableCrudObject;
|
||||
use FacebookAds\Object\AdLabel;
|
||||
use FacebookAds\Object\CanRedownloadInterface;
|
||||
use FacebookAds\Object\Fields\AbstractArchivableCrudObjectFields;
|
||||
use FacebookAds\Object\Fields\AdLabelFields;
|
||||
use FacebookAds\Object\Traits\AdLabelAwareCrudObjectTrait;
|
||||
use FacebookAdsTest\AbstractIntegrationTestCase;
|
||||
|
||||
abstract class AbstractCrudObjectTestCase extends AbstractIntegrationTestCase {
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
* @param array $params
|
||||
*/
|
||||
public function assertCanCreate(
|
||||
AbstractCrudObject $subject, array $params = array()) {
|
||||
|
||||
if ($subject instanceof CanRedownloadInterface) {
|
||||
$params[CanRedownloadInterface::PARAM_REDOWNLOAD] = true;
|
||||
}
|
||||
|
||||
$this->assertEmpty($subject->{AbstractCrudObject::FIELD_ID});
|
||||
$subject->create($params);
|
||||
$this->assertNotEmpty($subject->{AbstractCrudObject::FIELD_ID});
|
||||
|
||||
/** @var AbstractCrudObject $subject */
|
||||
if ($subject instanceof CanRedownloadInterface) {
|
||||
$non_null_count = 0;
|
||||
foreach ($subject->getData() as $key => $value) {
|
||||
if ($key !== AbstractCrudObject::FIELD_ID && $value !== null) {
|
||||
++$non_null_count;
|
||||
// Normalize assert function behaviour with non-redownloadable objects
|
||||
$subject->{$key} = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertGreaterThan(0, $non_null_count);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $object
|
||||
* @return AbstractCrudObject
|
||||
*/
|
||||
protected function getEmptyClone(AbstractCrudObject $object) {
|
||||
$fqn = get_class($object);
|
||||
return new $fqn(
|
||||
$object->{AbstractCrudObject::FIELD_ID},
|
||||
$object->getParentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
*/
|
||||
public function assertCannotCreate(AbstractCrudObject $subject) {
|
||||
$has_throw_exception = false;
|
||||
try {
|
||||
$subject->create();
|
||||
} catch (\Exception $e) {
|
||||
$has_throw_exception = true;
|
||||
}
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
*/
|
||||
public function assertCanRead(AbstractCrudObject $subject) {
|
||||
$this->assertNotEmpty($subject->{AbstractCrudObject::FIELD_ID});
|
||||
$mirror = $this->getEmptyClone($subject);
|
||||
$mirror->read();
|
||||
$this->assertEquals(
|
||||
$subject->{AbstractCrudObject::FIELD_ID},
|
||||
$mirror->{AbstractCrudObject::FIELD_ID});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
* @param string $connection_name
|
||||
* @param array $fields
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
*/
|
||||
protected function fetchConnection(
|
||||
AbstractCrudObject $subject,
|
||||
$connection_name,
|
||||
array $fields = array(),
|
||||
array $params = array()) {
|
||||
|
||||
$this->assertNotEmpty($subject->{AbstractCrudObject::FIELD_ID});
|
||||
$mirror = $this->getEmptyClone($subject);
|
||||
return call_user_func(array($mirror, $connection_name), $fields, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
* @param string $connection_name
|
||||
* @param array $fields
|
||||
* @param array $params
|
||||
*/
|
||||
public function assertCanFetchConnection(
|
||||
AbstractCrudObject $subject,
|
||||
$connection_name,
|
||||
array $fields = array(),
|
||||
array $params = array()) {
|
||||
|
||||
$result = $this->fetchConnection(
|
||||
$subject, $connection_name, $fields, $params);
|
||||
|
||||
$this->assertTrue(
|
||||
$result instanceof Cursor
|
||||
|| $result instanceof AbstractObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
* @param string $connection_name
|
||||
* @param array $fields
|
||||
* @param array $params
|
||||
*/
|
||||
public function assertCanFetchConnectionAsArray(
|
||||
AbstractCrudObject $subject,
|
||||
$connection_name,
|
||||
array $fields = array(),
|
||||
array $params = array()) {
|
||||
|
||||
$result = $this->fetchConnection(
|
||||
$subject, $connection_name, $fields, $params);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
|
||||
foreach ($result as $object) {
|
||||
if (!$object instanceof AbstractObject) {
|
||||
$this->fail("Not an instance of AbstractObject");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $object
|
||||
* @param array $diff
|
||||
* @return array
|
||||
*/
|
||||
private function extractDiffFromObject(
|
||||
AbstractCrudObject $object,
|
||||
array $diff) {
|
||||
|
||||
$sub_diff = array();
|
||||
foreach ($object->getData() as $key => $val) {
|
||||
if (array_key_exists($key, $diff)) {
|
||||
$sub_diff[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $sub_diff + array_combine(
|
||||
array_keys($diff),
|
||||
array_fill(0, count($diff), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
* @param array $diff Data to be changed in the object
|
||||
*/
|
||||
public function assertCanUpdate(
|
||||
AbstractCrudObject $subject,
|
||||
array $diff) {
|
||||
|
||||
$this->assertNotEmpty($subject->{AbstractCrudObject::FIELD_ID});
|
||||
$mirror = $this->getEmptyClone($subject);
|
||||
$mirror->read();
|
||||
$mirror->setData($diff);
|
||||
$mirror->update();
|
||||
$this->assertNotEmpty($subject->id);
|
||||
$mirror2 = $this->getEmptyClone($subject);
|
||||
$mirror2->read(array_keys($diff));
|
||||
$this->assertEquals(
|
||||
$this->extractDiffFromObject($mirror, $diff),
|
||||
$this->extractDiffFromObject($mirror2, $diff));
|
||||
|
||||
$subject->read(array_keys($diff));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
*/
|
||||
public function assertCannotUpdate(AbstractCrudObject $subject) {
|
||||
$has_throw_exception = false;
|
||||
try {
|
||||
$subject->update();
|
||||
} catch (\Exception $e) {
|
||||
$has_throw_exception = true;
|
||||
}
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractArchivableCrudObject $subject
|
||||
* @param string $status
|
||||
*/
|
||||
private function assertArchivableCrudObjectStatus(
|
||||
AbstractArchivableCrudObject $subject, $status) {
|
||||
|
||||
$fields = array(
|
||||
AbstractArchivableCrudObjectFields::CONFIGURED_STATUS,
|
||||
AbstractArchivableCrudObjectFields::EFFECTIVE_STATUS,
|
||||
);
|
||||
|
||||
$mirror = $this->getEmptyClone($subject);
|
||||
$mirror->read($fields);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$this->assertEquals($mirror->{$field}, $status);
|
||||
$subject->{$field} = $status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
*/
|
||||
public function assertCanDelete(AbstractCrudObject $subject) {
|
||||
$this->assertNotEmpty($subject->{AbstractCrudObject::FIELD_ID});
|
||||
$subject->deleteSelf();
|
||||
if ($subject instanceof AbstractArchivableCrudObject) {
|
||||
$this->assertArchivableCrudObjectStatus(
|
||||
$subject, AbstractArchivableCrudObject::STATUS_DELETED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractCrudObject $subject
|
||||
*/
|
||||
public function assertCannotDelete(AbstractCrudObject $subject) {
|
||||
$has_throw_exception = false;
|
||||
try {
|
||||
$subject->deleteSelf();
|
||||
} catch (\Exception $e) {
|
||||
$has_throw_exception = true;
|
||||
}
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractArchivableCrudObject $subject
|
||||
*/
|
||||
public function assertCanArchive(AbstractArchivableCrudObject $subject) {
|
||||
$this->assertNotEmpty($subject->{AbstractCrudObject::FIELD_ID});
|
||||
$subject->archiveSelf();
|
||||
if ($subject instanceof AbstractArchivableCrudObject) {
|
||||
$this->assertArchivableCrudObjectStatus(
|
||||
$subject, AbstractArchivableCrudObject::STATUS_ARCHIVED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $response_content
|
||||
*/
|
||||
public function assertSuccessResponse(array $response_content) {
|
||||
$this->assertTrue(is_array($response_content));
|
||||
$this->assertArrayHasKey('success', $response_content);
|
||||
$this->assertTrue($response_content['success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AdLabelAwareCrudObjectTrait|AbstractCrudObject $object
|
||||
*/
|
||||
public function assertCanBeLabeled(AbstractCrudObject $object) {
|
||||
$label = new AdLabel(null, $this->getConfig()->accountId);
|
||||
$label->{AdLabelFields::NAME} = $this->getConfig()->testRunId;
|
||||
$label->create();
|
||||
|
||||
/** @var AdLabelAwareCrudObjectTrait|AbstractCrudObject $mirror */
|
||||
$mirror = $this->getEmptyClone($object);
|
||||
$mirror->addAdLabels(array($label->{AdLabelFields::ID}));
|
||||
|
||||
$mirror = $this->getEmptyClone($object);
|
||||
$mirror->read(array('adlabels'));
|
||||
$this->assertCount(1, $mirror->{'adlabels'});
|
||||
|
||||
$mirror = $this->getEmptyClone($object);
|
||||
$mirror->removeAdLabels(array($label->{AdLabelFields::ID}));
|
||||
$mirror->read(array('adlabels'));
|
||||
$this->assertNull($mirror->{'adlabels'});
|
||||
|
||||
$label->deleteSelf();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdAccountGroup;
|
||||
use FacebookAds\Object\Fields\AdAccountGroupFields;
|
||||
|
||||
class AdAccountGroupTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrudAccess() {
|
||||
$group = new AdAccountGroup();
|
||||
$group->{AdAccountGroupFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->assertCanCreate($group);
|
||||
$this->assertCanRead($group);
|
||||
$this->assertCanUpdate($group, array(
|
||||
AdAccountGroupFields::NAME => $this->getConfig()->testRunId.' updated'));
|
||||
|
||||
$this->assertCanFetchConnectionAsArray($group, 'getUsers');
|
||||
$this->assertCanFetchConnectionAsArray($group, 'getAdAccounts');
|
||||
|
||||
$this->assertCanDelete($group);
|
||||
}
|
||||
}
|
||||
165
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdAccountTest.php
vendored
Normal file
165
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdAccountTest.php
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\AdCreative;
|
||||
use FacebookAds\Object\AdLabel;
|
||||
use FacebookAds\Object\Fields\AdAccountFields;
|
||||
use FacebookAds\Object\Fields\AdCreativeFields;
|
||||
use FacebookAds\Object\Fields\AdLabelFields;
|
||||
use FacebookAds\Object\Values\AdAccountRoles;
|
||||
use FacebookAds\Object\Fields\TargetingSpecsFields;
|
||||
use FacebookAds\Object\TargetingSpecs;
|
||||
use FacebookAds\Object\Values\AdFormats;
|
||||
use FacebookAds\Object\Values\OptimizationGoals;
|
||||
|
||||
class AdAccountTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var AdLabel
|
||||
*/
|
||||
protected $adLabel;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$this->adLabel = new AdLabel(null, $this->getConfig()->accountId);
|
||||
$this->adLabel->{AdLabelFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->adLabel->create();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->adLabel !== null) {
|
||||
$this->adLabel->deleteSelf();
|
||||
$this->adLabel = null;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrud() {
|
||||
$account = new AdAccount($this->getConfig()->accountId);
|
||||
|
||||
$this->assertCanRead($account);
|
||||
$name = $account->read(array(AdAccountFields::NAME))
|
||||
->{AdAccountFields::NAME};
|
||||
$this->assertCanUpdate(
|
||||
$account,
|
||||
array(AdAccountFields::NAME => $this->getConfig()->testRunId));
|
||||
|
||||
// Restore original account name
|
||||
$account->{AdAccountFields::NAME} = $name;
|
||||
$account->save();
|
||||
|
||||
$this->assertCannotDelete($account);
|
||||
|
||||
$targeting = new TargetingSpecs();
|
||||
$targeting->setData(array(
|
||||
TargetingSpecsFields::GEO_LOCATIONS =>
|
||||
array('countries' => array('US', 'JP')),
|
||||
TargetingSpecsFields::GENDERS => array(1),
|
||||
TargetingSpecsFields::AGE_MIN => 20,
|
||||
TargetingSpecsFields::AGE_MAX => 24,
|
||||
));
|
||||
|
||||
$creative = (new AdCreative())->setData(array(
|
||||
AdCreativeFields::TITLE => 'My Test Creative',
|
||||
AdCreativeFields::BODY => 'My Test Ad Creative Body',
|
||||
AdCreativeFields::OBJECT_URL => 'https://www.facebook.com/facebook',
|
||||
));
|
||||
|
||||
$targeting_params = array(
|
||||
'targeting_spec' => $targeting->exportData(),
|
||||
);
|
||||
|
||||
$label_params = array(
|
||||
'ad_label_ids' => array(
|
||||
$this->adLabel->{AdLabelFields::ID},
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertCanFetchConnection($account, 'getActivities');
|
||||
$this->assertCanFetchConnection($account, 'getAdUsers');
|
||||
$this->assertCanFetchConnection($account, 'getCampaigns');
|
||||
$this->assertCanFetchConnection($account, 'getAdSets');
|
||||
$this->assertCanFetchConnection($account, 'getAds');
|
||||
$this->assertCanFetchConnection($account, 'getAdCreatives');
|
||||
$this->assertCanFetchConnection($account, 'getAdImages');
|
||||
$this->assertCanFetchConnection($account, 'getAdsPixels');
|
||||
$this->assertCanFetchConnection($account, 'getAdVideos');
|
||||
$this->assertCanFetchConnection($account, 'getBroadCategoryTargeting');
|
||||
$this->assertCanFetchConnection($account, 'getCustomAudiences');
|
||||
$this->assertCanFetchConnection($account, 'getConversionPixels');
|
||||
$this->assertCanFetchConnection($account, 'getPartnerCategories');
|
||||
$this->assertCanFetchConnection($account, 'getRateCards');
|
||||
$this->assertCanFetchConnection(
|
||||
$account,
|
||||
'getReachEstimate',
|
||||
array(),
|
||||
array_merge(
|
||||
$targeting_params,
|
||||
array(
|
||||
'optimize_for' => OptimizationGoals::OFFSITE_CONVERSIONS,
|
||||
)));
|
||||
|
||||
if (!$this->shouldSkipTest('no_reach_and_frequency')) {
|
||||
$this->assertCanFetchConnection($account, 'getReachFrequencyPredictions');
|
||||
}
|
||||
|
||||
$this->assertCanFetchConnection(
|
||||
$account, 'getTargetingDescription', array(), $targeting_params);
|
||||
|
||||
$this->assertCanFetchConnection($account, 'getTransactions');
|
||||
$this->assertCanFetchConnection($account, 'getAdPreviews', array(), array(
|
||||
'ad_format' => AdFormats::DESKTOP_FEED_STANDARD,
|
||||
'creative' => $creative->exportData(),
|
||||
));
|
||||
$this->assertCanFetchConnection($account, 'getInsights');
|
||||
$this->assertCanFetchConnection($account, 'getInsightsAsync');
|
||||
$this->assertCanFetchConnection($account, 'getAgencies');
|
||||
$this->assertCanFetchConnection($account, 'getMinimumBudgets');
|
||||
$this->assertCanFetchConnection($account, 'getAdLabels');
|
||||
$this->assertCanFetchConnection(
|
||||
$account, 'getCampaignsByLabel', array(), $label_params);
|
||||
$this->assertCanFetchConnection(
|
||||
$account, 'getAdSetsByLabel', array(), $label_params);
|
||||
$this->assertCanFetchConnection(
|
||||
$account, 'getAdsByLabel', array(), $label_params);
|
||||
$this->assertCanFetchConnection(
|
||||
$account, 'getAdCreativesByLabel', array(), $label_params);
|
||||
|
||||
|
||||
if (!$this->getSkippableFeaturesManager()
|
||||
->isSkipKey('no_business_manager')) {
|
||||
|
||||
$account->grantAgencyAcccess(
|
||||
$this->getConfig()->secondaryBusinessId,
|
||||
array(AdAccountRoles::GENERAL_USER));
|
||||
|
||||
$account->revokeAgencyAccess($this->getConfig()->secondaryBusinessId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdConversionPixel;
|
||||
use FacebookAds\Object\Fields\AdConversionPixelFields;
|
||||
|
||||
class AdConversionPixelTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrud() {
|
||||
$conversionPixel = new AdConversionPixel(
|
||||
null, $this->getConfig()->accountId);
|
||||
$conversionPixel->{AdConversionPixelFields::NAME}
|
||||
= $this->getConfig()->testRunId;
|
||||
$conversionPixel->{AdConversionPixelFields::TAG} = 'checkout';
|
||||
|
||||
$this->assertCanCreate($conversionPixel);
|
||||
$this->assertCanRead($conversionPixel);
|
||||
$this->assertCanUpdate(
|
||||
$conversionPixel,
|
||||
array(
|
||||
AdConversionPixelFields::TAG => 'add_to_cart',
|
||||
));
|
||||
$this->assertCanDelete($conversionPixel);
|
||||
}
|
||||
}
|
||||
111
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdCreativeTest.php
vendored
Normal file
111
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdCreativeTest.php
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdCreative;
|
||||
use FacebookAds\Object\AdImage;
|
||||
use FacebookAds\Object\ObjectStorySpec;
|
||||
use FacebookAds\Object\ObjectStory\LinkData;
|
||||
use FacebookAds\Object\ObjectStory\AttachmentData;
|
||||
use FacebookAds\Object\Fields\AdCreativeFields;
|
||||
use FacebookAds\Object\Fields\AdImageFields;
|
||||
use FacebookAds\Object\Fields\ObjectStorySpecFields;
|
||||
use FacebookAds\Object\Fields\ObjectStory\LinkDataFields;
|
||||
use FacebookAds\Object\Fields\ObjectStory\AttachmentDataFields;
|
||||
|
||||
class AdCreativeTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrud() {
|
||||
$creative = new AdCreative(null, $this->getConfig()->accountId);
|
||||
$creative->{AdCreativeFields::TITLE} = 'My Test Ad';
|
||||
$creative->{AdCreativeFields::NAME} = 'My Test Ad';
|
||||
$creative->{AdCreativeFields::BODY} = 'My Test Ad Body';
|
||||
$creative->{AdCreativeFields::OBJECT_ID} = $this->getConfig()->pageId;
|
||||
$this->assertCanCreate($creative);
|
||||
$this->assertCanRead($creative);
|
||||
$this->assertCanUpdate(
|
||||
$creative,
|
||||
array(
|
||||
AdCreativeFields::NAME => 'My Test Ad '. $this->getConfig()->testRunId,
|
||||
));
|
||||
$this->assertCanBeLabeled($creative);
|
||||
$this->assertCanDelete($creative);
|
||||
}
|
||||
|
||||
public function testMultiProductObjectSpec() {
|
||||
// Create a new AdCreative
|
||||
$creative = new AdCreative(null, $this->getConfig()->accountId);
|
||||
$creative->{AdCreativeFields::NAME} = 'Multi Product Ad Creative';
|
||||
|
||||
// Create a new ObjectStorySpec to create an unpublished post
|
||||
$story = new ObjectStorySpec();
|
||||
$story->{ObjectStorySpecFields::PAGE_ID} = $this->getConfig()->pageId;
|
||||
|
||||
// Create LinkData object representing data for a link page post
|
||||
$link = new LinkData();
|
||||
$link->{LinkDataFields::LINK} = $this->getConfig()->appUrl;
|
||||
$link->{LinkDataFields::CAPTION} = 'My Caption';
|
||||
|
||||
// Upload a test image to use in Attachments
|
||||
$adImage = new AdImage(null, $this->getConfig()->accountId);
|
||||
$adImage->{AdImageFields::FILENAME} = $this->getConfig()->testImagePath;
|
||||
$adImage->save();
|
||||
|
||||
// Create 3 products as this will be a multi-product ad
|
||||
$product1 = (new AttachmentData())->setData(array(
|
||||
AttachmentDataFields::LINK => $this->getConfig()->appUrl.'p1',
|
||||
AttachmentDataFields::IMAGE_HASH => $adImage->hash,
|
||||
AttachmentDataFields::NAME => 'Product 1',
|
||||
AttachmentDataFields::DESCRIPTION => '$100',
|
||||
));
|
||||
|
||||
$product2 = (new AttachmentData())->setData(array(
|
||||
AttachmentDataFields::LINK => $this->getConfig()->appUrl.'p2',
|
||||
AttachmentDataFields::IMAGE_HASH => $adImage->hash,
|
||||
AttachmentDataFields::NAME => 'Product 2',
|
||||
AttachmentDataFields::DESCRIPTION => '$200',
|
||||
));
|
||||
|
||||
$product3 = (new AttachmentData())->setData(array(
|
||||
AttachmentDataFields::LINK => $this->getConfig()->appUrl.'p3',
|
||||
AttachmentDataFields::IMAGE_HASH => $adImage->hash,
|
||||
AttachmentDataFields::NAME => 'Product 3',
|
||||
AttachmentDataFields::DESCRIPTION => '$300',
|
||||
));
|
||||
|
||||
// Add the products into the child attachments
|
||||
$link->{LinkDataFields::CHILD_ATTACHMENTS} = array(
|
||||
$product1,
|
||||
$product2,
|
||||
$product3,
|
||||
);
|
||||
|
||||
$story->{ObjectStorySpecFields::LINK_DATA} = $link;
|
||||
$creative->{AdCreativeFields::OBJECT_STORY_SPEC} = $story;
|
||||
|
||||
$this->assertCanCreate($creative);
|
||||
$this->assertCanDelete($creative);
|
||||
}
|
||||
}
|
||||
61
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdImageTest.php
vendored
Normal file
61
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdImageTest.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdImage;
|
||||
use FacebookAds\Object\Fields\AdImageFields;
|
||||
|
||||
class AdImageTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrud() {
|
||||
$image = new AdImage(null, $this->getConfig()->accountId);
|
||||
$image->{AdImageFields::FILENAME} = $this->getConfig()->testImagePath;
|
||||
$this->assertCanCreate($image);
|
||||
$this->assertCanRead($image);
|
||||
$this->assertCannotUpdate($image);
|
||||
$this->assertCanDelete($image);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testZipFileInNormalCreate() {
|
||||
$image = new AdImage(null, $this->getConfig()->accountId);
|
||||
$image->{AdImageFields::FILENAME}
|
||||
= $this->getConfig()->testZippedImagesPath;
|
||||
$image->create();
|
||||
}
|
||||
|
||||
public function testBulkZipUpload() {
|
||||
$images = AdImage::createFromZip(
|
||||
$this->getConfig()->testZippedImagesPath,
|
||||
$this->getConfig()->accountId);
|
||||
$this->assertTrue(is_array($images));
|
||||
|
||||
foreach ($images as $image) {
|
||||
$this->assertCanDelete($image);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdLabelTest.php
vendored
Normal file
44
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdLabelTest.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdLabel;
|
||||
use FacebookAds\Object\Fields\AdLabelFields;
|
||||
|
||||
class AdLabelTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrudAccess() {
|
||||
$label = new AdLabel(null, $this->getConfig()->accountId);
|
||||
$label->{AdLabelFields::NAME} = $this->getConfig()->testRunId;
|
||||
|
||||
$this->assertCanCreate($label);
|
||||
$this->assertCanRead($label);
|
||||
$this->assertCanUpdate(
|
||||
$label,
|
||||
array(AdLabelFields::NAME => $this->getConfig()->testRunId . ' updated'));
|
||||
|
||||
$this->assertCanDelete($label);
|
||||
}
|
||||
}
|
||||
212
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdPreviewTest.php
vendored
Normal file
212
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdPreviewTest.php
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdImage;
|
||||
use FacebookAds\Object\AdCreative;
|
||||
use FacebookAds\Object\Ad;
|
||||
use FacebookAds\Object\AdSet;
|
||||
use FacebookAds\Object\Campaign;
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\Fields\AdImageFields;
|
||||
use FacebookAds\Object\TargetingSpecs;
|
||||
use FacebookAds\Object\Fields\AdPreviewFields;
|
||||
use FacebookAds\Object\Fields\AdCreativeFields;
|
||||
use FacebookAds\Object\Fields\AdFields;
|
||||
use FacebookAds\Object\Fields\AdSetFields;
|
||||
use FacebookAds\Object\Fields\CampaignFields;
|
||||
use FacebookAds\Object\Fields\TargetingSpecsFields;
|
||||
use FacebookAds\Object\Values\AdFormats;
|
||||
use FacebookAds\Object\Values\BillingEvents;
|
||||
use FacebookAds\Object\Values\OptimizationGoals;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
|
||||
class AdPreviewTest extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @var Campaign
|
||||
*/
|
||||
protected $campaign;
|
||||
|
||||
/**
|
||||
* @var AdSet
|
||||
*/
|
||||
protected $adSet;
|
||||
|
||||
/**
|
||||
* @var Ad
|
||||
*/
|
||||
protected $ad;
|
||||
|
||||
/**
|
||||
* @var AdImage
|
||||
*/
|
||||
protected $adImage;
|
||||
|
||||
/**
|
||||
* @var AdCreative
|
||||
*/
|
||||
protected $adCreative;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_payment_method');
|
||||
}
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$targeting = new TargetingSpecs();
|
||||
$targeting->{TargetingSpecsFields::GEO_LOCATIONS}
|
||||
= array('countries' => array('US'));
|
||||
|
||||
$this->campaign = new Campaign(null, $this->getConfig()->accountId);
|
||||
$this->campaign->{CampaignFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->campaign->create();
|
||||
|
||||
$this->adSet = new AdSet(null, $this->getConfig()->accountId);
|
||||
$this->adSet->{AdSetFields::CAMPAIGN_ID}
|
||||
= (int) $this->campaign->{AdSetFields::ID};
|
||||
$this->adSet->{AdSetFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->adSet->{AdSetFields::DAILY_BUDGET} = '150';
|
||||
$this->adSet->{AdSetFields::START_TIME}
|
||||
= (new \DateTime("+1 week"))->format(\DateTime::ISO8601);
|
||||
$this->adSet->{AdSetFields::END_TIME}
|
||||
= (new \DateTime("+2 week"))->format(\DateTime::ISO8601);
|
||||
$this->adSet->{AdFields::TARGETING} = $targeting;
|
||||
$this->adSet->{AdSetFields::OPTIMIZATION_GOAL} = OptimizationGoals::REACH;
|
||||
$this->adSet->{AdSetFields::BILLING_EVENT} = BillingEvents::IMPRESSIONS;
|
||||
$this->adSet->{AdSetFields::BID_AMOUNT} = 2;
|
||||
$this->adSet->create(array(
|
||||
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
|
||||
));
|
||||
|
||||
$this->adImage = new AdImage(null, $this->getConfig()->accountId);
|
||||
$this->adImage->{AdImageFields::FILENAME}
|
||||
= $this->getConfig()->testImagePath;
|
||||
$this->adImage->save();
|
||||
|
||||
$this->adCreative = new AdCreative(null, $this->getConfig()->accountId);
|
||||
$this->adCreative->{AdCreativeFields::TITLE} = 'My Test Ad';
|
||||
$this->adCreative->{AdCreativeFields::BODY} = 'My Test Ad Body';
|
||||
$this->adCreative->{AdCreativeFields::OBJECT_ID}
|
||||
= $this->getConfig()->pageId;
|
||||
$this->adCreative->{AdCreativeFields::IMAGE_HASH}
|
||||
= $this->adImage->{AdImageFields::HASH};
|
||||
$this->adCreative->create();
|
||||
|
||||
$this->ad = new Ad(null, $this->getConfig()->accountId);
|
||||
$this->ad->{AdFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->ad->{AdFields::ADSET_ID}
|
||||
= (int) $this->adSet->{AdSetFields::ID};
|
||||
$this->ad->{AdFields::CREATIVE}
|
||||
= array('creative_id' => $this->adCreative->{AdCreativeFields::ID});
|
||||
$this->ad->create(array(
|
||||
Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
|
||||
));
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
|
||||
if ($this->ad) {
|
||||
$this->ad->deleteSelf();
|
||||
$this->ad = null;
|
||||
}
|
||||
|
||||
if ($this->adSet) {
|
||||
$this->adSet->deleteSelf();
|
||||
$this->adSet = null;
|
||||
}
|
||||
|
||||
if ($this->campaign) {
|
||||
$this->campaign->deleteSelf();
|
||||
$this->campaign = null;
|
||||
}
|
||||
|
||||
if ($this->adCreative) {
|
||||
$this->adCreative->deleteSelf();
|
||||
$this->adCreative = null;
|
||||
}
|
||||
|
||||
if ($this->adImage) {
|
||||
$this->adImage->deleteSelf();
|
||||
$this->adImage = null;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testAdPreviews() {
|
||||
// Preview with actual creative
|
||||
$previews = $this->adCreative->getAdPreviews(
|
||||
array(),
|
||||
array(
|
||||
AdPreviewFields::AD_FORMAT => AdFormats::RIGHT_COLUMN_STANDARD
|
||||
)
|
||||
);
|
||||
$this->assertNotEquals(0, $previews->count());
|
||||
$preview = $previews->offsetGet(0);
|
||||
$this->assertRegExp(
|
||||
'/iframe/',
|
||||
$preview->{AdPreviewFields::BODY}
|
||||
);
|
||||
|
||||
// Preview with actual adgroup
|
||||
$previews = $this->ad->getAdPreviews(
|
||||
array(),
|
||||
array(
|
||||
AdPreviewFields::AD_FORMAT => AdFormats::RIGHT_COLUMN_STANDARD
|
||||
)
|
||||
);
|
||||
$this->assertNotEquals(0, $previews->count());
|
||||
$preview = $previews->offsetGet(0);
|
||||
$this->assertRegExp(
|
||||
'/iframe/',
|
||||
$preview->{AdPreviewFields::BODY}
|
||||
);
|
||||
|
||||
// Preview with creative specs
|
||||
$account = new AdAccount($this->getConfig()->accountId);
|
||||
$previews = $account->getAdPreviews(
|
||||
array(),
|
||||
array(
|
||||
AdPreviewFields::CREATIVE => array(
|
||||
AdCreativeFields::BODY => 'Testing the creative preview',
|
||||
AdCreativeFields::OBJECT_ID => $this->getConfig()->pageId,
|
||||
),
|
||||
AdPreviewFields::AD_FORMAT => AdFormats::RIGHT_COLUMN_STANDARD,
|
||||
)
|
||||
);
|
||||
$this->assertNotEquals(0, $previews->count());
|
||||
$preview = $previews->offsetGet(0);
|
||||
$this->assertRegExp(
|
||||
'/iframe/',
|
||||
$preview->{AdPreviewFields::BODY}
|
||||
);
|
||||
}
|
||||
}
|
||||
93
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdSetTest.php
vendored
Normal file
93
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdSetTest.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Campaign;
|
||||
use FacebookAds\Object\AdSet;
|
||||
use FacebookAds\Object\Fields\CampaignFields;
|
||||
use FacebookAds\Object\Fields\AdSetFields;
|
||||
use FacebookAds\Object\Fields\TargetingSpecsFields;
|
||||
use FacebookAds\Object\TargetingSpecs;
|
||||
use FacebookAds\Object\Values\BillingEvents;
|
||||
use FacebookAds\Object\Values\OptimizationGoals;
|
||||
|
||||
class AdSetTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var Campaign
|
||||
*/
|
||||
protected $campaign;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$this->campaign = new Campaign(null, $this->getConfig()->accountId);
|
||||
$this->campaign->{CampaignFields::NAME}
|
||||
= $this->getConfig()->testRunId;
|
||||
$this->campaign->create();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->campaign->deleteSelf();
|
||||
$this->campaign = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrud() {
|
||||
$targeting = new TargetingSpecs();
|
||||
$targeting->{TargetingSpecsFields::GEO_LOCATIONS}
|
||||
= array('countries' => array('US'));
|
||||
|
||||
$set = new AdSet(null, $this->getConfig()->accountId);
|
||||
$set->{AdSetFields::CAMPAIGN_ID}
|
||||
= $this->campaign->{CampaignFields::ID};
|
||||
$set->{AdSetFields::NAME} = $this->getConfig()->testRunId;
|
||||
$set->{AdSetFields::OPTIMIZATION_GOAL} = OptimizationGoals::REACH;
|
||||
$set->{AdSetFields::BILLING_EVENT} = BillingEvents::IMPRESSIONS;
|
||||
$set->{AdSetFields::BID_AMOUNT} = 2;
|
||||
$set->{AdSetFields::DAILY_BUDGET} = '150';
|
||||
$set->{AdSetFields::TARGETING} = $targeting;
|
||||
$set->{AdSetFields::START_TIME}
|
||||
= (new \DateTime("+1 week"))->format(\DateTime::ISO8601);
|
||||
$set->{AdSetFields::END_TIME}
|
||||
= (new \DateTime("+2 week"))->format(\DateTime::ISO8601);
|
||||
|
||||
$this->assertCanCreate($set, array(
|
||||
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
|
||||
));
|
||||
$this->assertCanRead($set);
|
||||
$this->assertCanUpdate($set, array(
|
||||
AdSetFields::NAME => $this->getConfig()->testRunId.' updated',
|
||||
));
|
||||
$this->assertCanFetchConnection($set, 'getAds');
|
||||
$this->assertCanFetchConnection($set, 'getAdCreatives');
|
||||
$this->assertCanFetchConnection($set, 'getInsights');
|
||||
$this->assertCanFetchConnection($set, 'getInsightsAsync');
|
||||
|
||||
$this->assertCanBeLabeled($set);
|
||||
$this->assertCanArchive($set);
|
||||
|
||||
$this->assertCanDelete($set);
|
||||
}
|
||||
}
|
||||
185
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdTest.php
vendored
Normal file
185
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdTest.php
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Campaign;
|
||||
use FacebookAds\Object\AdCreative;
|
||||
use FacebookAds\Object\Ad;
|
||||
use FacebookAds\Object\AdImage;
|
||||
use FacebookAds\Object\AdSet;
|
||||
use FacebookAds\Object\Fields\CampaignFields;
|
||||
use FacebookAds\Object\Fields\AdCreativeFields;
|
||||
use FacebookAds\Object\Fields\AdFields;
|
||||
use FacebookAds\Object\Fields\AdImageFields;
|
||||
use FacebookAds\Object\Fields\AdSetFields;
|
||||
use FacebookAds\Object\Fields\ObjectStory\LinkDataFields;
|
||||
use FacebookAds\Object\Fields\ObjectStorySpecFields;
|
||||
use FacebookAds\Object\ObjectStory\LinkData;
|
||||
use FacebookAds\Object\ObjectStorySpec;
|
||||
use FacebookAds\Object\TargetingSpecs;
|
||||
use FacebookAds\Object\Fields\TargetingSpecsFields;
|
||||
use FacebookAds\Object\Values\BillingEvents;
|
||||
use FacebookAds\Object\Values\OptimizationGoals;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
|
||||
class AdTest extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @var Campaign
|
||||
*/
|
||||
protected $campaign;
|
||||
|
||||
/**
|
||||
* @var AdSet
|
||||
*/
|
||||
protected $adSet;
|
||||
|
||||
/**
|
||||
* @var AdCreative
|
||||
*/
|
||||
protected $adCreative;
|
||||
|
||||
/**
|
||||
* @var AdImage
|
||||
*/
|
||||
protected $adImage;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_payment_method');
|
||||
}
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$targeting = new TargetingSpecs();
|
||||
$targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array(
|
||||
'countries' => array('US'),
|
||||
);
|
||||
|
||||
$this->campaign = new Campaign(null, $this->getConfig()->accountId);
|
||||
$this->campaign->{CampaignFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->campaign->create();
|
||||
|
||||
$this->adSet = new AdSet(null, $this->getConfig()->accountId);
|
||||
$this->adSet->{AdSetFields::CAMPAIGN_ID}
|
||||
= (int) $this->campaign->{AdSetFields::ID};
|
||||
$this->adSet->{AdSetFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->adSet->{AdSetFields::DAILY_BUDGET} = '150';
|
||||
$this->adSet->{AdSetFields::START_TIME}
|
||||
= (new \DateTime("+1 week"))->format(\DateTime::ISO8601);
|
||||
$this->adSet->{AdSetFields::END_TIME}
|
||||
= (new \DateTime("+2 week"))->format(\DateTime::ISO8601);
|
||||
$this->adSet->{AdSetFields::TARGETING} = $targeting;
|
||||
$this->adSet->{AdSetFields::OPTIMIZATION_GOAL} = OptimizationGoals::REACH;
|
||||
$this->adSet->{AdSetFields::BILLING_EVENT} = BillingEvents::IMPRESSIONS;
|
||||
$this->adSet->{AdSetFields::BID_AMOUNT} = 2;
|
||||
$this->adSet->save(array(
|
||||
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
|
||||
));
|
||||
|
||||
$this->adImage = new AdImage(null, $this->getConfig()->accountId);
|
||||
$this->adImage->{AdImageFields::FILENAME}
|
||||
= $this->getConfig()->testImagePath;
|
||||
$this->adImage->save();
|
||||
|
||||
$link = new LinkData();
|
||||
$link->{LinkDataFields::MESSAGE} = 'Message';
|
||||
$link->{LinkDataFields::IMAGE_HASH} = $this->adImage->{AdImageFields::HASH};
|
||||
$link->{LinkDataFields::LINK} = $this->getConfig()->appUrl;
|
||||
|
||||
$story = new ObjectStorySpec();
|
||||
$story->{ObjectStorySpecFields::PAGE_ID} = $this->getConfig()->pageId;
|
||||
$story->{ObjectStorySpecFields::LINK_DATA} = $link;
|
||||
|
||||
$this->adCreative = new AdCreative(null, $this->getConfig()->accountId);
|
||||
$this->adCreative->{AdCreativeFields::OBJECT_STORY_SPEC} = $story;
|
||||
$this->adCreative->create();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->adSet) {
|
||||
$this->adSet->deleteSelf();
|
||||
$this->adSet = null;
|
||||
}
|
||||
|
||||
if ($this->campaign) {
|
||||
$this->campaign->deleteSelf();
|
||||
$this->campaign = null;
|
||||
}
|
||||
|
||||
if ($this->adCreative) {
|
||||
$this->adCreative->deleteSelf();
|
||||
$this->adCreative = null;
|
||||
}
|
||||
|
||||
if ($this->adImage) {
|
||||
$this->adImage->deleteSelf();
|
||||
$this->adImage = null;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrudAccess() {
|
||||
|
||||
$group = new Ad(null, $this->getConfig()->accountId);
|
||||
$group->{AdFields::NAME} = $this->getConfig()->testRunId;
|
||||
$group->{AdFields::ADSET_ID}
|
||||
= (int) $this->adSet->{AdSetFields::ID};
|
||||
$group->{AdFields::CREATIVE}
|
||||
= array('creative_id' => $this->adCreative->{AdCreativeFields::ID});
|
||||
|
||||
$this->assertCanCreate($group, array(
|
||||
Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
|
||||
));
|
||||
$this->assertCanRead($group);
|
||||
$this->assertCanUpdate($group, array(
|
||||
AdFields::NAME => $this->getConfig()->testRunId.' updated',
|
||||
));
|
||||
|
||||
$this->assertCanFetchConnection($group, 'getAdCreatives');
|
||||
$this->assertCanFetchConnection($group, 'getLeads');
|
||||
$this->assertCanFetchConnection($group, 'getTargetingDescription');
|
||||
$this->assertCanFetchConnection($group, 'getAdPreviews',
|
||||
array(),
|
||||
array('ad_format' => 'RIGHT_COLUMN_STANDARD'));
|
||||
|
||||
if (!$this->shouldSkipTest('no_reach_and_frequency')) {
|
||||
$this->assertCanFetchConnection($group, 'getReachEstimate');
|
||||
}
|
||||
$this->assertCanFetchConnection($group, 'getClickTrackingTag');
|
||||
$this->assertCanFetchConnection($group, 'getInsights');
|
||||
$this->assertCanFetchConnection($group, 'getInsightsAsync');
|
||||
|
||||
$this->assertCanBeLabeled($group);
|
||||
$this->assertCanArchive($group);
|
||||
|
||||
$this->assertCanDelete($group);
|
||||
}
|
||||
}
|
||||
52
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdUserTest.php
vendored
Normal file
52
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdUserTest.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\AdUser;
|
||||
use FacebookAds\Object\Fields\AdUserFields;
|
||||
|
||||
class AdUserTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrudAccess() {
|
||||
$ad_account = new AdAccount($this->getConfig()->accountId);
|
||||
$ad_users = $ad_account->getAdUsers();
|
||||
|
||||
$this->assertGreaterThan(0, $ad_users->count());
|
||||
|
||||
$uid = (new AdUser('me'))->read()->{AdUserFields::ID};
|
||||
$found = false;
|
||||
foreach ($ad_users as $ad_user) {
|
||||
if ($ad_user->id === $uid) {
|
||||
$this->assertCanFetchConnection($ad_user, 'getAdAccounts');
|
||||
$this->assertCanFetchConnection($ad_user, 'getAdAccountGroups');
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue($found);
|
||||
}
|
||||
}
|
||||
52
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdVideoTest.php
vendored
Normal file
52
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdVideoTest.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdVideo;
|
||||
use FacebookAds\Object\Fields\AdVideoFields;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
|
||||
class AdVideoTest extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_video_upload');
|
||||
}
|
||||
|
||||
public function testCrud() {
|
||||
$video = new AdVideo(null, $this->getConfig()->accountId);
|
||||
$video->{AdVideoFields::NAME} = $this->getConfig()->testRunId;
|
||||
$video->{AdVideoFields::SOURCE} = $this->getConfig()->testVideoPath;
|
||||
$this->assertCanCreate($video);
|
||||
$this->assertCanRead($video);
|
||||
$this->assertCanUpdate($video, array(
|
||||
AdVideoFields::NAME => $this->getConfig()->testRunId.' updated',
|
||||
));
|
||||
$this->assertCanDelete($video);
|
||||
}
|
||||
}
|
||||
166
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdsPixelTest.php
vendored
Normal file
166
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/AdsPixelTest.php
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\AdsPixel;
|
||||
use FacebookAds\Object\Business;
|
||||
use FacebookAds\Object\Fields\AdsPixelsFields;
|
||||
use FacebookAds\Object\Values\AdsPixelStatAggregations;
|
||||
|
||||
class AdsPixelTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* AdsPixels can be created but only one per account can exist
|
||||
*/
|
||||
public function testCreate() {
|
||||
// make sure there's at least one pixel
|
||||
$account = new AdAccount($this->getConfig()->accountId);
|
||||
$pixels = $account->getAdsPixels();
|
||||
$pixel = null;
|
||||
|
||||
if (!$pixels->count()) {
|
||||
$pixel = new AdsPixel(null, $this->getConfig()->accountId);
|
||||
$pixel->{AdsPixelsFields::NAME} = 'WCA Pixel';
|
||||
$this->assertCanCreate($pixel);
|
||||
} else {
|
||||
$pixel = $pixels->current();
|
||||
}
|
||||
|
||||
$pixel = new AdsPixel(null, $this->getConfig()->accountId);
|
||||
$pixel->{AdsPixelsFields::NAME} = $this->getConfig()->testRunId;
|
||||
$this->assertCannotCreate($pixel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AdsPixel
|
||||
*/
|
||||
protected function getAccountPixel() {
|
||||
$cursor = (new AdAccount($this->getConfig()->accountId))->getAdsPixels();
|
||||
$this->assertGreaterThanOrEqual(1, $cursor->count());
|
||||
|
||||
return $cursor->current();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*/
|
||||
public function testCrud() {
|
||||
$pixel = $this->getAccountPixel();
|
||||
|
||||
$this->assertCanRead($pixel, array(
|
||||
AdsPixelsFields::NAME,
|
||||
));
|
||||
|
||||
$name = $pixel->{AdsPixelsFields::NAME};
|
||||
|
||||
$this->assertCanUpdate(
|
||||
$pixel,
|
||||
array(
|
||||
AdsPixelsFields::NAME => $this->getConfig()->testRunId.' updated',
|
||||
));
|
||||
|
||||
$pixel->{AdsPixelsFields::NAME} = $name;
|
||||
$pixel->update();
|
||||
|
||||
$this->assertCanFetchConnection($pixel, 'getAdAccounts', array(), array(
|
||||
'business' => $this->getConfig()->businessId,
|
||||
));
|
||||
$this->assertCanFetchConnection($pixel, 'getAgencies');
|
||||
$this->assertCanFetchConnection($pixel, 'getStats', array(), array(
|
||||
'aggregation' => AdsPixelStatAggregations::EVENT,
|
||||
));
|
||||
|
||||
$this->assertCannotDelete($pixel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*/
|
||||
public function testShareWithAdAccount() {
|
||||
$this->skipIf('no_business_manager');
|
||||
|
||||
if (!$this->getConfig()->secondaryBusinessId) {
|
||||
$this->markTestSkipped('No secondary business provided in config');
|
||||
}
|
||||
|
||||
if (!$this->getConfig()->secondaryAccountId) {
|
||||
$this->markTestSkipped('No secondary ad account provided in config');
|
||||
}
|
||||
|
||||
$account_id_int = (int) substr($this->getConfig()->secondaryAccountId, 4);
|
||||
|
||||
$pixel = $this->getAccountPixel();
|
||||
|
||||
$pixel->sharePixelWithAdAccount(
|
||||
$this->getConfig()->secondaryBusinessId,
|
||||
$account_id_int);
|
||||
|
||||
$pixel->unsharePixelWithAdAccount(
|
||||
$this->getConfig()->secondaryBusinessId,
|
||||
$account_id_int);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*/
|
||||
public function testShareWithAgency() {
|
||||
$this->skipIf('no_business_manager');
|
||||
|
||||
if (!$this->getConfig()->secondaryAccountId) {
|
||||
$this->markTestSkipped('No secondary business provided in config');
|
||||
}
|
||||
|
||||
$pixel = $this->getAccountPixel();
|
||||
|
||||
$business = new Business($this->getConfig()->businessId);
|
||||
$cursor = $business->getAgencies();
|
||||
$cursor->setUseImplicitFetch(true);
|
||||
|
||||
$agency_id = null;
|
||||
foreach ($cursor as $agency) {
|
||||
if (
|
||||
$agency->{AbstractCrudObject::FIELD_ID}
|
||||
== $this->getConfig()->secondaryBusinessId
|
||||
) {
|
||||
$agency_id = $agency->{AbstractCrudObject::FIELD_ID};
|
||||
}
|
||||
}
|
||||
|
||||
if ($agency_id === null) {
|
||||
$this->markTestSkipped("Secondary business is not a valid agency");
|
||||
}
|
||||
|
||||
$pixel->sharePixelWithAgency(
|
||||
$this->getConfig()->businessId,
|
||||
$this->getConfig()->secondaryBusinessId);
|
||||
|
||||
$pixel->unsharePixelWithAgency(
|
||||
$this->getConfig()->businessId,
|
||||
$this->getConfig()->secondaryBusinessId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\Fields\AdAccountFields;
|
||||
use FacebookAds\Object\AdReportRun;
|
||||
use FacebookAds\Object\Fields\AdsInsightsFields;
|
||||
use FacebookAds\Api;
|
||||
|
||||
class AsyncJobInsightsTest extends AbstractAsyncJobTestCase {
|
||||
|
||||
public function testCrud() {
|
||||
$account = new AdAccount($this->getConfig()->accountId);
|
||||
$job = $account->getInsightsAsync();
|
||||
$this->assertTrue($job instanceof AdReportRun);
|
||||
$this->waitTillJobComplete($job);
|
||||
$job->getInsights();
|
||||
}
|
||||
|
||||
public function testFields() {
|
||||
$account = new AdAccount($this->getConfig()->accountId);
|
||||
$fields = array(AdAccountFields::ACCOUNT_ID);
|
||||
$account->{AdAccountFields::ACCOUNT_ID} = $account->getSelf($fields)->{AdAccountFields::ACCOUNT_ID};
|
||||
$fields = array(AdsInsightsFields::ACCOUNT_ID);
|
||||
$job = $account->getInsightsAsync($fields);
|
||||
$this->assertTrue($job instanceof AdReportRun);
|
||||
$this->waitTillJobComplete($job);
|
||||
$result = $job->getInsights();
|
||||
$this->assertEquals(
|
||||
$result[0]->{AdsInsightsFields::ACCOUNT_ID},
|
||||
$account->{AdAccountFields::ACCOUNT_ID});
|
||||
}
|
||||
}
|
||||
109
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/BusinessTest.php
vendored
Normal file
109
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/BusinessTest.php
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdUser;
|
||||
use FacebookAds\Object\Business;
|
||||
use FacebookAds\Object\Fields\AdUserFields;
|
||||
use FacebookAds\Object\Fields\BusinessFields;
|
||||
use FacebookAds\Object\Values\AdAccountRoles;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
use FacebookAds\Object\Values\BusinessRoles;
|
||||
|
||||
class BusinessTest extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_business_manager');
|
||||
}
|
||||
|
||||
public function testCrud() {
|
||||
$business = new Business($this->getConfig()->businessId);
|
||||
$this->assertCanRead($business);
|
||||
$this->assertCannotDelete($business);
|
||||
|
||||
|
||||
$name = $business->read(array(BusinessFields::NAME))
|
||||
->{BusinessFields::NAME};
|
||||
|
||||
$this->assertCanUpdate($business, array(
|
||||
BusinessFields::NAME => "My Awesome Business"
|
||||
));
|
||||
|
||||
$business->{BusinessFields::NAME} = $name;
|
||||
$business->save();
|
||||
|
||||
|
||||
if ($this->getConfig()->secondaryPageId) {
|
||||
$business->claimPage(
|
||||
$this->getConfig()->secondaryPageId,
|
||||
BusinessRoles::OWNER);
|
||||
$business->deletePage($this->getConfig()->secondaryPageId);
|
||||
}
|
||||
|
||||
$business->inviteUserByEmail('test@example.com', BusinessRoles::EMPLOYEE);
|
||||
$business->deleteUserByEmail('test@example.com');
|
||||
|
||||
$user = (new AdUser('me'))->read(array('id'));
|
||||
$business->addUserPermissionById(
|
||||
$user->{AdUserFields::ID},
|
||||
BusinessRoles::ADMIN);
|
||||
|
||||
if ($this->getConfig()->secondaryAccountId) {
|
||||
$business->claimAdAccount(
|
||||
$this->getConfig()->secondaryAccountId,
|
||||
BusinessRoles::AGENCY,
|
||||
array(AdAccountRoles::ADMIN));
|
||||
$business->deleteAdAccount(
|
||||
$this->getConfig()->secondaryAccountId);
|
||||
}
|
||||
|
||||
if ($this->getConfig()->secondaryAppId) {
|
||||
$business->claimApp(
|
||||
$this->getConfig()->secondaryAppId,
|
||||
BusinessRoles::OWNER);
|
||||
$business->deleteApp($this->getConfig()->secondaryAppId);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConnections() {
|
||||
$business = new Business($this->getConfig()->businessId);
|
||||
$this->assertCanFetchConnection($business, 'getAdAccounts');
|
||||
$this->assertCanFetchConnection($business, 'getUserPermissions');
|
||||
$this->assertCanFetchConnection($business, 'getProjects');
|
||||
$this->assertCanFetchConnection($business, 'getPages');
|
||||
$this->assertCanFetchConnection($business, 'getApps');
|
||||
$this->assertCanFetchConnection($business, 'getClients');
|
||||
$this->assertCanFetchConnection($business, 'getAgencies');
|
||||
$this->assertCanFetchConnection($business, 'getCreditCards');
|
||||
$this->assertCanFetchConnection($business, 'getExtendedCredits');
|
||||
$this->assertCanFetchConnection($business, 'getProductCatalogues');
|
||||
$this->assertCanFetchConnection($business, 'getSystemUsers');
|
||||
$this->assertCanFetchConnection($business, 'getAdsPixels');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Campaign;
|
||||
use FacebookAds\Object\Fields\CampaignFields;
|
||||
|
||||
class CampaignTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrud() {
|
||||
$campaign = new Campaign(null, $this->getConfig()->accountId);
|
||||
$campaign->{CampaignFields::NAME} = $this->getConfig()->testRunId;
|
||||
|
||||
$this->assertCanCreate($campaign);
|
||||
$this->assertCanRead($campaign);
|
||||
$this->assertCanUpdate(
|
||||
$campaign,
|
||||
array(
|
||||
CampaignFields::NAME => $this->getConfig()->testRunId.' updated',
|
||||
));
|
||||
$this->assertCanFetchConnection($campaign, 'getAdSets');
|
||||
$this->assertCanFetchConnection($campaign, 'getAds');
|
||||
$this->assertCanFetchConnection($campaign, 'getInsights');
|
||||
$this->assertCanFetchConnection($campaign, 'getInsightsAsync');
|
||||
|
||||
$this->assertCanBeLabeled($campaign);
|
||||
$this->assertCanArchive($campaign);
|
||||
|
||||
$this->assertCanDelete($campaign);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\CustomAudience;
|
||||
use FacebookAds\Object\Fields\CustomAudienceFields;
|
||||
use FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;
|
||||
use FacebookAds\Object\Values\CustomAudienceSubtypes;
|
||||
use FacebookAds\Object\Values\CustomAudienceTypes;
|
||||
|
||||
class CustomAudienceMultikeyTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var CustomAudience
|
||||
*/
|
||||
protected $customaudience;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$adaccount = new AdAccount($this->getConfig()->accountId);
|
||||
$params = array(
|
||||
CustomAudienceFields::NAME => $this->getConfig()->testRunId,
|
||||
CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::CUSTOM,
|
||||
);
|
||||
$this->customaudience = $adaccount->createCustomAudience(
|
||||
array(),
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->customaudience) {
|
||||
$this->customaudience->deleteSelf();
|
||||
}
|
||||
}
|
||||
|
||||
private function checkServerResponse(
|
||||
CustomAudience $ca,
|
||||
array $users,
|
||||
array $schema,
|
||||
$is_hashed,
|
||||
$is_normalized) {
|
||||
$add = $ca->addUsersMultiKey($users, $schema, $is_hashed, $is_normalized);
|
||||
$this->assertClusterChangesResponse($ca, $users, $add);
|
||||
$remove = $ca->removeUsersMultiKey($users, $schema, $is_hashed, $is_normalized);
|
||||
$this->assertClusterChangesResponse($ca, $users, $remove);
|
||||
}
|
||||
|
||||
|
||||
protected function assertClusterChangesResponse(
|
||||
CustomAudience $ca, array $users, $response) {
|
||||
|
||||
$this->assertTrue(is_array($response));
|
||||
|
||||
$this->assertArrayHasKey('audience_id', $response);
|
||||
$this->assertEquals(
|
||||
$response['audience_id'], $ca->{CustomAudienceFields::ID});
|
||||
$this->assertArrayHasKey('num_received', $response);
|
||||
$this->assertEquals($response['num_received'], count($users));
|
||||
$this->assertArrayHasKey('num_invalid_entries', $response);
|
||||
$this->assertEquals($response['num_invalid_entries'], 0);
|
||||
}
|
||||
|
||||
public function testMultikeyCustomAudiences() {
|
||||
$users = array(
|
||||
array('abc123def', 'fname', 'lname', 'someone@example.com'),
|
||||
array('abc234def', 'fname_new', 'lname_new', 'someone_new@example.com'),
|
||||
);
|
||||
$schema = array(
|
||||
CustomAudienceMultikeySchemaFields::EXTERN_ID,
|
||||
CustomAudienceMultikeySchemaFields::FIRST_NAME,
|
||||
CustomAudienceMultikeySchemaFields::LAST_NAME,
|
||||
CustomAudienceMultikeySchemaFields::EMAIL,
|
||||
);
|
||||
$is_hashed = false;
|
||||
$is_normalized = false;
|
||||
$this->checkServerResponse(
|
||||
$this->customaudience,
|
||||
$users,
|
||||
$schema,
|
||||
$is_hashed,
|
||||
$is_normalized);
|
||||
}
|
||||
|
||||
public function testSinglekeyExternIDCustomAudiences() {
|
||||
$users = array(
|
||||
array('abc123def'),
|
||||
array('abc234def'),
|
||||
array('abc345def'),
|
||||
array('abc456def'),
|
||||
);
|
||||
$schema = array(
|
||||
CustomAudienceMultikeySchemaFields::EXTERN_ID,
|
||||
);
|
||||
$is_hashed = false;
|
||||
$is_normalized = false;
|
||||
$this->checkServerResponse(
|
||||
$this->customaudience,
|
||||
$users,
|
||||
$schema,
|
||||
$is_hashed,
|
||||
$is_normalized);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\CustomAudienceNormalizers;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\CustomAudienceNormalizers\EmailNormalizer;
|
||||
|
||||
class EmailNormalizerTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @var EmailNormalizer
|
||||
*/
|
||||
protected $emailNormalizer;
|
||||
|
||||
public function setUp() {
|
||||
$this->emailNormalizer = new EmailNormalizer();
|
||||
}
|
||||
|
||||
public function testNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
"foo@fb.com\t\r\n\0\x0B.",
|
||||
'foo@fb.com',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testNormalizeData
|
||||
*/
|
||||
public function testNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->emailNormalizer->normalize('email', $input));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\CustomAudience;
|
||||
use FacebookAds\Object\Fields\CustomAudienceFields;
|
||||
use FacebookAds\Object\Values\CustomAudienceSubtypes;
|
||||
use FacebookAds\Object\Values\CustomAudienceTypes;
|
||||
|
||||
class CustomAudienceTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
protected function assertClusterChangesResponse(
|
||||
CustomAudience $ca, array $users, $response) {
|
||||
|
||||
$this->assertTrue(is_array($response));
|
||||
|
||||
$this->assertArrayHasKey('audience_id', $response);
|
||||
$this->assertEquals(
|
||||
$response['audience_id'], $ca->{CustomAudienceFields::ID});
|
||||
$this->assertArrayHasKey('num_received', $response);
|
||||
$this->assertEquals($response['num_received'], count($users));
|
||||
$this->assertArrayHasKey('num_invalid_entries', $response);
|
||||
$this->assertEquals($response['num_invalid_entries'], 0);
|
||||
}
|
||||
|
||||
public function testCustomAudiences() {
|
||||
$ca = new CustomAudience(null, $this->getConfig()->accountId);
|
||||
$ca->{CustomAudienceFields::NAME} = $this->getConfig()->testRunId;
|
||||
$ca->{CustomAudienceFields::SUBTYPE} = CustomAudienceSubtypes::CUSTOM;
|
||||
|
||||
$this->assertCanCreate($ca);
|
||||
|
||||
$this->assertCanRead($ca);
|
||||
$this->assertCanUpdate(
|
||||
$ca,
|
||||
array(
|
||||
CustomAudienceFields::NAME => $this->getConfig()->testRunId.' updated',
|
||||
));
|
||||
|
||||
$users = array('someone@example.com');
|
||||
|
||||
$add = $ca->addUsers($users, CustomAudienceTypes::EMAIL);
|
||||
$this->assertClusterChangesResponse($ca, $users, $add);
|
||||
|
||||
$remove = $ca->removeUsers($users, CustomAudienceTypes::EMAIL);
|
||||
$this->assertClusterChangesResponse($ca, $users, $remove);
|
||||
|
||||
$optout = $ca->optOutUsers($users, CustomAudienceTypes::EMAIL);
|
||||
$this->assertSuccessResponse($optout);
|
||||
|
||||
$this->assertCanDelete($ca);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCustomAudiences
|
||||
*/
|
||||
public function testAppIdsPayload() {
|
||||
$ca = new CustomAudience(null, $this->getConfig()->accountId);
|
||||
$ca->{CustomAudienceFields::NAME} = $this->getConfig()->testRunId;
|
||||
$ca->{CustomAudienceFields::SUBTYPE} = CustomAudienceSubtypes::CUSTOM;
|
||||
$ca->create();
|
||||
|
||||
$users = array($this->getApi()->call('/me')->getContent()['id']);
|
||||
|
||||
$add = $ca->addUsers(
|
||||
$users, CustomAudienceTypes::ID, array($this->getConfig()->appId));
|
||||
$this->assertClusterChangesResponse($ca, $users, $add);
|
||||
|
||||
$remove = $ca->removeUsers(
|
||||
$users, CustomAudienceTypes::ID, array($this->getConfig()->appId));
|
||||
$this->assertClusterChangesResponse($ca, $users, $remove);
|
||||
|
||||
$optout = $ca->optOutUsers(
|
||||
$users, CustomAudienceTypes::ID, array($this->getConfig()->appId));
|
||||
$this->assertSuccessResponse($optout);
|
||||
|
||||
$ca->deleteSelf();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\Campaign;
|
||||
use FacebookAds\Object\AdCreative;
|
||||
use FacebookAds\Object\Ad;
|
||||
use FacebookAds\Object\AdSet;
|
||||
use FacebookAds\Object\AdsPixel;
|
||||
use FacebookAds\Object\ObjectStorySpec;
|
||||
use FacebookAds\Object\ProductAudience;
|
||||
use FacebookAds\Object\ProductCatalog;
|
||||
use FacebookAds\Object\ProductSet;
|
||||
use FacebookAds\Object\TargetingSpecs;
|
||||
use FacebookAds\Object\ObjectStory\TemplateData;
|
||||
use FacebookAds\Object\Fields\CampaignFields;
|
||||
use FacebookAds\Object\Fields\AdCreativeFields;
|
||||
use FacebookAds\Object\Fields\AdFields;
|
||||
use FacebookAds\Object\Fields\AdSetFields;
|
||||
use FacebookAds\Object\Fields\AdsPixelsFields;
|
||||
use FacebookAds\Object\Fields\ObjectStory\TemplateDataFields;
|
||||
use FacebookAds\Object\Fields\ObjectStorySpecFields;
|
||||
use FacebookAds\Object\Fields\ProductAudienceFields;
|
||||
use FacebookAds\Object\Fields\ProductCatalogFields;
|
||||
use FacebookAds\Object\Fields\ProductSetFields;
|
||||
use FacebookAds\Object\Fields\TargetingSpecsFields;
|
||||
use FacebookAds\Object\Values\AdObjectives;
|
||||
use FacebookAds\Object\Values\BillingEvents;
|
||||
use FacebookAds\Object\Values\CallToActionTypes;
|
||||
use FacebookAds\Object\Values\OptimizationGoals;
|
||||
|
||||
class DynamicProductAdsAdvertTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var ProductSet
|
||||
*/
|
||||
protected $productSet;
|
||||
|
||||
/**
|
||||
* @var ProductCatalog
|
||||
*/
|
||||
protected $productCatalog;
|
||||
|
||||
/**
|
||||
* @var AdsPixel
|
||||
*/
|
||||
protected $adsPixel;
|
||||
|
||||
/**
|
||||
* @var ProductAudience
|
||||
*/
|
||||
protected $productAudience;
|
||||
|
||||
/**
|
||||
* @var Campaign
|
||||
*/
|
||||
protected $campaign;
|
||||
|
||||
/**
|
||||
* @var AdSet
|
||||
*/
|
||||
protected $adSet;
|
||||
|
||||
/**
|
||||
* @var Ad
|
||||
*/
|
||||
protected $ad;
|
||||
|
||||
/**
|
||||
* @var AdCreative
|
||||
*/
|
||||
protected $creative;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$account = new AdAccount($this->getConfig()->accountId);
|
||||
$this->adsPixel = $account->getAdsPixels()->current();
|
||||
if ($this->adsPixel === null) {
|
||||
throw new \Exception('Ads Pixel is null');
|
||||
}
|
||||
|
||||
$this->productCatalog =
|
||||
new ProductCatalog(null, $this->getConfig()->businessId);
|
||||
$this->productCatalog->setData(array(
|
||||
ProductCatalogFields::NAME => $this->getConfig()->testRunId,
|
||||
));
|
||||
$this->productCatalog->create();
|
||||
|
||||
$this->productSet =
|
||||
new ProductSet(null, $this->productCatalog->{ProductCatalogFields::ID});
|
||||
$this->productSet->setData(array(
|
||||
ProductSetFields::NAME => $this->getConfig()->testRunId,
|
||||
ProductSetFields::FILTER => array(
|
||||
'retailer_id' => array(
|
||||
'is_any' => array('pid1', 'pid2')
|
||||
)
|
||||
)
|
||||
));
|
||||
$this->productSet->create();
|
||||
|
||||
$this->productAudience
|
||||
= new ProductAudience(null, $this->getConfig()->accountId);
|
||||
$this->productAudience->setData(array(
|
||||
ProductAudienceFields::NAME => $this->getConfig()->testRunId,
|
||||
ProductAudienceFields::PRODUCT_SET_ID =>
|
||||
$this->productSet->{ProductSetFields::ID},
|
||||
ProductAudienceFields::PIXEL_ID =>
|
||||
$this->adsPixel->{AdsPixelsFields::ID},
|
||||
ProductAudienceFields::INCLUSIONS => array(array(
|
||||
'retention_seconds' => 86400,
|
||||
'rule' => array(
|
||||
'and' => array(
|
||||
array('event' => array('eq'=>'ViewContent')),
|
||||
array('userAgent' => array('i_contains'=>'iPhone'))
|
||||
)
|
||||
)
|
||||
)),
|
||||
));
|
||||
|
||||
$this->productAudience->create();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->productSet) {
|
||||
$this->productSet->deleteSelf();
|
||||
$this->productSet = null;
|
||||
}
|
||||
|
||||
if ($this->productCatalog) {
|
||||
$this->productCatalog->deleteSelf();
|
||||
$this->productCatalog = null;
|
||||
}
|
||||
|
||||
if ($this->productAudience) {
|
||||
$this->productAudience->deleteSelf();
|
||||
$this->productAudience = null;
|
||||
}
|
||||
|
||||
if ($this->campaign) {
|
||||
$this->campaign->deleteSelf();
|
||||
$this->campaign = null;
|
||||
}
|
||||
|
||||
if ($this->adSet) {
|
||||
$this->adSet->deleteSelf();
|
||||
$this->adSet = null;
|
||||
}
|
||||
|
||||
if ($this->ad) {
|
||||
$this->ad->deleteSelf();
|
||||
$this->ad = null;
|
||||
}
|
||||
|
||||
if ($this->creative) {
|
||||
$this->creative->deleteSelf();
|
||||
$this->creative = null;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testDynamicProductAdsCreation() {
|
||||
$this->campaign = new Campaign(null, $this->getConfig()->accountId);
|
||||
$this->campaign->setData(array(
|
||||
CampaignFields::NAME => $this->getConfig()->testRunId,
|
||||
CampaignFields::OBJECTIVE => AdObjectives::PRODUCT_CATALOG_SALES,
|
||||
CampaignFields::PROMOTED_OBJECT =>
|
||||
array('product_catalog_id' =>
|
||||
$this->productCatalog->{ProductCatalogFields::ID})
|
||||
));
|
||||
$this->assertCanCreate($this->campaign);
|
||||
|
||||
$targeting = new TargetingSpecs();
|
||||
$targeting->{TargetingSpecsFields::GEO_LOCATIONS} =
|
||||
array('countries' => array('US'));
|
||||
$targeting->{TargetingSpecsFields::DYNAMIC_AUDIENCE_IDS} =
|
||||
array($this->productAudience->{ProductAudienceFields::ID});
|
||||
|
||||
$this->adSet = new AdSet(null, $this->getConfig()->accountId);
|
||||
$this->adSet->setData(array(
|
||||
AdSetFields::NAME => $this->getConfig()->testRunId,
|
||||
AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::LINK_CLICKS,
|
||||
AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS,
|
||||
AdSetFields::BID_AMOUNT => 2,
|
||||
AdSetFields::DAILY_BUDGET => 2000,
|
||||
AdSetFields::CAMPAIGN_ID =>
|
||||
$this->campaign->{CampaignFields::ID},
|
||||
AdSetFields::TARGETING => $targeting,
|
||||
AdsetFields::PROMOTED_OBJECT =>
|
||||
array(
|
||||
'product_set_id' => $this->productSet->{ProductSetFields::ID},
|
||||
),
|
||||
));
|
||||
$this->assertCanCreate($this->adSet);
|
||||
|
||||
$template = new TemplateData();
|
||||
$template->setData(array(
|
||||
TemplateDataFields::DESCRIPTION => '{{product.description}}',
|
||||
TemplateDataFields::LINK => 'http://www.example.com/',
|
||||
TemplateDataFields::MESSAGE => 'Test DPA Ad Message',
|
||||
TemplateDataFields::NAME => '{{product.name | titleize}}',
|
||||
TemplateDataFields::CALL_TO_ACTION => array(
|
||||
'type' => CallToActionTypes::SHOP_NOW
|
||||
),
|
||||
));
|
||||
|
||||
$story = new ObjectStorySpec();
|
||||
$story->setData(array(
|
||||
ObjectStorySpecFields::PAGE_ID => $this->getConfig()->pageId,
|
||||
ObjectStorySpecFields::TEMPLATE_DATA => $template,
|
||||
));
|
||||
|
||||
$this->creative = new AdCreative(null, $this->getConfig()->accountId);
|
||||
$this->creative->setData(array(
|
||||
AdCreativeFields::NAME => $this->getConfig()->testRunId,
|
||||
AdCreativeFields::OBJECT_STORY_SPEC => $story,
|
||||
AdCreativeFields::PRODUCT_SET_ID =>
|
||||
$this->productSet->{ProductSetFields::ID},
|
||||
));
|
||||
$this->assertCanCreate($this->creative);
|
||||
|
||||
$this->ad = new Ad(null, $this->getConfig()->accountId);
|
||||
$this->ad->setData(array(
|
||||
AdFields::NAME => 'DPA Test Ad 1 '.$this->getConfig()->testRunId,
|
||||
AdFields::ADSET_ID => $this->adSet->{AdSetFields::ID},
|
||||
AdFields::CREATIVE =>
|
||||
array('creative_id' => $this->creative->{AdCreativeFields::ID}),
|
||||
));
|
||||
$this->assertCanCreate($this->ad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
|
||||
class EmptyCrudObject extends AbstractCrudObject {
|
||||
}
|
||||
38
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/EmptyObject.php
vendored
Normal file
38
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/EmptyObject.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
use FacebookAds\Object\AbstractObject;
|
||||
|
||||
class EmptyObject extends AbstractObject {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $fields = array(
|
||||
AbstractCrudObject::FIELD_ID,
|
||||
);
|
||||
}
|
||||
83
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/LeadTest.php
vendored
Normal file
83
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/LeadTest.php
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Fields\LeadFields;
|
||||
use FacebookAds\Object\Fields\LeadgenFormFields;
|
||||
use FacebookAds\Object\Lead;
|
||||
use FacebookAds\Object\LeadgenForm;
|
||||
use FacebookAds\Object\Page;
|
||||
|
||||
class LeadTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $leadId;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$limit = 25;
|
||||
$page = new Page($this->getConfig()->pageId);
|
||||
$forms = $page->getLeadgenForms(
|
||||
array(LeadgenFormFields::ID),
|
||||
array('limit' => $limit));
|
||||
|
||||
$forms->setUseImplicitFetch(false); // Force-disable pagination
|
||||
|
||||
/** @var LeadgenForm $form */
|
||||
foreach ($forms as $form) {
|
||||
$leads = $form->getLeads();
|
||||
if ($leads->count() > 0) {
|
||||
$this->leadId = $leads->current()->{LeadFields::ID};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->leadId === null) {
|
||||
$this->markTestSkipped(sprintf(
|
||||
'Leads can\'t be created through the API.'
|
||||
.' The first %d leadgen forms of Page %s have no leads',
|
||||
$limit,
|
||||
(string)$this->getConfig()->pageId));
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->leadId = null;
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrud() {
|
||||
$lead = new Lead($this->leadId);
|
||||
|
||||
$this->assertCannotCreate($lead);
|
||||
$this->assertCanRead($lead);
|
||||
$this->assertCannotUpdate($lead);
|
||||
$this->assertCannotDelete($lead);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Fields\LeadgenFormFields;
|
||||
use FacebookAds\Object\LeadgenForm;
|
||||
use FacebookAds\Object\Page;
|
||||
|
||||
class LeadgenFormTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $leadgenFormId;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$page = new Page($this->getConfig()->pageId);
|
||||
$forms = $page->getLeadgenForms();
|
||||
|
||||
if ($forms->count() === 0) {
|
||||
$this->markTestSkipped(sprintf(
|
||||
'LeadgenForms can\'t be created through the API.'
|
||||
.' Page %s has no leadgen forms',
|
||||
(string)$this->getConfig()->pageId));
|
||||
}
|
||||
|
||||
$this->leadgenFormId = $forms->current()->{LeadgenFormFields::ID};
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->leadgenFormId = null;
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrud() {
|
||||
$form = new LeadgenForm($this->leadgenFormId);
|
||||
|
||||
$this->assertCannotCreate($form);
|
||||
$this->assertCanRead($form);
|
||||
$this->assertCannotUpdate($form);
|
||||
$this->assertCanFetchConnection($form, 'getLeads');
|
||||
$this->assertCannotDelete($form);
|
||||
}
|
||||
}
|
||||
40
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/PageTest.php
vendored
Normal file
40
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/PageTest.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Page;
|
||||
|
||||
class PageTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testConnections() {
|
||||
$page = new Page($this->getConfig()->pageId);
|
||||
|
||||
$this->assertCannotCreate($page);
|
||||
$this->assertCanRead($page);
|
||||
$this->assertCanFetchConnection($page, 'getLeadgenForms');
|
||||
|
||||
// Page editing is currently not supported in the SDK
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\PartnerCategory;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
|
||||
class PartnerCategoryTest extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_partner_categories');
|
||||
}
|
||||
|
||||
public function testCrudAccess() {
|
||||
$account = new AdAccount($this->getConfig()->accountId);
|
||||
$cursor = $account->getPartnerCategories();
|
||||
if (!$cursor->count()) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/* @var $category AbstractCrudObject */
|
||||
$category = $cursor->current();
|
||||
|
||||
$this->assertTrue($category instanceof PartnerCategory);
|
||||
$this->assertCanRead($category);
|
||||
$this->assertCannotUpdate($category);
|
||||
$this->assertCannotDelete($category);
|
||||
$this->assertCannotCreate(
|
||||
new PartnerCategory(null, $this->getConfig()->accountId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AdAccount;
|
||||
use FacebookAds\Object\AdsPixel;
|
||||
use FacebookAds\Object\ProductAudience;
|
||||
use FacebookAds\Object\ProductCatalog;
|
||||
use FacebookAds\Object\ProductSet;
|
||||
use FacebookAds\Object\Fields\AdsPixelsFields;
|
||||
use FacebookAds\Object\Fields\ProductAudienceFields;
|
||||
use FacebookAds\Object\Fields\ProductCatalogFields;
|
||||
use FacebookAds\Object\Fields\ProductSetFields;
|
||||
|
||||
class ProductAudienceTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var ProductSet
|
||||
*/
|
||||
protected $productSet;
|
||||
|
||||
/**
|
||||
* @var ProductCatalog
|
||||
*/
|
||||
protected $productCatalog;
|
||||
|
||||
/**
|
||||
* @var AdAccount
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* @var AdsPixel
|
||||
*/
|
||||
protected $adsPixel;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$this->account = new AdAccount($this->getConfig()->accountId);
|
||||
|
||||
$cursor = $this->account->getAdsPixels();
|
||||
$this->adsPixel = $cursor->current();
|
||||
|
||||
$this->productCatalog =
|
||||
new ProductCatalog(null, $this->getConfig()->businessId);
|
||||
$this->productCatalog->setData(array(
|
||||
ProductCatalogFields::NAME => $this->getConfig()->testRunId,
|
||||
));
|
||||
$this->productCatalog->create();
|
||||
|
||||
$this->productSet =
|
||||
new ProductSet(null, $this->productCatalog->{ProductCatalogFields::ID});
|
||||
$this->productSet->setData(array(
|
||||
ProductSetFields::NAME => $this->getConfig()->testRunId,
|
||||
ProductSetFields::FILTER => array(
|
||||
'retailer_id' => array(
|
||||
'is_any' => array('pid1', 'pid2')
|
||||
)
|
||||
)
|
||||
));
|
||||
$this->productSet->create();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->productSet) {
|
||||
$this->productSet->deleteSelf();
|
||||
$this->productSet = null;
|
||||
}
|
||||
|
||||
if ($this->productCatalog) {
|
||||
$this->productCatalog->deleteSelf();
|
||||
$this->productCatalog = null;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrudAccess() {
|
||||
$audience_name = $this->getConfig()->testRunId;
|
||||
$this->adsPixel->{AdsPixelsFields::ID};
|
||||
|
||||
$audience = new ProductAudience(null, $this->getConfig()->accountId);
|
||||
$audience->setData(array(
|
||||
ProductAudienceFields::NAME => $audience_name,
|
||||
ProductAudienceFields::PRODUCT_SET_ID =>
|
||||
$this->productSet->{ProductSetFields::ID},
|
||||
ProductAudienceFields::PIXEL_ID =>
|
||||
$this->adsPixel->{AdsPixelsFields::ID},
|
||||
ProductAudienceFields::INCLUSIONS => array(array(
|
||||
'retention_seconds' => 86400,
|
||||
'rule' => array(
|
||||
'and' => array(
|
||||
array('event' => array('eq'=>'ViewContent')),
|
||||
array('userAgent' => array('i_contains'=>'iPhone'))
|
||||
)
|
||||
)
|
||||
)),
|
||||
));
|
||||
|
||||
$this->assertCanCreate($audience);
|
||||
$this->assertCanRead($audience);
|
||||
$this->assertCanUpdate($audience, array(
|
||||
ProductAudienceFields::NAME => $audience_name.' updated',
|
||||
));
|
||||
$this->assertCanDelete($audience);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\ProductCatalog;
|
||||
use FacebookAds\Object\Fields\ProductCatalogFields;
|
||||
|
||||
class ProductCatalogTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrud() {
|
||||
$catalog_name = $this->getConfig()->testRunId;
|
||||
$catalog = new ProductCatalog(null, $this->getConfig()->businessId);
|
||||
$catalog->setData(array(
|
||||
ProductCatalogFields::NAME => $catalog_name,
|
||||
));
|
||||
|
||||
$this->assertCanCreate($catalog);
|
||||
$this->assertCanRead($catalog);
|
||||
$this->assertCanUpdate($catalog, array(
|
||||
ProductCatalogFields::NAME => $catalog_name.' updated',
|
||||
));
|
||||
$this->assertCanFetchConnectionAsArray($catalog, 'getExternalEventSources');
|
||||
$this->assertCanFetchConnection($catalog, 'getProductSets');
|
||||
$this->assertCanFetchConnection($catalog, 'getProductFeeds');
|
||||
$this->assertCanDelete($catalog);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\ProductCatalog;
|
||||
use FacebookAds\Object\ProductFeed;
|
||||
use FacebookAds\Object\Fields\ProductCatalogFields;
|
||||
use FacebookAds\Object\Fields\ProductFeedFields;
|
||||
|
||||
class ProductFeedTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var ProductCatalog
|
||||
*/
|
||||
protected $productCatalog;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$this->productCatalog
|
||||
= new ProductCatalog(null, $this->getConfig()->businessId);
|
||||
$this->productCatalog->setData(array(
|
||||
ProductCatalogFields::NAME => $this->getConfig()->testRunId,
|
||||
));
|
||||
$this->productCatalog->create();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->productCatalog) {
|
||||
$this->productCatalog->deleteSelf();
|
||||
$this->productCatalog = null;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrudAccess() {
|
||||
$feed_name = $this->getConfig()->testRunId;
|
||||
$feed = new ProductFeed(null, $this->productCatalog->id);
|
||||
$feed->setData(array(
|
||||
ProductFeedFields::FILE_NAME => 'my_product_feed.tsv',
|
||||
ProductFeedFields::NAME => $feed_name,
|
||||
));
|
||||
|
||||
$this->assertCanCreate($feed);
|
||||
$this->assertCanRead($feed);
|
||||
$this->assertCanUpdate($feed, array(
|
||||
ProductFeedFields::NAME => $feed_name.' updated',
|
||||
));
|
||||
$this->assertCanFetchConnection($feed, 'getProducts');
|
||||
$this->assertCanFetchConnection($feed, 'getUploads');
|
||||
$this->assertCanDelete($feed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\ProductCatalog;
|
||||
use FacebookAds\Object\ProductSet;
|
||||
use FacebookAds\Object\Fields\ProductCatalogFields;
|
||||
use FacebookAds\Object\Fields\ProductSetFields;
|
||||
|
||||
class ProductSetTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
/**
|
||||
* @var ProductCatalog
|
||||
*/
|
||||
protected $productCatalog;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
|
||||
$this->productCatalog
|
||||
= new ProductCatalog(null, $this->getConfig()->businessId);
|
||||
$this->productCatalog->setData(array(
|
||||
ProductCatalogFields::NAME => $this->getConfig()->testRunId,
|
||||
));
|
||||
$this->productCatalog->create();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->productCatalog) {
|
||||
$this->productCatalog->deleteSelf();
|
||||
$this->productCatalog = null;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCrudAccess() {
|
||||
$feed_name = $this->getConfig()->testRunId;
|
||||
$product_set = new ProductSet(null, $this->productCatalog->id);
|
||||
$product_set->setData(array(
|
||||
ProductSetFields::NAME => $feed_name,
|
||||
ProductSetFields::FILTER => array(
|
||||
'retailer_id' => array(
|
||||
'is_any' => array('pid1', 'pid2')
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertCanCreate($product_set);
|
||||
$this->assertCanRead($product_set);
|
||||
$this->assertCanUpdate($product_set, array(
|
||||
ProductSetFields::NAME => $feed_name.' updated',
|
||||
));
|
||||
$this->assertCanFetchConnection($product_set, 'getProductGroups');
|
||||
$this->assertCanDelete($product_set);
|
||||
}
|
||||
}
|
||||
66
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/ProjectTest.php
vendored
Normal file
66
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/Object/ProjectTest.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Project;
|
||||
use FacebookAds\Object\Fields\ProjectFields;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
|
||||
class ProjectTest extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_business_manager');
|
||||
}
|
||||
|
||||
public function testCrud() {
|
||||
$project = new Project(null, $this->getConfig()->businessId);
|
||||
$project->{ProjectFields::NAME} = 'Test Project';
|
||||
|
||||
$this->assertCanCreate($project);
|
||||
$this->assertCanRead($project);
|
||||
$this->assertCanUpdate($project, array(
|
||||
ProjectFields::NAME => 'Updated Test Project Name'
|
||||
));
|
||||
|
||||
$this->assertCanFetchConnection($project, 'getPages');
|
||||
$this->assertCanFetchConnection($project, 'getAdAccounts');
|
||||
$this->assertCanFetchConnection($project, 'getApps');
|
||||
|
||||
$project->addPage($this->getConfig()->pageId);
|
||||
$project->deletePage($this->getConfig()->pageId);
|
||||
|
||||
$project->adAdAccount($this->getConfig()->accountId);
|
||||
$project->deleteAdAccount($this->getConfig()->accountId);
|
||||
|
||||
$project->addApp($this->getConfig()->appId);
|
||||
$project->deleteApp($this->getConfig()->appId);
|
||||
|
||||
$this->assertCanDelete($project);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAdsTest\AbstractTestCase;
|
||||
use FacebookAds\Object\ReachEstimate;
|
||||
use FacebookAds\Object\Fields\ReachEstimateFields;
|
||||
|
||||
class ReachEstimateTest extends AbstractTestCase {
|
||||
|
||||
public function testOnlyInnerData() {
|
||||
$reach_estimate = new ReachEstimate();
|
||||
$reach_estimate->setData(array(
|
||||
'data' => array(
|
||||
ReachEstimateFields::ESTIMATE_READY => true,
|
||||
),
|
||||
));
|
||||
$this->assertTrue($reach_estimate->{ReachEstimateFields::ESTIMATE_READY});
|
||||
}
|
||||
|
||||
public function testOnlyOuterData() {
|
||||
$reach_estimate = new ReachEstimate();
|
||||
$reach_estimate->setData(array(
|
||||
ReachEstimateFields::ESTIMATE_READY => true,
|
||||
));
|
||||
$this->assertTrue($reach_estimate->{ReachEstimateFields::ESTIMATE_READY});
|
||||
}
|
||||
|
||||
public function testInnerDataTakesPrecedenceOverOuterData() {
|
||||
$reach_estimate = new ReachEstimate();
|
||||
$reach_estimate->setData(array(
|
||||
ReachEstimateFields::ESTIMATE_READY => false,
|
||||
'data' => array(
|
||||
ReachEstimateFields::ESTIMATE_READY => true,
|
||||
),
|
||||
));
|
||||
$this->assertTrue($reach_estimate->{ReachEstimateFields::ESTIMATE_READY});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\Fields\TargetingFields;
|
||||
use FacebookAds\Object\ReachFrequencyPrediction;
|
||||
use FacebookAds\Object\Fields\ReachFrequencyPredictionFields as RF;
|
||||
use FacebookAds\Object\TargetingSpecs;
|
||||
use FacebookAds\Object\Values\AdObjectives;
|
||||
use FacebookAdsTest\Config\SkippableFeatureTestInterface;
|
||||
|
||||
class ReachFrequencyPredictionTest extends AbstractCrudObjectTestCase
|
||||
implements SkippableFeatureTestInterface {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function skipIfAny() {
|
||||
return array('no_reach_and_frequency');
|
||||
}
|
||||
|
||||
public function testCrudAccess() {
|
||||
|
||||
$prediction
|
||||
= new ReachFrequencyPrediction(null, $this->getConfig()->accountId);
|
||||
|
||||
$targeting = new TargetingSpecs();
|
||||
$targeting->{TargetingSpecsFields::GEO_LOCATIONS}
|
||||
= array('countries' => array('US'));
|
||||
$targeting->{TargetingFields::AGE_MAX} = 35;
|
||||
$targeting->{TargetingFields::AGE_MIN} = 20;
|
||||
$targeting->{TargetingFields::GENDERS} = array(2);
|
||||
$targeting->{TargetingFields::PUBLISHER_PLATFORMS} = array('facebook');
|
||||
$targeting->{TargetingFields::DEVICE_PLATFORMS} = array('desktop');
|
||||
$targeting->{TargetingFields::FACEBOOK_POSITIONS} = array('feed');
|
||||
|
||||
$prediction->setData(array(
|
||||
RF::BUDGET => 3000000,
|
||||
RF::TARGET_SPEC => $targeting,
|
||||
RF::START_TIME => strtotime('midnight + 2 weeks'),
|
||||
RF::END_TIME => strtotime('midnight + 3 weeks'),
|
||||
RF::FREQUENCY_CAP => 4,
|
||||
RF::DESTINATION_ID => $this->getConfig()->pageId,
|
||||
RF::PREDICTION_MODE => ReachFrequencyPrediction::PREDICTION_MODE_REACH,
|
||||
RF::OBJECTIVE => AdObjectives::POST_ENGAGEMENT,
|
||||
RF::STORY_EVENT_TYPE => 128,
|
||||
));
|
||||
|
||||
$this->assertCanCreate($prediction);
|
||||
$this->assertCanDelete($prediction);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\AsyncClient;
|
||||
use FacebookAds\Api;
|
||||
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Handler\CurlHandler;
|
||||
|
||||
Api::init(null, null, 'access-token', false);
|
||||
|
||||
class AsyncClientTest extends AbstractUnitTestCase {
|
||||
public function testSingleton() {
|
||||
$client1 = AsyncClient::getInstance()->getClient();
|
||||
$client2 = AsyncClient::getInstance()->getClient();
|
||||
|
||||
$this->assertEquals($client1, $client2);
|
||||
}
|
||||
|
||||
public function testCurlOptions() {
|
||||
$async_client = AsyncClient::getInstance()->getClient();
|
||||
$expected_handler = HandlerStack::create(new CurlHandler([
|
||||
'options' => [
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_CAINFO => Api::instance()->getHttpClient()->getCaBundlePath(),
|
||||
]
|
||||
]));
|
||||
|
||||
$this->assertEquals($expected_handler, $async_client->getConfig()['handler']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\Event;
|
||||
use FacebookAds\Object\ServerSide\UserData;
|
||||
use FacebookAds\Object\ServerSide\BatchProcessor;
|
||||
use FacebookAds\Api;
|
||||
use GuzzleHttp\Promise;
|
||||
use Mockery as m;
|
||||
|
||||
class BatchProcessorTest extends AbstractUnitTestCase {
|
||||
protected function setUp(): void {
|
||||
$this->user_data = (new UserData())->setEmail('joe@eg.com');
|
||||
$this->event = (new Event())
|
||||
->setEventName('Purchase')
|
||||
->setEventTime(time())
|
||||
->setUserData($this->user_data);
|
||||
$this->pixel_id = 'pixel-id-0';
|
||||
$this->test_event_code = 'test-code-1';
|
||||
$batch_size = 5;
|
||||
$concurrent_requests = 2;
|
||||
$this->batch_processor = new BatchProcessor($this->pixel_id, $batch_size, $concurrent_requests);
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testProcessEvents() {
|
||||
$expected_event_request_params = array(
|
||||
'events' => array_fill(0, 5, $this->event),
|
||||
'test_event_code' => $this->test_event_code,
|
||||
);
|
||||
|
||||
$mock_event_request_async = m::mock('overload:FacebookAds\Object\ServerSide\EventRequestAsync');
|
||||
$mock_guzzle_promise = m::mock();
|
||||
|
||||
$mock_event_request_async
|
||||
->shouldReceive('__construct')
|
||||
->atLeast()
|
||||
->once()
|
||||
->with($this->pixel_id, $expected_event_request_params);
|
||||
$mock_event_request_async
|
||||
->shouldReceive('execute')
|
||||
->atLeast()
|
||||
->once()
|
||||
->andReturn($mock_guzzle_promise);
|
||||
$mock_guzzle_promise
|
||||
->shouldReceive('wait')
|
||||
->times(3);
|
||||
$this->addToAssertionCount(
|
||||
m::getContainer()->mockery_getExpectationCount()
|
||||
);
|
||||
|
||||
$events = array_fill(0, 15, $this->event);
|
||||
$this->batch_processor->processEvents(
|
||||
array('test_event_code' => $this->test_event_code),
|
||||
$events
|
||||
);
|
||||
}
|
||||
|
||||
public function testProcessEventsGenerator() {
|
||||
$expected_event_request_params = array(
|
||||
'events' => array_fill(0, 5, $this->event),
|
||||
'test_event_code' => $this->test_event_code,
|
||||
);
|
||||
|
||||
$mock_event_request_async = m::mock('overload:FacebookAds\Object\ServerSide\EventRequestAsync');
|
||||
$mock_guzzle_promise = m::mock();
|
||||
|
||||
$mock_event_request_async
|
||||
->shouldReceive('__construct')
|
||||
->atLeast()
|
||||
->once()
|
||||
->with($this->pixel_id, $expected_event_request_params);
|
||||
$mock_event_request_async
|
||||
->shouldReceive('execute')
|
||||
->atLeast()
|
||||
->once()
|
||||
->andReturn($mock_guzzle_promise);
|
||||
$mock_guzzle_promise
|
||||
->shouldReceive('wait')
|
||||
->times(3);
|
||||
|
||||
$events = array_fill(0, 15, $this->event);
|
||||
$generator = $this->batch_processor->processEventsGenerator(
|
||||
array('test_event_code' => $this->test_event_code),
|
||||
$events
|
||||
);
|
||||
$iterations = 0;
|
||||
foreach ($generator as $promises) {
|
||||
$iterations += 1;
|
||||
Promise\unwrap($promises);
|
||||
}
|
||||
|
||||
$this->assertEquals($iterations, 2);
|
||||
}
|
||||
|
||||
public function testProcessEventRequests() {
|
||||
$mock_event_request_async = m::mock();
|
||||
$mock_guzzle_promise = m::mock();
|
||||
$expected_event_request_params = array_fill(0, 5, $mock_event_request_async);
|
||||
|
||||
$mock_event_request_async
|
||||
->shouldReceive('execute')
|
||||
->times(5)
|
||||
->andReturn($mock_guzzle_promise);
|
||||
$mock_guzzle_promise
|
||||
->shouldReceive('wait')
|
||||
->times(5);
|
||||
$this->addToAssertionCount(
|
||||
m::getContainer()->mockery_getExpectationCount()
|
||||
);
|
||||
|
||||
$event_requests = array_fill(0, 5, $mock_event_request_async);
|
||||
$this->batch_processor->processEventRequests($event_requests);
|
||||
}
|
||||
|
||||
public function testProcessEventRequestsGenerator() {
|
||||
$mock_event_request_async = m::mock();
|
||||
$mock_guzzle_promise = m::mock();
|
||||
$expected_event_request_params = array_fill(0, 5, $mock_event_request_async);
|
||||
|
||||
$mock_event_request_async
|
||||
->shouldReceive('execute')
|
||||
->times(5)
|
||||
->andReturn($mock_guzzle_promise);
|
||||
$mock_guzzle_promise
|
||||
->shouldReceive('wait')
|
||||
->times(5);
|
||||
|
||||
$event_requests = array_fill(0, 5, $mock_event_request_async);
|
||||
$generator = $this->batch_processor->processEventRequestsGenerator($event_requests);
|
||||
$iterations = 0;
|
||||
foreach ($generator as $promises) {
|
||||
$iterations += 1;
|
||||
Promise\unwrap($promises);
|
||||
}
|
||||
|
||||
$this->assertEquals(3, $iterations);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\Content;
|
||||
use FacebookAds\Object\ServerSide\DeliveryCategory;
|
||||
|
||||
|
||||
class ContentTest extends AbstractUnitTestCase {
|
||||
public function testContentBuilder() {
|
||||
$expected = array(
|
||||
'id' => 'product-test',
|
||||
'quantity' => 10,
|
||||
'item_price' => 4.99,
|
||||
'title' => 'title-test',
|
||||
'description' => 'description-test',
|
||||
'brand' => 'brand-test',
|
||||
'category' => 'category-test',
|
||||
'delivery_category' => DeliveryCategory::CURBSIDE,
|
||||
);
|
||||
|
||||
$content = (new Content())
|
||||
->setProductId($expected['id'])
|
||||
->setQuantity($expected['quantity'])
|
||||
->setItemPrice($expected['item_price'])
|
||||
->setTitle($expected['title'])
|
||||
->setDescription($expected['description'])
|
||||
->setBrand($expected['brand'])
|
||||
->setCategory($expected['category'])
|
||||
->setDeliveryCategory($expected['delivery_category']);
|
||||
|
||||
$this->assertEquals($content->normalize(), $expected);
|
||||
}
|
||||
|
||||
public function testContentConstructor() {
|
||||
$initial = array(
|
||||
'product_id' => 'product-test',
|
||||
'quantity' => 10,
|
||||
'item_price' => 4.99,
|
||||
'title' => 'title-test',
|
||||
'description' => 'description-test',
|
||||
'brand' => 'brand-test',
|
||||
'category' => 'category-test',
|
||||
'delivery_category' => DeliveryCategory::CURBSIDE,
|
||||
);
|
||||
$expected = array(
|
||||
'id' => $initial['product_id'],
|
||||
'quantity' => $initial['quantity'],
|
||||
'item_price' => $initial['item_price'],
|
||||
'title' => $initial['title'],
|
||||
'description' => $initial['description'],
|
||||
'brand' => $initial['brand'],
|
||||
'category' => $initial['category'],
|
||||
'delivery_category' => DeliveryCategory::CURBSIDE,
|
||||
);
|
||||
$content = new Content($initial);
|
||||
|
||||
$this->assertEquals($content->normalize(), $expected);
|
||||
}
|
||||
|
||||
public function testInvalidDeliveryCategory() {
|
||||
$test_delivery_category = 'invalid_delivery_category';
|
||||
$content = (new Content())->setDeliveryCategory($test_delivery_category);
|
||||
try {
|
||||
$normalized_payload = $content->normalize();
|
||||
} catch (\Exception $exception) {
|
||||
$threw_exception = true;
|
||||
$expected_string = sprintf("Invalid delivery_category passed: %s", $test_delivery_category);
|
||||
$this->assertStringContainsString($expected_string, $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertTrue($threw_exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\CustomData;
|
||||
use FacebookAds\Object\ServerSide\Content;
|
||||
use FacebookAds\Object\ServerSide\DeliveryCategory;
|
||||
|
||||
class CustomDataTest extends AbstractUnitTestCase {
|
||||
public function testBuilderAndConstructor() {
|
||||
$custom_properties = array(
|
||||
'custom1' => 'property1',
|
||||
'custom2' => 'property2'
|
||||
);
|
||||
$content_state = array('title' => 'content-1');
|
||||
$content = new Content($content_state);
|
||||
$state = array(
|
||||
'value' => 0.1,
|
||||
'currency' => 'usd',
|
||||
'content_name' => 'content-name-2',
|
||||
'content_category' => 'content-category-3',
|
||||
'content_ids' => array('id-1', 'id2'),
|
||||
'content_type' => 'content-type-4',
|
||||
'order_id' => 'order-id-5',
|
||||
'predicted_ltv' => 6.10,
|
||||
'num_items' => 7,
|
||||
'status' => 'status-8',
|
||||
'search_string' => 'search-string-9',
|
||||
'item_number' => 'item-number-10',
|
||||
'delivery_category' => DeliveryCategory::CURBSIDE,
|
||||
);
|
||||
$expected = array_merge(
|
||||
$state,
|
||||
array('contents' => array($content_state)),
|
||||
$custom_properties
|
||||
);
|
||||
$builder = (new CustomData())
|
||||
->setValue($state['value'])
|
||||
->setCurrency($state['currency'])
|
||||
->setContentName($state['content_name'])
|
||||
->setContentCategory($state['content_category'])
|
||||
->setContentIds($state['content_ids'])
|
||||
->setContents(array($content))
|
||||
->setContentType($state['content_type'])
|
||||
->setOrderId($state['order_id'])
|
||||
->setPredictedLtv($state['predicted_ltv'])
|
||||
->setNumItems($state['num_items'])
|
||||
->setStatus($state['status'])
|
||||
->setSearchString($state['search_string'])
|
||||
->setItemNumber($state['item_number'])
|
||||
->setDeliveryCategory($state['delivery_category'])
|
||||
->setCustomProperties($custom_properties);
|
||||
$this->assertEquals($expected, $builder->normalize());
|
||||
|
||||
$constructor = new CustomData(array(
|
||||
'value' => $state['value'],
|
||||
'currency' => $state['currency'],
|
||||
'content_name' => $state['content_name'],
|
||||
'content_category' => $state['content_category'],
|
||||
'content_ids' => $state['content_ids'],
|
||||
'contents' => array($content),
|
||||
'content_type' => $state['content_type'],
|
||||
'order_id' => $state['order_id'],
|
||||
'predicted_ltv' => $state['predicted_ltv'],
|
||||
'num_items' => $state['num_items'],
|
||||
'status' => $state['status'],
|
||||
'search_string' => $state['search_string'],
|
||||
'item_number' => $state['item_number'],
|
||||
'delivery_category' => $state['delivery_category'],
|
||||
'custom_properties' => $custom_properties
|
||||
));
|
||||
$this->assertEquals($expected, $constructor->normalize());
|
||||
}
|
||||
|
||||
public function testInvalidDeliveryCategory() {
|
||||
$test_delivery_category = 'invalid_delivery_category';
|
||||
|
||||
$custom_data = (new CustomData())->setDeliveryCategory($test_delivery_category);
|
||||
|
||||
try {
|
||||
$normalized_payload = $custom_data->normalize();
|
||||
} catch (\Exception $exception) {
|
||||
$has_throw_exception = true;
|
||||
$expected_string = sprintf("Invalid delivery_category passed: %s",$test_delivery_category);
|
||||
$this->assertStringContainsString($expected_string, $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
public function testZeroCustomDataValue() {
|
||||
$custom_data = (new CustomData())->setValue(0.0);
|
||||
|
||||
$normalized_payload = $custom_data->normalize();
|
||||
$this->assertEquals($normalized_payload['value'], 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\Event;
|
||||
use FacebookAds\Object\ServerSide\EventRequestAsync;
|
||||
use FacebookAds\Api;
|
||||
|
||||
class EventRequestAsyncTest extends AbstractUnitTestCase {
|
||||
public function testBuilder() {
|
||||
$event = new Event(array('event_name' => 'my-event'));
|
||||
$expected = array(
|
||||
'data' => array(array('event_name' => $event['event_name'])),
|
||||
'test_event_code' => 'test-event-code-0',
|
||||
'partner_agent' => 'partner-agent-1',
|
||||
'namespace_id' => 'namespace-id-2',
|
||||
'upload_id' => 'upload-id-3',
|
||||
'upload_tag' => 'upload-tag-4',
|
||||
'upload_source' => 'upload-source-5',
|
||||
);
|
||||
$event_request_async = (new EventRequestAsync('pixel-id'))
|
||||
->setEvents(array($event))
|
||||
->setTestEventCode($expected['test_event_code'])
|
||||
->setPartnerAgent($expected['partner_agent'])
|
||||
->setNamespaceId($expected['namespace_id'])
|
||||
->setUploadId($expected['upload_id'])
|
||||
->setUploadTag($expected['upload_tag'])
|
||||
->setUploadSource($expected['upload_source']);
|
||||
|
||||
$this->assertEquals($expected, $event_request_async->normalize());
|
||||
}
|
||||
|
||||
public function testConstructor() {
|
||||
$event = new Event(array('event_name' => 'my-event'));
|
||||
$expected_event = array('data' => [array('event_name' => $event['event_name'])]);
|
||||
$state = array(
|
||||
'test_event_code' => 'test-event-code-0',
|
||||
'partner_agent' => 'partner-agent-1',
|
||||
'namespace_id' => 'namespace-id-2',
|
||||
'upload_id' => 'upload-id-3',
|
||||
'upload_tag' => 'upload-tag-4',
|
||||
'upload_source' => 'upload-source-5',
|
||||
);
|
||||
$data = array_merge(array('events' => array($event)), $state);
|
||||
$expected = array_merge($state, $expected_event);
|
||||
$event_request_async = new EventRequestAsync('pixel-id', $data);
|
||||
|
||||
$this->assertEquals($expected, $event_request_async->normalize());
|
||||
}
|
||||
|
||||
public function testPromiseCancel() {
|
||||
Api::init(null, null, 'access-token-123');
|
||||
$event_request_async = new EventRequestAsync('pixel-id-456', array(
|
||||
'test_event_code' => 'test-event-code-0',
|
||||
'events' => array(new Event(array('event_name' => 'my-event')))
|
||||
));
|
||||
$promise = $event_request_async->execute();
|
||||
$promise->cancel();
|
||||
|
||||
$this->assertEquals('rejected', $promise->getState());
|
||||
}
|
||||
|
||||
public function testPromiseReject() {
|
||||
Api::init(null, null, 'access-token-123');
|
||||
$event_request_async = new EventRequestAsync('pixel-id-456', array(
|
||||
'test_event_code' => 'test-event-code-0',
|
||||
'events' => array(new Event(array('event_name' => 'my-event')))
|
||||
));
|
||||
$promise = $event_request_async->execute();
|
||||
$promise->reject('some error');
|
||||
|
||||
$this->assertEquals('rejected', $promise->getState());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAdsTest\Object\ServerSide\TestHelpers\FakeHttpService;
|
||||
use FacebookAdsTest\Object\ServerSide\TestHelpers\AnotherHttpService;
|
||||
use FacebookAds\Api;
|
||||
use FacebookAds\ApiConfig;
|
||||
use FacebookAds\Http\Client;
|
||||
use FacebookAds\Object\AbstractObject;
|
||||
use FacebookAds\Object\ServerSide\Event;
|
||||
use FacebookAds\Object\ServerSide\EventRequest;
|
||||
use FacebookAds\Object\ServerSide\EventResponse;
|
||||
use FacebookAds\Object\ServerSide\HttpServiceClientConfig;
|
||||
use FacebookAds\Object\ServerSide\Util;
|
||||
use Mockery as m;
|
||||
|
||||
class EventRequestTest extends AbstractUnitTestCase {
|
||||
protected function setUp(): void {
|
||||
$this->expected_pixel_id = 'pixel-1000';
|
||||
$this->expected_url = 'https://graph.facebook.com/v'
|
||||
. ApiConfig::APIVersion
|
||||
. '/'
|
||||
. $this->expected_pixel_id
|
||||
. '/events';
|
||||
$this->expected_headers = array(
|
||||
'User-Agent' => 'fbbizsdk-php-v' . ApiConfig::SDKVersion,
|
||||
'Accept-Encoding' => '*',
|
||||
);
|
||||
$this->expected_access_token = 'a-test-token';
|
||||
$this->expected_curl_options = array(
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_CAINFO => Util::getCaBundlePath(),
|
||||
);
|
||||
HttpServiceClientConfig::getInstance()->setAccessToken(null);
|
||||
HttpServiceClientConfig::getInstance()->setClient(null);
|
||||
HttpServiceClientConfig::getInstance()->setAppsecret(null);
|
||||
Api::init(null, null, null, false);
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testBuilder() {
|
||||
$event = new Event(array('event_name' => 'event-123'));
|
||||
$expected = array(
|
||||
'data' => array(array('event_name' => $event['event_name'])),
|
||||
'test_event_code' => 'test-event-code-0',
|
||||
'partner_agent' => 'partner-agent-1',
|
||||
'namespace_id' => 'namespace-id-2',
|
||||
'upload_id' => 'upload-id-3',
|
||||
'upload_tag' => 'upload-tag-4',
|
||||
'upload_source' => 'upload-source-5',
|
||||
);
|
||||
$event_request = (new EventRequest('pixel-id'))
|
||||
->setEvents(array($event))
|
||||
->setTestEventCode($expected['test_event_code'])
|
||||
->setPartnerAgent($expected['partner_agent'])
|
||||
->setNamespaceId($expected['namespace_id'])
|
||||
->setUploadId($expected['upload_id'])
|
||||
->setUploadTag($expected['upload_tag'])
|
||||
->setUploadSource($expected['upload_source']);
|
||||
|
||||
$this->assertEquals($expected, $event_request->normalize());
|
||||
}
|
||||
|
||||
public function testConstructor() {
|
||||
$event = new Event(array('event_name' => 'event-123'));
|
||||
$expected_event = array('data' => [array('event_name' => $event['event_name'])]);
|
||||
$state = array(
|
||||
'test_event_code' => 'test-event-code-0',
|
||||
'partner_agent' => 'partner-agent-1',
|
||||
'namespace_id' => 'namespace-id-2',
|
||||
'upload_id' => 'upload-id-3',
|
||||
'upload_tag' => 'upload-tag-4',
|
||||
'upload_source' => 'upload-source-5',
|
||||
);
|
||||
$data = array_merge(array('events' => array($event)), $state);
|
||||
$expected = array_merge($state, $expected_event);
|
||||
$event_request = new EventRequest('pixel-id', $data);
|
||||
|
||||
$this->assertEquals($expected, $event_request->normalize());
|
||||
}
|
||||
|
||||
public function testDefaultHttpService() {
|
||||
$mock_ads_pixel = m::mock('overload:FacebookAds\Object\AdsPixel');
|
||||
$mock_ads_pixel
|
||||
->shouldReceive('__construct')
|
||||
->once()
|
||||
->with($this->expected_pixel_id);
|
||||
$event_response_contents = array('data' => array('events_received' => 1));
|
||||
$expected_event_response = new EventResponse($event_response_contents);
|
||||
$create_response_mock = $this->createMock(AbstractObject::class);
|
||||
$create_response_mock
|
||||
->expects($this->once())
|
||||
->method('exportAllData')
|
||||
->willReturn($event_response_contents);
|
||||
$event_request = new EventRequest($this->expected_pixel_id);
|
||||
$event_request->setEvents(array(new Event(array('event_name' => 'event-123'))));
|
||||
$mock_ads_pixel
|
||||
->shouldReceive('createEvent')
|
||||
->once()
|
||||
->with(array(), $event_request->normalize())
|
||||
->andReturn($create_response_mock);
|
||||
$actual_event_response = $event_request->execute();
|
||||
|
||||
$this->assertEquals($expected_event_response, $actual_event_response);
|
||||
}
|
||||
|
||||
public function testSetHttpClient() {
|
||||
$appsecret = 'appsecret-012';
|
||||
Api::init(null, $appsecret, $this->expected_access_token, false);
|
||||
$mock_client = m::mock('FacebookAdsTest\Object\ServerSide\TestHelpers\FakeHttpService');
|
||||
$expected_event_response = new EventResponse(
|
||||
array(
|
||||
'data' => array('events_received' => 1)
|
||||
)
|
||||
);
|
||||
$event_request = new EventRequest($this->expected_pixel_id);
|
||||
$event_request->setEvents(array(new Event(array('event_name' => 'event-123'))));
|
||||
$event_request->setHttpClient($mock_client);
|
||||
$mock_client
|
||||
->shouldReceive('executeRequest')
|
||||
->once()
|
||||
->with(
|
||||
$this->expected_url,
|
||||
'POST',
|
||||
$this->expected_curl_options,
|
||||
$this->expected_headers,
|
||||
$this->normalize_and_merge($event_request, $this->expected_access_token, $appsecret)
|
||||
)
|
||||
->andReturn($expected_event_response);
|
||||
$actual_event_response = $event_request->execute();
|
||||
|
||||
$this->assertEquals($expected_event_response, $actual_event_response);
|
||||
}
|
||||
|
||||
public function testSetHttpClientClientConfig() {
|
||||
$mock_client = m::mock('FacebookAdsTest\Object\ServerSide\TestHelpers\FakeHttpService');
|
||||
$expected_event_response = new EventResponse(
|
||||
array(
|
||||
'data' => array('events_received' => 1)
|
||||
)
|
||||
);
|
||||
$event_request = new EventRequest($this->expected_pixel_id);
|
||||
$event_request->setEvents(array(new Event(array('event_name' => 'event-123'))));
|
||||
$mock_client
|
||||
->shouldReceive('executeRequest')
|
||||
->once()
|
||||
->with(
|
||||
$this->expected_url,
|
||||
'POST',
|
||||
$this->expected_curl_options,
|
||||
$this->expected_headers,
|
||||
$this->normalize_and_merge($event_request, $this->expected_access_token, null)
|
||||
)
|
||||
->andReturn($expected_event_response);
|
||||
HttpServiceClientConfig::getInstance()->setClient($mock_client);
|
||||
HttpServiceClientConfig::getInstance()->setAccessToken($this->expected_access_token);
|
||||
$actual_event_response = $event_request->execute();
|
||||
|
||||
$this->assertEquals($expected_event_response, $actual_event_response);
|
||||
}
|
||||
|
||||
public function testEventRequestHttpClientOverridesClientConfig() {
|
||||
$appsecret = 'appsecret-012';
|
||||
Api::init(null, 'a-different-app-secret', 'a-different-access-token', false);
|
||||
$mock_used_client = m::mock('FacebookAdsTest\Object\ServerSide\TestHelpers\AnotherHttpService');
|
||||
$mock_unused_client = m::mock('FacebookAdsTest\Object\ServerSide\TestHelpers\AnotherHttpService');
|
||||
$expected_event_response = new EventResponse(
|
||||
array(
|
||||
'data' => array('events_received' => 1)
|
||||
)
|
||||
);
|
||||
$event_request = new EventRequest($this->expected_pixel_id);
|
||||
$event_request->setEvents(array(new Event(array('event_name' => 'event-123'))));
|
||||
$event_request->setHttpClient($mock_used_client);
|
||||
$mock_used_client
|
||||
->shouldReceive('executeRequest')
|
||||
->once()
|
||||
->with(
|
||||
$this->expected_url,
|
||||
'POST',
|
||||
$this->expected_curl_options,
|
||||
$this->expected_headers,
|
||||
$this->normalize_and_merge($event_request, $this->expected_access_token, $appsecret)
|
||||
)
|
||||
->andReturn($expected_event_response);
|
||||
HttpServiceClientConfig::getInstance()->setClient($mock_unused_client);
|
||||
HttpServiceClientConfig::getInstance()->setAccessToken($this->expected_access_token);
|
||||
HttpServiceClientConfig::getInstance()->setAppsecret($appsecret);
|
||||
$actual_event_response = $event_request->execute();
|
||||
|
||||
$this->assertEquals($expected_event_response, $actual_event_response);
|
||||
}
|
||||
|
||||
// Test helper functions
|
||||
|
||||
protected function normalize_and_merge($event_request, $access_token, $appsecret) {
|
||||
$normalized_merged = $event_request->normalize();
|
||||
$normalized_merged['access_token'] = $access_token;
|
||||
if ($appsecret != null) {
|
||||
$normalized_merged['appsecret_proof'] = Util::getAppsecretProof($access_token, $appsecret);
|
||||
}
|
||||
return $normalized_merged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\ActionSource;
|
||||
use FacebookAds\Object\ServerSide\CustomData;
|
||||
use FacebookAds\Object\ServerSide\Event;
|
||||
use FacebookAds\Object\ServerSide\UserData;
|
||||
|
||||
class EventTest extends AbstractUnitTestCase {
|
||||
public function testBuilder() {
|
||||
$user_data = new UserData(array('email' => 'eg@test.com'));
|
||||
$custom_data = new CustomData(array('order_id' => '123'));
|
||||
$expected = array(
|
||||
'event_name' => 'event_name-0',
|
||||
'event_time' => 1234,
|
||||
'event_source_url' => 'event_source_url-2',
|
||||
'opt_out' => false,
|
||||
'event_id' => 'event_id-3',
|
||||
'user_data' => $user_data->normalize(),
|
||||
'custom_data' => $custom_data->normalize(),
|
||||
'data_processing_options' => array('1', '2'),
|
||||
'data_processing_options_country' => 1,
|
||||
'data_processing_options_state' => 2,
|
||||
'action_source' => ActionSource::WEBSITE,
|
||||
);
|
||||
|
||||
$event = (new Event())
|
||||
->setEventName($expected['event_name'])
|
||||
->setEventTime($expected['event_time'])
|
||||
->setEventSourceUrl($expected['event_source_url'])
|
||||
->setOptOut($expected['opt_out'])
|
||||
->setEventId($expected['event_id'])
|
||||
->setUserData($user_data)
|
||||
->setCustomData($custom_data)
|
||||
->setDataProcessingOptions($expected['data_processing_options'])
|
||||
->setDataProcessingOptionsCountry($expected['data_processing_options_country'])
|
||||
->setDataProcessingOptionsState($expected['data_processing_options_state'])
|
||||
->setActionSource($expected['action_source']);
|
||||
|
||||
$this->assertEquals($expected, $event->normalize());
|
||||
}
|
||||
|
||||
public function testWhenOptOutIsTrue() {
|
||||
$event = (new Event())->setOptOut(true);
|
||||
|
||||
$this->assertEquals(array('opt_out' => true), $event->normalize());
|
||||
}
|
||||
|
||||
public function testInvalidActionSource() {
|
||||
$action_source = 'invalid action source';
|
||||
$event = (new Event())->setActionSource($action_source);
|
||||
|
||||
try {
|
||||
$normalized_payload = $event->normalize();
|
||||
} catch (\Exception $exception) {
|
||||
$has_thrown_exception = true;
|
||||
$expected_string = sprintf("Invalid action_source passed: %s",$action_source);
|
||||
$this->assertStringContainsString($expected_string, $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertTrue($has_thrown_exception);
|
||||
}
|
||||
|
||||
public function testActionSourceGetsNormalized() {
|
||||
$event = (new Event())->setActionSource('Email');
|
||||
$normalized_payload = $event->normalize();
|
||||
|
||||
$this->assertEquals($normalized_payload['action_source'], 'email');
|
||||
}
|
||||
|
||||
public function testActionSourceIsNull() {
|
||||
$event = (new Event());
|
||||
$normalized_payload = $event->normalize();
|
||||
|
||||
$this->assertFalse(array_key_exists('action_source', $normalized_payload));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\Event;
|
||||
|
||||
|
||||
class ServerSideNormalizeTest extends AbstractUnitTestCase {
|
||||
|
||||
public function testEventData(){
|
||||
$testName = 'Test123Event';
|
||||
$testUrl = 'www.example.com';
|
||||
$testTime = time();
|
||||
|
||||
$event = (new Event())
|
||||
->setEventName($testName)
|
||||
->setEventTime($testTime)
|
||||
->setEventSourceUrl($testUrl);
|
||||
|
||||
$normalized_array = $event->normalize();
|
||||
$this->assertEquals($normalized_array['event_name'], $testName);
|
||||
$this->assertEquals($normalized_array['event_time'], $testTime);
|
||||
$this->assertEquals($normalized_array['event_source_url'], $testUrl);
|
||||
}
|
||||
|
||||
public function testEmptyLDUData(){
|
||||
$event = (new Event())
|
||||
->setEventName('TestEvent')
|
||||
->setDataProcessingOptions([]);
|
||||
|
||||
$normalized_array = $event->normalize();
|
||||
|
||||
$this->assertEquals($normalized_array['data_processing_options'], array());
|
||||
}
|
||||
|
||||
public function testDefaultLDUData(){
|
||||
$event = (new Event())
|
||||
->setEventName('TestEvent')
|
||||
->setDataProcessingOptions(['LDU'])
|
||||
->setDataProcessingOptionsCountry(0)
|
||||
->setDataProcessingOptionsState(0);
|
||||
|
||||
$normalized_array = $event->normalize();
|
||||
|
||||
$this->assertEquals($normalized_array['data_processing_options'], array("LDU"));
|
||||
$this->assertEquals($normalized_array['data_processing_options_state'], "0");
|
||||
$this->assertEquals($normalized_array['data_processing_options_country'], "0");
|
||||
}
|
||||
|
||||
public function testValidLDUStateCountryData(){
|
||||
$event = (new Event())
|
||||
->setEventName('TestEvent')
|
||||
->setDataProcessingOptions(['LDU'])
|
||||
->setDataProcessingOptionsCountry(1)
|
||||
->setDataProcessingOptionsState(1000);
|
||||
|
||||
$normalized_array = $event->normalize();
|
||||
|
||||
$this->assertEquals($normalized_array['data_processing_options'], array("LDU"));
|
||||
$this->assertEquals($normalized_array['data_processing_options_state'], "1000");
|
||||
$this->assertEquals($normalized_array['data_processing_options_country'], "1");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\Normalizer;
|
||||
|
||||
|
||||
class ServerSideNormalizeTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* Test cases for Email Normalization
|
||||
*/
|
||||
public function emailNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
"foo(.bar)@baz.com/",
|
||||
'foo.bar@baz.com',
|
||||
),
|
||||
array(
|
||||
'foo"@bar.com',
|
||||
'foo@bar.com',
|
||||
),
|
||||
array(
|
||||
'foo()@bar.com',
|
||||
'foo@bar.com',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider emailNormalizeData
|
||||
*/
|
||||
public function testEmailNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('em', $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for Phone Normalization
|
||||
*/
|
||||
public function phoneNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
'123-456-7890',
|
||||
'1234567890',
|
||||
),
|
||||
array(
|
||||
'777 747 (3515)',
|
||||
'7777473515',
|
||||
),
|
||||
array(
|
||||
'+442071838750',
|
||||
'442071838750',
|
||||
),
|
||||
array(
|
||||
'44-12390821300A',
|
||||
'4412390821300',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider phoneNormalizeData
|
||||
*/
|
||||
public function testPhoneNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('ph', $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for Postal Code Normalization
|
||||
*/
|
||||
public function postalCodeNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
' 98121',
|
||||
'98121',
|
||||
),
|
||||
array(
|
||||
'98121-4892',
|
||||
'98121',
|
||||
),
|
||||
array(
|
||||
'NR9 5AL',
|
||||
'nr95al',
|
||||
),
|
||||
array(
|
||||
'98-121-4892',
|
||||
'98',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider postalCodeNormalizeData
|
||||
*/
|
||||
public function testPostalCodeNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('zp', $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for City Normalization
|
||||
*/
|
||||
public function cityNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
'Menlo Park',
|
||||
'menlopark',
|
||||
),
|
||||
array(
|
||||
'Seattle-98121',
|
||||
'seattle',
|
||||
),
|
||||
array(
|
||||
'Washington D.C',
|
||||
'washingtondc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider cityNormalizeData
|
||||
*/
|
||||
public function testCityNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('ct', $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for Country Normalization
|
||||
*/
|
||||
public function countryNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
' US ',
|
||||
'us',
|
||||
),
|
||||
array(
|
||||
'*****UU*****', // Can't validate, just normalizes
|
||||
'uu',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider countryNormalizeData
|
||||
*/
|
||||
public function testCountryNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('country', $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for Currency Normalization
|
||||
*/
|
||||
public function currencyNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
' ABC ', // Can't validate the data, just normalizes.
|
||||
'abc',
|
||||
),
|
||||
array(
|
||||
'INR',
|
||||
'inr',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider currencyNormalizeData
|
||||
*/
|
||||
public function testCurrencyNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('currency', $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* test for asserting valid exception is thrown for invalid (ISO)currency format
|
||||
*/
|
||||
public function testCurrencyException() {
|
||||
$has_throw_exception = false;
|
||||
try {
|
||||
Normalizer::normalize('currency', 'Us Dollar');
|
||||
} catch (\Exception $e) {
|
||||
$has_throw_exception = true;
|
||||
}
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for asserting valid exception is thrown for invalid (ISO)country format
|
||||
*/
|
||||
public function testCountryException() {
|
||||
$has_throw_exception = false;
|
||||
try {
|
||||
Normalizer::normalize('country', 'United States of America');
|
||||
} catch (\Exception $e) {
|
||||
$has_throw_exception = true;
|
||||
}
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for asserting valid exception is thrown for invalid Email format
|
||||
*/
|
||||
public function testEmailException() {
|
||||
$has_throw_exception = false;
|
||||
try {
|
||||
Normalizer::normalize('em', '324342@@@@bar.com');
|
||||
} catch (\Exception $e) {
|
||||
$has_throw_exception = true;
|
||||
}
|
||||
$this->assertTrue($has_throw_exception);
|
||||
}
|
||||
|
||||
public function f5firstData() {
|
||||
return array(
|
||||
array(
|
||||
'George',
|
||||
'georg',
|
||||
),
|
||||
array(
|
||||
'John',
|
||||
'john',
|
||||
),
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider f5firstData
|
||||
*/
|
||||
public function testF5first($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('f5first', $input)
|
||||
);
|
||||
}
|
||||
|
||||
public function f5lastData() {
|
||||
return array(
|
||||
array(
|
||||
'Washington',
|
||||
'washi',
|
||||
),
|
||||
array(
|
||||
'Adams',
|
||||
'adams',
|
||||
),
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider f5lastData
|
||||
*/
|
||||
public function testF5last($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('f5last', $input)
|
||||
);
|
||||
}
|
||||
|
||||
public function fiData() {
|
||||
return array(
|
||||
array(
|
||||
'GW',
|
||||
'g',
|
||||
),
|
||||
array(
|
||||
'j',
|
||||
'j',
|
||||
),
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider fiData
|
||||
*/
|
||||
public function testFi($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('fi', $input)
|
||||
);
|
||||
}
|
||||
|
||||
public function dobdData() {
|
||||
return array(
|
||||
array(
|
||||
'1',
|
||||
'01',
|
||||
),
|
||||
array(
|
||||
'9',
|
||||
'09',
|
||||
),
|
||||
array(
|
||||
'31',
|
||||
'31',
|
||||
),
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dobdData
|
||||
*/
|
||||
public function testDobd($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('dobd', $input)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDobdException() {
|
||||
$failure_cases = array(
|
||||
'-1',
|
||||
'0',
|
||||
'32',
|
||||
'2b',
|
||||
'ab',
|
||||
);
|
||||
$exceptions_counter = 0;
|
||||
$has_throw_exception = false;
|
||||
foreach ($failure_cases as $case) {
|
||||
try {
|
||||
Normalizer::normalize('dobd', $case);
|
||||
} catch (\Exception $e) {
|
||||
$exceptions_counter += 1;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(count($failure_cases), $exceptions_counter);
|
||||
}
|
||||
|
||||
public function dobmData() {
|
||||
return array(
|
||||
array(
|
||||
'1',
|
||||
'01',
|
||||
),
|
||||
array(
|
||||
'5',
|
||||
'05',
|
||||
),
|
||||
array(
|
||||
'12',
|
||||
'12',
|
||||
),
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dobmData
|
||||
*/
|
||||
public function testDobm($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('dobm', $input)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDobmException() {
|
||||
$failure_cases = array(
|
||||
'-1',
|
||||
'0',
|
||||
'13',
|
||||
'1a',
|
||||
'May',
|
||||
'oc',
|
||||
);
|
||||
$exceptions_counter = 0;
|
||||
$has_throw_exception = false;
|
||||
foreach ($failure_cases as $case) {
|
||||
try {
|
||||
Normalizer::normalize('dobm', $case);
|
||||
} catch (\Exception $e) {
|
||||
$exceptions_counter += 1;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(count($failure_cases), $exceptions_counter);
|
||||
}
|
||||
|
||||
public function dobyData() {
|
||||
return array(
|
||||
array(
|
||||
'1995',
|
||||
'1995',
|
||||
),
|
||||
array(
|
||||
'9999',
|
||||
'9999',
|
||||
),
|
||||
array(
|
||||
'1000',
|
||||
'1000',
|
||||
),
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dobyData
|
||||
*/
|
||||
public function testDoby($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('doby', $input)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDobyException() {
|
||||
$failure_cases = array(
|
||||
'-1',
|
||||
'0',
|
||||
'20',
|
||||
'12345',
|
||||
'nineteen-eighty',
|
||||
);
|
||||
$exceptions_counter = 0;
|
||||
$has_throw_exception = false;
|
||||
foreach ($failure_cases as $case) {
|
||||
try {
|
||||
Normalizer::normalize('doby', $case);
|
||||
} catch (\Exception $e) {
|
||||
$exceptions_counter += 1;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(count($failure_cases), $exceptions_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for DeliveryCategory Normalization
|
||||
*/
|
||||
public function deliveryCategoryNormalizeData() {
|
||||
return array(
|
||||
array(
|
||||
'home_delivery',
|
||||
'home_delivery',
|
||||
),
|
||||
array(
|
||||
'CURBSIDE',
|
||||
'curbside',
|
||||
),
|
||||
array(
|
||||
' IN_STORE ',
|
||||
'in_store',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider deliveryCategoryNormalizeData
|
||||
*/
|
||||
public function testDeliveryCategoryNormalize($input, $expected) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Normalizer::normalize('delivery_category', $input));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use FacebookAds\Object\ServerSide\Util;
|
||||
|
||||
class ServerSideUtilTest extends TestCase {
|
||||
|
||||
public function setUp(): void {
|
||||
$_SERVER = [];
|
||||
$_COOKIE = [];
|
||||
}
|
||||
|
||||
public function testNewEventTakesIpAddressFromHttpClientIP() {
|
||||
$_SERVER["HTTP_CLIENT_IP"] = "HTTP_CLIENT_IP_VALUE";
|
||||
$_SERVER["HTTP_X_FORWARDED_FOR"] = "HTTP_X_FORWARDED_FOR_VALUE";
|
||||
$_SERVER["REMOTE_ADDR"] = "REMOTE_ADDR";
|
||||
$this->assertEquals("HTTP_CLIENT_IP_VALUE",
|
||||
Util::getIpAddress());
|
||||
}
|
||||
|
||||
public function testNewEventTakesIpAddressFromHttpXForwardedFor() {
|
||||
$_SERVER["HTTP_X_FORWARDED_FOR"] = "HTTP_X_FORWARDED_FOR_VALUE";
|
||||
$_SERVER["REMOTE_ADDR"] = "REMOTE_ADDR";
|
||||
$this->assertEquals("HTTP_X_FORWARDED_FOR_VALUE",
|
||||
Util::getIpAddress());
|
||||
}
|
||||
|
||||
public function testNewEventTakesIpAddressFromRemoteAddr() {
|
||||
$_SERVER["REMOTE_ADDR"] = "REMOTE_ADDR_VALUE";
|
||||
$this->assertEquals("REMOTE_ADDR_VALUE",
|
||||
Util::getIpAddress());
|
||||
}
|
||||
|
||||
public function testNewEventHasUserAgent() {
|
||||
$_SERVER["HTTP_USER_AGENT"] = "HTTP_USER_AGENT_VALUE";
|
||||
|
||||
$this->assertEquals("HTTP_USER_AGENT_VALUE",
|
||||
Util::getHttpUserAgent());
|
||||
}
|
||||
|
||||
public function testNewEventHasEventSourceUrlWithHttps() {
|
||||
$_SERVER["HTTPS"] = "anyvalue";
|
||||
$_SERVER["HTTP_HOST"] = "www.pikachu.com";
|
||||
$_SERVER["REQUEST_URI"] = "/index.php";
|
||||
|
||||
$this->assertEquals("https://www.pikachu.com/index.php", Util::getRequestUri());
|
||||
}
|
||||
|
||||
public function testNewEventHasEventSourceUrlWithHttp() {
|
||||
$_SERVER["HTTPS"] = "";
|
||||
$_SERVER["HTTP_HOST"] = "www.pikachu.com";
|
||||
$_SERVER["REQUEST_URI"] = "/index.php";
|
||||
|
||||
|
||||
$this->assertEquals("http://www.pikachu.com/index.php", Util::getRequestUri());
|
||||
}
|
||||
|
||||
public function testNewEventHasEventSourceUrlWithHttpsOff() {
|
||||
$_SERVER["HTTPS"] = "off";
|
||||
$_SERVER["HTTP_HOST"] = "www.pikachu.com";
|
||||
$_SERVER["REQUEST_URI"] = "/index.php";
|
||||
|
||||
$this->assertEquals("http://www.pikachu.com/index.php", Util::getRequestUri());
|
||||
}
|
||||
|
||||
|
||||
public function testNewEventHasFbc() {
|
||||
$_COOKIE["_fbc"] = "_fbc_value";
|
||||
|
||||
$this->assertEquals("_fbc_value", Util::getFbc());
|
||||
}
|
||||
|
||||
public function testNewEventHasFbp() {
|
||||
$_COOKIE["_fbp"] = "_fbp_value";
|
||||
|
||||
$this->assertEquals("_fbp_value", Util::getFbp());
|
||||
}
|
||||
|
||||
public function testGetCaBundlePath() {
|
||||
$this->assertTrue(file_exists(Util::getCaBundlePath()));
|
||||
}
|
||||
|
||||
public function testGetAppsecretProof() {
|
||||
$access_token = 'accesstoken0';
|
||||
$appsecret = 'appsecret1';
|
||||
$expected_appsecret_proof = hash_hmac(
|
||||
'sha256',
|
||||
$access_token,
|
||||
$appsecret
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
Util::getAppsecretProof($access_token, $appsecret),
|
||||
$expected_appsecret_proof
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide\TestHelpers;
|
||||
use FacebookAds\Object\ServerSide\HttpServiceInterface;
|
||||
|
||||
class AnotherHttpService implements HttpServiceInterface {
|
||||
public function executeRequest($url, $method, array $curl_options, array $headers, array $params) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\ServerSide\TestHelpers;
|
||||
use FacebookAds\Object\ServerSide\HttpServiceInterface;
|
||||
|
||||
class FakeHttpService implements HttpServiceInterface {
|
||||
public function executeRequest($url, $method, array $curl_options, array $headers, array $params) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\ServerSide\UserData;
|
||||
use FacebookAds\Object\ServerSide\Util;
|
||||
use InvalidArgumentException;
|
||||
|
||||
|
||||
class UserDataTest extends AbstractUnitTestCase {
|
||||
public function testBuilderAndConstructor() {
|
||||
$initial_state = array(
|
||||
'email' => 'email-0@test.com',
|
||||
'phone' => '1234567890',
|
||||
'gender' => 'f',
|
||||
'date_of_birth' => '01/01/2001',
|
||||
'last_name' => 'last_name-4',
|
||||
'first_name' => 'first_name-5',
|
||||
'city' => 'city',
|
||||
'state' => 'state',
|
||||
'country_code' => 'us',
|
||||
'zip_code' => '12345',
|
||||
'external_id' => 'external_id-10',
|
||||
'client_ip_address' => 'client_ip_address-11',
|
||||
'client_user_agent' => 'client_user_agent-12',
|
||||
'fbc' => 'fbc-13',
|
||||
'fbp' => 'fbp-14',
|
||||
'subscription_id' => 'subscription_id-15',
|
||||
'fb_login_id' => 'fb_login_id-16',
|
||||
'lead_id' => 'lead_id-17',
|
||||
'f5first' => 'f5fir',
|
||||
'f5last' => 'f5las',
|
||||
'fi' => 'f',
|
||||
'dobd' => '01',
|
||||
'dobm' => '01',
|
||||
'doby' => '2001'
|
||||
);
|
||||
$expected = array(
|
||||
'em' => array(Util::hash($initial_state['email'])),
|
||||
'ph' => array(Util::hash($initial_state['phone'])),
|
||||
'ge' => array(Util::hash($initial_state['gender'])),
|
||||
'db' => array(Util::hash($initial_state['date_of_birth'])),
|
||||
'ln' => array(Util::hash($initial_state['last_name'])),
|
||||
'fn' => array(Util::hash($initial_state['first_name'])),
|
||||
'ct' => array(Util::hash($initial_state['city'])),
|
||||
'st' => array(Util::hash($initial_state['state'])),
|
||||
'country' => array(Util::hash($initial_state['country_code'])),
|
||||
'zp' => array(Util::hash($initial_state['zip_code'])),
|
||||
'external_id' => array('external_id-10'),
|
||||
'client_ip_address' => 'client_ip_address-11',
|
||||
'client_user_agent' => 'client_user_agent-12',
|
||||
'fbc' => 'fbc-13',
|
||||
'fbp' => 'fbp-14',
|
||||
'subscription_id' => 'subscription_id-15',
|
||||
'fb_login_id' => 'fb_login_id-16',
|
||||
'lead_id' => 'lead_id-17',
|
||||
'f5first' => Util::hash($initial_state['f5first']),
|
||||
'f5last' => Util::hash($initial_state['f5last']),
|
||||
'fi' => Util::hash($initial_state['fi']),
|
||||
'dobd' => Util::hash($initial_state['dobd']),
|
||||
'dobm' => Util::hash($initial_state['dobm']),
|
||||
'doby' => Util::hash($initial_state['doby'])
|
||||
);
|
||||
$builder = (new UserData())
|
||||
->setEmail($initial_state['email'])
|
||||
->setPhone($initial_state['phone'])
|
||||
->setGender($initial_state['gender'])
|
||||
->setDateOfBirth($initial_state['date_of_birth'])
|
||||
->setLastName($initial_state['last_name'])
|
||||
->setFirstName($initial_state['first_name'])
|
||||
->setCity($initial_state['city'])
|
||||
->setState($initial_state['state'])
|
||||
->setCountryCode($initial_state['country_code'])
|
||||
->setZipCode($initial_state['zip_code'])
|
||||
->setExternalId($initial_state['external_id'])
|
||||
->setClientIpAddress($initial_state['client_ip_address'])
|
||||
->setClientUserAgent($initial_state['client_user_agent'])
|
||||
->setFbc($initial_state['fbc'])
|
||||
->setFbp($initial_state['fbp'])
|
||||
->setSubscriptionId($initial_state['subscription_id'])
|
||||
->setFbLoginId($initial_state['fb_login_id'])
|
||||
->setLeadId($initial_state['lead_id'])
|
||||
->setF5first($initial_state['f5first'])
|
||||
->setF5last($initial_state['f5last'])
|
||||
->setFi($initial_state['fi'])
|
||||
->setDobd($initial_state['dobd'])
|
||||
->setDobm($initial_state['dobm'])
|
||||
->setDoby($initial_state['doby']);
|
||||
|
||||
$this->assertEquals($expected, $builder->normalize());
|
||||
|
||||
$constructor = new UserData($initial_state);
|
||||
$this->assertEquals($expected, $constructor->normalize());
|
||||
|
||||
// Make sure single value getters still work, since we store these fields as arrays internally.
|
||||
$this->assertEquals($initial_state['email'], $constructor->getEmail());
|
||||
$this->assertEquals($initial_state['phone'], $constructor->getPhone());
|
||||
$this->assertEquals($initial_state['gender'], $constructor->getGender());
|
||||
$this->assertEquals($initial_state['date_of_birth'], $constructor->getDateOfBirth());
|
||||
$this->assertEquals($initial_state['last_name'], $constructor->getLastName());
|
||||
$this->assertEquals($initial_state['first_name'], $constructor->getFirstName());
|
||||
$this->assertEquals($initial_state['city'], $constructor->getCity());
|
||||
$this->assertEquals($initial_state['state'], $constructor->getState());
|
||||
$this->assertEquals($initial_state['country_code'], $constructor->getCountryCode());
|
||||
$this->assertEquals($initial_state['zip_code'], $constructor->getZipCode());
|
||||
$this->assertEquals($initial_state['external_id'], $constructor->getExternalId());
|
||||
}
|
||||
|
||||
public function testMultiValueFieldsGettersAndSetters() {
|
||||
$initial_state = array(
|
||||
'emails' => array('email-0@test.com', 'email-1@eg.com'),
|
||||
'phones' => array('1234567890', '10000000000'),
|
||||
'genders' => array('f', 'm'),
|
||||
'dates_of_birth' => array('01/01/2001', '02/09/2008'),
|
||||
'last_names' => array('last_name-4', 'smith'),
|
||||
'first_names' => array('first_name-5', 'joe'),
|
||||
'cities' => array('seattle', 'san fransisco'),
|
||||
'states' => array('WA', 'CA'),
|
||||
'country_codes' => array('us', 'ca'),
|
||||
'zip_codes' => array('12345', '00000'),
|
||||
'external_ids' => array('external_id-10', '123')
|
||||
);
|
||||
|
||||
$userData = (new UserData())
|
||||
->setEmails($initial_state['emails'])
|
||||
->setPhones($initial_state['phones'])
|
||||
->setGenders($initial_state['genders'])
|
||||
->setDatesOfBirth($initial_state['dates_of_birth'])
|
||||
->setLastNames($initial_state['last_names'])
|
||||
->setFirstNames($initial_state['first_names'])
|
||||
->setCities($initial_state['cities'])
|
||||
->setStates($initial_state['states'])
|
||||
->setCountryCodes($initial_state['country_codes'])
|
||||
->setZipCodes($initial_state['zip_codes'])
|
||||
->setExternalIds($initial_state['external_ids']);
|
||||
|
||||
$this->assertEquals($initial_state['emails'], $userData->getEmails());
|
||||
$this->assertEquals($initial_state['phones'], $userData->getPhones());
|
||||
$this->assertEquals($initial_state['genders'], $userData->getGenders());
|
||||
$this->assertEquals($initial_state['dates_of_birth'], $userData->getDatesOfBirth());
|
||||
$this->assertEquals($initial_state['last_names'], $userData->getLastNames());
|
||||
$this->assertEquals($initial_state['first_names'], $userData->getFirstNames());
|
||||
$this->assertEquals($initial_state['cities'], $userData->getCities());
|
||||
$this->assertEquals($initial_state['states'], $userData->getStates());
|
||||
$this->assertEquals($initial_state['country_codes'], $userData->getCountryCodes());
|
||||
$this->assertEquals($initial_state['zip_codes'], $userData->getZipCodes());
|
||||
$this->assertEquals($initial_state['external_ids'], $userData->getExternalIds());
|
||||
}
|
||||
|
||||
public function testConstructorWithBothSingularAndPluralParams() {
|
||||
$params = array(
|
||||
array('email', 'emails'),
|
||||
array('phone', 'phones'),
|
||||
array('gender', 'genders'),
|
||||
array('date_of_birth', 'dates_of_birth'),
|
||||
array('last_name', 'last_names'),
|
||||
array('first_name', 'first_names'),
|
||||
array('city', 'cities'),
|
||||
array('state', 'states'),
|
||||
array('country_code', 'country_codes'),
|
||||
array('zip_code', 'zip_codes'),
|
||||
array('external_id', 'external_ids')
|
||||
);
|
||||
|
||||
$exception_count = 0;
|
||||
foreach ($params as $p){
|
||||
$initial_state = array(
|
||||
$p[0] => 'testStr1',
|
||||
$p[1] => array('testStr2', 'testStr3')
|
||||
);
|
||||
try {
|
||||
$userData = new UserData($initial_state);
|
||||
} catch(InvalidArgumentException $e) {
|
||||
$exception_count++;
|
||||
}
|
||||
}
|
||||
self::assertEquals(count($params), $exception_count);
|
||||
}
|
||||
|
||||
public function testConstructorWithOnlyPluralParams() {
|
||||
$initial_state = array(
|
||||
'emails' => array('email-0@test.com', 'email-1@eg.com'),
|
||||
'phones' => array('1234567890', '10000000000'),
|
||||
'genders' => array('f', 'm'),
|
||||
'dates_of_birth' => array('01/01/2001', '02/09/2008'),
|
||||
'last_names' => array('last_name-4', 'smith'),
|
||||
'first_names' => array('first_name-5', 'joe'),
|
||||
'cities' => array('seattle', 'san fransisco'),
|
||||
'states' => array('WA', 'CA'),
|
||||
'country_codes' => array('us', 'ca'),
|
||||
'zip_codes' => array('12345', '00000'),
|
||||
'external_ids' => array('external_id-10', '123')
|
||||
);
|
||||
|
||||
$userData = new UserData($initial_state);
|
||||
|
||||
$this->assertEquals($initial_state['emails'], $userData->getEmails());
|
||||
$this->assertEquals($initial_state['phones'], $userData->getPhones());
|
||||
$this->assertEquals($initial_state['genders'], $userData->getGenders());
|
||||
$this->assertEquals($initial_state['dates_of_birth'], $userData->getDatesOfBirth());
|
||||
$this->assertEquals($initial_state['last_names'], $userData->getLastNames());
|
||||
$this->assertEquals($initial_state['first_names'], $userData->getFirstNames());
|
||||
$this->assertEquals($initial_state['cities'], $userData->getCities());
|
||||
$this->assertEquals($initial_state['states'], $userData->getStates());
|
||||
$this->assertEquals($initial_state['country_codes'], $userData->getCountryCodes());
|
||||
$this->assertEquals($initial_state['zip_codes'], $userData->getZipCodes());
|
||||
$this->assertEquals($initial_state['external_ids'], $userData->getExternalIds());
|
||||
}
|
||||
|
||||
public function testGettersAndSettersWithNull() {
|
||||
$userData = (new UserData())
|
||||
->setEmail(null)
|
||||
->setPhone(null)
|
||||
->setGender(null)
|
||||
->setDateOfBirth(null)
|
||||
->setLastName(null)
|
||||
->setFirstName(null)
|
||||
->setCity(null)
|
||||
->setState(null)
|
||||
->setCountryCode(null)
|
||||
->setZipCode(null)
|
||||
->setExternalId(null);
|
||||
|
||||
$this->assertEquals(null, $userData->getEmail());
|
||||
$this->assertEquals(null, $userData->getPhone());
|
||||
$this->assertEquals(null, $userData->getGender());
|
||||
$this->assertEquals(null, $userData->getDateOfBirth());
|
||||
$this->assertEquals(null, $userData->getLastName());
|
||||
$this->assertEquals(null, $userData->getFirstName());
|
||||
$this->assertEquals(null, $userData->getCity());
|
||||
$this->assertEquals(null, $userData->getState());
|
||||
$this->assertEquals(null, $userData->getCountryCode());
|
||||
$this->assertEquals(null, $userData->getZipCode());
|
||||
$this->assertEquals(null, $userData->getExternalId());
|
||||
}
|
||||
|
||||
public function testGettersAndSettersWithEmpty() {
|
||||
$userData = (new UserData())
|
||||
->setEmails(array())
|
||||
->setPhones(array())
|
||||
->setGenders(array())
|
||||
->setDatesOfBirth(array())
|
||||
->setLastNames(array())
|
||||
->setFirstNames(array())
|
||||
->setCities(array())
|
||||
->setStates(array())
|
||||
->setCountryCodes(array())
|
||||
->setZipCodes(array())
|
||||
->setExternalIds(array());
|
||||
|
||||
$this->assertEquals(null, $userData->getEmail());
|
||||
$this->assertEquals(null, $userData->getPhone());
|
||||
$this->assertEquals(null, $userData->getGender());
|
||||
$this->assertEquals(null, $userData->getDateOfBirth());
|
||||
$this->assertEquals(null, $userData->getLastName());
|
||||
$this->assertEquals(null, $userData->getFirstName());
|
||||
$this->assertEquals(null, $userData->getCity());
|
||||
$this->assertEquals(null, $userData->getState());
|
||||
$this->assertEquals(null, $userData->getCountryCode());
|
||||
$this->assertEquals(null, $userData->getZipCode());
|
||||
$this->assertEquals(null, $userData->getExternalId());
|
||||
}
|
||||
|
||||
public function testMultiValueFieldsDeduplication() {
|
||||
$initial_state = array(
|
||||
'emails' => array('email-0@test.com', 'email-1@eg.com', 'email-1@eg.com'),
|
||||
'phones' => array('1234567890', '10000000000', '10000000000'),
|
||||
'genders' => array('f', 'm', 'm'),
|
||||
'dates_of_birth' => array('01/01/2001', '02/09/2008', '02/09/2008'),
|
||||
'last_names' => array('last_name-4', 'smith', 'smith'),
|
||||
'first_names' => array('first_name-5', 'joe', 'first_name-5'),
|
||||
'cities' => array('seattle', 'sanfransisco', 'seattle'),
|
||||
'states' => array('wa', 'ca', 'wa'),
|
||||
'country_codes' => array('us', 'ca', 'us'),
|
||||
'zip_codes' => array('12345', '00000', '12345'),
|
||||
'external_ids' => array('external_id-10', '123', 'external_id-10')
|
||||
);
|
||||
|
||||
$userData = (new UserData())
|
||||
->setEmails($initial_state['emails'])
|
||||
->setPhones($initial_state['phones'])
|
||||
->setGenders($initial_state['genders'])
|
||||
->setDatesOfBirth($initial_state['dates_of_birth'])
|
||||
->setLastNames($initial_state['last_names'])
|
||||
->setFirstNames($initial_state['first_names'])
|
||||
->setCities($initial_state['cities'])
|
||||
->setStates($initial_state['states'])
|
||||
->setCountryCodes($initial_state['country_codes'])
|
||||
->setZipCodes($initial_state['zip_codes'])
|
||||
->setExternalIds($initial_state['external_ids']);
|
||||
|
||||
$normalized = $userData->normalize();
|
||||
|
||||
$this->assertEquals(2, count($normalized['em']));
|
||||
$this->assertEquals(2, count($normalized['ph']));
|
||||
$this->assertEquals(2, count($normalized['ge']));
|
||||
$this->assertEquals(2, count($normalized['db']));
|
||||
$this->assertEquals(2, count($normalized['ln']));
|
||||
$this->assertEquals(2, count($normalized['fn']));
|
||||
$this->assertEquals(2, count($normalized['ct']));
|
||||
$this->assertEquals(2, count($normalized['st']));
|
||||
$this->assertEquals(2, count($normalized['country']));
|
||||
$this->assertEquals(2, count($normalized['zp']));
|
||||
$this->assertEquals(2, count($normalized['external_id']));
|
||||
}
|
||||
|
||||
public function testNormalizeMultiValueFields() {
|
||||
$initial_state = array(
|
||||
'email' => array('email-0@test.com', 'email-1@eg.com'),
|
||||
'phone' => array('1234567890', '10000000000'),
|
||||
'gender' => array('f', 'm'),
|
||||
'date_of_birth' => array('01/01/2001', '02/09/2008'),
|
||||
'last_name' => array('last_name-4', 'smith'),
|
||||
'first_name' => array('first_name-5', 'joe'),
|
||||
'city' => array('seattle', 'sanfransisco'),
|
||||
'state' => array('wa', 'ca'),
|
||||
'country_code' => array('us', 'ca'),
|
||||
'zip_code' => array('12345', '00000'),
|
||||
'external_id' => array('external_id-10', '123')
|
||||
);
|
||||
|
||||
$userData = (new UserData())
|
||||
->setEmails($initial_state['email'])
|
||||
->setPhones($initial_state['phone'])
|
||||
->setGenders($initial_state['gender'])
|
||||
->setDatesOfBirth($initial_state['date_of_birth'])
|
||||
->setLastNames($initial_state['last_name'])
|
||||
->setFirstNames($initial_state['first_name'])
|
||||
->setCities($initial_state['city'])
|
||||
->setStates($initial_state['state'])
|
||||
->setCountryCodes($initial_state['country_code'])
|
||||
->setZipCodes($initial_state['zip_code'])
|
||||
->setExternalIds($initial_state['external_id']);
|
||||
|
||||
$expected = array(
|
||||
'em' => $this->hashList($initial_state['email']),
|
||||
'ph' => $this->hashList($initial_state['phone']),
|
||||
'ge' => $this->hashList($initial_state['gender']),
|
||||
'db' => $this->hashList($initial_state['date_of_birth']),
|
||||
'ln' => $this->hashList($initial_state['last_name']),
|
||||
'fn' => $this->hashList($initial_state['first_name']),
|
||||
'ct' => $this->hashList($initial_state['city']),
|
||||
'st' => $this->hashList($initial_state['state']),
|
||||
'country' => $this->hashList($initial_state['country_code']),
|
||||
'zp' => $this->hashList($initial_state['zip_code']),
|
||||
'external_id' => $initial_state['external_id']
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $userData->normalize());
|
||||
}
|
||||
|
||||
public function testMultiValueFieldsCanNormalizeEmpty() {
|
||||
$userData = new UserData();
|
||||
$normalized = $userData->normalize();
|
||||
|
||||
$this->assertEquals(array(), $normalized);
|
||||
}
|
||||
|
||||
private function hashList($arr){
|
||||
return array_map(
|
||||
function($val){
|
||||
return Util::hash($val);
|
||||
},
|
||||
$arr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object\Signal;
|
||||
|
||||
use FacebookAdsTest\AbstractUnitTestCase;
|
||||
use FacebookAds\Object\Signal\CustomData;
|
||||
use FacebookAds\Object\Signal\Event;
|
||||
use FacebookAds\Object\Signal\UserData;
|
||||
|
||||
class EventTest extends AbstractUnitTestCase {
|
||||
public function testBuilder() {
|
||||
$user_data = new UserData(array('email' => 'aaa@fb.com'));
|
||||
$billing_contact = new UserData(array('email' => 'bbb@fb.com'));
|
||||
$shipping_contact = new UserData(array('email' => 'ccc@fb.com'));
|
||||
$custom_data = (new CustomData())
|
||||
->setOrderId('order_id')
|
||||
->setBillingContact($billing_contact)
|
||||
->setShippingContact($shipping_contact);
|
||||
$expected = array(
|
||||
'event_name' => 'event_name',
|
||||
'event_time' => 1234,
|
||||
'event_id' => 'event_id',
|
||||
'data_processing_options' => array('LDU'),
|
||||
'data_processing_options_country' => 1,
|
||||
'data_processing_options_state' => 1000,
|
||||
);
|
||||
|
||||
$event = (new Event())
|
||||
->setEventName($expected['event_name'])
|
||||
->setEventTime($expected['event_time'])
|
||||
->setEventId($expected['event_id'])
|
||||
->setUserData($user_data)
|
||||
->setCustomData($custom_data)
|
||||
->setDataProcessingOptions($expected['data_processing_options'])
|
||||
->setDataProcessingOptionsCountry($expected['data_processing_options_country'])
|
||||
->setDataProcessingOptionsState($expected['data_processing_options_state']);
|
||||
|
||||
$expected['user_data'] = $user_data->getBusinessDataUserData()->toJson();
|
||||
$expected['custom_data'] = $custom_data->getBusinessDataCustomData()->toJson();
|
||||
$this->assertEquals($expected, $event->getBusinessDataEvent()->toJson());
|
||||
$this->assertEquals('order_id', $event->getBusinessDataEvent()->getCustomData()->getOrderId());
|
||||
$this->assertEquals('ccc@fb.com', $event->getBusinessDataEvent()->getCustomData()->getShippingContact()->getEmail());
|
||||
$this->assertEquals('bbb@fb.com', $event->getBusinessDataEvent()->getCustomData()->getBillingContact()->getEmail());
|
||||
$this->assertEquals('aaa@fb.com', $event->getBusinessDataEvent()->getUserData()->getEmail());
|
||||
|
||||
$expected['user_data'] = $user_data->getServerSideUserData()->normalize();
|
||||
$expected['custom_data'] = $custom_data->getServerSideCustomData()->normalize();
|
||||
$this->assertEquals($expected, $event->getServerSideEvent()->normalize());
|
||||
$this->assertEquals('order_id', $event->getServerSideEvent()->getCustomData()->getOrderId());
|
||||
$this->assertEquals('aaa@fb.com', $event->getServerSideEvent()->getUserData()->getEmail());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Object;
|
||||
|
||||
use FacebookAds\Object\AbstractCrudObject;
|
||||
use FacebookAds\Object\TargetingSearch;
|
||||
use FacebookAds\Object\Search\TargetingSearchTypes;
|
||||
|
||||
class TargetingSearchTest extends AbstractCrudObjectTestCase {
|
||||
|
||||
public function testCrudAccess() {
|
||||
$cursor = TargetingSearch::search(
|
||||
TargetingSearchTypes::GEOLOCATION, null, 'Lon');
|
||||
|
||||
/* @var $category AbstractCrudObject */
|
||||
$result = $cursor->current();
|
||||
$this->assertTrue($result instanceof TargetingSearch);
|
||||
$this->assertNotEmpty($result->key);
|
||||
}
|
||||
}
|
||||
59
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/SessionTest.php
vendored
Normal file
59
modules/ps_facebook/vendor/facebook/php-business-sdk/test/FacebookAdsTest/SessionTest.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest;
|
||||
|
||||
use FacebookAds\Session;
|
||||
|
||||
class SessionTest extends AbstractUnitTestCase {
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
protected function createSession() {
|
||||
return new Session(
|
||||
static::VALUE_SESSION_APP_ID,
|
||||
static::VALUE_SESSION_APP_SECRET,
|
||||
static::VALUE_SESSION_ACCESS_TOKEN);
|
||||
}
|
||||
|
||||
public function testGetters() {
|
||||
$session = $this->createSession();
|
||||
|
||||
$this->assertEquals(
|
||||
static::VALUE_SESSION_APP_ID, $session->getAppId());
|
||||
$this->assertEquals(
|
||||
static::VALUE_SESSION_APP_SECRET, $session->getAppSecret());
|
||||
$this->assertEquals(
|
||||
static::VALUE_SESSION_ACCESS_TOKEN, $session->getAccessToken());
|
||||
}
|
||||
|
||||
public function testAppSecretProof() {
|
||||
$session = $this->createSession();
|
||||
$proof = $session->getAppSecretProof();
|
||||
|
||||
// Assert SHA-2 > 256 bits > 64 chars
|
||||
$this->assertTrue(strlen($proof) == 64);
|
||||
}
|
||||
}
|
||||
164
modules/ps_facebook/vendor/facebook/php-business-sdk/test/config.php
vendored
Normal file
164
modules/ps_facebook/vendor/facebook/php-business-sdk/test/config.php
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
return array(
|
||||
|
||||
/**
|
||||
* @var string Numeric Facebook app id, espressed as string
|
||||
*/
|
||||
'app_id' => '',
|
||||
|
||||
/**
|
||||
* @var string App Secret
|
||||
* @see https://developers.facebook.com/apps/<APP_ID>/dashboard/
|
||||
*/
|
||||
'app_secret' => '',
|
||||
|
||||
/**
|
||||
* @var string User Access Token
|
||||
* @see https://developers.facebook.com/docs/facebook-login/access-tokens/
|
||||
*/
|
||||
'access_token' => '',
|
||||
|
||||
/**
|
||||
* @var string Numeric Facebook Business Manager id, espressed as string
|
||||
*/
|
||||
'business_id' => '',
|
||||
|
||||
/**
|
||||
* @var string Numeric Facebook id, preceded by 'act_', espressed as string
|
||||
* @see https://www.facebook.com/ads/manage/home/
|
||||
*/
|
||||
'act_id' => '',
|
||||
|
||||
/**
|
||||
* @var string PHP timezone compatible with the AdAccount timezone, override php.ini config
|
||||
* @see http://php.net/manual/en/timezones.php
|
||||
*/
|
||||
'act_timezone' => '',
|
||||
|
||||
/**
|
||||
* @var string Numeric Facebook id, espressed as string
|
||||
* @see https://www.facebook.com/ads/manage/home/
|
||||
*/
|
||||
'page_id' => '',
|
||||
|
||||
/**
|
||||
* @var string Url of your app [Stream post URL security]
|
||||
* Example: 'http://my.domain.com/'
|
||||
* @see https://developers.facebook.com/docs/facebook-login/security/#surfacearea
|
||||
*/
|
||||
'app_url' => '',
|
||||
|
||||
/**
|
||||
* @var string Numeric Instagram actor id, espressed as string
|
||||
*/
|
||||
'instagram_actor_id' => '',
|
||||
|
||||
// OPTIONAL INTEGRATION TESTS
|
||||
|
||||
'skip_if' => array(
|
||||
|
||||
/**
|
||||
* @var bool Skip tests that require an business manager
|
||||
* @see https://developers.facebook.com/docs/marketing-api/businessmanager/
|
||||
*/
|
||||
'no_business_manager' => true,
|
||||
|
||||
/**
|
||||
* @var bool Skip tests that require an account with a valid payment method
|
||||
* @see https://secure.facebook.com/ads/manage/funding.php
|
||||
*/
|
||||
'no_payment_method' => true,
|
||||
|
||||
/**
|
||||
* @var bool Skip tests that require parnet categories whitelisting
|
||||
* @see https://developers.facebook.com/docs/reference/ads-api/partnercategories
|
||||
*/
|
||||
'no_partner_categories' => true,
|
||||
|
||||
/**
|
||||
* @var bool Skip tests that require video upload
|
||||
*/
|
||||
'no_video_upload' => true,
|
||||
|
||||
/**
|
||||
* @var bool Skip tests that require reach and frequency whitelisting
|
||||
*/
|
||||
'no_reach_and_frequency_whitelist' => true,
|
||||
|
||||
/**
|
||||
* @var bool Skip tests that require polling for async jobs execution
|
||||
*/
|
||||
'no_async_jobs' => true,
|
||||
|
||||
/**
|
||||
* @var bool Skip tests that require an instagram actor
|
||||
*/
|
||||
'no_instagram' => true,
|
||||
),
|
||||
|
||||
// OPTIONAL CONFIGURATIONS
|
||||
|
||||
/**
|
||||
* @var string Override Facebook graph domain
|
||||
* Example: try hitting beta.facebook.com
|
||||
*/
|
||||
'graph_base_domain' => '',
|
||||
|
||||
/**
|
||||
* @var string Disable SSL verification between CA and host
|
||||
* [Security] Do not change this unless you trust your network
|
||||
*/
|
||||
'skip_ssl_verification' => false,
|
||||
|
||||
/**
|
||||
* @var string Filepath to which cUrl shell equivalents will be dumped
|
||||
* Tip: access std streams with 'php://stdout' or 'php://stderr'
|
||||
*/
|
||||
'curl_logger' => '',
|
||||
|
||||
// OPTIONAL SECONDARY ENTITIES
|
||||
// Do not set the same as primary. May incurr in lost permissions.
|
||||
|
||||
/**
|
||||
* @var string Ausiliary Business ID for permissions and sharing testing
|
||||
*/
|
||||
'secondary_business_id' => '',
|
||||
|
||||
/**
|
||||
* @var string Ausiliary Account ID for permissions and sharing testing
|
||||
*/
|
||||
'secondary_account_id' => '',
|
||||
|
||||
/**
|
||||
* @var string Ausiliary Page ID for permissions and sharing testing
|
||||
*/
|
||||
'secondary_page_id' => '',
|
||||
|
||||
/**
|
||||
* @var string Ausiliary Page ID for permissions and sharing testing
|
||||
*/
|
||||
'secondary_app_id' => '',
|
||||
);
|
||||
38
modules/ps_facebook/vendor/facebook/php-business-sdk/test/init_integration.php
vendored
Normal file
38
modules/ps_facebook/vendor/facebook/php-business-sdk/test/init_integration.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Bootstrap;
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
if (!ini_get('date.timezone')) {
|
||||
ini_set('date.timezone', 'UTC');
|
||||
}
|
||||
|
||||
require_once __DIR__.'/FacebookAdsTest/Bootstrap/Bootstrap.php';
|
||||
require_once __DIR__.'/FacebookAdsTest/Bootstrap/IntegrationBootstrap.php';
|
||||
|
||||
$bootstrap = new IntegrationBootstrap();
|
||||
$bootstrap->init();
|
||||
|
||||
return $bootstrap;
|
||||
36
modules/ps_facebook/vendor/facebook/php-business-sdk/test/init_unit.php
vendored
Normal file
36
modules/ps_facebook/vendor/facebook/php-business-sdk/test/init_unit.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace FacebookAdsTest\Bootstrap;
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
if (!ini_get('date.timezone')) {
|
||||
ini_set('date.timezone', 'UTC');
|
||||
}
|
||||
require_once __DIR__.'/FacebookAdsTest/Bootstrap/Bootstrap.php';
|
||||
|
||||
$bootstrap = new Bootstrap();
|
||||
$bootstrap->init();
|
||||
|
||||
return $bootstrap;
|
||||
BIN
modules/ps_facebook/vendor/facebook/php-business-sdk/test/misc/image.png
vendored
Normal file
BIN
modules/ps_facebook/vendor/facebook/php-business-sdk/test/misc/image.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
BIN
modules/ps_facebook/vendor/facebook/php-business-sdk/test/misc/images.zip
vendored
Normal file
BIN
modules/ps_facebook/vendor/facebook/php-business-sdk/test/misc/images.zip
vendored
Normal file
Binary file not shown.
BIN
modules/ps_facebook/vendor/facebook/php-business-sdk/test/misc/video.mp4
vendored
Normal file
BIN
modules/ps_facebook/vendor/facebook/php-business-sdk/test/misc/video.mp4
vendored
Normal file
Binary file not shown.
21
modules/ps_facebook/vendor/facebook/php-business-sdk/test/phpunit-travis.xml
vendored
Normal file
21
modules/ps_facebook/vendor/facebook/php-business-sdk/test/phpunit-travis.xml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<phpunit bootstrap="init_unit.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Facebook AdsAPI PHP SDK">
|
||||
<directory>./FacebookAdsTest</directory>
|
||||
<exclude>./FacebookAdsTest/Object</exclude>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<logging>
|
||||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
|
||||
<log type="coverage-html" target="report/" charset="UTF-8" highlight="false" lowUpperBound="60" highLowerBound="99"/>
|
||||
</logging>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">../src</directory>
|
||||
<exclude>
|
||||
<directory>../src/FacebookAds/Http/Adapter/Curl/</directory>
|
||||
<directory>../src/FacebookAds/Object/</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
16
modules/ps_facebook/vendor/facebook/php-business-sdk/test/phpunit.xml
vendored
Normal file
16
modules/ps_facebook/vendor/facebook/php-business-sdk/test/phpunit.xml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<phpunit bootstrap="init_integration.php" colors="true" backupGlobals="true">
|
||||
<testsuites>
|
||||
<testsuite name="Facebook AdsAPI PHP SDK">
|
||||
<directory>./FacebookAdsTest</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<logging>
|
||||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
|
||||
<log type="coverage-html" target="report/" charset="UTF-8" highlight="false" lowUpperBound="60" highLowerBound="99"/>
|
||||
</logging>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">../src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user