1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
2
|
|
|
/** |
3
|
|
|
* Test methods from Automattic\Jetpack\Blocks |
4
|
|
|
* |
5
|
|
|
* @since 9.0.0 |
6
|
|
|
* |
7
|
|
|
* @package automattic/jetpack-blocks |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Automattic\Jetpack; |
11
|
|
|
|
12
|
|
|
use Automattic\Jetpack\Blocks; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Test_Blocks |
17
|
|
|
*/ |
18
|
|
|
class Test_Blocks extends TestCase { |
19
|
|
|
/** |
20
|
|
|
* Test the different inputs and matching output for Classes. |
21
|
|
|
* |
22
|
|
|
* @since 9.0.0 |
23
|
|
|
* |
24
|
|
|
* @covers Automattic\Jetpack\Blocks::classes |
25
|
|
|
*/ |
26
|
|
|
public function test_block_classes() { |
27
|
|
|
$block_name = 'foo'; |
28
|
|
|
$attr = array( |
29
|
|
|
'bar' => 'baz', |
30
|
|
|
'align' => 'wide', |
31
|
|
|
'className' => 'editorclass', |
32
|
|
|
); |
33
|
|
|
$extra = array( 'extraclass' ); |
34
|
|
|
|
35
|
|
|
$block_classes = Blocks::classes( $block_name, $attr, $extra ); |
36
|
|
|
|
37
|
|
|
$this->assertContains( 'wp-block-jetpack-foo', $block_classes ); // a general class is created from the block name. |
38
|
|
|
$this->assertNotContains( 'bar', $block_classes ); // The extra 'bar' attribute should be dropped. |
39
|
|
|
$this->assertNotContains( 'baz', $block_classes ); // The extra 'baz' attribute should be dropped. |
40
|
|
|
$this->assertNotContains( 'align ', $block_classes ); // The align attribute should only be used to create a new attribute. |
41
|
|
|
$this->assertNotContains( 'className', $block_classes ); // The className attribute should be dropped, only the editorclass value should remain. |
42
|
|
|
$this->assertContains( 'alignwide', $block_classes ); // an alignment class is created. |
43
|
|
|
$this->assertContains( 'editorclass', $block_classes ); // className classes are passed. |
44
|
|
|
$this->assertContains( 'extraclass', $block_classes ); // Extra class remains. |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test for invalid alignment values. |
49
|
|
|
* |
50
|
|
|
* @since 9.0.0 |
51
|
|
|
* |
52
|
|
|
* @covers Automattic\Jetpack\Blocks::classes |
53
|
|
|
*/ |
54
|
|
|
public function test_block_classes_invalid_align() { |
55
|
|
|
$attr = array( 'align' => 'test' ); |
56
|
|
|
$block_classes = Blocks::classes( 'test', $attr ); |
57
|
|
|
|
58
|
|
|
$this->assertNotContains( 'aligntest', $block_classes ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Test whether we can detect an AMP view. |
63
|
|
|
* |
64
|
|
|
* @since 9.0.0 |
65
|
|
|
* |
66
|
|
|
* @covers Automattic\Jetpack\Blocks::is_amp_request |
67
|
|
|
*/ |
68
|
|
|
public function test_is_amp_request() { |
69
|
|
|
add_filter( 'jetpack_is_amp_request', '__return_true' ); |
70
|
|
|
try { |
71
|
|
|
$this->assertTrue( Blocks::is_amp_request() ); |
72
|
|
|
} finally { |
73
|
|
|
remove_filter( 'jetpack_is_amp_request', '__return_true' ); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Test whether we can detect an AMP view. |
79
|
|
|
* |
80
|
|
|
* @since 9.0.0 |
81
|
|
|
* |
82
|
|
|
* @covers Automattic\Jetpack\Blocks::is_amp_request |
83
|
|
|
*/ |
84
|
|
|
public function test_is_not_amp_request() { |
85
|
|
|
$this->assertFalse( Blocks::is_amp_request() ); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|