|
4 | 4 |
|
5 | 5 | use ReflectionClass; |
6 | 6 | use AlexWestergaard\PhpGa4\Helper\EventHelper; |
| 7 | +use AlexWestergaard\PhpGa4\Helper\EventMainHelper; |
7 | 8 | use AlexWestergaard\PhpGa4\Helper\ConvertHelper; |
8 | 9 | use AlexWestergaard\PhpGa4\Facade\Type; |
9 | 10 | use AlexWestergaard\PhpGa4\Facade\Group; |
10 | 11 | use AlexWestergaard\PhpGa4\Exception\Ga4Exception; |
11 | 12 | use AlexWestergaard\PhpGa4\Exception\Ga4EventException; |
12 | 13 | use AlexWestergaard\PhpGa4\Event; |
13 | | -use AlexWestergaard\PhpGa4\Campaign; |
14 | 14 | use AlexWestergaard\PhpGa4Test\MeasurementTestCase; |
15 | 15 |
|
16 | 16 | final class EventTest extends MeasurementTestCase |
17 | 17 | { |
| 18 | + public function test_page_view() |
| 19 | + { |
| 20 | + $event = new Event\PageView; |
| 21 | + |
| 22 | + $this->assertEventNaming($event); |
| 23 | + $this->assertEventFills($this->populateEventByMethod(clone $event)); |
| 24 | + $this->assertEventFills($this->populateEventByArrayable(clone $event)); |
| 25 | + $this->assertEventFills($this->populateEventByFromArray(clone $event)); |
| 26 | + |
| 27 | + $this->assertImportableByConvertHelper( |
| 28 | + [ |
| 29 | + [ConvertHelper::camel($event->getName()) => $this->populateEventByFromArray(clone $event)->toArray()] |
| 30 | + ], |
| 31 | + $event |
| 32 | + ); |
| 33 | + |
| 34 | + $this->analytics->addEvent($this->populateEventByFromArray(clone $event)); |
| 35 | + $this->analytics->post(); |
| 36 | + } |
| 37 | + |
18 | 38 | public function test_addpaymentinfo() |
19 | 39 | { |
20 | 40 | $event = new Event\AddPaymentInfo; |
@@ -738,7 +758,7 @@ public function test_exception() |
738 | 758 | protected function assertEventNaming($event) |
739 | 759 | { |
740 | 760 | $this->assertInstanceOf(Type\EventType::class, $event); |
741 | | - $this->assertInstanceOf(EventHelper::class, $event); |
| 761 | + $this->assertInstanceOf(EventMainHelper::class, $event); |
742 | 762 |
|
743 | 763 | $reflection = new ReflectionClass($event); |
744 | 764 | $filename = $reflection->getFileName(); |
@@ -825,9 +845,9 @@ private function populateEventByFromArray(Type\EventType $event) |
825 | 845 | private function populateEventByArrayable(Type\EventType $event) |
826 | 846 | { |
827 | 847 | $event['language'] = 'en-US'; |
828 | | - $event['page_location'] = '/'; |
| 848 | + $event['page_location'] = 'https://example.com/'; |
829 | 849 | $event['page_referrer'] = 'https://example.com/'; |
830 | | - $event['page_title'] = 'Home - Site'; |
| 850 | + $event['page_title'] = 'Home - Example'; |
831 | 851 | $event['screen_resolution'] = '1920x1080'; |
832 | 852 |
|
833 | 853 | $event['description'] = 'This is a short description'; |
@@ -869,15 +889,32 @@ private function populateEventByArrayable(Type\EventType $event) |
869 | 889 | } |
870 | 890 |
|
871 | 891 | private function populateEventByMethod( |
872 | | - Type\EventType|Group\ExceptionFacade|Group\AddPaymentInfoFacade|Group\AddShippingInfoFacade|Group\AddToCartFacade|Group\AddToWishlistFacade|Group\AnalyticsFacade|Group\BeginCheckoutFacade|Group\EarnVirtualCurrencyFacade|Group\ExportFacade|Group\GenerateLeadFacade|Group\ItemFacade|Group\JoinGroupFacade|Group\LevelUpFacade|Group\LoginFacade|Group\PostScoreFacade|Group\PurchaseFacade|Group\RefundFacade|Group\RemoveFromCartFacade|Group\SearchFacade|Group\SelectContentFacade|Group\SelectItemFacade|Group\SelectPromotionFacade|Group\ShareFacade|Group\SignUpFacade|Group\SpendVirtualCurrencyFacade|Group\UnlockAchievementFacade|Group\ViewCartFacade|Group\ViewItemFacade|Group\ViewItemListFacade|Group\ViewPromotionFacade|Group\ViewSearchResultsFacade|Group\hasItemsFacade $event |
| 892 | + Type\EventType|Group\ExceptionFacade|Group\PageViewFacade|Group\AddPaymentInfoFacade|Group\AddShippingInfoFacade|Group\AddToCartFacade|Group\AddToWishlistFacade|Group\AnalyticsFacade|Group\BeginCheckoutFacade|Group\EarnVirtualCurrencyFacade|Group\ExportFacade|Group\GenerateLeadFacade|Group\ItemFacade|Group\JoinGroupFacade|Group\LevelUpFacade|Group\LoginFacade|Group\PostScoreFacade|Group\PurchaseFacade|Group\RefundFacade|Group\RemoveFromCartFacade|Group\SearchFacade|Group\SelectContentFacade|Group\SelectItemFacade|Group\SelectPromotionFacade|Group\ShareFacade|Group\SignUpFacade|Group\SpendVirtualCurrencyFacade|Group\UnlockAchievementFacade|Group\ViewCartFacade|Group\ViewItemFacade|Group\ViewItemListFacade|Group\ViewPromotionFacade|Group\ViewSearchResultsFacade|Group\hasItemsFacade $event |
873 | 893 | ) { |
874 | 894 | $params = $event->getAllParams(); |
875 | 895 |
|
876 | | - $event->setLanguage('en-US'); |
877 | | - $event->setPageLocation('/'); |
878 | | - $event->setPageReferrer('https://example.com/'); |
879 | | - $event->setPageTitle('Home - Site'); |
880 | | - $event->setScreenResolution('1920x1080'); |
| 896 | + if ($event instanceof EventHelper) { |
| 897 | + $event->setLanguage('en-US'); |
| 898 | + $event->setPageLocation('https://example.com/'); |
| 899 | + $event->setPageReferrer('https://example.com/'); |
| 900 | + $event->setPageTitle('Home - Example'); |
| 901 | + $event->setScreenResolution('1920x1080'); |
| 902 | + } |
| 903 | + |
| 904 | + if (in_array('page_title', $params)) { |
| 905 | + $event->setPageTitle('Home - Example'); |
| 906 | + } |
| 907 | + |
| 908 | + if (in_array('page_title', $params)) { |
| 909 | + $event->setPageLocation('https://example.com/'); |
| 910 | + } |
| 911 | + |
| 912 | + if (in_array('description', $params)) { |
| 913 | + $event->setDescription("This is a short description"); |
| 914 | + if (in_array('fatal', $params)) { |
| 915 | + $event->setFatal(1); |
| 916 | + } |
| 917 | + } |
881 | 918 |
|
882 | 919 | if (in_array('description', $params)) { |
883 | 920 | $event->setDescription("This is a short description"); |
|
0 commit comments