Skip to content
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

pkp/pkp-lib#10292 Controlled Vocab DAO to Eloquent Model #10324

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

touhidurabir
Copy link
Member

for #10292

Comment on lines 30 to 33
public function scopeGetLocaleFieldNames(Builder $query): array
{
return ['submissionAgency'];
}
Copy link
Member Author

@touhidurabir touhidurabir Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if these methods have any use (here is other similar class to get the locale field name)

Copy link
Member

@asmecher asmecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've added some early review comments!

classes/controlledVocab/ControlledVocab.php Outdated Show resolved Hide resolved
classes/controlledVocab/ControlledVocab.php Outdated Show resolved Hide resolved
classes/controlledVocab/Repository.php Outdated Show resolved Hide resolved
classes/publication/DAO.php Outdated Show resolved Hide resolved
classes/submission/SubmissionAgencyVocab.php Outdated Show resolved Hide resolved
classes/submission/SubmissionAgencyVocab.php Outdated Show resolved Hide resolved
classes/user/UserInterest.php Outdated Show resolved Hide resolved
@touhidurabir touhidurabir force-pushed the i10292_main branch 3 times, most recently from d68630a to 3e91b7a Compare October 8, 2024 03:58
@touhidurabir touhidurabir marked this pull request as ready for review October 8, 2024 11:58
fn ($query) => $query->withSymbolic($symbolic)->withAssoc($assocType, $assocId)
)
->withLocale($locale)
->withSetting($symbolic, $value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here previously setting name passed as name but is that correct as for controlled vocabs we have specific settings ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my comment above -- setting names and controlled vocab symbolic names are different things, and I think this PR mixes them accidentally.

return $controlledVocabDao->enumerate($this->getId(), $settingName);
}
}
public function enumerate(?string $settingName = null): array
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here $settingName previously have default value to name but that seems not right as for controlled vocab, we have a specific sets to settings only . Or I am missing something ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setting name (the setting_name column in a _settings table) is not the same as the controlled vocab symbolic name, which is the symbolic column in controlled_vocabs. Be careful to keep the two distinct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@touhidurabir, I think this comment still applies; you're mixing the symbolic name of the controlled vocabulary with the setting name, and they're different things.

'controlledVocabEntryId' => $interestId,
]));

Repo::controlledVocab()->resequence($controlledVocab->id);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to resequence the vocabs for user interest, don't see any benefit or usage of it ?

Comment on lines +36 to +40
$assocId = (DB::table("publications")
->select("publication_id as id")
->orderBy("publication_id", "desc")
->first()
->id ?? 0) + 100;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than setting a fixed value like 333, it's better to build one based on what we have in DB and add a const value (like here 100) to just to be safe .

Comment on lines 42 to 83
$testControlledVocab = Repo::controlledVocab()->build(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
Application::ASSOC_TYPE_CITATION,
$assocId
);

// Mock the ControlledVocabDAO
$mockControlledVocabDao = $this->getMockBuilder(ControlledVocabDAO::class)
->onlyMethods(['getBySymbolic'])
->getMock();
$controlledVocabEntryId1 = ControlledVocabEntry::create([
'controlledVocabId' => $testControlledVocab->id,
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD => [
'en' => 'testEntry',
],
])->id;

// Set up the mock getBySymbolic() method
$mockControlledVocabDao->expects($this->any())
->method('getBySymbolic')
->with('testVocab', Application::ASSOC_TYPE_CITATION, 333)
->willReturn($mockControlledVocab);

DAORegistry::registerDAO('ControlledVocabDAO', $mockControlledVocabDao);
$controlledVocabEntryId2 = ControlledVocabEntry::create([
'controlledVocabId' => $testControlledVocab->id,
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD => [
'en' => 'testEntry',
],
])->id;

// Instantiate validator
$validator = new \PKP\form\validation\FormValidatorControlledVocab($form, 'testData', FormValidator::FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key', 'testVocab', Application::ASSOC_TYPE_CITATION, 333);
$validator = new FormValidatorControlledVocab(
$form,
'testData',
FormValidator::FORM_VALIDATOR_REQUIRED_VALUE,
'some.message.key',
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
Application::ASSOC_TYPE_CITATION,
$assocId
);

$form->setData('testData', '1');
$form->setData('testData', $controlledVocabEntryId1);
self::assertTrue($validator->isValid());

$form->setData('testData', '2');
$form->setData('testData', $controlledVocabEntryId2);
self::assertTrue($validator->isValid());

$form->setData('testData', '3');
$form->setData('testData', 3);
self::assertFalse($validator->isValid());

// Delete the test vocab along with entries
ControlledVocab::find($testControlledVocab->id)->delete();
Copy link
Member Author

@touhidurabir touhidurabir Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With implementation of setting table based eloquent, we can not add any arbitrary setting data so only options seems to create data and delete at the end of test . Another option can be is to backup/restore specific tables or full DB but that make the test time high. For this and other similar tests t below .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants