From 2744fec4a2d5c2eda32d25005aa3bef7c693e642 Mon Sep 17 00:00:00 2001 From: Nami Falhan <10213761+namfal@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:19:01 +0200 Subject: [PATCH 1/4] Added chart validation methods --- src/Charts/Charts.php | 22 +- tests/Charts/validateChartTest.php | 18 ++ tests/SeatsioClientTest.php | 7 +- tests/sampleChartWithErrors.json | 444 +++++++++++++++++++++++++++++ 4 files changed, 489 insertions(+), 2 deletions(-) create mode 100644 tests/Charts/validateChartTest.php create mode 100644 tests/sampleChartWithErrors.json diff --git a/src/Charts/Charts.php b/src/Charts/Charts.php index f0174f3..fd7ced9 100644 --- a/src/Charts/Charts.php +++ b/src/Charts/Charts.php @@ -189,6 +189,26 @@ public function retrievePublishedVersionThumbnail($key) return $res->getBody(); } + /** + * @param $key string + * @return object + */ + public function validatePublishedVersion($key) + { + $res = $this->client->post('/charts/' . $key . '/version/published/actions/validate'); + return \GuzzleHttp\json_decode($res->getBody()); + } + + /** + * @param $key string + * @return object + */ + public function validateDraftVersion($key) + { + $res = $this->client->post('/charts/' . $key . '/version/draft/actions/validate'); + return \GuzzleHttp\json_decode($res->getBody()); + } + /** * @param $key string * @return StreamInterface @@ -287,4 +307,4 @@ private function listParamsToArray($chartListParams) return $chartListParams->toArray(); } -} \ No newline at end of file +} diff --git a/tests/Charts/validateChartTest.php b/tests/Charts/validateChartTest.php new file mode 100644 index 0000000..cbcd2d6 --- /dev/null +++ b/tests/Charts/validateChartTest.php @@ -0,0 +1,18 @@ +createTestChartWithErrors(); + + $validationErrors = $this->seatsioClient->charts->validatePublishedVersion($chartKey); + + $errors = \Functional\map($validationErrors->errors, function($error) { return $error->validatorKey; }); + self::assertEquals(['VALIDATE_UNLABELED_OBJECTS', 'VALIDATE_DUPLICATE_LABELS', 'VALIDATE_OBJECTS_WITHOUT_CATEGORIES'], $errors, '', 0.0, 10, true); + } +} diff --git a/tests/SeatsioClientTest.php b/tests/SeatsioClientTest.php index e53e0b7..d0bedeb 100644 --- a/tests/SeatsioClientTest.php +++ b/tests/SeatsioClientTest.php @@ -55,6 +55,11 @@ protected function createTestChartWithSections() return $this->createTestChartFromFile('sampleChartWithSections.json'); } + protected function createTestChartWithErrors() + { + return $this->createTestChartFromFile('sampleChartWithErrors.json'); + } + private function createTestChartFromFile($file) { $client = new Client(); @@ -89,4 +94,4 @@ private static function uuid() mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); } -} \ No newline at end of file +} diff --git a/tests/sampleChartWithErrors.json b/tests/sampleChartWithErrors.json new file mode 100644 index 0000000..501c1ef --- /dev/null +++ b/tests/sampleChartWithErrors.json @@ -0,0 +1,444 @@ +{ + "name": "Sample chart", + "tablesLabelCounter": 3, + "uuidCounter": 369, + "categories": { + "list": [ + { + "label": "Cat1", + "color": "#87A9CD", + "accessible": false, + "key": 9 + }, + { + "label": "Cat2", + "color": "#5E42ED", + "accessible": false, + "key": 10 + } + ], + "maxCategoryKey": 10 + }, + "version": 17, + "venueType": "ROWS_WITHOUT_SECTIONS", + "showAllButtons": false, + "sectionScaleFactor": 100, + "subChart": { + "height": 95, + "width": 442, + "tables": [], + "texts": [], + "rows": [ + { + "label": "A", + "seatLabeling": { + "algoName": "SimpleNumbers", + "startAtIndex": 0, + "isInverted": false + }, + "objectLabeling": { + "algoName": "SimpleLettersUppercase", + "prefix": "", + "startAtIndex": 0 + }, + "seats": [ + { + "x": 151.94, + "y": 9, + "label": "1", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid288" + }, + { + "x": 171.94, + "y": 9, + "label": "1", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid289" + }, + { + "x": 191.94, + "y": 9, + "label": "?", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid290" + }, + { + "x": 211.94, + "y": 9, + "label": "4", + "uuid": "uuid291" + }, + { + "x": 231.94, + "y": 9, + "label": "5", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid292" + }, + { + "x": 251.94, + "y": 9, + "label": "6", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid293" + }, + { + "x": 271.94, + "y": 9, + "label": "7", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid294" + }, + { + "x": 291.94, + "y": 9, + "label": "8", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid295" + } + ], + "curve": 0, + "chairSpacing": 4, + "objectType": "row", + "uuid": "uuid297" + }, + { + "label": "B", + "seatLabeling": { + "algoName": "SimpleNumbers", + "startAtIndex": 0, + "isInverted": false + }, + "objectLabeling": { + "algoName": "SimpleLettersUppercase", + "prefix": "", + "startAtIndex": 0 + }, + "seats": [ + { + "x": 151.94, + "y": 33, + "label": "1", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid298" + }, + { + "x": 171.94, + "y": 33, + "label": "2", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid299" + }, + { + "x": 191.94, + "y": 33, + "label": "3", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid300" + }, + { + "x": 211.94, + "y": 33, + "label": "4", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid301" + }, + { + "x": 231.94, + "y": 33, + "label": "5", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid302" + }, + { + "x": 251.94, + "y": 33, + "label": "6", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid303" + }, + { + "x": 271.94, + "y": 33, + "label": "7", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid304" + }, + { + "x": 291.94, + "y": 33, + "label": "8", + "categoryLabel": "Cat1", + "categoryAccessible": false, + "categoryKey": 9, + "uuid": "uuid305" + } + ], + "curve": 0, + "chairSpacing": 4, + "objectType": "row", + "uuid": "uuid307" + }, + { + "label": "C", + "seatLabeling": { + "algoName": "SimpleNumbers", + "startAtIndex": 0, + "isInverted": false + }, + "objectLabeling": { + "algoName": "SimpleLettersUppercase", + "prefix": "", + "startAtIndex": 0 + }, + "seats": [ + { + "x": 151.94, + "y": 57, + "label": "1", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid308" + }, + { + "x": 171.94, + "y": 57, + "label": "2", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid309" + }, + { + "x": 191.94, + "y": 57, + "label": "3", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid310" + }, + { + "x": 211.94, + "y": 57, + "label": "4", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid311" + }, + { + "x": 231.94, + "y": 57, + "label": "5", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid312" + }, + { + "x": 251.94, + "y": 57, + "label": "6", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid313" + }, + { + "x": 271.94, + "y": 57, + "label": "7", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid314" + }, + { + "x": 291.94, + "y": 57, + "label": "8", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid315" + } + ], + "curve": 0, + "chairSpacing": 4, + "objectType": "row", + "uuid": "uuid317" + }, + { + "label": "D", + "seatLabeling": { + "algoName": "SimpleNumbers", + "startAtIndex": 0, + "isInverted": false + }, + "objectLabeling": { + "algoName": "SimpleLettersUppercase", + "prefix": "", + "startAtIndex": 0 + }, + "seats": [ + { + "x": 151.94, + "y": 81, + "label": "1", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid318" + }, + { + "x": 171.94, + "y": 81, + "label": "2", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid319" + }, + { + "x": 191.94, + "y": 81, + "label": "3", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid320" + }, + { + "x": 211.94, + "y": 81, + "label": "4", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid321" + }, + { + "x": 231.94, + "y": 81, + "label": "5", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid322" + }, + { + "x": 251.94, + "y": 81, + "label": "6", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid323" + }, + { + "x": 271.94, + "y": 81, + "label": "7", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid324" + }, + { + "x": 291.94, + "y": 81, + "label": "8", + "categoryLabel": "Cat2", + "categoryAccessible": false, + "categoryKey": 10, + "uuid": "uuid325" + } + ], + "curve": 0, + "chairSpacing": 4, + "objectType": "row", + "uuid": "uuid327" + } + ], + "shapes": [], + "booths": [], + "generalAdmissionAreas": [ + { + "categoryLabel": "Cat1", + "categoryKey": 9, + "capacity": 100, + "label": "GA1", + "labelSize": 24, + "labelShown": true, + "labelHorizontalOffset": 0, + "labelVerticalOffset": 0, + "objectType": "generalAdmission", + "uuid": "uuid368", + "type": "circle", + "center": { + "x": 53.22, + "y": 48.89 + }, + "rotationAngle": 0, + "radius1": 52.222222222222626, + "radius2": 45.55555555555566 + }, + { + "categoryLabel": "Cat2", + "categoryKey": 10, + "capacity": 100, + "label": "34", + "labelSize": 24, + "labelShown": true, + "labelHorizontalOffset": 0, + "labelVerticalOffset": 0, + "objectType": "generalAdmission", + "uuid": "uuid369", + "type": "circle", + "center": { + "x": 389.22, + "y": 48.89 + }, + "rotationAngle": 0, + "radius1": 52.222222222222626, + "radius2": 45.55555555555566 + } + ], + "sections": [], + "snapOffset": { + "x": 0.06, + "y": 3 + } + } +} From 7a8d78a9d08cdd220ca803d7a74ec6e21e0ccf33 Mon Sep 17 00:00:00 2001 From: Nami Falhan <10213761+namfal@users.noreply.github.com> Date: Tue, 16 Apr 2019 15:40:35 +0200 Subject: [PATCH 2/4] updated the test to match the new response object --- tests/Charts/validateChartTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Charts/validateChartTest.php b/tests/Charts/validateChartTest.php index cbcd2d6..3af760a 100644 --- a/tests/Charts/validateChartTest.php +++ b/tests/Charts/validateChartTest.php @@ -10,9 +10,9 @@ public function testValidatePublishedVersion() { $chartKey = $this->createTestChartWithErrors(); - $validationErrors = $this->seatsioClient->charts->validatePublishedVersion($chartKey); + $validationRes = $this->seatsioClient->charts->validatePublishedVersion($chartKey); - $errors = \Functional\map($validationErrors->errors, function($error) { return $error->validatorKey; }); - self::assertEquals(['VALIDATE_UNLABELED_OBJECTS', 'VALIDATE_DUPLICATE_LABELS', 'VALIDATE_OBJECTS_WITHOUT_CATEGORIES'], $errors, '', 0.0, 10, true); + self::assertEmpty($validationRes->warnings); + self::assertEquals(['VALIDATE_UNLABELED_OBJECTS', 'VALIDATE_DUPLICATE_LABELS', 'VALIDATE_OBJECTS_WITHOUT_CATEGORIES'], $validationRes->errors, '', 0.0, 10, true); } } From 4843af1d124599a575899e5b81027fcf72273576 Mon Sep 17 00:00:00 2001 From: Nami Falhan <10213761+namfal@users.noreply.github.com> Date: Wed, 17 Apr 2019 13:52:18 +0200 Subject: [PATCH 3/4] added updateSetting method to accounts --- src/Accounts/Accounts.php | 14 +++++++++++- src/Accounts/ChartValidationSettings.php | 12 +++++++++- tests/Accounts/RetrieveMyAccountTest.php | 2 ++ .../UpdateChartValidationSettingsTest.php | 22 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/Accounts/UpdateChartValidationSettingsTest.php diff --git a/src/Accounts/Accounts.php b/src/Accounts/Accounts.php index 4aca2f5..72ab7ae 100644 --- a/src/Accounts/Accounts.php +++ b/src/Accounts/Accounts.php @@ -28,4 +28,16 @@ public function retrieveMyAccount() return \GuzzleHttp\json_decode($res->getBody()); } -} \ No newline at end of file + /** + * @param $key string + * @param $value string + * @return void + */ + public function updateSetting ($key, $value) { + $request = new \stdClass(); + $request->key = $key; + $request->value = $value; + $this->client->post('/accounts/me/settings', ['json' => $request]); + } + +} diff --git a/src/Accounts/ChartValidationSettings.php b/src/Accounts/ChartValidationSettings.php index e76b038..898c90f 100644 --- a/src/Accounts/ChartValidationSettings.php +++ b/src/Accounts/ChartValidationSettings.php @@ -19,4 +19,14 @@ class ChartValidationSettings */ public $VALIDATE_UNLABELED_OBJECTS; -} \ No newline at end of file + /** + * @var string + */ + public $VALIDATE_FOCAL_POINT; + + /** + * @var string + */ + public $VALIDATE_OBJECT_TYPES_PER_CATEGORY; + +} diff --git a/tests/Accounts/RetrieveMyAccountTest.php b/tests/Accounts/RetrieveMyAccountTest.php index 5accf30..9195fad 100644 --- a/tests/Accounts/RetrieveMyAccountTest.php +++ b/tests/Accounts/RetrieveMyAccountTest.php @@ -21,5 +21,7 @@ public function test() self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_DUPLICATE_LABELS); self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_OBJECTS_WITHOUT_CATEGORIES); self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_UNLABELED_OBJECTS); + self::assertEquals("OFF", $account->settings->chartValidation->VALIDATE_FOCAL_POINT); + self::assertEquals("OFF", $account->settings->chartValidation->VALIDATE_OBJECT_TYPES_PER_CATEGORY); } } diff --git a/tests/Accounts/UpdateChartValidationSettingsTest.php b/tests/Accounts/UpdateChartValidationSettingsTest.php new file mode 100644 index 0000000..49ad3f6 --- /dev/null +++ b/tests/Accounts/UpdateChartValidationSettingsTest.php @@ -0,0 +1,22 @@ +seatsioClient->accounts->updateSetting('VALIDATE_DUPLICATE_LABELS', 'WARNING'); + $this->seatsioClient->accounts->updateSetting('VALIDATE_OBJECT_TYPES_PER_CATEGORY', 'ERROR'); + + $account = $this->seatsioClient->accounts->retrieveMyAccount(); + self::assertEquals("WARNING", $account->settings->chartValidation->VALIDATE_DUPLICATE_LABELS); + self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_OBJECTS_WITHOUT_CATEGORIES); + self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_UNLABELED_OBJECTS); + self::assertEquals("OFF", $account->settings->chartValidation->VALIDATE_FOCAL_POINT); + self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_OBJECT_TYPES_PER_CATEGORY); + } +} From 14aa99be4c6458786af36dc48a8aea4fac752da5 Mon Sep 17 00:00:00 2001 From: Nami Falhan <10213761+namfal@users.noreply.github.com> Date: Wed, 17 Apr 2019 13:58:37 +0200 Subject: [PATCH 4/4] added a test for validateDraftVersion --- tests/Charts/validateChartTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Charts/validateChartTest.php b/tests/Charts/validateChartTest.php index 3af760a..df0eae9 100644 --- a/tests/Charts/validateChartTest.php +++ b/tests/Charts/validateChartTest.php @@ -15,4 +15,21 @@ public function testValidatePublishedVersion() self::assertEmpty($validationRes->warnings); self::assertEquals(['VALIDATE_UNLABELED_OBJECTS', 'VALIDATE_DUPLICATE_LABELS', 'VALIDATE_OBJECTS_WITHOUT_CATEGORIES'], $validationRes->errors, '', 0.0, 10, true); } + + public function testValidateDraftVersion() { + $this->seatsioClient->accounts->updateSetting('VALIDATE_DUPLICATE_LABELS', 'WARNING'); + $this->seatsioClient->accounts->updateSetting('VALIDATE_UNLABELED_OBJECTS', 'WARNING'); + $this->seatsioClient->accounts->updateSetting('VALIDATE_OBJECTS_WITHOUT_CATEGORIES', 'WARNING'); + $this->seatsioClient->accounts->updateSetting('VALIDATE_FOCAL_POINT', 'WARNING'); + $this->seatsioClient->accounts->updateSetting('VALIDATE_OBJECT_TYPES_PER_CATEGORY', 'WARNING'); + + $chartKey = $this->createTestChartWithErrors(); + $this->seatsioClient->events->create($chartKey); + $this->seatsioClient->charts->update($chartKey, 'New name'); + + $validationRes = $this->seatsioClient->charts->validateDraftVersion($chartKey); + + self::assertEmpty($validationRes->errors); + self::assertEquals(['VALIDATE_UNLABELED_OBJECTS', 'VALIDATE_DUPLICATE_LABELS', 'VALIDATE_OBJECTS_WITHOUT_CATEGORIES', 'VALIDATE_FOCAL_POINT', 'VALIDATE_OBJECT_TYPES_PER_CATEGORY'], $validationRes->warnings, '', 0.0, 10, true); + } }