feat(wpmc S3): ShortcodeDmr::render resolves text by current town

This commit is contained in:
Vladimir Bryzgalov
2026-05-12 20:07:01 +05:00
parent 464d254f1c
commit 0be1a5a08f
3 changed files with 65 additions and 2 deletions
+25
View File
@@ -27,4 +27,29 @@ final class ShortcodeDmrTest extends TestCase
self::assertTrue(true);
}
public function test_render_returns_text_when_row_matches_current_town(): void
{
$_SERVER['REQUEST_URI'] = '/tyumen/';
\Brain\Monkey\Functions\when('get_terms')->justReturn([10 => 'spb', 11 => 'tyumen']);
$term = new \WP_Term();
$term->term_id = 11;
$term->slug = 'tyumen';
\Brain\Monkey\Functions\when('get_term_by')->alias(function ($field, $slug, $tax) use ($term) {
return ($field === 'slug' && $slug === 'tyumen' && $tax === 'town') ? $term : false;
});
\Brain\Monkey\Functions\expect('get_field')
->once()
->with('list_shortcode', 42)
->andReturn([
['town' => 10, 'text' => 'СПб-текст'],
['town' => 11, 'text' => 'Тюмень-текст'],
]);
$result = ShortcodeDmr::render(['id' => 42]);
self::assertSame('Тюмень-текст', $result);
}
}
+3
View File
@@ -15,6 +15,9 @@ abstract class TestCase extends BaseTestCase
parent::setUp();
Monkey\setUp();
Monkey\Functions\stubTranslationFunctions();
Monkey\Functions\when('shortcode_atts')->alias(function (array $defaults, array $atts): array {
return array_merge($defaults, array_intersect_key($atts, $defaults));
});
Helpers::reset_cache();
ShortcodeDmr::reset_cache();
}