From 69c3410e03ad3034051fa98295400c4b8917f943 Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Wed, 21 Dec 2016 01:09:35 -0300 Subject: [PATCH] Guillermo - add test supported languages [skip ci] --- server/controllers/system/get-settings.php | 4 +- server/controllers/ticket/create.php | 4 ++ server/models/Language.php | 19 ++++++++++ server/models/Ticket.php | 3 +- tests/scripts.rb | 1 + tests/staff/get-all-tickets.rb | 1 + tests/system/delete-department.rb | 3 ++ tests/system/edit-settings.rb | 43 +++++++++++++++++++++- tests/system/get-settings.rb | 11 ++++++ tests/ticket/create.rb | 10 +++++ tests/ticket/events.rb | 1 + tests/ticket/get.rb | 1 + tests/user/get.rb | 2 + 13 files changed, 100 insertions(+), 3 deletions(-) diff --git a/server/controllers/system/get-settings.php b/server/controllers/system/get-settings.php index e0e555ab..7a5b07cf 100644 --- a/server/controllers/system/get-settings.php +++ b/server/controllers/system/get-settings.php @@ -19,7 +19,9 @@ class GetSettingsController extends Controller { 'layout' => Setting::getSetting('layout')->getValue(), 'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(), 'max-size' => Setting::getSetting('max-size')->getValue(), - 'departments' => Department::getDepartmentNames() + 'departments' => Department::getDepartmentNames(), + 'supportedLanguages' => Language::getSupportedLanguages(), + 'allowedLanguages' => Language::getAllowedLanguages() ]); } } \ No newline at end of file diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index 2d9294ba..501b8896 100644 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -26,6 +26,10 @@ class CreateController extends Controller { 'departmentId' => [ 'validation' => DataValidator::dataStoreId('department'), 'error' => ERRORS::INVALID_DEPARTMENT + ], + 'language' => [ + 'validation' => DataValidator::in(Language::getSupportedLanguages()), + 'error' => ERRORS::INVALID_LANGUAGE ] ] ]; diff --git a/server/models/Language.php b/server/models/Language.php index fcd1b9b1..c070e5ab 100644 --- a/server/models/Language.php +++ b/server/models/Language.php @@ -24,5 +24,24 @@ class Language extends DataStore { ]; } + public static function getSupportedLanguages() { + $array = []; + foreach(Language::LANGUAGES as $languageCode) { + if (self::getDataStore($languageCode,'code')->supported) { + array_push($array, $languageCode); + } + } + return $array; + } + public static function getAllowedLanguages() { + $array = []; + foreach(Language::LANGUAGES as $languageCode) { + if (self::getDataStore($languageCode,'code')->allowed) { + array_push($array, $languageCode); + } + } + return $array; + } + } \ No newline at end of file diff --git a/server/models/Ticket.php b/server/models/Ticket.php index 911b2f8f..315434e8 100644 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -19,7 +19,8 @@ class Ticket extends DataStore { 'author', 'owner', 'ownTicketeventList', - 'unreadStaff' + 'unreadStaff', + 'language' ); } diff --git a/tests/scripts.rb b/tests/scripts.rb index 6b91569e..3eb973e0 100644 --- a/tests/scripts.rb +++ b/tests/scripts.rb @@ -32,6 +32,7 @@ class Scripts title: 'Winter is coming', content: 'The north remembers', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) diff --git a/tests/staff/get-all-tickets.rb b/tests/staff/get-all-tickets.rb index fdedc865..7d3e9c03 100644 --- a/tests/staff/get-all-tickets.rb +++ b/tests/staff/get-all-tickets.rb @@ -7,6 +7,7 @@ describe 'Retrieve all tickets' do title: title, content: 'The north remembers', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) diff --git a/tests/system/delete-department.rb b/tests/system/delete-department.rb index 2286540f..ee9ded50 100644 --- a/tests/system/delete-department.rb +++ b/tests/system/delete-department.rb @@ -7,6 +7,7 @@ describe 'system/delete-department' do title: 'Transferible ticket 1', content: 'The north remembers', departmentId: 4, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -14,6 +15,7 @@ describe 'system/delete-department' do title: 'Transferible ticket 2', content: 'The north remembers', departmentId: 4, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -21,6 +23,7 @@ describe 'system/delete-department' do title: 'Transferible ticket 3', content: 'The north remembers', departmentId: 4, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) diff --git a/tests/system/edit-settings.rb b/tests/system/edit-settings.rb index beb96aa1..75373456 100644 --- a/tests/system/edit-settings.rb +++ b/tests/system/edit-settings.rb @@ -18,7 +18,6 @@ describe'system/edit-settings' do "smtp-user" => 'admin', "smtp-pass" => 'pass1234', }) - puts result['message'] (result['status']).should.equal('success') @@ -52,6 +51,48 @@ describe'system/edit-settings' do row = $database.getRow('setting', 'smtp-pass', 'name') (row['value']).should.equal('pass1234') + request('/user/logout') + end + it 'should change allowed and supported languages' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + result= request('/system/edit-settings', { + "csrf_userid" => $csrf_userid, + "csrf_token" => $csrf_token, + "supportedLanguages" => '["en", "pr", "jp", "ru"]', + "allowedLanguages" => '["en","pr", "jp", "ru", "de"]' + }) + + (result['status']).should.equal('success') + + row = $database.getRow('language', 'en', 'code') + (row['supported']).should.equal('1') + + row = $database.getRow('language', 'pr', 'code') + (row['supported']).should.equal('1') + + row = $database.getRow('language', 'jp', 'code') + (row['supported']).should.equal('1') + + row = $database.getRow('language', 'ru', 'code') + (row['supported']).should.equal('1') + + row = $database.getRow('language', 'en', 'code') + (row['allowed']).should.equal('1') + + row = $database.getRow('language', 'pr', 'code') + (row['allowed']).should.equal('1') + + row = $database.getRow('language', 'jp', 'code') + (row['allowed']).should.equal('1') + + row = $database.getRow('language', 'ru', 'code') + (row['allowed']).should.equal('1') + + row = $database.getRow('language', 'de', 'code') + (row['allowed']).should.equal('1') + request('/user/logout') end end \ No newline at end of file diff --git a/tests/system/get-settings.rb b/tests/system/get-settings.rb index 2368c73f..4a4b6a0a 100644 --- a/tests/system/get-settings.rb +++ b/tests/system/get-settings.rb @@ -7,5 +7,16 @@ describe '/system/get-settings' do (result['data']['departments'][0]['name']).should.equal('Tech Support') (result['data']['departments'][1]['name']).should.equal('Suggestions') (result['data']['departments'][2]['name']).should.equal('Sales and Subscriptions') + (result['data']['allowedLanguages'][0]).should.equal('en') + (result['data']['allowedLanguages'][1]).should.equal('es') + (result['data']['allowedLanguages'][2]).should.equal('de') + (result['data']['allowedLanguages'][3]).should.equal('fr') + (result['data']['allowedLanguages'][4]).should.equal('pr') + (result['data']['allowedLanguages'][5]).should.equal('jp') + (result['data']['allowedLanguages'][6]).should.equal('ru') + (result['data']['allowedLanguages'][7]).should.equal('cn') + (result['data']['allowedLanguages'][8]).should.equal('in') + (result['data']['allowedLanguages'][9]).should.equal('tr') + (result['data']['supportedLanguages'][0]).should.equal('en') end end \ No newline at end of file diff --git a/tests/ticket/create.rb b/tests/ticket/create.rb index abafdc07..5789b53d 100644 --- a/tests/ticket/create.rb +++ b/tests/ticket/create.rb @@ -7,6 +7,7 @@ describe '/ticket/create' do result = request('/ticket/create', { title: 'GG', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: 'INVALID_TOKEN' }) @@ -20,6 +21,7 @@ describe '/ticket/create' do result = request('/ticket/create', { title: 'GG', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -35,6 +37,7 @@ describe '/ticket/create' do result = request('/ticket/create',{ title: long_text, departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -48,6 +51,7 @@ describe '/ticket/create' do title: 'Winter is coming', content: 'Test', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -64,6 +68,7 @@ describe '/ticket/create' do title: 'Winter is coming', content: long_text, departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -78,6 +83,7 @@ describe '/ticket/create' do title: 'Winter is coming', content: 'The north remembers', departmentId: 30, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -92,6 +98,7 @@ describe '/ticket/create' do title: 'Winter is coming', content: 'The north remembers', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -116,6 +123,7 @@ describe '/ticket/create' do title: 'Winter is coming1', content: 'The north remembers', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -123,6 +131,7 @@ describe '/ticket/create' do title: 'Winter is coming2', content: 'The north remembers', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) @@ -130,6 +139,7 @@ describe '/ticket/create' do title: 'Winter is coming3', content: 'The north remembers', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) diff --git a/tests/ticket/events.rb b/tests/ticket/events.rb index 876fef83..be6b71d0 100644 --- a/tests/ticket/events.rb +++ b/tests/ticket/events.rb @@ -8,6 +8,7 @@ describe 'Ticket Events' do title: 'Ticket with many events', content: 'This is a ticket with many events', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) diff --git a/tests/ticket/get.rb b/tests/ticket/get.rb index 29a26545..cb945269 100644 --- a/tests/ticket/get.rb +++ b/tests/ticket/get.rb @@ -11,6 +11,7 @@ describe '/ticket/get/' do title: 'Should we pay?', content: 'A Lannister always pays his debts.', departmentId: 1, + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token }) diff --git a/tests/user/get.rb b/tests/user/get.rb index ef89384e..1ade559e 100644 --- a/tests/user/get.rb +++ b/tests/user/get.rb @@ -7,6 +7,8 @@ describe '/user/get' do title: 'Should we pay?', content: 'A Lannister always pays his debts.', departmentId: 1, + language: 'en', + language: 'en', csrf_userid: $csrf_userid, csrf_token: $csrf_token })