test(wpmc S3): ShortcodeDmr::render edge-case coverage
This commit is contained in:
@@ -52,4 +52,57 @@ final class ShortcodeDmrTest extends TestCase
|
|||||||
|
|
||||||
self::assertSame('Тюмень-текст', $result);
|
self::assertSame('Тюмень-текст', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_render_returns_empty_when_id_is_zero(): void
|
||||||
|
{
|
||||||
|
\Brain\Monkey\Functions\expect('get_field')->never();
|
||||||
|
self::assertSame('', ShortcodeDmr::render(['id' => 0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_render_returns_empty_when_current_town_is_null(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/no-matching-segment/';
|
||||||
|
\Brain\Monkey\Functions\when('get_terms')->justReturn([10 => 'spb']);
|
||||||
|
\Brain\Monkey\Functions\expect('get_field')->never();
|
||||||
|
|
||||||
|
self::assertSame('', ShortcodeDmr::render(['id' => 42]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_render_returns_empty_when_term_lookup_fails(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/tyumen/';
|
||||||
|
\Brain\Monkey\Functions\when('get_terms')->justReturn([11 => 'tyumen']);
|
||||||
|
\Brain\Monkey\Functions\when('get_term_by')->justReturn(false);
|
||||||
|
\Brain\Monkey\Functions\expect('get_field')->never();
|
||||||
|
|
||||||
|
self::assertSame('', ShortcodeDmr::render(['id' => 42]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_render_returns_empty_when_rows_are_empty(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/tyumen/';
|
||||||
|
\Brain\Monkey\Functions\when('get_terms')->justReturn([11 => 'tyumen']);
|
||||||
|
$term = new \WP_Term();
|
||||||
|
$term->term_id = 11;
|
||||||
|
$term->slug = 'tyumen';
|
||||||
|
\Brain\Monkey\Functions\when('get_term_by')->justReturn($term);
|
||||||
|
\Brain\Monkey\Functions\expect('get_field')->once()->andReturn([]);
|
||||||
|
|
||||||
|
self::assertSame('', ShortcodeDmr::render(['id' => 42]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_render_returns_empty_when_no_row_matches(): 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')->justReturn($term);
|
||||||
|
\Brain\Monkey\Functions\expect('get_field')
|
||||||
|
->once()
|
||||||
|
->andReturn([['town' => 10, 'text' => 'Только СПб']]);
|
||||||
|
|
||||||
|
self::assertSame('', ShortcodeDmr::render(['id' => 42]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user