first commit
This commit is contained in:
25
modules/pdgoogleanalytycs4pro/vendor/br33f/php-ga4-mp/tests/Common/BaseTestCase.php
vendored
Normal file
25
modules/pdgoogleanalytycs4pro/vendor/br33f/php-ga4-mp/tests/Common/BaseTestCase.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 14:49
|
||||
*/
|
||||
|
||||
namespace Tests\Common;
|
||||
|
||||
use Faker\Factory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BaseTestCase extends TestCase
|
||||
{
|
||||
protected $faker;
|
||||
|
||||
/**
|
||||
* BaseTestCase constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->faker = Factory::create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 15:23
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Common;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\EventCollection;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\BaseParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Enum\ErrorCode;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class EventCollectionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var EventCollection
|
||||
*/
|
||||
protected $eventCollection;
|
||||
|
||||
public function testEventList()
|
||||
{
|
||||
$setEventList = [];
|
||||
for ($i = 0; $i < rand(1, 25); $i++) {
|
||||
$setEventList[] = new BaseEvent();
|
||||
}
|
||||
|
||||
$this->eventCollection->setEventList($setEventList);
|
||||
|
||||
$this->assertEquals($setEventList, $this->eventCollection->getEventList());
|
||||
}
|
||||
|
||||
public function testSetEventListExceed25()
|
||||
{
|
||||
$setEventList = [];
|
||||
for ($i = 0; $i < rand(26, 50); $i++) {
|
||||
$setEventList[] = new BaseEvent();
|
||||
}
|
||||
|
||||
$this->expectExceptionCode(ErrorCode::MAX_EVENT_COUNT_EXCEED);
|
||||
$this->eventCollection->setEventList($setEventList);
|
||||
}
|
||||
|
||||
public function testAddEvent()
|
||||
{
|
||||
$this->eventCollection->setEventList([]);
|
||||
$newEvent = new BaseEvent();
|
||||
$this->eventCollection->addEvent($newEvent);
|
||||
|
||||
$this->assertEquals(1, count($this->eventCollection->getEventList()));
|
||||
$this->assertEquals($newEvent, $this->eventCollection->getEventList()[0]);
|
||||
}
|
||||
|
||||
public function testAddEventExceed25()
|
||||
{
|
||||
$setEventList = [];
|
||||
for ($i = 0; $i < 25; $i++) {
|
||||
$setEventList[] = new BaseEvent();
|
||||
}
|
||||
$this->eventCollection->setEventList($setEventList);
|
||||
|
||||
$newEvent = new BaseEvent();
|
||||
$this->expectExceptionCode(ErrorCode::MAX_EVENT_COUNT_EXCEED);
|
||||
$this->eventCollection->addEvent($newEvent);
|
||||
}
|
||||
|
||||
public function testExport()
|
||||
{
|
||||
$setEventListExport = [];
|
||||
$setEventList = [];
|
||||
for ($i = 0; $i < rand(1, 25); $i++) {
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$event->addParam($this->faker->word, new BaseParameter($this->faker->word));
|
||||
$setEventList[] = $event;
|
||||
$setEventListExport[] = $event->export();
|
||||
}
|
||||
|
||||
$this->eventCollection->setEventList($setEventList);
|
||||
|
||||
$this->assertEquals($setEventListExport, $this->eventCollection->export());
|
||||
}
|
||||
|
||||
public function testValidateFailed()
|
||||
{
|
||||
$newEventCollection = new EventCollection();
|
||||
|
||||
$this->expectExceptionCode(ErrorCode::VALIDATION_EVENTS_MUST_NOT_BE_EMPTY);
|
||||
$newEventCollection->validate();
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$newEventCollection = new EventCollection();
|
||||
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$event->addParam($this->faker->word, new BaseParameter($this->faker->word));
|
||||
$newEventCollection->addEvent($event);
|
||||
|
||||
$this->assertTrue($newEventCollection->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->eventCollection = new EventCollection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 15:56
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Common;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\UserProperties;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\UserProperty;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class UserPropertiesTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var UserProperties
|
||||
*/
|
||||
protected $userProperties;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedUserProperties = new UserProperties();
|
||||
|
||||
$this->assertEquals([], $constructedUserProperties->getUserPropertiesList());
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$setUserProperties = [
|
||||
new UserProperty(),
|
||||
new UserProperty()
|
||||
];
|
||||
$constructedUserProperties = new UserProperties($setUserProperties);
|
||||
|
||||
$this->assertEquals($setUserProperties, $constructedUserProperties->getUserPropertiesList());
|
||||
}
|
||||
|
||||
public function testUserPropertiesList()
|
||||
{
|
||||
$setUserProperties = [
|
||||
new UserProperty($this->faker->word, $this->faker->word),
|
||||
new UserProperty($this->faker->word, $this->faker->word),
|
||||
new UserProperty($this->faker->word, $this->faker->word)
|
||||
];
|
||||
|
||||
$this->userProperties->setUserPropertiesList($setUserProperties);
|
||||
|
||||
$this->assertEquals($setUserProperties, $this->userProperties->getUserPropertiesList());
|
||||
}
|
||||
|
||||
public function testUserPropertyAdd()
|
||||
{
|
||||
$this->userProperties->setUserPropertiesList([]);
|
||||
|
||||
$addUserProperty = new UserProperty($this->faker->word, $this->faker->word);
|
||||
$this->userProperties->addUserProperty($addUserProperty);
|
||||
|
||||
$this->assertEquals(1, count($this->userProperties->getUserPropertiesList()));
|
||||
$this->assertEquals($addUserProperty, $this->userProperties->getUserPropertiesList()[0]);
|
||||
}
|
||||
|
||||
public function testExport()
|
||||
{
|
||||
$setUserProperties = [
|
||||
new UserProperty($this->faker->word, $this->faker->word),
|
||||
new UserProperty($this->faker->word, $this->faker->word),
|
||||
new UserProperty($this->faker->word, $this->faker->word)
|
||||
];
|
||||
|
||||
$this->userProperties->setUserPropertiesList($setUserProperties);
|
||||
|
||||
$this->assertEquals([
|
||||
$setUserProperties[0]->getName() => [
|
||||
'value' => $setUserProperties[0]->getValue()
|
||||
],
|
||||
$setUserProperties[1]->getName() => [
|
||||
'value' => $setUserProperties[1]->getValue()
|
||||
],
|
||||
$setUserProperties[2]->getName() => [
|
||||
'value' => $setUserProperties[2]->getValue()
|
||||
],
|
||||
], $this->userProperties->export());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->userProperties = new UserProperties();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 15:47
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Common;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\UserProperty;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class UserPropertyTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var UserProperty
|
||||
*/
|
||||
protected $userProperty;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedUserProperty = new UserProperty();
|
||||
|
||||
$this->assertEquals(null, $constructedUserProperty->getName());
|
||||
$this->assertEquals(null, $constructedUserProperty->getValue());
|
||||
}
|
||||
|
||||
public function testParametrizedConstructor()
|
||||
{
|
||||
$setName = $this->faker->word;
|
||||
$setValue = $this->faker->word;
|
||||
$constructedUserProperty = new UserProperty($setName, $setValue);
|
||||
|
||||
$this->assertEquals($setName, $constructedUserProperty->getName());
|
||||
$this->assertEquals($setValue, $constructedUserProperty->getValue());
|
||||
}
|
||||
|
||||
public function testName()
|
||||
{
|
||||
$setName = $this->faker->word;
|
||||
$this->userProperty->setName($setName);
|
||||
|
||||
$this->assertEquals($setName, $this->userProperty->getName());
|
||||
}
|
||||
|
||||
public function testValue()
|
||||
{
|
||||
$setValue = $this->faker->word;
|
||||
$this->userProperty->setValue($setValue);
|
||||
|
||||
$this->assertEquals($setValue, $this->userProperty->getValue());
|
||||
}
|
||||
|
||||
public function testExportEmpty()
|
||||
{
|
||||
$emptyUserProperty = new UserProperty();
|
||||
|
||||
$this->assertEquals([null => ['value' => null]], $emptyUserProperty->export());
|
||||
}
|
||||
|
||||
public function testExport()
|
||||
{
|
||||
$setName = $this->faker->word;
|
||||
$setValue = $this->faker->word;
|
||||
$emptyUserProperty = new UserProperty($setName, $setValue);
|
||||
|
||||
$this->assertEquals([$setName => ['value' => $setValue]], $emptyUserProperty->export());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->userProperty = new UserProperty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 24.06.2021
|
||||
* Time: 13:54
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Common;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\ValidationMessage;
|
||||
use Br33f\Ga4\MeasurementProtocol\Enum\ValidationCode;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ValidationMessageTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var ValidationMessage
|
||||
*/
|
||||
protected $validationMessage;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedValidationMessage = new ValidationMessage();
|
||||
|
||||
$this->assertNotNull($constructedValidationMessage);
|
||||
}
|
||||
|
||||
public function testArrayBlueprintConstructor()
|
||||
{
|
||||
$blueprint = ['fieldPath' => $this->faker->word];
|
||||
$constructedValidationMessage = new ValidationMessage($blueprint);
|
||||
|
||||
$this->assertNotNull($constructedValidationMessage);
|
||||
$this->assertEquals($blueprint['fieldPath'], $constructedValidationMessage->getFieldPath());
|
||||
$this->assertEquals(null, $constructedValidationMessage->getDescription());
|
||||
$this->assertEquals(null, $constructedValidationMessage->getValidationCode());
|
||||
}
|
||||
|
||||
public function testHydrate()
|
||||
{
|
||||
$blueprint = [
|
||||
'fieldPath' => $this->faker->word,
|
||||
'description' => $this->faker->text,
|
||||
'validationCode' => $this->faker->randomElement([ValidationCode::EXCEEDED_MAX_ENTITIES, ValidationCode::NAME_DUPLICATED, ValidationCode::NAME_RESERVED])
|
||||
];
|
||||
$constructedValidationMessage = new ValidationMessage($blueprint);
|
||||
|
||||
$this->assertNotNull($constructedValidationMessage);
|
||||
$this->assertEquals($blueprint['fieldPath'], $constructedValidationMessage->getFieldPath());
|
||||
$this->assertEquals($blueprint['description'], $constructedValidationMessage->getDescription());
|
||||
$this->assertEquals($blueprint['validationCode'], $constructedValidationMessage->getValidationCode());
|
||||
}
|
||||
|
||||
public function testFieldPath()
|
||||
{
|
||||
$setFieldPath = $this->faker->word;
|
||||
$this->validationMessage->setFieldPath($setFieldPath);
|
||||
|
||||
$this->assertEquals($setFieldPath, $this->validationMessage->getFieldPath());
|
||||
}
|
||||
|
||||
public function testValidationCode()
|
||||
{
|
||||
$setValidationCode = $this->faker->randomElement([ValidationCode::EXCEEDED_MAX_ENTITIES, ValidationCode::NAME_DUPLICATED, ValidationCode::NAME_RESERVED]);
|
||||
$this->validationMessage->setValidationCode($setValidationCode);
|
||||
|
||||
$this->assertEquals($setValidationCode, $this->validationMessage->getValidationCode());
|
||||
}
|
||||
|
||||
public function testDescription()
|
||||
{
|
||||
$setDescription = $this->faker->text;
|
||||
$this->validationMessage->setDescription($setDescription);
|
||||
|
||||
$this->assertEquals($setDescription, $this->validationMessage->getDescription());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validationMessage = new ValidationMessage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddPaymentInfoEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class AddPaymentInfoEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var AddPaymentInfoEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new AddPaymentInfoEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('add_payment_info', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFail()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new AddPaymentInfoEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddShippingInfoEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class AddShippingInfoEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var AddShippingInfoEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new AddShippingInfoEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('add_shipping_info', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFail()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new AddShippingInfoEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddToCartEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class AddToCartEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var AddToCartEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new AddToCartEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('add_to_cart', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFail()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new AddToCartEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 15:05
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\BaseParameter;
|
||||
use InvalidArgumentException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class BaseEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var BaseEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new BaseEvent();
|
||||
|
||||
$this->assertEquals(null, $constructedEvent->getName());
|
||||
$this->assertEquals([], $constructedEvent->getParamList());
|
||||
}
|
||||
|
||||
public function testNameOnlyConstructor()
|
||||
{
|
||||
$setupName = $this->faker->word;
|
||||
$constructedEvent = new BaseEvent($setupName);
|
||||
|
||||
$this->assertEquals($setupName, $constructedEvent->getName());
|
||||
$this->assertEquals([], $constructedEvent->getParamList());
|
||||
}
|
||||
|
||||
public function testParamListOnlyConstructor()
|
||||
{
|
||||
$baseParams = [];
|
||||
for ($i = 0; $i < rand(4, 10); $i++) {
|
||||
$baseParams[$this->faker->word] = new BaseParameter($this->faker->word);
|
||||
}
|
||||
$constructedEvent = new BaseEvent(null, $baseParams);
|
||||
|
||||
$this->assertEquals(null, $constructedEvent->getName());
|
||||
$this->assertEquals($baseParams, $constructedEvent->getParamList());
|
||||
}
|
||||
|
||||
public function testFullConstructor()
|
||||
{
|
||||
$setupName = $this->faker->word;
|
||||
|
||||
$baseParams = [];
|
||||
for ($i = 0; $i < rand(4, 10); $i++) {
|
||||
$baseParams[$this->faker->word] = new BaseParameter($this->faker->word);
|
||||
}
|
||||
$constructedEvent = new BaseEvent($setupName, $baseParams);
|
||||
|
||||
$this->assertEquals($setupName, $constructedEvent->getName());
|
||||
$this->assertEquals($baseParams, $constructedEvent->getParamList());
|
||||
}
|
||||
|
||||
public function testName()
|
||||
{
|
||||
$setupName = $this->faker->word;
|
||||
$this->event->setName($setupName);
|
||||
|
||||
$this->assertEquals($setupName, $this->event->getName());
|
||||
}
|
||||
|
||||
public function testParamList()
|
||||
{
|
||||
$baseParams = [];
|
||||
for ($i = 0; $i < rand(4, 10); $i++) {
|
||||
$baseParams[$this->faker->word] = new BaseParameter($this->faker->word);
|
||||
}
|
||||
$this->event->setParamList($baseParams);
|
||||
|
||||
$this->assertEquals($baseParams, $this->event->getParamList());
|
||||
}
|
||||
|
||||
public function testAddParam()
|
||||
{
|
||||
$this->event->setParamList([]);
|
||||
|
||||
$paramName = $this->faker->word;
|
||||
$paramToAdd = new BaseParameter($this->faker->word);
|
||||
$this->event->addParam($paramName, $paramToAdd);
|
||||
|
||||
$this->assertEquals(1, count($this->event->getParamList()));
|
||||
$this->assertEquals($paramToAdd, $this->event->getParamList()[$paramName]);
|
||||
}
|
||||
|
||||
public function testDeleteParam()
|
||||
{
|
||||
$this->event->setParamList([]);
|
||||
|
||||
$paramName = $this->faker->word;
|
||||
$paramToAdd = new BaseParameter($this->faker->word);
|
||||
$this->event->addParam($paramName, $paramToAdd);
|
||||
$this->assertEquals(1, count($this->event->getParamList()));
|
||||
|
||||
$this->event->deleteParameter($paramName);
|
||||
$this->assertEquals(0, count($this->event->getParamList()));
|
||||
}
|
||||
|
||||
public function testExportEmpty()
|
||||
{
|
||||
$emptyEvent = new BaseEvent();
|
||||
|
||||
$this->assertEquals(['name' => null, 'params' => new \ArrayObject()], $emptyEvent->export());
|
||||
}
|
||||
|
||||
public function testExport()
|
||||
{
|
||||
$setupName = $this->faker->word;
|
||||
|
||||
$baseParamsExport = [];
|
||||
$baseParams = [];
|
||||
for ($i = 0; $i < rand(4, 10); $i++) {
|
||||
$baseParamName = $this->faker->word;
|
||||
$baseParam = new BaseParameter($this->faker->word);
|
||||
$baseParams[$baseParamName] = $baseParam;
|
||||
$baseParamsExport[$baseParamName] = $baseParam->export();
|
||||
}
|
||||
$constructedEvent = new BaseEvent($setupName, $baseParams);
|
||||
|
||||
$this->assertEquals(['name' => $setupName, 'params' => new \ArrayObject($baseParamsExport)], $constructedEvent->export());
|
||||
}
|
||||
|
||||
public function testSetGetCall()
|
||||
{
|
||||
$this->event->setTest1('test1value');
|
||||
|
||||
$this->assertEquals('test1value', $this->event->getTest1());
|
||||
}
|
||||
|
||||
public function testSetCallNoParams()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->event->setTest2();
|
||||
}
|
||||
|
||||
public function testUnknownCallMethod()
|
||||
{
|
||||
$this->expectException(BadMethodCallException::class);
|
||||
$this->event->invalidMethodName();
|
||||
}
|
||||
|
||||
public function testValidate()
|
||||
{
|
||||
$setupName = $this->faker->word;
|
||||
|
||||
$baseParams = [];
|
||||
for ($i = 0; $i < rand(4, 10); $i++) {
|
||||
$baseParam = new BaseParameter($this->faker->word);
|
||||
$baseParams[$this->faker->word] = $baseParam;
|
||||
}
|
||||
$constructedEvent = new BaseEvent($setupName, $baseParams);
|
||||
|
||||
$this->assertTrue($constructedEvent->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->event = new BaseEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BeginCheckoutEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class BeginCheckoutEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var BeginCheckoutEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new BeginCheckoutEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('begin_checkout', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFail()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new BeginCheckoutEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\LoginEvent;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class LoginEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var LoginEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new LoginEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('login', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setMethod($this->faker->word);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new LoginEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\PurchaseEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class PurchaseEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var PurchaseEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new PurchaseEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('purchase', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
$this->event->setTransactionId($this->faker->bothify('*#*#*#_transaction'));
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFailNoCurrency()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setTransactionId($this->faker->bothify('*#*#*#_transaction'));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
public function testValidateFailNoTransaction()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new PurchaseEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\RefundEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class RefundEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var RefundEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new RefundEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('refund', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
$this->event->setTransactionId($this->faker->bothify('*#*#*#_transaction'));
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFailNoCurrency()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setTransactionId($this->faker->bothify('*#*#*#_transaction'));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
public function testValidateFailNoTransaction()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new RefundEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\RemoveFromCartEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class RemoveFromCartEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var RemoveFromCartEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new RemoveFromCartEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('remove_from_cart', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFail()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new RemoveFromCartEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SearchEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class SearchEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var SearchEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new SearchEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('search', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setSearchTerm($this->faker->paragraph);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFail()
|
||||
{
|
||||
$this->event = new SearchEvent();
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new SearchEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 10:44
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SelectItemEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\BaseParameter;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class SelectItemEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var SelectItemEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new SelectItemEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('select_item', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testParameterConstructor()
|
||||
{
|
||||
$setParameters = [
|
||||
$this->faker->word => new BaseParameter($this->faker->word),
|
||||
$this->faker->word => new BaseParameter($this->faker->word)
|
||||
];
|
||||
|
||||
$constructedEvent = new ViewItemEvent($setParameters);
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals($setParameters, $constructedEvent->getParamList());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$newViewItemEvent = new ViewItemEvent();
|
||||
|
||||
$this->assertTrue($newViewItemEvent->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new SelectItemEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SignUpEvent;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class SignUpEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var SignUpEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new SignUpEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('sign_up', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setMethod($this->faker->word);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new SignUpEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewCartEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ViewCartEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var ViewCartEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new ViewCartEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('view_cart', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
$this->event->setCurrency($this->faker->currencyCode);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
public function testValidateFail()
|
||||
{
|
||||
$this->event->setValue($this->faker->randomFloat(2, 10, 3000));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->event->validate();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new ViewCartEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 10:44
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\BaseParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemCollectionParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemParameter;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ViewItemEventTest extends BaseTestCase
|
||||
{
|
||||
protected $viewItemEvent;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new ViewItemEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
}
|
||||
|
||||
public function testParameterConstructor()
|
||||
{
|
||||
$setParameters = [
|
||||
$this->faker->word => new BaseParameter($this->faker->word),
|
||||
$this->faker->word => new BaseParameter($this->faker->word)
|
||||
];
|
||||
|
||||
$constructedEvent = new ViewItemEvent($setParameters);
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals($setParameters, $constructedEvent->getParamList());
|
||||
}
|
||||
|
||||
public function testSetGetItems()
|
||||
{
|
||||
$setItems = new ItemCollectionParameter([
|
||||
new ItemParameter(['item_name' => $this->faker->word]),
|
||||
new ItemParameter(['item_name' => $this->faker->word, 'price' => $this->faker->randomFloat(2, 10, 100)])
|
||||
]);
|
||||
|
||||
$this->viewItemEvent->setItems($setItems);
|
||||
|
||||
$this->assertEquals($setItems, $this->viewItemEvent->getItems());
|
||||
}
|
||||
|
||||
public function testGetItemsEmpty()
|
||||
{
|
||||
$newViewItemEvent = new ViewItemEvent();
|
||||
|
||||
$this->assertNotNull($newViewItemEvent->getItems());
|
||||
}
|
||||
|
||||
public function testAddItem()
|
||||
{
|
||||
$this->viewItemEvent->setItems(new ItemCollectionParameter());
|
||||
|
||||
$itemToAdd = new ItemParameter(['item_name' => $this->faker->word]);
|
||||
$this->viewItemEvent->addItem($itemToAdd);
|
||||
|
||||
$this->assertEquals(1, count($this->viewItemEvent->getItems()->getItemList()));
|
||||
$this->assertEquals($itemToAdd, $this->viewItemEvent->getItems()->getItemList()[0]);
|
||||
}
|
||||
|
||||
public function testCurrency()
|
||||
{
|
||||
$setCurrency = $this->faker->currencyCode;
|
||||
$this->viewItemEvent->setCurrency($setCurrency);
|
||||
|
||||
$this->assertEquals($setCurrency, $this->viewItemEvent->getCurrency());
|
||||
}
|
||||
|
||||
public function testValue()
|
||||
{
|
||||
$setValue = $this->faker->randomFloat(2, 10, 2000);
|
||||
$this->viewItemEvent->setValue($setValue);
|
||||
|
||||
$this->assertEquals($setValue, $this->viewItemEvent->getValue());
|
||||
}
|
||||
|
||||
public function testValidateEmpty()
|
||||
{
|
||||
$newViewItemEvent = new ViewItemEvent();
|
||||
|
||||
$this->assertTrue($newViewItemEvent->validate());
|
||||
}
|
||||
|
||||
public function testValidate()
|
||||
{
|
||||
$setItems = new ItemCollectionParameter([
|
||||
new ItemParameter(['item_name' => $this->faker->word]),
|
||||
new ItemParameter(['item_name' => $this->faker->word, 'price' => $this->faker->randomFloat(2, 10, 100)])
|
||||
]);
|
||||
$newViewItemEvent = new ViewItemEvent([$setItems]);
|
||||
|
||||
$this->assertTrue($newViewItemEvent->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewItemEvent = new ViewItemEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 10:44
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemListEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\BaseParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemCollectionParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemParameter;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ViewItemListEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var ViewItemEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new ViewItemListEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('view_item_list', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testParameterConstructor()
|
||||
{
|
||||
$setParameters = [
|
||||
$this->faker->word => new BaseParameter($this->faker->word),
|
||||
$this->faker->word => new BaseParameter($this->faker->word)
|
||||
];
|
||||
|
||||
$constructedEvent = new ViewItemEvent($setParameters);
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals($setParameters, $constructedEvent->getParamList());
|
||||
}
|
||||
|
||||
public function testSetGetItems()
|
||||
{
|
||||
$setItems = new ItemCollectionParameter([
|
||||
new ItemParameter(['item_name' => $this->faker->word]),
|
||||
new ItemParameter(['item_name' => $this->faker->word, 'price' => $this->faker->randomFloat(2, 10, 100)])
|
||||
]);
|
||||
|
||||
$this->event->setItems($setItems);
|
||||
|
||||
$this->assertEquals($setItems, $this->event->getItems());
|
||||
}
|
||||
|
||||
public function testGetItemsEmpty()
|
||||
{
|
||||
$newViewItemEvent = new ViewItemEvent();
|
||||
|
||||
$this->assertNotNull($newViewItemEvent->getItems());
|
||||
}
|
||||
|
||||
public function testAddItem()
|
||||
{
|
||||
$this->event->setItems(new ItemCollectionParameter());
|
||||
|
||||
$itemToAdd = new ItemParameter(['item_name' => $this->faker->word]);
|
||||
$this->event->addItem($itemToAdd);
|
||||
|
||||
$this->assertEquals(1, count($this->event->getItems()->getItemList()));
|
||||
$this->assertEquals($itemToAdd, $this->event->getItems()->getItemList()[0]);
|
||||
}
|
||||
|
||||
public function testCurrency()
|
||||
{
|
||||
$setCurrency = $this->faker->currencyCode;
|
||||
$this->event->setCurrency($setCurrency);
|
||||
|
||||
$this->assertEquals($setCurrency, $this->event->getCurrency());
|
||||
}
|
||||
|
||||
public function testValue()
|
||||
{
|
||||
$setValue = $this->faker->randomFloat(2, 10, 2000);
|
||||
$this->event->setValue($setValue);
|
||||
|
||||
$this->assertEquals($setValue, $this->event->getValue());
|
||||
}
|
||||
|
||||
public function testValidate()
|
||||
{
|
||||
$newViewItemEvent = new ViewItemEvent();
|
||||
|
||||
$this->assertTrue($newViewItemEvent->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new ViewItemListEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:40
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Event;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewSearchResultsEvent;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ViewSearchResultsEventTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var ViewSearchResultsEvent
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedEvent = new ViewSearchResultsEvent();
|
||||
|
||||
$this->assertNotNull($constructedEvent);
|
||||
$this->assertEquals('view_search_results', $constructedEvent->getName());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$this->event->setSearchTerm($this->faker->paragraph);
|
||||
|
||||
$this->assertTrue($this->event->validate());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->event = new ViewSearchResultsEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 14:22
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Parameter;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\BaseParameter;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class BaseParameterTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var BaseParameter
|
||||
*/
|
||||
protected $baseParameter;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->baseParameter = new BaseParameter();
|
||||
}
|
||||
|
||||
public function testValueString()
|
||||
{
|
||||
$valueToSet = $this->faker->word;
|
||||
$this->baseParameter->setValue($valueToSet);
|
||||
|
||||
$this->assertEquals($valueToSet, $this->baseParameter->getValue());
|
||||
}
|
||||
|
||||
public function testValueArray()
|
||||
{
|
||||
$valueToSet = [];
|
||||
for ($i = 0; $i < $this->faker->randomDigit; $i++) {
|
||||
$valueToSet[] = $this->faker->word;
|
||||
}
|
||||
$this->baseParameter->setValue($valueToSet);
|
||||
|
||||
$this->assertEquals($valueToSet, $this->baseParameter->getValue());
|
||||
}
|
||||
|
||||
public function testValueBaseParam()
|
||||
{
|
||||
$valueToSet = new BaseParameter();
|
||||
$valueToSet->setValue($this->faker->word);
|
||||
$this->baseParameter->setValue($valueToSet);
|
||||
|
||||
$this->assertEquals($valueToSet, $this->baseParameter->getValue());
|
||||
}
|
||||
|
||||
public function testExportSimple()
|
||||
{
|
||||
$valueToSet = $this->faker->word;
|
||||
$this->baseParameter->setValue($valueToSet);
|
||||
|
||||
$this->assertEquals($valueToSet, $this->baseParameter->export());
|
||||
}
|
||||
|
||||
public function testExportBaseParameter()
|
||||
{
|
||||
$valueToSet = new BaseParameter();
|
||||
$valueToSet->setValue($this->faker->word);
|
||||
$this->baseParameter->setValue($valueToSet);
|
||||
|
||||
$this->assertEquals($valueToSet->getValue(), $this->baseParameter->export());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 14:22
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Parameter;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemCollectionParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ItemCollectionParameterTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var ItemCollectionParameter
|
||||
*/
|
||||
protected $itemCollectionParameter;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->itemCollectionParameter = new ItemCollectionParameter();
|
||||
}
|
||||
|
||||
public function testDefaultContructor()
|
||||
{
|
||||
$constructedItemCollectionParameter = new ItemCollectionParameter();
|
||||
|
||||
$this->assertNotNull($constructedItemCollectionParameter);
|
||||
}
|
||||
|
||||
public function testItemList()
|
||||
{
|
||||
$setItemList = [
|
||||
new ItemParameter(['item_name' => 'test1']),
|
||||
new ItemParameter(['item_id' => '123', 'price' => 15.55])
|
||||
];
|
||||
$this->itemCollectionParameter->setItemList($setItemList);
|
||||
|
||||
$this->assertEquals($setItemList, $this->itemCollectionParameter->getItemList());
|
||||
}
|
||||
|
||||
public function testAddItem()
|
||||
{
|
||||
$itemToAdd = new ItemParameter(['item_name' => $this->faker->name, 'item_id' => '123', 'price' => 15.55]);
|
||||
$this->itemCollectionParameter
|
||||
->setItemList([])
|
||||
->addItem($itemToAdd);
|
||||
|
||||
$this->assertEquals(1, count($this->itemCollectionParameter->getItemList()));
|
||||
$this->assertEquals($itemToAdd, $this->itemCollectionParameter->getItemList()[0]);
|
||||
}
|
||||
|
||||
public function testExportSimple()
|
||||
{
|
||||
$setItemList = [
|
||||
new ItemParameter(['item_name' => 'test1']),
|
||||
new ItemParameter(['item_id' => '123', 'price' => 15.55])
|
||||
];
|
||||
$this->itemCollectionParameter->setItemList($setItemList);
|
||||
|
||||
$this->assertEquals([
|
||||
['item_name' => 'test1'],
|
||||
['item_id' => '123', 'price' => 15.55]
|
||||
], $this->itemCollectionParameter->export());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$setItemList = [
|
||||
new ItemParameter(['item_name' => 'test1']),
|
||||
new ItemParameter(['item_id' => '123', 'price' => 15.55])
|
||||
];
|
||||
$this->itemCollectionParameter->setItemList($setItemList);
|
||||
|
||||
$this->assertTrue($this->itemCollectionParameter->validate());
|
||||
}
|
||||
|
||||
public function testValidateError()
|
||||
{
|
||||
$setItemList = [
|
||||
new ItemParameter(['item_name' => 'test1']),
|
||||
new ItemParameter(['price' => 15.55])
|
||||
];
|
||||
$this->itemCollectionParameter->setItemList($setItemList);
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$this->itemCollectionParameter->validate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 25.06.2021
|
||||
* Time: 13:03
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Parameter;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ItemParameterTest extends BaseTestCase
|
||||
{
|
||||
protected $itemParameter;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedItemParameter = new ItemParameter();
|
||||
|
||||
$this->assertNotNull($constructedItemParameter);
|
||||
}
|
||||
|
||||
public function testParametrizedConstructor()
|
||||
{
|
||||
$blueprint = [
|
||||
'item_id' => $this->faker->name,
|
||||
'price' => $this->faker->randomFloat(2, 10, 1000),
|
||||
'quantity' => $this->faker->numberBetween(1, 3)
|
||||
];
|
||||
$constructedItemParameter = new ItemParameter($blueprint);
|
||||
|
||||
$this->assertNotNull($constructedItemParameter);
|
||||
$this->assertEquals($blueprint['item_id'], $constructedItemParameter->getItemId());
|
||||
$this->assertEquals($blueprint['price'], $constructedItemParameter->getPrice());
|
||||
$this->assertEquals($blueprint['quantity'], $constructedItemParameter->getQuantity());
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$setIndex = $this->faker->numberBetween(1, 9);
|
||||
$this->itemParameter->setIndex($setIndex);
|
||||
|
||||
$this->assertEquals($setIndex, $this->itemParameter->getIndex());
|
||||
}
|
||||
|
||||
public function testAffiliation()
|
||||
{
|
||||
$setAffiliation = $this->faker->word;
|
||||
$this->itemParameter->setAffiliation($setAffiliation);
|
||||
|
||||
$this->assertEquals($setAffiliation, $this->itemParameter->getAffiliation());
|
||||
}
|
||||
|
||||
public function testCurrency()
|
||||
{
|
||||
$setCurrency = $this->faker->currencyCode;
|
||||
$this->itemParameter->setCurrency($setCurrency);
|
||||
|
||||
$this->assertEquals($setCurrency, $this->itemParameter->getCurrency());
|
||||
}
|
||||
|
||||
public function testQuantity()
|
||||
{
|
||||
$setQuantity = $this->faker->numberBetween(1, 30);
|
||||
$this->itemParameter->setQuantity($setQuantity);
|
||||
|
||||
$this->assertEquals($setQuantity, $this->itemParameter->getQuantity());
|
||||
}
|
||||
|
||||
public function testItemName()
|
||||
{
|
||||
$setName = $this->faker->word . $this->faker->colorName;
|
||||
$this->itemParameter->setItemName($setName);
|
||||
|
||||
$this->assertEquals($setName, $this->itemParameter->getItemName());
|
||||
}
|
||||
|
||||
public function testLocationId()
|
||||
{
|
||||
$setLocationId = $this->faker->bothify('*_#####');
|
||||
$this->itemParameter->setLocationId($setLocationId);
|
||||
|
||||
$this->assertEquals($setLocationId, $this->itemParameter->getLocationId());
|
||||
}
|
||||
|
||||
public function testItemCategory()
|
||||
{
|
||||
$setCategory = $this->faker->word;
|
||||
$this->itemParameter->setItemCategory($setCategory);
|
||||
$this->itemParameter->setItemCategory2($setCategory);
|
||||
$this->itemParameter->setItemCategory3($setCategory);
|
||||
$this->itemParameter->setItemCategory4($setCategory);
|
||||
$this->itemParameter->setItemCategory5($setCategory);
|
||||
|
||||
$this->assertEquals($setCategory, $this->itemParameter->getItemCategory());
|
||||
$this->assertEquals($setCategory, $this->itemParameter->getItemCategory2());
|
||||
$this->assertEquals($setCategory, $this->itemParameter->getItemCategory3());
|
||||
$this->assertEquals($setCategory, $this->itemParameter->getItemCategory4());
|
||||
$this->assertEquals($setCategory, $this->itemParameter->getItemCategory5());
|
||||
}
|
||||
|
||||
public function testPrice()
|
||||
{
|
||||
$setPrice = $this->faker->randomFloat(2, 1, 10000);
|
||||
$this->itemParameter->setPrice($setPrice);
|
||||
|
||||
$this->assertEquals($setPrice, $this->itemParameter->getPrice());
|
||||
}
|
||||
|
||||
public function testSetItemId()
|
||||
{
|
||||
$setItemId = $this->faker->bothify('***_#####');
|
||||
$this->itemParameter->setItemId($setItemId);
|
||||
|
||||
$this->assertEquals($setItemId, $this->itemParameter->getItemId());
|
||||
}
|
||||
|
||||
public function testItemListId()
|
||||
{
|
||||
$setItemListId = $this->faker->bothify('ITEM_LIST_#####');
|
||||
$this->itemParameter->setItemListId($setItemListId);
|
||||
|
||||
$this->assertEquals($setItemListId, $this->itemParameter->getItemListId());
|
||||
}
|
||||
|
||||
public function testItemListName()
|
||||
{
|
||||
$setItemListName = $this->faker->word;
|
||||
$this->itemParameter->setItemListName($setItemListName);
|
||||
|
||||
$this->assertEquals($setItemListName, $this->itemParameter->getItemListName());
|
||||
}
|
||||
|
||||
public function testCoupon()
|
||||
{
|
||||
$setCoupon = $this->faker->bothify('***-#####-#####');
|
||||
$this->itemParameter->setCoupon($setCoupon);
|
||||
|
||||
$this->assertEquals($setCoupon, $this->itemParameter->getCoupon());
|
||||
}
|
||||
|
||||
public function testDiscount()
|
||||
{
|
||||
$setDiscount = $this->faker->randomFloat(2, 1, 20);
|
||||
$this->itemParameter->setDiscount($setDiscount);
|
||||
|
||||
$this->assertEquals($setDiscount, $this->itemParameter->getDiscount());
|
||||
}
|
||||
|
||||
public function testItemVariant()
|
||||
{
|
||||
$setItemVariant = $this->faker->colorName;
|
||||
$this->itemParameter->setItemVariant($setItemVariant);
|
||||
|
||||
$this->assertEquals($setItemVariant, $this->itemParameter->getItemVariant());
|
||||
}
|
||||
|
||||
public function testSetItemBrand()
|
||||
{
|
||||
$setItemBrand = $this->faker->company;
|
||||
$this->itemParameter->setItemBrand($setItemBrand);
|
||||
|
||||
$this->assertEquals($setItemBrand, $this->itemParameter->getItemBrand());
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$validatedParameter = new ItemParameter(['item_name' => 'test1']);
|
||||
|
||||
$this->assertTrue($validatedParameter->validate());
|
||||
}
|
||||
|
||||
public function testValidateError()
|
||||
{
|
||||
$validatedParameter = new ItemParameter(['price' => 15.55]);
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$validatedParameter->validate();
|
||||
}
|
||||
|
||||
public function testHydrate()
|
||||
{
|
||||
$blueprint = [
|
||||
'item_id' => $this->faker->name,
|
||||
'item_name' => $this->faker->name,
|
||||
'affiliation' => $this->faker->name,
|
||||
'coupon' => $this->faker->name,
|
||||
'currency' => $this->faker->currencyCode,
|
||||
'discount' => $this->faker->randomFloat(2, 10, 30),
|
||||
'index' => $this->faker->numberBetween(1, 5),
|
||||
'item_brand' => $this->faker->company,
|
||||
'item_category' => $this->faker->name,
|
||||
'item_category2' => $this->faker->name,
|
||||
'item_category3' => $this->faker->name,
|
||||
'item_category4' => $this->faker->name,
|
||||
'item_category5' => $this->faker->name,
|
||||
'item_list_id' => $this->faker->name,
|
||||
'item_list_name' => $this->faker->name,
|
||||
'item_variant' => $this->faker->name,
|
||||
'location_id' => $this->faker->name,
|
||||
'price' => $this->faker->randomFloat(2, 10, 1000),
|
||||
'quantity' => $this->faker->numberBetween(1, 3)
|
||||
];
|
||||
|
||||
$constructedItemParameter = new ItemParameter();
|
||||
$constructedItemParameter->hydrate($blueprint);
|
||||
|
||||
$this->assertEquals($blueprint['item_id'], $constructedItemParameter->getItemId());
|
||||
$this->assertEquals($blueprint['item_name'], $constructedItemParameter->getItemName());
|
||||
$this->assertEquals($blueprint['affiliation'], $constructedItemParameter->getAffiliation());
|
||||
$this->assertEquals($blueprint['coupon'], $constructedItemParameter->getCoupon());
|
||||
$this->assertEquals($blueprint['currency'], $constructedItemParameter->getCurrency());
|
||||
$this->assertEquals($blueprint['discount'], $constructedItemParameter->getDiscount());
|
||||
$this->assertEquals($blueprint['index'], $constructedItemParameter->getIndex());
|
||||
$this->assertEquals($blueprint['item_brand'], $constructedItemParameter->getItemBrand());
|
||||
$this->assertEquals($blueprint['item_category'], $constructedItemParameter->getItemCategory());
|
||||
$this->assertEquals($blueprint['item_category2'], $constructedItemParameter->getItemCategory2());
|
||||
$this->assertEquals($blueprint['item_category3'], $constructedItemParameter->getItemCategory3());
|
||||
$this->assertEquals($blueprint['item_category4'], $constructedItemParameter->getItemCategory4());
|
||||
$this->assertEquals($blueprint['item_category5'], $constructedItemParameter->getItemCategory5());
|
||||
$this->assertEquals($blueprint['item_list_id'], $constructedItemParameter->getItemListId());
|
||||
$this->assertEquals($blueprint['item_list_name'], $constructedItemParameter->getItemListName());
|
||||
$this->assertEquals($blueprint['item_variant'], $constructedItemParameter->getItemVariant());
|
||||
$this->assertEquals($blueprint['location_id'], $constructedItemParameter->getLocationId());
|
||||
$this->assertEquals($blueprint['price'], $constructedItemParameter->getPrice());
|
||||
$this->assertEquals($blueprint['quantity'], $constructedItemParameter->getQuantity());
|
||||
}
|
||||
|
||||
public function testExport()
|
||||
{
|
||||
$blueprint = [
|
||||
'item_id' => $this->faker->name,
|
||||
'item_name' => $this->faker->name,
|
||||
'affiliation' => $this->faker->name,
|
||||
'coupon' => $this->faker->name,
|
||||
'currency' => $this->faker->currencyCode,
|
||||
'discount' => $this->faker->randomFloat(2, 10, 30),
|
||||
'index' => $this->faker->numberBetween(1, 5),
|
||||
'item_brand' => $this->faker->company,
|
||||
'item_category' => $this->faker->name,
|
||||
'item_category2' => $this->faker->name,
|
||||
'item_category3' => $this->faker->name,
|
||||
'item_category4' => $this->faker->name,
|
||||
'item_category5' => $this->faker->name,
|
||||
'item_list_id' => $this->faker->name,
|
||||
'item_list_name' => $this->faker->name,
|
||||
'item_variant' => $this->faker->name,
|
||||
'location_id' => $this->faker->name,
|
||||
'price' => $this->faker->randomFloat(2, 10, 1000),
|
||||
'quantity' => $this->faker->numberBetween(1, 3)
|
||||
];
|
||||
|
||||
$constructedItemParameter = new ItemParameter($blueprint);
|
||||
|
||||
$this->assertEquals($blueprint, $constructedItemParameter->export());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->itemParameter = new ItemParameter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 22.06.2021
|
||||
* Time: 16:06
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Request;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\EventCollection;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\UserProperties;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\UserProperty;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\BaseParameter;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Request\BaseRequest;
|
||||
use Br33f\Ga4\MeasurementProtocol\Enum\ErrorCode;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class BaseRequestTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var BaseRequest
|
||||
*/
|
||||
protected $baseRequest;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedBaseRequest = new BaseRequest();
|
||||
|
||||
$this->assertNotNull($constructedBaseRequest);
|
||||
}
|
||||
|
||||
public function testAbstractEventConstructor()
|
||||
{
|
||||
$event = new BaseEvent();
|
||||
$constructedBaseRequest = new BaseRequest(null, $event);
|
||||
|
||||
$this->assertNotNull($constructedBaseRequest);
|
||||
$this->assertCount(1, $constructedBaseRequest->getEvents()->getEventList());
|
||||
$this->assertEquals($event, $constructedBaseRequest->getEvents()->getEventList()[0]);
|
||||
}
|
||||
|
||||
public function testClientId()
|
||||
{
|
||||
$setClientId = $this->faker->asciify('********************.********************');
|
||||
$this->baseRequest->setClientId($setClientId);
|
||||
|
||||
$this->assertEquals($setClientId, $this->baseRequest->getClientId());
|
||||
}
|
||||
|
||||
public function testUserId()
|
||||
{
|
||||
$setUserId = $this->faker->asciify('*********');
|
||||
$this->baseRequest->setUserId($setUserId);
|
||||
|
||||
$this->assertEquals($setUserId, $this->baseRequest->getUserId());
|
||||
}
|
||||
|
||||
public function testTimestampMicros()
|
||||
{
|
||||
$setTimestampMicros = $this->faker->unixTime * 1000;
|
||||
$this->baseRequest->setTimestampMicros($setTimestampMicros);
|
||||
|
||||
$this->assertEquals($setTimestampMicros, $this->baseRequest->getTimestampMicros());
|
||||
}
|
||||
|
||||
public function testNonPersonalizedAds()
|
||||
{
|
||||
$this->baseRequest->setNonPersonalizedAds(true);
|
||||
$this->assertEquals(true, $this->baseRequest->isNonPersonalizedAds());
|
||||
|
||||
$this->baseRequest->setNonPersonalizedAds(false);
|
||||
$this->assertEquals(false, $this->baseRequest->isNonPersonalizedAds());
|
||||
}
|
||||
|
||||
public function testUserProperties()
|
||||
{
|
||||
$setUserProperties = new UserProperties();
|
||||
$this->baseRequest->setUserProperties($setUserProperties);
|
||||
|
||||
$this->assertEquals($setUserProperties, $this->baseRequest->getUserProperties());
|
||||
}
|
||||
|
||||
public function testAddUserProperty()
|
||||
{
|
||||
$addUserProperty = new UserProperty($this->faker->word, $this->faker->word);
|
||||
$this->baseRequest->addUserProperty($addUserProperty);
|
||||
|
||||
$this->assertEquals(1, count($this->baseRequest->getUserProperties()->getUserPropertiesList()));
|
||||
$this->assertEquals($addUserProperty, $this->baseRequest->getUserProperties()->getUserPropertiesList()[0]);
|
||||
}
|
||||
|
||||
public function testEvents()
|
||||
{
|
||||
$setEvents = new EventCollection();
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$event->addParam($this->faker->word, new BaseParameter($this->faker->word));
|
||||
$setEvents->addEvent($event);
|
||||
$this->baseRequest->setEvents($setEvents);
|
||||
|
||||
$this->assertEquals($setEvents, $this->baseRequest->getEvents());
|
||||
}
|
||||
|
||||
public function testAddEvent()
|
||||
{
|
||||
$this->baseRequest->setEvents(new EventCollection());
|
||||
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$event->addParam($this->faker->word, new BaseParameter($this->faker->word));
|
||||
|
||||
$this->baseRequest->addEvent($event);
|
||||
|
||||
$this->assertEquals(1, count($this->baseRequest->getEvents()->getEventList()));
|
||||
$this->assertEquals($event, $this->baseRequest->getEvents()->getEventList()[0]);
|
||||
}
|
||||
|
||||
public function testValidateClientIdRequiredFailed()
|
||||
{
|
||||
$newBaseRequest = new BaseRequest();
|
||||
|
||||
$this->expectExceptionCode(ErrorCode::VALIDATION_CLIENT_ID_REQUIRED);
|
||||
$newBaseRequest->validate('web');
|
||||
}
|
||||
|
||||
public function testValidateAppInstanceIdRequiredFailed()
|
||||
{
|
||||
$newBaseRequest = new BaseRequest();
|
||||
|
||||
$this->expectExceptionCode(ErrorCode::VALIDATION_APP_INSTANCE_ID_REQUIRED);
|
||||
$newBaseRequest->validate('firebase');
|
||||
}
|
||||
|
||||
public function testValidateBothClientIdAppInstanceIdRequiredFailed()
|
||||
{
|
||||
$newBaseRequest = new BaseRequest();
|
||||
$setAppInstanceId = $this->faker->bothify('**-########');
|
||||
$setFirebaseId = $this->faker->bothify('**-########');
|
||||
|
||||
$newBaseRequest->setAppInstanceId($setAppInstanceId);
|
||||
$newBaseRequest->setClientId($setFirebaseId);
|
||||
|
||||
$this->expectExceptionCode(ErrorCode::VALIDATION_CLIENT_IDENTIFIER_MISCONFIGURED);
|
||||
$newBaseRequest->validate();
|
||||
}
|
||||
|
||||
public function testValidateSuccess()
|
||||
{
|
||||
$setClientId = $this->faker->asciify('********************.********************');
|
||||
$setEventCollection = new EventCollection();
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$event->addParam($this->faker->word, new BaseParameter($this->faker->word));
|
||||
$setEventCollection->addEvent($event);
|
||||
$newBaseRequest = new BaseRequest($setClientId, $setEventCollection);
|
||||
|
||||
$this->assertTrue($newBaseRequest->validate());
|
||||
}
|
||||
|
||||
public function testExportOnlyRequiredParameters()
|
||||
{
|
||||
$setClientId = $this->faker->asciify('********************.********************');
|
||||
$setEventCollection = new EventCollection();
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$event->addParam($this->faker->word, new BaseParameter($this->faker->word));
|
||||
$setEventCollection->addEvent($event);
|
||||
|
||||
$exportBaseRequest = new BaseRequest($setClientId, $setEventCollection);
|
||||
|
||||
$this->assertEquals([
|
||||
'client_id' => $setClientId,
|
||||
'events' => $setEventCollection->export(),
|
||||
], $exportBaseRequest->export());
|
||||
}
|
||||
|
||||
public function testExportAllParameters()
|
||||
{
|
||||
$setClientId = $this->faker->asciify('********************.********************');
|
||||
$setEventCollection = new EventCollection();
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$event->addParam($this->faker->word, new BaseParameter($this->faker->word));
|
||||
$setEventCollection->addEvent($event);
|
||||
|
||||
$exportBaseRequest = new BaseRequest($setClientId, $setEventCollection);
|
||||
|
||||
$setUserId = $this->faker->asciify('************');
|
||||
$exportBaseRequest->setUserId($setUserId);
|
||||
|
||||
$setTimestampMicros = $this->faker->unixTime * 1000;
|
||||
$exportBaseRequest->setTimestampMicros($setTimestampMicros);
|
||||
|
||||
$setUserProperties = new UserProperties();
|
||||
$exportBaseRequest->setUserProperties($setUserProperties);
|
||||
|
||||
$this->assertEquals([
|
||||
'client_id' => $setClientId,
|
||||
'events' => $setEventCollection->export(),
|
||||
'user_id' => $setUserId,
|
||||
'timestamp_micros' => $setTimestampMicros,
|
||||
'user_properties' => $setUserProperties->export()
|
||||
], $exportBaseRequest->export());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->baseRequest = new BaseRequest();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 24.06.2021
|
||||
* Time: 14:25
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Response;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Response\BaseResponse;
|
||||
use GuzzleHttp7\Psr7\Response;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class BaseResponseTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var BaseResponse
|
||||
*/
|
||||
protected $baseResponse;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedBaseResponse = new BaseResponse();
|
||||
|
||||
$this->assertNotNull($constructedBaseResponse);
|
||||
}
|
||||
|
||||
public function testBlueprintConstructor()
|
||||
{
|
||||
$response = new Response(200, [], '{"test_field": {"value": "123"}}');
|
||||
$constructedBaseResponse = new BaseResponse($response);
|
||||
|
||||
$this->assertNotNull($constructedBaseResponse);
|
||||
$this->assertEquals(200, $constructedBaseResponse->getStatusCode());
|
||||
$this->assertEquals('{"test_field": {"value": "123"}}', $constructedBaseResponse->getBody());
|
||||
}
|
||||
|
||||
public function testStatusCode()
|
||||
{
|
||||
$setStatusCode = 204;
|
||||
$this->baseResponse->setStatusCode($setStatusCode);
|
||||
|
||||
$this->assertEquals(204, $this->baseResponse->getStatusCode());
|
||||
}
|
||||
|
||||
public function testData()
|
||||
{
|
||||
$setBody = '{"test_field": {"value": "321"}}';
|
||||
$this->baseResponse->setBody($setBody);
|
||||
|
||||
$this->assertEquals($setBody, $this->baseResponse->getBody());
|
||||
$this->assertEquals(json_decode($setBody, true), $this->baseResponse->getData());
|
||||
}
|
||||
|
||||
public function testBody()
|
||||
{
|
||||
$setBody = '{"test_field": {"value": "321"}}';
|
||||
$this->baseResponse->setBody($setBody);
|
||||
|
||||
$this->assertEquals($setBody, $this->baseResponse->getBody());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->baseResponse = new BaseResponse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 24.06.2021
|
||||
* Time: 14:25
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Dto\Response;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Common\ValidationMessage;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Response\DebugResponse;
|
||||
use GuzzleHttp7\Psr7\Response;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class DebugResponseTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var DebugResponse
|
||||
*/
|
||||
protected $debugResponse;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedDebugResponse = new DebugResponse();
|
||||
|
||||
$this->assertNotNull($constructedDebugResponse);
|
||||
}
|
||||
|
||||
public function testBlueprintConstructor()
|
||||
{
|
||||
$response = new Response(200, [], '{
|
||||
"validationMessages": [
|
||||
{
|
||||
"description": "Unable to parse Measurement Protocol JSON payload. (events[0]) names: Cannot find field.",
|
||||
"validationCode": "VALUE_INVALID"
|
||||
}
|
||||
]
|
||||
}');
|
||||
|
||||
$parsedValidationMessage = new ValidationMessage(json_decode('{
|
||||
"description": "Unable to parse Measurement Protocol JSON payload. (events[0]) names: Cannot find field.",
|
||||
"validationCode": "VALUE_INVALID"
|
||||
}', true));
|
||||
|
||||
$constructedDebugResponse = new DebugResponse($response);
|
||||
|
||||
$this->assertNotNull($constructedDebugResponse);
|
||||
$this->assertEquals(200, $constructedDebugResponse->getStatusCode());
|
||||
$this->assertEquals(1, count($constructedDebugResponse->getValidationMessages()));
|
||||
$this->assertEquals($parsedValidationMessage, $constructedDebugResponse->getValidationMessages()[0]);
|
||||
}
|
||||
|
||||
public function testBody()
|
||||
{
|
||||
$setValidationMessages = [new ValidationMessage(['fieldPath' => 'test123'])];
|
||||
$this->debugResponse->setValidationMessages($setValidationMessages);
|
||||
|
||||
$this->assertEquals($setValidationMessages, $this->debugResponse->getValidationMessages());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->debugResponse = new DebugResponse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 23.06.2021
|
||||
* Time: 12:17
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Exception;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\HydrationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class HydrationExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function test__construct()
|
||||
{
|
||||
$setMessage = $this->faker->word;
|
||||
$setCode = $this->faker->numerify('#######');
|
||||
$constructedValidationException = new HydrationException($setMessage, $setCode);
|
||||
|
||||
$this->assertEquals($setMessage, $constructedValidationException->getMessage());
|
||||
$this->assertEquals($setCode, $constructedValidationException->getCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 23.06.2021
|
||||
* Time: 12:17
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol\Exception;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ValidationExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function test__construct()
|
||||
{
|
||||
$setMessage = $this->faker->word;
|
||||
$setCode = $this->faker->numerify('#######');
|
||||
$setFieldName = $this->faker->word;
|
||||
$constructedValidationException = new ValidationException($setMessage, $setCode, $setFieldName);
|
||||
|
||||
$this->assertEquals($setMessage, $constructedValidationException->getMessage());
|
||||
$this->assertEquals($setCode, $constructedValidationException->getCode());
|
||||
$this->assertEquals($setFieldName, $constructedValidationException->getFieldName());
|
||||
}
|
||||
|
||||
public function testFieldName()
|
||||
{
|
||||
$setFieldName = $this->faker->word;
|
||||
|
||||
$constructedValidationException = new ValidationException();
|
||||
$constructedValidationException->setFieldName($setFieldName);
|
||||
|
||||
$this->assertEquals($setFieldName, $constructedValidationException->getFieldName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 23.06.2021
|
||||
* Time: 12:23
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\HttpClient;
|
||||
use GuzzleHttp7\Client;
|
||||
use GuzzleHttp7\Handler\MockHandler;
|
||||
use GuzzleHttp7\HandlerStack;
|
||||
use GuzzleHttp7\Psr7\Response;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class HttpClientTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var HttpClient
|
||||
*/
|
||||
protected $httpClient;
|
||||
|
||||
public function testDefaultConstructor()
|
||||
{
|
||||
$constructedHttpClient = new HttpClient();
|
||||
|
||||
$this->assertNotNull($constructedHttpClient);
|
||||
}
|
||||
|
||||
public function testClient()
|
||||
{
|
||||
$setClient = new Client();
|
||||
$this->httpClient->setClient($setClient);
|
||||
|
||||
$this->assertEquals($setClient, $this->httpClient->getClient());
|
||||
}
|
||||
|
||||
public function testGetClientWhenNotSet()
|
||||
{
|
||||
$emptyHttpClient = new HttpClient();
|
||||
|
||||
$this->assertNotNull($emptyHttpClient->getClient());
|
||||
}
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(204),
|
||||
new Response(403),
|
||||
new Response(500)
|
||||
]);
|
||||
|
||||
$handlerStack = HandlerStack::create($mock);
|
||||
$mockClient = new Client(['handler' => $handlerStack]);
|
||||
|
||||
$newHttpClient = new HttpClient();
|
||||
$newHttpClient->setClient($mockClient);
|
||||
|
||||
$response = $newHttpClient->post($this->faker->url, []);
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
|
||||
$response = $newHttpClient->post($this->faker->url, []);
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
|
||||
$response = $newHttpClient->post($this->faker->url, []);
|
||||
$this->assertEquals(500, $response->getStatusCode());
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->httpClient = new HttpClient();
|
||||
}
|
||||
}
|
||||
264
modules/pdgoogleanalytycs4pro/vendor/br33f/php-ga4-mp/tests/Ga4/MeasurementProtocol/ServiceTest.php
vendored
Normal file
264
modules/pdgoogleanalytycs4pro/vendor/br33f/php-ga4-mp/tests/Ga4/MeasurementProtocol/ServiceTest.php
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
/**
|
||||
* User: Damian Zamojski (br33f)
|
||||
* Date: 23.06.2021
|
||||
* Time: 14:42
|
||||
*/
|
||||
|
||||
namespace Tests\Ga4\MeasurementProtocol;
|
||||
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Request\BaseRequest;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Response\AbstractResponse;
|
||||
use Br33f\Ga4\MeasurementProtocol\Dto\Response\DebugResponse;
|
||||
use Br33f\Ga4\MeasurementProtocol\Exception\MisconfigurationException;
|
||||
use Br33f\Ga4\MeasurementProtocol\HttpClient;
|
||||
use Br33f\Ga4\MeasurementProtocol\Service;
|
||||
use GuzzleHttp7\Client;
|
||||
use GuzzleHttp7\Handler\MockHandler;
|
||||
use GuzzleHttp7\HandlerStack;
|
||||
use GuzzleHttp7\Psr7\Response;
|
||||
use Tests\Common\BaseTestCase;
|
||||
|
||||
class ServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var Service
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$constructedService = new Service($setApiSecret, $setMeasurementId);
|
||||
|
||||
$this->assertEquals($setApiSecret, $constructedService->getApiSecret());
|
||||
$this->assertEquals($setMeasurementId, $constructedService->getMeasurementId());
|
||||
}
|
||||
|
||||
public function testUseSsl()
|
||||
{
|
||||
$this->service->setUseSsl(true);
|
||||
$this->assertTrue($this->service->isUseSsl());
|
||||
|
||||
$this->service->setUseSsl(false);
|
||||
$this->assertFalse($this->service->isUseSsl());
|
||||
}
|
||||
|
||||
public function testUsewww()
|
||||
{
|
||||
$this->service->setUseWww(true);
|
||||
$this->assertTrue($this->service->isUseWww());
|
||||
|
||||
$this->service->setUseWww(false);
|
||||
$this->assertFalse($this->service->isUseWww());
|
||||
}
|
||||
|
||||
public function testCollectEndpoint()
|
||||
{
|
||||
$setCollectEndpoint = str_replace('https://', '', $this->faker->url);
|
||||
$setCollectEndpoint = str_replace('http://', '', $setCollectEndpoint);
|
||||
|
||||
$this->service->setCollectEndpoint($setCollectEndpoint);
|
||||
|
||||
$this->assertEquals($setCollectEndpoint, $this->service->getCollectEndpoint());
|
||||
}
|
||||
|
||||
public function testCollectDebugEndpoint()
|
||||
{
|
||||
$setCollectDebugEndpoint = str_replace('https://', '', $this->faker->url);
|
||||
$setCollectDebugEndpoint = str_replace('http://', '', $setCollectDebugEndpoint);
|
||||
|
||||
$this->service->setCollectDebugEndpoint($setCollectDebugEndpoint);
|
||||
|
||||
$this->assertEquals($setCollectDebugEndpoint, $this->service->getCollectDebugEndpoint());
|
||||
}
|
||||
|
||||
public function testMeasurementId()
|
||||
{
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$this->service->setMeasurementId($setMeasurementId);
|
||||
|
||||
$this->assertEquals($setMeasurementId, $this->service->getMeasurementId());
|
||||
}
|
||||
|
||||
public function testSetApiSecret()
|
||||
{
|
||||
$setApiSecret = $this->faker->word;
|
||||
$this->service->setApiSecret($setApiSecret);
|
||||
|
||||
$this->assertEquals($setApiSecret, $this->service->getApiSecret());
|
||||
}
|
||||
|
||||
public function testHttpClient()
|
||||
{
|
||||
$setHttpClient = new HttpClient();
|
||||
$this->service->setHttpClient($setHttpClient);
|
||||
|
||||
$this->assertEquals($setHttpClient, $this->service->getHttpClient());
|
||||
}
|
||||
|
||||
public function testHttpClientWhenEmpty()
|
||||
{
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$constructedService = new Service($setApiSecret, $setMeasurementId);
|
||||
|
||||
$this->assertNotNull($constructedService->getHttpClient());
|
||||
}
|
||||
|
||||
public function testEndpoint()
|
||||
{
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
|
||||
$newService = new Service($setApiSecret, $setMeasurementId);
|
||||
|
||||
$setCollectEndpoint = str_replace('https://', '', $this->faker->url);
|
||||
$setCollectEndpoint = str_replace('http://', '', $setCollectEndpoint);
|
||||
$newService->setCollectEndpoint($setCollectEndpoint);
|
||||
$newService->setUseSsl(true);
|
||||
|
||||
$getParams = '?' . http_build_query(['api_secret' => $newService->getApiSecret(), 'measurement_id' => $newService->getMeasurementId()]);
|
||||
$this->assertEquals(Service::SSL_SCHEME . $setCollectEndpoint . $getParams, $newService->getEndpoint());
|
||||
|
||||
$newService->setUseSsl(false);
|
||||
$this->assertEquals(Service::NOT_SSL_SCHEME . $setCollectEndpoint . $getParams, $newService->getEndpoint());
|
||||
|
||||
$setCollectDebugEndpoint = str_replace('https://', '', $this->faker->url);
|
||||
$setCollectDebugEndpoint = str_replace('http://', '', $setCollectDebugEndpoint);
|
||||
$newService->setCollectDebugEndpoint($setCollectDebugEndpoint);
|
||||
$newService->setUseSsl(true);
|
||||
$this->assertEquals(Service::SSL_SCHEME . $setCollectDebugEndpoint . $getParams, $newService->getEndpoint(true));
|
||||
|
||||
$newService->setUseSsl(false);
|
||||
$this->assertEquals(Service::NOT_SSL_SCHEME . $setCollectDebugEndpoint . $getParams, $newService->getEndpoint(true));
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
$setOptions = [
|
||||
'timeout' => '25',
|
||||
'headers' => [
|
||||
'User-Agent' => 'Test User Agent'
|
||||
]
|
||||
];
|
||||
$this->service->setOptions($setOptions);
|
||||
|
||||
$this->assertEquals($setOptions, $this->service->getOptions());
|
||||
}
|
||||
|
||||
public function testSend()
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(200)
|
||||
]);
|
||||
|
||||
$handlerStack = HandlerStack::create($mock);
|
||||
$mockClient = new Client(['handler' => $handlerStack]);
|
||||
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$sendService = new Service($setApiSecret, $setMeasurementId);
|
||||
$sendService->getHttpClient()->setClient($mockClient);
|
||||
|
||||
$setClientId = $this->faker->asciify('********************.********************');
|
||||
$sentRequest = new BaseRequest($setClientId);
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$sentRequest->addEvent($event);
|
||||
|
||||
$baseResponse = $sendService->send($sentRequest);
|
||||
$this->assertTrue($baseResponse instanceof AbstractResponse);
|
||||
$this->assertEquals(200, $baseResponse->getStatusCode());
|
||||
}
|
||||
|
||||
public function testSendWithIpOverride()
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(200)
|
||||
]);
|
||||
|
||||
$handlerStack = HandlerStack::create($mock);
|
||||
$mockClient = new Client(['handler' => $handlerStack]);
|
||||
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$sendService = new Service($setApiSecret, $setMeasurementId);
|
||||
$sendService->getHttpClient()->setClient($mockClient);
|
||||
|
||||
$sendService->setIpOverride($this->faker->ipv4);
|
||||
|
||||
$setClientId = $this->faker->asciify('********************.********************');
|
||||
$sentRequest = new BaseRequest($setClientId);
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$sentRequest->addEvent($event);
|
||||
|
||||
$baseResponse = $sendService->send($sentRequest);
|
||||
$this->assertTrue($baseResponse instanceof AbstractResponse);
|
||||
$this->assertEquals(200, $baseResponse->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
public function testSendDebugWithError()
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
new Response(200, [], '{
|
||||
"validationMessages": [
|
||||
{
|
||||
"description": "Unable to parse Measurement Protocol JSON payload. (events[0]) names: Cannot find field.",
|
||||
"validationCode": "VALUE_INVALID"
|
||||
}
|
||||
]
|
||||
}')
|
||||
]);
|
||||
|
||||
$handlerStack = HandlerStack::create($mock);
|
||||
$mockClient = new Client(['handler' => $handlerStack]);
|
||||
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$sendService = new Service($setApiSecret, $setMeasurementId);
|
||||
$sendService->getHttpClient()->setClient($mockClient);
|
||||
|
||||
$setClientId = $this->faker->asciify('********************.********************');
|
||||
$sentRequest = new BaseRequest($setClientId);
|
||||
$event = new BaseEvent($this->faker->word);
|
||||
$sentRequest->addEvent($event);
|
||||
|
||||
$debugResponse = $sendService->sendDebug($sentRequest);
|
||||
$this->assertTrue($debugResponse instanceof DebugResponse);
|
||||
$this->assertEquals(200, $debugResponse->getStatusCode());
|
||||
$this->assertEquals(1, count($debugResponse->getValidationMessages()));
|
||||
}
|
||||
|
||||
public function testMisconfigBothInGetQueryParameters()
|
||||
{
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$setFirebaseId = $this->faker->bothify('**-########');
|
||||
$testService = new Service($setApiSecret, $setMeasurementId);
|
||||
$testService->setFirebaseId($setFirebaseId);
|
||||
|
||||
$this->expectException(MisconfigurationException::class);
|
||||
$testService->getQueryParameters();
|
||||
}
|
||||
|
||||
public function testMisconfigApiSecretEmptyInGetQueryParameters()
|
||||
{
|
||||
$setApiSecret = $this->faker->word;
|
||||
$setMeasurementId = $this->faker->bothify('**-########');
|
||||
$setFirebaseId = $this->faker->bothify('**-########');
|
||||
$testService = new Service($setApiSecret, $setMeasurementId);
|
||||
$testService->setFirebaseId($setFirebaseId);
|
||||
|
||||
$this->expectException(MisconfigurationException::class);
|
||||
$testService->getQueryParameters();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->service = new Service($this->faker->word, $this->faker->bothify('**-########'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user