Skip to content

Commit

Permalink
chore(test): Add tests for @field format values
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Jul 29, 2023
1 parent 261ac55 commit 6efe9b7
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions tests/Unit/AcfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,71 @@

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item')['key']; ?>");
expect($compiled)->toEqual("<?php echo get_field('item', null, true)['key']; ?>");
});

it('compiles correctly with post ID', function () {
$directive = "@field('item', 1)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', 1); ?>");
expect($compiled)->toEqual("<?php echo get_field('item', 1, true); ?>");
});

it('compiles correctly with key and post ID', function () {
$directive = "@field('item', 'key', 1)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', 1)['key']; ?>");
expect($compiled)->toEqual("<?php echo get_field('item', 1, true)['key']; ?>");
});

it('compiles correctly with post ID and formatting', function () {
$directive = "@field('item', 1, false)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', 1, false); ?>");
});

it('compiles correctly with key, post ID and formatting', function () {
$directive = "@field('item', 'key', 1, false)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', 1, false)['key']; ?>");
});

it('compiles correctly with post object', function () {
$directive = "@field('item', \$post->ID)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', \$post->ID); ?>");
expect($compiled)->toEqual("<?php echo get_field('item', \$post->ID, true); ?>");
});

it('compiles correctly with key and post object', function () {
$directive = "@field('item', 'key', \$post->ID)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', \$post->ID)['key']; ?>");
expect($compiled)->toEqual("<?php echo get_field('item', \$post->ID, true)['key']; ?>");
});

it('compiles correctly with post object and formatting', function () {
$directive = "@field('item', \$post->ID, false)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', \$post->ID, false); ?>");
});

it('compiles correctly with key, post object and formatting', function () {
$directive = "@field('item', 'key', \$post->ID, false)";

$compiled = $this->compile($directive);

expect($compiled)->toEqual("<?php echo get_field('item', \$post->ID, false)['key']; ?>");
});
});

Expand Down

0 comments on commit 6efe9b7

Please sign in to comment.