Skip to content

Commit

Permalink
pkp#10292 resolved all but one TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Nov 15, 2024
1 parent 40b78c8 commit dc5f31b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 60 deletions.
31 changes: 1 addition & 30 deletions classes/controlledVocab/ControlledVocab.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,6 @@ public static function hasDefinedVocabSymbolic(string $vocab): bool
return in_array($vocab, static::getDefinedVocabSymbolic());
}

// TODO: Investigate if this is necessary anymore
/**
* Get the locale field names for this controlled vocab
*/
public function getLocaleFieldNames(): array
{
if (!$this->symbolic) {
return [];
}

return static::hasDefinedVocabSymbolic($this->symbolic)
? [$this->symbolic]
: [];
}

// TODO: Investigate if this is necessary anymore
/**
* Compatibility function for including note IDs in grids.
*
* @deprecated 3.5.0 Use $model->id instead. Can be removed once the DataObject pattern is removed.
*/
public function getId(): int
{
return $this->id;
}

/**
* Get all controlled vocab entries for this controlled vocab
*/
Expand Down Expand Up @@ -216,10 +190,7 @@ public function enumerate(?string $settingName = null): array
'e.controlled_vocab_entry_id',
DB::raw(
'COALESCE (l.setting_value, p.setting_value, n.setting_value) as setting_value'
),
DB::raw(
'COALESCE (l.setting_type, p.setting_type, n.setting_type) as setting_type'
),
)
])
->where('e.controlled_vocab_id', $this->id)
->orderBy('e.seq')
Expand Down
8 changes: 4 additions & 4 deletions classes/controlledVocab/ControlledVocabEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ControlledVocabEntry extends Model
public $timestamps = false;

/**
* @inheritDoc
* @copydoc \PKP\core\traits\ModelWithSettings::getSettingsTable
*/
public function getSettingsTable(): string
{
Expand All @@ -72,15 +72,15 @@ protected function casts(): array
}

/**
* @inheritDoc
* @copydoc \PKP\core\traits\ModelWithSettings::getSchemaName
*/
public static function getSchemaName(): ?string
{
return null;
}

/**
* @inheritDoc
* @copydoc \PKP\core\traits\ModelWithSettings::getMultilingualProps
*/
public function getMultilingualProps(): array
{
Expand All @@ -92,7 +92,7 @@ public function getMultilingualProps(): array
}

/**
* @inheritDoc
* @copydoc \PKP\core\traits\ModelWithSettings::getSettings
*/
public function getSettings(): array
{
Expand Down
3 changes: 1 addition & 2 deletions classes/metadata/MetadataProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ public function isValid($value, $locale = null)
fn ($query) => $query->withSymbolic($symbolic)->withAssoc($assocType, $assocId)
)
->withLocale($locale)
// TODO: Investigate if this need to be 'name' or $symbolic for settingName
->withSetting('name', $value)
->withSetting($symbolic, $value)
->first();

if (!is_null($entry)) {
Expand Down
1 change: 0 additions & 1 deletion classes/user/interest/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function setInterestsForUser(User $user, string|array|null $interests = n
])->id
);

// TODO: Investigate the impact of applied patch from https://github.com/pkp/pkp-lib/issues/10423
collect($currentInterests->pluck('id'))
->merge($newInterestIds)
->each(fn ($interestId) => UserInterest::create([
Expand Down
11 changes: 0 additions & 11 deletions classes/user/interest/UserInterest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ public function controlledVocabEntries(): HasMany
return $this->hasMany(ControlledVocabEntry::class, 'controlled_vocab_entry_id', 'controlled_vocab_entry_id');
}

// TODO: Investigate if this is necessary anymore
/**
* Compatibility function for including note IDs in grids.
*
* @deprecated 3.5.0 Use $model->id instead. Can be removed once the DataObject pattern is removed.
*/
public function getId(): int
{
return $this->id;
}

/**
* Scope a query to only include interests with a specific user id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function testIsValid()
$assocId
);

// TODO : Investigate if possible to insert dummy symbolic in `controlled_vocab_entry_settings` table
$controlledVocabEntryId1 = ControlledVocabEntry::create([
'controlledVocabId' => $testControlledVocab->id,
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD => [
Expand Down Expand Up @@ -80,7 +79,7 @@ public function testIsValid()
$form->setData('testData', 3);
self::assertFalse($validator->isValid());

// Delete the test entries
// Delete the test vocab along with entries
ControlledVocab::find($testControlledVocab->id)->delete();
}
}
15 changes: 7 additions & 8 deletions tests/classes/metadata/MetadataPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

use APP\facades\Repo;
use InvalidArgumentException;
use PKP\controlledVocab\ControlledVocab;
use PKP\controlledVocab\ControlledVocabEntry;
use PKP\metadata\MetadataDescription;
use PKP\metadata\MetadataProperty;
use PKP\tests\PKPTestCase;
use stdClass;
use PHPUnit\Framework\Attributes\CoversClass;
use PKP\user\interest\UserInterest;

#[CoversClass(MetadataProperty::class)]
class MetadataPropertyTest extends PKPTestCase
Expand Down Expand Up @@ -148,32 +148,31 @@ public function testValidateControlledVocabulary()
{
// Build a test vocabulary. (Assoc type and id are 0 to simulate a site-wide vocabulary).
$vocab = Repo::controlledVocab()->build(
UserInterest::CONTROLLED_VOCAB_INTEREST, 0, 0
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, 0, 0
);

// TODO : Investigate if possible to insert dummy symbolic in `controlled_vocab_entry_settings` table
$controlledVocabEntry = ControlledVocabEntry::create([
'controlledVocabId' => $vocab->id,
UserInterest::CONTROLLED_VOCAB_INTEREST => [
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD => [
'en' => 'testEntry',
],
]);

$metadataProperty = new MetadataProperty(
'testElement',
[],
[MetadataProperty::METADATA_PROPERTY_TYPE_VOCABULARY => UserInterest::CONTROLLED_VOCAB_INTEREST]
[MetadataProperty::METADATA_PROPERTY_TYPE_VOCABULARY => ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD]
);

// This validator checks numeric values
self::assertEquals(
[MetadataProperty::METADATA_PROPERTY_TYPE_VOCABULARY => UserInterest::CONTROLLED_VOCAB_INTEREST],
[MetadataProperty::METADATA_PROPERTY_TYPE_VOCABULARY => ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD],
$metadataProperty->isValid($controlledVocabEntry->id)
);
self::assertFalse($metadataProperty->isValid($controlledVocabEntry->id + 1));

// Delete the test vocabulary entry
$controlledVocabEntry->delete();
// Delete the test vocab along with entry
$vocab->delete();

}

Expand Down
3 changes: 1 addition & 2 deletions tests/classes/validation/ValidatorControlledVocabTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function testValidatorControlledVocab()
$assocId
);

// TODO : Investigate if possible to insert dummy symbolic in `controlled_vocab_entry_settings` table
$controlledVocabEntryId1 = ControlledVocabEntry::create([
'controlledVocabId' => $testControlledVocab->id,
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD => [
Expand All @@ -64,7 +63,7 @@ public function testValidatorControlledVocab()
self::assertTrue($validator->isValid($controlledVocabEntryId2));
self::assertFalse($validator->isValid(3));

// Delete the test entried
// Delete the test vocab along with entries
ControlledVocab::find($testControlledVocab->id)->delete();
}
}

0 comments on commit dc5f31b

Please sign in to comment.