Skip to content

Commit 99ea757

Browse files
committed
Add tests for tools and services
1 parent bf5ac50 commit 99ea757

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

tests/Services/AssetsTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Services;
4+
5+
use BEA\Theme\Framework\Service_Container;
6+
use BEA\Theme\Framework\Services\Acf;
7+
use BEA\Theme\Framework\Services\Assets;
8+
use BEA\Theme\Framework\Services\Svg;
9+
use InvalidArgumentException;
10+
use WP_Mock;
11+
use WP_Mock\Tools\TestCase;
12+
13+
class AssetsTest extends TestCase {
14+
public function setUp(): void {
15+
WP_Mock::setUp();
16+
}
17+
18+
public function tearDown(): void {
19+
WP_Mock::tearDown();
20+
}
21+
22+
public function testName() {
23+
$assets = new Assets();
24+
$this->assertEquals( 'assets', $assets->get_service_name() );
25+
}
26+
27+
public function testStyleSheetURIWithScriptDebug() {
28+
$assets = new Assets();
29+
30+
WP_Mock::passthruFunction( 'get_theme_file_path', [ 'times' => 1 ] );
31+
32+
$this->assertSame( 'ok.css', $assets->stylesheet_uri( 'ok.css' ) );
33+
}
34+
35+
}

tests/Tools/AssetsTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Tools;
4+
5+
use BEA\Theme\Framework\Service_Container;
6+
use BEA\Theme\Framework\Tools\Assets;
7+
use WP_Mock;
8+
use WP_Mock\Tools\TestCase;
9+
10+
class AssetsTest extends TestCase {
11+
public function setUp(): void {
12+
WP_Mock::setUp();
13+
}
14+
15+
public function tearDown(): void {
16+
WP_Mock::tearDown();
17+
}
18+
19+
public function testRegisterScript() {
20+
WP_Mock::passthruFunction( 'get_theme_file_uri', [ 'times' => 1 ] );
21+
WP_Mock::passthruFunction(
22+
'wp_register_script',
23+
[
24+
'times' => 1,
25+
'args' => [
26+
'handle',
27+
'src',
28+
[],
29+
false,
30+
false,
31+
],
32+
]
33+
);
34+
35+
$assets = new Assets();
36+
$assets->register_script( 'handle', 'src' );
37+
}
38+
39+
public function testEnqueueScript() {
40+
WP_Mock::passthruFunction(
41+
'wp_enqueue_script',
42+
[
43+
'times' => 1,
44+
'args' => [
45+
'handle',
46+
],
47+
]
48+
);
49+
50+
$assets = new Assets();
51+
$assets->enqueue_script( 'handle' );
52+
}
53+
54+
public function testRegisterStyle() {
55+
WP_Mock::passthruFunction( 'get_theme_file_uri', [ 'times' => 1 ] );
56+
WP_Mock::passthruFunction(
57+
'wp_register_style',
58+
[
59+
'times' => 1,
60+
'args' => [
61+
'handle',
62+
'src',
63+
[],
64+
false,
65+
'all',
66+
],
67+
]
68+
);
69+
70+
$assets = new Assets();
71+
$assets->register_style( 'handle', 'src' );
72+
}
73+
74+
public function testEnqueueStyle() {
75+
WP_Mock::passthruFunction(
76+
'wp_enqueue_style',
77+
[
78+
'times' => 1,
79+
'args' => [
80+
'handle',
81+
],
82+
]
83+
);
84+
85+
$assets = new Assets();
86+
$assets->enqueue_style( 'handle' );
87+
}
88+
}

0 commit comments

Comments
 (0)