-
Notifications
You must be signed in to change notification settings - Fork 993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New feature #14782: Possibility to override single translations by database #2213
Conversation
…tabase Dev: working solution for user with DB access, no GUI
I am very hesitant to have this as a core feature, because I am afraid that this will diminish contributions to translate.limesurvey.org, because why correct a wrong translation (and contribute back) if you can just quickly fix it in your own instance, only. |
See your comment here : https://bugs.limesurvey.org/view.php?id=17163
seems i made an error in bug report, i update the title |
@olleharstedt if it('s OK to be included in core, can you help me on the DB update issue ? I update myself (from 479) : it's OK … |
Dev: merge issue with other DB update
OK, seems i have it : 6a87152 |
Then , for information :. To have own translation, not translated currently. With DB (this commit)
With po (no commit)
|
The issue in «Compare upgrade and fresh install» is not related to MYISAM against InnoDB ? Since only InnoDB accept foreignKey. I can not force foreign key and create model, but since we don't use this model … @olleharstedt an idea ? |
Hm |
I'd like a unit-test of any kind to test this feature, too. If Carsten is willing to merge it, that is. |
DB update allowed ? I'm think of a system :
Allowed ? Else : need to replace LSMessageSource->loadMessages function. |
Dev: remove uneeded update of db version
Dev: fixed, not updatabale by config
Dev: fixed, not updatabale by config
…rvey-Shnoulle into develop_translation # Conflicts: # application/core/LSMessageSource.php
If you mock getDbConnection, you won't need to touch the db at all. I can show you how. Alternatively, you can do anything in the db as long as you restore the previous state. The problem is different tests affecting each other, as we've seen before. |
function is now this :
I need to mock->createCommand() and queryAll() right. It's already exist in another test ? More quick to copy/paste ;) |
Something like that. But what you need to mock differs depending on which function (unit) you test. Let me check... |
Hm, maybe it's easier to mock getMessagesFromDb() instead. And then test getMessagesFromDb() with real db data (which is deleted after test is run, so called fixture). |
Mock docs for PHPUnit: https://phpunit.readthedocs.io/en/9.5/test-doubles.html?highlight=mock I don't think we're using version 9.5 tho, you'd have to double check. |
public function testLsMessageSource()
{
$messageSource = new LSMessageSource();
$messageSource->basePath = YII_PATH . '/../locale/';
$ref = new ReflectionClass('LSMessageSource');
$met = $ref->getMethod('loadMessages');
$met->setAccessible(true);
$messages = $met->invokeArgs($messageSource, ['', 'en']);
$this->assertNotEmpty($messages);
} One example of calling loadMessages (even tho it's protected) and test the result. |
Interest ? Testing a 2 functions via phpunit … I can add if you want , but didn't see the interest. The current test check gT function. |
Well, optimally, you're supposed to test each possible path in the function - with cache, without cache, with db, without db, etc. That will be hard only using gT(). Just using gT(), you might not get 100% or 50% coverage. You're also supposed to do negative tests - testing that the function fails correctly. |
Hm, on another note, I'm not able to repeat your test multiple times locally. It works once, but then I get this:
Related to random string? |
And with your test : what is the coverage ? What do you test ? I can not create test for all previous feature each time : it's not part of the coverage… i have to test only the new feature. What is the coverage here : «Possibility to override single translation by db» OK to add caching (translation not updated with DB update only), but don't understand witout db … |
Related to caching … cache for 1 hour by default. With caching : we don't get the new translation : we return the cache. |
OK, so I need to disable caching? You see one benefit at once with my approach: just set |
I already think we need to check if caching work . Best seems to
The lack is update core string , then if i can add a translation for Submit : it's OK. But in this condition : if user have updated his own language : didn't work … I create all of this |
Maaaybe. Caching is part of Yii, and we should assume it's working (Yii has its own test suite). |
???? |
Oh, I'm contradicting myself. 🤦 |
Like : we should assume po/mo file work (or not ?) The «we should assume» the default way to get translation use LSMessageSource can not be assumed. gT whole system can be updated too easily … |
I think, assuming po/mo files are correct, is the same as mocking the access to mo/po files in the unit test. Which is one way to do it. But it's OK to just access those files, too. |
Again : mocking a 2 function call in same class … i don't really understand the point here … I don't understand what you want … |
Any idea to mock loadMessagesFromDb here ? Because without this : i didn't test this feature … |
Check if po translation work + check if file cache (by default) work + DB new source + DB replace source. I don't see what i can do now … |
Great! Is it now possible to run the test multiple times locally? |
I add a resetCache function. LimeSurvey/tests/TestBaseClass.php Line 40 in 30d8f21
I add https://github.com/LimeSurvey/LimeSurvey/pull/2213/files#diff-3cc131b4d608fd992d775790fbc8c5f5b04a49347a85a54390af3291c6b504e0R44 |
OK, gonna test locally again... |
|
Works multiple times for me locally 👍 🌟 |
…into develop_translation
Dev: working solution for user with DB access, no GUI