Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 24, 2024
1 parent 1ae764d commit 73cd71c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
6 changes: 4 additions & 2 deletions tests/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ _Tests the saving of cached values, element cache records and element query reco
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record for entry in single sections is not saved.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record with option field data is converted to value.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record with multi options field data is converted to array of values.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record keeps order by if a limit or offset is present.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record does not keep order by if no limit or offset is present.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record keeps limit and offset params.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record keeps order by if a limit param is present.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record keeps order by if an offset param is present.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query record does not keep order by if no limit or offset param is present.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query cache records are saved.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query source records with specific source identifiers are saved.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Element query source records without specific source identifiers are not saved.
Expand Down
32 changes: 27 additions & 5 deletions tests/pest/Feature/GenerateCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,45 @@
->toEqual([1, 2]);
});

test('Element query record keeps order by if a limit or offset is present', function() {
$elementQuery = Entry::find()->orderBy('title')->limit(10)->offset(10);
test('Element query record keeps limit and offset params', function() {
$elementQuery = Entry::find()->limit(10)->offset(10);
Blitz::$plugin->generateCache->addElementQuery($elementQuery);

/** @var ElementQueryRecord $record */
$record = ElementQueryRecord::find()->one();
$params = Json::decodeIfJson($record->params);

expect($params)
->toHaveKey('orderBy')
->and($params)
->toHaveKey('limit')
->and($params)
->toHaveKey('offset');
});

test('Element query record does not keep order by if no limit or offset is present', function() {
test('Element query record keeps order by if a limit param is present', function() {
$elementQuery = Entry::find()->orderBy('title')->limit(10);
Blitz::$plugin->generateCache->addElementQuery($elementQuery);

/** @var ElementQueryRecord $record */
$record = ElementQueryRecord::find()->one();
$params = Json::decodeIfJson($record->params);

expect($params)
->toHaveKey('orderBy');
});

test('Element query record keeps order by if an offset param is present', function() {
$elementQuery = Entry::find()->orderBy('title')->offset(10);
Blitz::$plugin->generateCache->addElementQuery($elementQuery);

/** @var ElementQueryRecord $record */
$record = ElementQueryRecord::find()->one();
$params = Json::decodeIfJson($record->params);

expect($params)
->toHaveKey('orderBy');
});

test('Element query record does not keep order by if no limit or offset param is present', function() {
$elementQuery = Entry::find()->orderBy('title');
Blitz::$plugin->generateCache->addElementQuery($elementQuery);

Expand Down

0 comments on commit 73cd71c

Please sign in to comment.