-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathPolyfillsTest.php
96 lines (80 loc) · 2.79 KB
/
PolyfillsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Tests for Polyfills class.
*
* @package AmpProject\AmpWP\Tests
*/
namespace AmpProject\AmpWP\Tests\Admin;
use AmpProject\AmpWP\Admin\Polyfills;
use AmpProject\AmpWP\Infrastructure\Conditional;
use AmpProject\AmpWP\Infrastructure\Delayed;
use AmpProject\AmpWP\Infrastructure\HasRequirements;
use AmpProject\AmpWP\Infrastructure\Registerable;
use AmpProject\AmpWP\Infrastructure\Service;
use AmpProject\AmpWP\Tests\TestCase;
use WP_Scripts;
use WP_Styles;
/**
* Tests for Polyfills class.
*
* @since 2.0
*
* @coversDefaultClass \AmpProject\AmpWP\Admin\Polyfills
*/
class PolyfillsTest extends TestCase {
/**
* Test instance.
*
* @var Polyfills
*/
private $instance;
/**
* Setup.
*
* @inheritdoc
*/
public function setUp() {
parent::setUp();
$this->instance = new Polyfills();
}
public function test__construct() {
$this->assertInstanceOf( Polyfills::class, $this->instance );
$this->assertInstanceOf( Service::class, $this->instance );
$this->assertInstanceOf( Delayed::class, $this->instance );
$this->assertInstanceOf( Conditional::class, $this->instance );
$this->assertInstanceOf( Registerable::class, $this->instance );
$this->assertInstanceOf( HasRequirements::class, $this->instance );
}
/** @covers ::get_requirements() */
public function test_get_requirements() {
$this->assertSame( [ 'dependency_support' ], Polyfills::get_requirements() );
}
/**
* Tests Polyfills::register
*
* @covers ::register
* @covers ::register_shimmed_scripts
* @covers ::register_shimmed_styles
*/
public function test_registration() {
global $wp_scripts, $wp_styles;
$this->instance->register();
$wp_scripts = new WP_Scripts();
$wp_styles = new WP_Styles();
/** This action is documented in includes/class-amp-theme-support.php */
do_action( 'amp_register_polyfills' );
// These should pass in WP < 5.6.
$this->assertTrue( wp_script_is( 'lodash', 'registered' ) );
$this->assertStringContainsString( '_.noConflict();', $wp_scripts->print_inline_script( 'lodash', 'after', false ) );
$this->assertTrue( wp_script_is( 'wp-api-fetch', 'registered' ) );
$this->assertStringContainsString( 'createRootURLMiddleware', $wp_scripts->print_inline_script( 'wp-api-fetch', 'after', false ) );
$this->assertStringContainsString( 'createNonceMiddleware', $wp_scripts->print_inline_script( 'wp-api-fetch', 'after', false ) );
$this->assertTrue( wp_script_is( 'wp-hooks', 'registered' ) );
$this->assertTrue( wp_script_is( 'wp-i18n', 'registered' ) );
$this->assertTrue( wp_script_is( 'wp-dom-ready', 'registered' ) );
$this->assertTrue( wp_script_is( 'wp-polyfill', 'registered' ) );
$this->assertTrue( wp_script_is( 'wp-url', 'registered' ) );
$this->assertTrue( wp_style_is( 'wp-components', 'registered' ) );
unset( $wp_scripts, $wp_styles );
}
}