1<?php
2
3namespace dokuwiki\plugin\swarmwebhook\test;
4
5/**
6 * General tests for the swarmwebhook plugin
7 *
8 * @group plugin_swarmwebhook
9 * @group plugins
10 */
11class ZapierExtractData extends \DokuWikiTest
12{
13    /** @var array alway enable the needed plugins */
14    protected $pluginsEnabled = ['swarmwebhook'];
15
16    public function dataProvider()
17    {
18        return [
19            [
20                '{"createdAt": "1525849118", "like": "False", "isMayor": "True", "editableUntil": "1525935518000", "posts": {"count": "0", "textCount": "0"}, "comments": {"count": "0"}, "photos": {"count": "0", "items": ""}, "likes": {"count": "0", "groups": ""}, "venue": {"stats": {"tipCount": "2", "checkinsCount": "1552", "usersCount": "24"}, "name": "CosmoCode", "venueRatingBlacklisted": "True", "url": "http://www.cosmocode.de", "contact": {"twitter": "cosmocode"}, "location": {"city": "Berlin", "labeledLatLngs": "label: display\nlat: 52.5341728565\nlng: 13.4235969339", "cc": "DE", "country": "Germany", "postalCode": "10405", "state": "Berlin", "formattedAddress": "Prenzlauer Allee 36 (Marienburger Strasse),10405 Berlin", "crossStreet": "Marienburger Strasse", "address": "Prenzlauer Allee 36", "lat": "52.5341728565", "lng": "13.4235969339"}, "beenHere": {"lastCheckinExpiredAt": "0"}, "verified": "False", "id": "4b4ca6c8f964a520f8b826e3", "categories": "icon: {u\'prefix\': u\'https://ss3.4sqi.net/img/categories_v2/building/default_\', u\'suffix\': u\'.png\'}\nid: 4bf58dd8d48988d124941735\nname: Office\npluralName: Offices\nprimary: True\nshortName: Office"}, "type": "checkin", "id": "5af29c1e6fd626002c38730b", "timeZoneOffset": "120", "source": {"url": "https://www.swarmapp.com", "name": "Swarm for Android"}}',
21                [
22                    'date' => '2018-05-09',
23                    'time' => '2018-05-09T08:58:38+02:00',
24                    'checkinid' => '5af29c1e6fd626002c38730b',
25                    'locname' => 'CosmoCode',
26                    'service' => 'Zapier',
27                ],
28                'normal event without shout',
29            ],
30            [
31                '{"entities": "", "createdAt": "1526051437", "like": "False", "isMayor": "False", "editableUntil": "1526137837000", "sticker": {"bonusStatus": "Use once per week. Recharges Sunday at midnight.", "group": {"index": "85", "name": "collectible"}, "name": "Baggs", "unlockText": "They\'re out of milk, your cart\'s wheel is busted, and that lady has way more than 10 items! Here\'s hoping Baggs doesn\'t dump your eggs on the ground.", "image": {"prefix": "https://irs1.4sqi.net/img/sticker/", "name": "/groceries_2a2425.png", "sizes": "60,94,150,300"}, "pickerPosition": {"index": "13", "page": "3"}, "points": "2", "teaseText": "Check in at food & drink shops to unlock this sticker.", "bonusText": "Use at Food & Drink Shops for a bonus.", "id": "55563bd52beaa0fbc4d1dc3f", "stickerType": "unlockable"}, "posts": {"count": "0", "textCount": "0"}, "comments": {"count": "0"}, "photos": {"count": "0", "items": ""}, "shout": "Reiswaffeln \ud83c\udf5a", "likes": {"count": "0", "groups": ""}, "venue": {"stats": {"tipCount": "0", "checkinsCount": "368", "usersCount": "140"}, "name": "EDEKA Rhinstra\u00dfe", "url": "http://www.kaisers.de", "allowMenuUrlEdit": "True", "contact": {"facebookName": "Kaiser\'s Berlin", "facebookUsername": "KaisersBerlin", "facebook": "352765558110244", "formattedPhone": "0208 37770", "phone": "020837770"}, "location": {"city": "Berlin", "labeledLatLngs": "label: display\nlat: 52.5135124211\nlng: 13.5182151518", "cc": "DE", "country": "Germany", "postalCode": "10315", "state": "Berlin", "formattedAddress": "Rhinstr. 17,10315 Berlin", "address": "Rhinstr. 17", "lat": "52.5135124211", "lng": "13.5182151518"}, "beenHere": {"lastCheckinExpiredAt": "0"}, "verified": "True", "id": "4d79bd5b7418a14366cfc05b", "categories": "icon: {u\'prefix\': u\'https://ss3.4sqi.net/img/categories_v2/shops/food_grocery_\', u\'suffix\': u\'.png\'}\nid: 52f2ab2ebcbc57f1066b8b46\nname: Supermarket\npluralName: Supermarkets\nprimary: True\nshortName: Supermarket"}, "type": "checkin", "id": "5af5b26d898bdc002c7a17db", "timeZoneOffset": "120", "source": {"url": "https://www.swarmapp.com", "name": "Swarm for Android"}}',
32                [
33                    'date' => '2018-05-11',
34                    'time' => '2018-05-11T17:10:37+02:00',
35                    'checkinid' => '5af5b26d898bdc002c7a17db',
36                    'locname' => 'EDEKA Rhinstraße',
37                    'shout' => 'Reiswaffeln ��',
38                    'service' => 'Zapier',
39                ],
40                'normal event with shout and sticker',
41            ]
42        ];
43    }
44
45    /**
46     * @dataProvider dataProvider
47     *
48     * @param $inputJSON
49     * @param $expectedExtractedData
50     * @param $msg
51     */
52    public function test_extractDataFromPayload($inputJSON, $expectedExtractedData, $msg)
53    {
54        $zapierWebhook = new mock\Zapier();
55        $inputArray = json_decode($inputJSON, true);
56
57        $actualExtractedData = $zapierWebhook->extractDataFromPayload($inputArray);
58
59        $this->assertEquals($expectedExtractedData, $actualExtractedData, $msg);
60    }
61}