| 1 |
<?php |
| 2 |
|
| 3 |
namespace Vimeography_Unit_Tests; |
| 4 |
|
| 5 |
class Tests_Shortcode extends Vimeography_UnitTestCase { |
| 6 |
|
| 7 |
protected $_class; |
| 8 |
|
| 9 |
protected $_gallery_atts; |
| 10 |
|
| 11 |
/** |
| 12 |
* Runs before every test. |
| 13 |
* Think of it as emulating what would usually happen once the plugin is activated on a Wordpress site. |
| 14 |
*/ |
| 15 |
public function setUp() |
| 16 |
{ |
| 17 |
parent::setUp(); |
| 18 |
$this->_class = new \Vimeography_Shortcode; |
| 19 |
|
| 20 |
$this->_gallery_atts = array( |
| 21 |
'theme' => 'bugsauce', |
| 22 |
'featured' => '', |
| 23 |
'source' => 'https://vimeo.com/channels/staffpicks/', |
| 24 |
'limit' => 25, |
| 25 |
'cache' => 3600, |
| 26 |
'width' => '', |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
public function test_shortcodes_are_registered() { |
| 31 |
global $shortcode_tags; |
| 32 |
$this->assertArrayHasKey( 'vimeography', $shortcode_tags ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @covers Vimeography_Shortcode::_apply_shortcode_gallery_settings() |
| 37 |
*/ |
| 38 |
public function test_apply_shortcode_gallery_settings() { |
| 39 |
$expected = array( |
| 40 |
'theme' => 'bugsauce', |
| 41 |
'featured' => '', |
| 42 |
'source' => '/channels/staffpicks/videos', |
| 43 |
'limit' => 25, |
| 44 |
'cache' => 3600, |
| 45 |
'width' => '', |
| 46 |
); |
| 47 |
|
| 48 |
// Get a handle to the private method |
| 49 |
$apply_shortcode_gallery_settings = new \ReflectionMethod( |
| 50 |
'Vimeography_Shortcode', |
| 51 |
'_apply_shortcode_gallery_settings' |
| 52 |
); |
| 53 |
|
| 54 |
$apply_shortcode_gallery_settings->setAccessible( true ); |
| 55 |
$actual = $apply_shortcode_gallery_settings->invoke( $this->_class, $this->_gallery_atts ); |
| 56 |
|
| 57 |
$this->assertEquals($expected, $actual); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* @covers Vimeography_Shortcode::_validate_gallery_width() |
| 62 |
*/ |
| 63 |
public function test_gallery_width_when_giving_pixel_amount_without_suffix() { |
| 64 |
|
| 65 |
// Get a handle to the private method |
| 66 |
$validate_gallery_width = new \ReflectionMethod( |
| 67 |
'Vimeography_Shortcode', |
| 68 |
'_validate_gallery_width' |
| 69 |
); |
| 70 |
|
| 71 |
$validate_gallery_width->setAccessible( true ); |
| 72 |
$actual = $validate_gallery_width->invoke( $this->_class, '600' ); |
| 73 |
|
| 74 |
$this->assertEquals('600px', $actual ); |
| 75 |
} |
| 76 |
|
| 77 |
public function test_gallery_width_when_giving_pixel_amount_with_suffix() { |
| 78 |
// Get a handle to the private method |
| 79 |
$validate_gallery_width = new \ReflectionMethod( |
| 80 |
'Vimeography_Shortcode', |
| 81 |
'_validate_gallery_width' |
| 82 |
); |
| 83 |
|
| 84 |
$validate_gallery_width->setAccessible( true ); |
| 85 |
$actual = $validate_gallery_width->invoke( $this->_class, '600px' ); |
| 86 |
|
| 87 |
$this->assertEquals('600px', $actual); |
| 88 |
} |
| 89 |
|
| 90 |
public function test_gallery_width_when_giving_percentage_value() { |
| 91 |
// Get a handle to the private method |
| 92 |
$validate_gallery_width = new \ReflectionMethod( |
| 93 |
'Vimeography_Shortcode', |
| 94 |
'_validate_gallery_width' |
| 95 |
); |
| 96 |
|
| 97 |
$validate_gallery_width->setAccessible( true ); |
| 98 |
$actual = $validate_gallery_width->invoke( $this->_class, '60%' ); |
| 99 |
$this->assertEquals('60%', $actual ); |
| 100 |
} |
| 101 |
|
| 102 |
public function test_invalid_gallery_width() { |
| 103 |
// Get a handle to the private method |
| 104 |
$validate_gallery_width = new \ReflectionMethod( |
| 105 |
'Vimeography_Shortcode', |
| 106 |
'_validate_gallery_width' |
| 107 |
); |
| 108 |
|
| 109 |
$validate_gallery_width->setAccessible( true ); |
| 110 |
$actual = $validate_gallery_width->invoke( $this->_class, 'fat' ); |
| 111 |
$this->assertEquals('', $actual ); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* @covers Vimeography_Shortcode::vimeography_shortcode |
| 116 |
*/ |
| 117 |
public function test_shortcode_output_is_a_string() |
| 118 |
{ |
| 119 |
$this->assertInternalType( 'string', $this->_class->vimeography_shortcode( array( 'id' => 1 ) ) ); |
| 120 |
} |
| 121 |
|
| 122 |
public function tearDown() { |
| 123 |
} |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|