-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from WPupdatePHP/notices-refactor
Notices refactor to multiple classes
- Loading branch information
Showing
11 changed files
with
119 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bootstrap: spec/bootstrap.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace spec; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
class WPUP_Minimum_NoticeSpec extends ObjectBehavior | ||
{ | ||
function let() | ||
{ | ||
$this->beConstructedWith('5.4.0', 'Test Plugin'); | ||
} | ||
|
||
function it_adds_plugin_name_to_admin_notice() | ||
{ | ||
$this->getNoticeText()->shouldMatch('/Test Plugin/i'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace spec; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
class WPUP_Recommended_NoticeSpec extends ObjectBehavior | ||
{ | ||
function let() | ||
{ | ||
$this->beConstructedWith('5.4.0', 'Test Plugin'); | ||
} | ||
|
||
function it_adds_plugin_name_to_admin_notice() | ||
{ | ||
$this->getNoticeText()->shouldMatch('/Test Plugin/i'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,27 @@ | ||
<?php | ||
|
||
namespace { | ||
function add_action( $hook, $callback ) { | ||
return true; | ||
} | ||
|
||
function is_admin() { | ||
return true; | ||
} | ||
} | ||
|
||
namespace spec { | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
namespace spec; | ||
|
||
class WPUpdatePhpSpec extends ObjectBehavior { | ||
function let() { | ||
$this->beConstructedWith( '5.4.0', '5.3.0' ); | ||
} | ||
use PhpSpec\ObjectBehavior; | ||
|
||
function it_can_run_on_minimum_version() { | ||
$this->does_it_meet_required_php_version( '5.4.0' )->shouldReturn( true ); | ||
} | ||
class WPUpdatePhpSpec extends ObjectBehavior { | ||
function let() { | ||
$this->beConstructedWith( '5.4.0', '5.3.0' ); | ||
} | ||
|
||
function it_passes_the_recommended_version() { | ||
$this->does_it_meet_recommended_php_version( '5.3.0' )->shouldReturn( true ); | ||
} | ||
function it_can_run_on_minimum_version() { | ||
$this->does_it_meet_required_php_version( '5.4.0' )->shouldReturn( true ); | ||
} | ||
|
||
function it_will_not_run_on_old_version() { | ||
$this->does_it_meet_required_php_version( '5.2.4' )->shouldReturn( false ); | ||
} | ||
function it_passes_the_recommended_version() { | ||
$this->does_it_meet_recommended_php_version( '5.3.0' )->shouldReturn( true ); | ||
} | ||
|
||
function it_fails_the_recommended_version() { | ||
$this->does_it_meet_recommended_php_version( '5.2.9' )->shouldReturn( false ); | ||
} | ||
function it_will_not_run_on_old_version() { | ||
$this->does_it_meet_required_php_version( '5.2.4' )->shouldReturn( false ); | ||
} | ||
|
||
function it_adds_plugin_name_to_admin_notice() { | ||
$this->set_plugin_name( 'Test Plugin' ); | ||
$this->get_admin_notice()->shouldMatch('/Test Plugin/i'); | ||
$this->get_admin_notice( 'recommended' )->shouldMatch('/Test Plugin/i'); | ||
} | ||
function it_fails_the_recommended_version() { | ||
$this->does_it_meet_recommended_php_version( '5.2.9' )->shouldReturn( false ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
function esc_url( $string ) { | ||
return $string; | ||
} | ||
|
||
function add_action( $hook, $callback ) { | ||
return true; | ||
} | ||
|
||
function is_admin() { | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
abstract class WPUP_Notice implements WPUP_Notice_Interface | ||
{ | ||
protected $version; | ||
protected $plugin_name; | ||
protected $url = 'http://wpupdatephp.com/update/'; | ||
|
||
public function __construct( $version, $plugin_name = NULL ) | ||
{ | ||
$this->version = $version; | ||
$this->plugin_name = $plugin_name; | ||
} | ||
|
||
public function display() | ||
{ | ||
return '<div class="error">' . $this->getNoticeText() . '</div>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
interface WPUP_Notice_Interface | ||
{ | ||
public function getNoticeText(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class WPUP_Minimum_Notice extends WPUP_Notice | ||
{ | ||
public function getNoticeText() | ||
{ | ||
$plugin_name = $this->plugin_name ? $this->plugin_name : 'this plugin'; | ||
|
||
return 'Unfortunately, ' . $plugin_name . ' cannot run on PHP versions older than ' . $this->version . '. Read more information about <a href="' . esc_url( $this->url ) . '">how you can update</a>.'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class WPUP_Recommended_Notice extends WPUP_Notice | ||
{ | ||
public function getNoticeText() | ||
{ | ||
$plugin_name = $this->plugin_name ? $this->plugin_name : 'This plugin'; | ||
|
||
return $plugin_name . ' recommends a PHP version higher than ' . $this->version . '. Read more information about <a href="' . esc_url( $this->url ) . '">how you can update</a>.'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters