|
5 | 5 | use Brain\Monkey; |
6 | 6 | use Brain\Monkey\Functions; |
7 | 7 |
|
8 | | -beforeAll( function () { |
9 | | - Monkey\setUp(); |
10 | | - |
11 | | - Functions\expect( 'load_plugin_textdomain' )->atLeast()->once(); |
12 | | - Functions\stubs( [ |
13 | | - 'plugin_basename' => 'abc', |
14 | | - '__', |
15 | | - 'selected' => 'selected="selected"', |
16 | | - ] ); |
17 | | -} ); |
18 | | - |
19 | | -beforeEach( function() { |
20 | | - $options = \Mockery::mock( 'lloc\Msls\MslsOptions' ); |
21 | | - $options->mslsmenu_theme_location = [ 'test' ]; |
22 | | - |
23 | | - $this->sut = \MslsMenu::init( $options ); |
24 | | -} ); |
25 | | - |
26 | | -afterAll( function () { |
27 | | - Monkey\tearDown(); |
28 | | -} ); |
29 | | - |
30 | | -it( 'returns an instance of MslsMenu when factory receives an MslsOptions object', function () { |
31 | | - expect( $this->sut )->toBeInstanceOf( \MslsMenu::class ); |
32 | | -} ); |
33 | | - |
34 | | -it( 'adds a filter when factory receives an MslsOptions object', function () { |
35 | | - expect( has_filter( 'wp_nav_menu_items', [ $this->sut, 'nav_item' ] ) )->toEqual( 10 ); |
36 | | -} ); |
37 | | - |
38 | | -it( 'adds an action when factory receives an MslsOptions object', function () { |
39 | | - expect( has_action( 'msls_admin_register', [ $this->sut, 'admin_register' ] ) )->toEqual( 10 ); |
40 | | -} ); |
41 | | - |
42 | | -it( 'calls add_settings_section on $sut->admin_register()', function () { |
43 | | - Functions\expect( 'add_settings_section' )->once(); |
44 | | - |
45 | | - $this->sut->admin_register( 'test' ); |
46 | | -} ); |
47 | | - |
48 | | -it( 'returns an empty string on $sut->nav_item()', function() { |
49 | | - $expected = ''; |
50 | | - |
51 | | - $args = new \stdClass(); |
52 | | - $args->theme_locations = 'test'; |
53 | | - |
54 | | - $result = $this->sut->nav_item( '', $args ); |
55 | | - |
56 | | - expect( $result )->toEqual( $expected ); |
57 | | -} ); |
58 | | - |
59 | | -it( 'calls add_settings_field on $sut->add_settings()', function () { |
60 | | - Functions\expect( 'add_settings_field' )->times( 6 ); |
61 | | - |
62 | | - $this->sut->add_settings(); |
63 | | -} ); |
64 | | - |
65 | | -it( 'calls get_nav_menu_locations on $sut->theme_location()', function () { |
66 | | - Functions\expect( 'get_nav_menu_locations' )->once()->andReturn( [ 'test' => 1 ] ); |
67 | | - Functions\expect( 'esc_attr' )->once()->andReturnFirstArg(); |
68 | | - Functions\expect( 'esc_html__' )->once()->andReturnFirstArg(); |
69 | | - |
70 | | - $expected = '<select id="mslsmenu_theme_location" name="msls[mslsmenu_theme_location][]" multiple="multiple"><option value="" selected="selected">-- empty --</option><option value="test" selected="selected">test</option></select>'; |
71 | | - |
72 | | - $this->sut->theme_location( [] ); |
73 | | - |
74 | | - $this->expectOutputString( $expected ); |
75 | | -} ); |
76 | | - |
77 | | -it( 'prints a string on $sut->display()', function () { |
78 | | - $expected = '<select></select>'; |
79 | | - |
80 | | - $this->sut->display( [] ); |
81 | | - |
82 | | - $this->expectOutputString( $expected ); |
83 | | -} ); |
84 | | - |
85 | | -it( 'prints a string on $sut->input()', function () { |
86 | | - $expected = '<input />'; |
87 | | - |
88 | | - $this->sut->input( [] ); |
89 | | - |
90 | | - $this->expectOutputString( $expected ); |
91 | | -} ); |
| 8 | +beforeAll( |
| 9 | + function () { |
| 10 | + Monkey\setUp(); |
| 11 | + |
| 12 | + Functions\stubs( |
| 13 | + array( |
| 14 | + 'plugin_basename' => 'abc', |
| 15 | + '__', |
| 16 | + 'selected' => 'selected="selected"', |
| 17 | + ) |
| 18 | + ); |
| 19 | + } |
| 20 | +); |
| 21 | + |
| 22 | +beforeEach( |
| 23 | + function () { |
| 24 | + $options = \Mockery::mock( 'lloc\Msls\MslsOptions' ); |
| 25 | + $options->mslsmenu_theme_location = array( 'test' ); |
| 26 | + |
| 27 | + $this->sut = \MslsMenu::init( $options ); |
| 28 | + } |
| 29 | +); |
| 30 | + |
| 31 | +afterAll( |
| 32 | + function () { |
| 33 | + Monkey\tearDown(); |
| 34 | + } |
| 35 | +); |
| 36 | + |
| 37 | +it( |
| 38 | + 'returns an instance of MslsMenu when factory receives an MslsOptions object', |
| 39 | + function () { |
| 40 | + expect( $this->sut )->toBeInstanceOf( \MslsMenu::class ); |
| 41 | + } |
| 42 | +); |
| 43 | + |
| 44 | +it( |
| 45 | + 'adds a filter when factory receives an MslsOptions object', |
| 46 | + function () { |
| 47 | + expect( has_filter( 'wp_nav_menu_items', array( $this->sut, 'nav_item' ) ) )->toEqual( 10 ); |
| 48 | + } |
| 49 | +); |
| 50 | + |
| 51 | +it( |
| 52 | + 'adds an action when factory receives an MslsOptions object', |
| 53 | + function () { |
| 54 | + expect( has_action( 'msls_admin_register', array( $this->sut, 'admin_register' ) ) )->toEqual( 10 ); |
| 55 | + } |
| 56 | +); |
| 57 | + |
| 58 | +it( |
| 59 | + 'calls add_settings_section on $sut->admin_register()', |
| 60 | + function () { |
| 61 | + Functions\expect( 'add_settings_section' )->once(); |
| 62 | + |
| 63 | + $this->sut->admin_register( 'test' ); |
| 64 | + } |
| 65 | +); |
| 66 | + |
| 67 | +it( |
| 68 | + 'returns an empty string on $sut->nav_item()', |
| 69 | + function () { |
| 70 | + $expected = ''; |
| 71 | + |
| 72 | + $args = new \stdClass(); |
| 73 | + $args->theme_locations = 'test'; |
| 74 | + |
| 75 | + $result = $this->sut->nav_item( '', $args ); |
| 76 | + |
| 77 | + expect( $result )->toEqual( $expected ); |
| 78 | + } |
| 79 | +); |
| 80 | + |
| 81 | +it( |
| 82 | + 'calls add_settings_field on $sut->add_settings()', |
| 83 | + function () { |
| 84 | + Functions\expect( 'add_settings_field' )->times( 6 ); |
| 85 | + |
| 86 | + $this->sut->add_settings(); |
| 87 | + } |
| 88 | +); |
| 89 | + |
| 90 | +it( |
| 91 | + 'calls get_nav_menu_locations on $sut->theme_location()', |
| 92 | + function () { |
| 93 | + Functions\expect( 'get_nav_menu_locations' )->once()->andReturn( array( 'test' => 1 ) ); |
| 94 | + Functions\expect( 'esc_attr' )->once()->andReturnFirstArg(); |
| 95 | + Functions\expect( 'esc_html__' )->once()->andReturnFirstArg(); |
| 96 | + |
| 97 | + $expected = '<select id="mslsmenu_theme_location" name="msls[mslsmenu_theme_location][]" multiple="multiple"><option value="" selected="selected">-- empty --</option><option value="test" selected="selected">test</option></select>'; |
| 98 | + |
| 99 | + $this->sut->theme_location( array() ); |
| 100 | + |
| 101 | + $this->expectOutputString( $expected ); |
| 102 | + } |
| 103 | +); |
| 104 | + |
| 105 | +it( |
| 106 | + 'prints a string on $sut->display()', |
| 107 | + function () { |
| 108 | + $expected = '<select></select>'; |
| 109 | + |
| 110 | + $this->sut->display( array() ); |
| 111 | + |
| 112 | + $this->expectOutputString( $expected ); |
| 113 | + } |
| 114 | +); |
| 115 | + |
| 116 | +it( |
| 117 | + 'prints a string on $sut->input()', |
| 118 | + function () { |
| 119 | + $expected = '<input />'; |
| 120 | + |
| 121 | + $this->sut->input( array() ); |
| 122 | + |
| 123 | + $this->expectOutputString( $expected ); |
| 124 | + } |
| 125 | +); |
0 commit comments