Changeset 1545834
- Timestamp:
- 12/05/2016 12:13:06 PM (9 years ago)
- Location:
- ag-custom-admin/trunk
- Files:
-
- 7 edited
-
readme.txt (modified) (3 diffs)
-
tests/_bootstrap.php (modified) (1 diff)
-
tests/_support/AcceptanceTester.php (modified) (2 diffs)
-
tests/_support/Page/AGCAPage.php (modified) (3 diffs)
-
tests/_support/Page/GeneralPage.php (modified) (1 diff)
-
tests/_support/Page/WPDashboardPage.php (modified) (1 diff)
-
tests/acceptance/GeneralSettingsCest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ag-custom-admin/trunk/readme.txt
r1545084 r1545834 5 5 Requires at least: 3.0 6 6 Tested up to: 4.7 7 Stable tag: 5.7 7 Stable tag: 5.7.1 8 8 License: GPLv3 or later 9 9 License URI: https://www.gnu.org/licenses/gpl.txt … … 153 153 == Change Log == 154 154 155 = 5.7.1 = 156 * Added General Options tests 157 155 158 = 5.7 = 156 159 * Added Save button on top … … 521 524 == Upgrade Notice == 522 525 526 = 5.7.1 = 527 * Added tests. 528 523 529 = 5.7 = 524 530 * Bug fixes. Ready for WordPress 4.7. -
ag-custom-admin/trunk/tests/_bootstrap.php
r1545084 r1545834 3 3 define('AGCA_SITE_USERNAME','admin'); 4 4 define('AGCA_SITE_PASSWORD','admin'); 5 define('AGCA_SITE_SUBSCRIBER_USERNAME','subscriber'); 6 define('AGCA_SITE_SUBSCRIBER_PASSWORD','subscriber'); 7 define('AGCA_SITE_EDITOR_USERNAME','editor'); 8 define('AGCA_SITE_EDITOR_PASSWORD','editor'); -
ag-custom-admin/trunk/tests/_support/AcceptanceTester.php
r1545828 r1545834 16 16 * 17 17 * @SuppressWarnings(PHPMD) 18 */18 */ 19 19 class AcceptanceTester extends \Codeception\Actor 20 20 { 21 21 use _generated\AcceptanceTesterActions; 22 22 23 p ublic function login()23 private function login($username = AGCA_SITE_USERNAME, $password = AGCA_SITE_PASSWORD) 24 24 { 25 25 $I = $this; 26 26 $I->amOnPage('/wp-login.php'); 27 27 $I->see('Username or Email Address'); 28 28 29 $I->submitForm('#loginform', [ 29 'log' => AGCA_SITE_USERNAME,30 'pwd' => AGCA_SITE_PASSWORD30 'log' => $username, 31 'pwd' => $password 31 32 ]); 32 33 … … 40 41 } 41 42 42 public function checkAgcaOption($name){43 try{44 $this->click("#agca_form input.agca-checkbox[name=$name]:not(:checked) + div");45 }catch (Exception $e){}43 public function loginAsAdmin() 44 { 45 $this->login(); 46 return $this; 46 47 } 47 48 48 public function isAgcaOptionChecked($name){ 49 return (bool) $this->executeJS( 50 'return jQuery("#agca_form input.agca-checkbox[name='.$name.']:checked").size()' 49 public function loginAsSubscriber() 50 { 51 $this->login( 52 AGCA_SITE_SUBSCRIBER_USERNAME, 53 AGCA_SITE_SUBSCRIBER_PASSWORD 54 ); 55 return $this; 56 } 57 58 public function loginAsEditor() 59 { 60 $this->login( 61 AGCA_SITE_EDITOR_USERNAME, 62 AGCA_SITE_EDITOR_PASSWORD 63 ); 64 return $this; 65 } 66 67 public function logOut(){ 68 $logOutLink = $this->executeJS('return jQuery("#wp-admin-bar-logout a").attr("href");'); 69 $this->amOnUrl($logOutLink); 70 return $this; 71 } 72 73 public function checkAgcaOption($name) 74 { 75 try { 76 if(!$this->isAgcaOptionChecked($name)){ 77 $this->click("#agca_form input.agca-checkbox[name=$name]:not(:checked) + div"); 78 } 79 } catch (Exception $e) { 80 } 81 } 82 83 public function isAgcaOptionChecked($name) 84 { 85 return (bool)$this->executeJS( 86 'return jQuery("#agca_form input.agca-checkbox[name=' . $name . ']:checked").size()' 51 87 ); 52 88 } 53 89 54 public function uncheckAgcaOption($name){ 55 try{ 56 $this->click("#agca_form input.agca-checkbox[name=$name]:checked + div"); 57 }catch (Exception $e){} 90 public function uncheckAgcaOption($name) 91 { 92 try { 93 if($this->isAgcaOptionChecked($name)){ 94 $this->click("#agca_form input.agca-checkbox[name=$name]:checked + div"); 95 } 96 } catch (Exception $e) { 97 } 58 98 } 59 99 60 public function getAGCAOptionLabel($name){ 100 public function getAGCAOptionLabel($name) 101 { 61 102 return $this->executeJS("return jQuery(\"label[for=$name]\").text();"); 62 103 } 63 104 64 public function changeAgcaSelectOption($selector, $value){ 105 public function changeAgcaSelectOption($selector, $value) 106 { 65 107 $this->executeJS("jQuery(\"#agca_form $selector\").val('$value');"); 66 108 } -
ag-custom-admin/trunk/tests/_support/Page/AGCAPage.php
r1545828 r1545834 8 8 // include url of current page 9 9 public static $URL = '/wp-admin/tools.php?page=ag-custom-admin/plugin.php#general-settings'; 10 public static $PAGE_TITLE = 'General Settings'; 10 11 11 12 /** … … 39 40 public function seeMenu($text){ 40 41 $this->I->see($text, '#ag_main_menu li.normal a'); 42 return $this; 41 43 } 42 44 43 45 public function selectedMenu($text){ 44 46 $this->I->see($text, '#ag_main_menu li.selected a'); 47 return $this; 45 48 } 46 49 47 public function amOnGeneralPage(){50 public function visit(){ 48 51 $this->I->amOnPage($this::$URL); 49 $this->I->see('General Settings'); 52 $this->I->see($this::$PAGE_TITLE); 53 return $this; 50 54 } 51 55 52 56 public function seeArea($text){ 53 57 $this->I->see($text, '#agca_form .ag_table_heading h3'); 58 return $this; 54 59 } 55 60 56 61 public function saveSettings(){ 57 62 $this->I->submitForm('#agca_form', []); 63 return $this; 58 64 } 59 65 … … 65 71 return $this->I->executeJS("return jQuery(\"#agca_form $selector\").val();"); 66 72 } 73 74 /** 75 * Prepares options before testing and persists them in database 76 * @param array $options 77 */ 78 public function prepareAgcaOptions($options = []){ 79 $I = $this->I; 80 81 foreach($options as $key=>$option){ 82 if(is_array($option)){ //selectbox or something else 83 switch($option['type']){ 84 case 'select': 85 $I->changeAgcaSelectOption($key, $option['value']); 86 default:; 87 } 88 }else if(is_bool($option)){ //checkbox 89 if($option){ 90 $I->checkAgcaOption($key); 91 }else{ 92 $I->uncheckAgcaOption($key); 93 } 94 }else{ //text 95 //TODO: Implement text options 96 } 97 } 98 99 $this->saveSettings()->visit(); 100 101 //Check if options are persisted correctly 102 foreach($options as $key=>$option){ 103 if(is_array($option)){ //select or something else 104 switch($option['type']){ 105 case 'select': 106 $I->assertEquals( 107 $option['value'], 108 $this->getAgcaSelectedOption($key) 109 ); 110 default:; 111 } 112 }else if(is_bool($option)){ //checkbox 113 $isOptionChecked = $I->isAgcaOptionChecked($key); 114 if($option){ 115 $I->assertTrue($isOptionChecked); 116 }else{ 117 $I->assertFalse($isOptionChecked); 118 } 119 }else{ //text 120 //TODO: Implement text options 121 } 122 } 123 } 67 124 } -
ag-custom-admin/trunk/tests/_support/Page/GeneralPage.php
r1545828 r1545834 4 4 class GeneralPage extends AGCAPage 5 5 { 6 public static $helpMenuOption = 'agca_help_menu'; 7 public static $helpMenuOptionLabel = '"Help" menu'; 8 9 public static $screenOption = 'agca_screen_options_menu'; 10 public static $screenOptionLabel = '"Screen Options" menu'; 11 6 12 public static $capabilityField = 'select#agca_admin_capability'; 7 13 public static $capabilityLabel = 'AGCA admin capability:'; 14 public static $capabilityEditDashboard = 'edit_dashboard'; 15 public static $capabilityCreateUsers = 'create_users'; 16 public static $capabilityEditPosts = 'edit_posts'; 17 18 public static $excludeAdministratorOption = 'agca_role_allbutadmin'; 19 public static $excludeAdministratorOptionLabel = 'Exclude AGCA admin from customizations'; 8 20 } -
ag-custom-admin/trunk/tests/_support/Page/WPDashboardPage.php
r1545828 r1545834 34 34 } 35 35 36 public function amOnDashboardPage(){36 public function visit(){ 37 37 $this->I->amOnPage($this::$URL); 38 38 $this->I->see('Dashboard', 'body h1:nth-child(1)'); 39 return $this; 39 40 } 40 41 -
ag-custom-admin/trunk/tests/acceptance/GeneralSettingsCest.php
r1545828 r1545834 6 6 class GeneralSettingsCest 7 7 { 8 /** 9 * @var GeneralPage 10 */ 11 private $generalPage; 12 8 13 public function _before(AcceptanceTester $I) 9 14 { 10 $I->login(); 15 $I->loginAsAdmin(); 16 $this->generalPage = new GeneralPage($I); 11 17 } 12 18 … … 18 24 public function test_general_settings_shows_up(AcceptanceTester $I) 19 25 { 20 (new GeneralPage($I))->amOnGeneralPage(); 21 } 22 23 public function test_main_menu(AcceptanceTester $I){ 24 $page = new GeneralPage($I); 25 $page->amOnGeneralPage(); 26 27 $page->selectedMenu('General'); 28 $page->seeMenu('Admin Bar'); 29 $page->seeMenu('Footer'); 30 $page->seeMenu('Dashboard'); 31 $page->seeMenu('Login Page'); 32 $page->seeMenu('Admin Menu'); 33 $page->seeMenu('Colorizer'); 34 $page->seeMenu('Advanced'); 35 $page->seeMenu('Themes'); 36 $page->seeMenu('Upgrade'); 37 } 38 39 public function test_areas(AcceptanceTester $I){ 40 $page = new GeneralPage($I); 41 $page->amOnGeneralPage(); 42 $page->seeArea('Pages'); 43 $page->seeArea('Security'); 44 $page->seeArea('Feedback and Support'); 45 } 46 47 public function test_feedback_and_support(AcceptanceTester $I){ 48 (new GeneralPage($I))->amOnGeneralPage(); 26 $this->generalPage->visit(); 27 } 28 29 public function test_main_menu(AcceptanceTester $I) 30 { 31 // Initialization ----------------------------------------- 32 33 $page = $this->generalPage->visit(); 34 35 // Assertions ------------------------------------------------ 36 37 $page 38 ->selectedMenu('General') 39 ->seeMenu('Admin Bar') 40 ->seeMenu('Footer') 41 ->seeMenu('Dashboard') 42 ->seeMenu('Login Page') 43 ->seeMenu('Admin Menu') 44 ->seeMenu('Colorizer') 45 ->seeMenu('Advanced') 46 ->seeMenu('Themes') 47 ->seeMenu('Upgrade'); 48 } 49 50 public function test_areas(AcceptanceTester $I) 51 { 52 // Initialization ----------------------------------------- 53 54 $page = $this->generalPage->visit(); 55 56 // Assertions ------------------------------------------------ 57 58 $page 59 ->seeArea('Pages') 60 ->seeArea('Security') 61 ->seeArea('Feedback and Support'); 62 } 63 64 public function test_feedback_and_support(AcceptanceTester $I) 65 { 66 // Initialization ----------------------------------------- 67 68 $this->generalPage->visit(); 69 70 // Assertions ------------------------------------------------ 49 71 50 72 $I->see('Idea for improvement'); … … 59 81 } 60 82 61 public function test_capability_field(AcceptanceTester $I){ 62 $page = new GeneralPage($I); 63 $page->amOnGeneralPage(); 64 65 $editDashboardOption = 'edit_dashboard'; 66 $createUsersOption = 'create_users'; 67 68 //set new value 69 $I->changeAgcaSelectOption(GeneralPage::$capabilityField, $createUsersOption); 70 $I->assertEquals($createUsersOption, $page->getAgcaSelectedOption(GeneralPage::$capabilityField)); 71 $page->saveSettings(); 72 $page->amOnGeneralPage(); 73 $I->assertEquals($createUsersOption, $page->getAgcaSelectedOption(GeneralPage::$capabilityField)); 74 75 //Return to default 76 $I->changeAgcaSelectOption(GeneralPage::$capabilityField, $editDashboardOption); 77 $I->assertEquals($editDashboardOption, $page->getAgcaSelectedOption(GeneralPage::$capabilityField)); 78 $page->saveSettings(); 79 $page->amOnGeneralPage(); 80 $I->assertEquals($editDashboardOption, $page->getAgcaSelectedOption(GeneralPage::$capabilityField)); 81 82 //TODO: Test if this actually affects user that does not have that capability. Login with subscriber 83 } 84 85 public function test_help_menu(AcceptanceTester $I) 86 { 87 $page = new GeneralPage($I); 88 $page->amOnGeneralPage(); 89 90 $option = 'agca_help_menu'; 91 $label = '"Help" menu'; 83 public function test_capability_field(AcceptanceTester $I) 84 { 85 // Initialization ----------------------------------------- 86 87 $dashboardPage = new WPDashboardPage($I); 88 $page = $this->generalPage->visit(); 89 90 // Prerequisites ------------------------------------------- 91 92 $page->prepareAgcaOptions([ 93 GeneralPage::$helpMenuOption => true, 94 GeneralPage::$excludeAdministratorOption =>true, 95 GeneralPage::$capabilityField => [ 96 'type' => 'select', 97 'value' => GeneralPage::$capabilityEditPosts 98 ] 99 ]); 100 101 // Assertions ------------------------------------------------ 102 103 //EDITOR SHOULD NOT SEE THE CHANGES 104 $I->logOut()->loginAsEditor(); 105 $dashboardPage->visit()->canSeeHelpOptions(); 106 107 //SUBSCRIBER SHOULD SEE THE CHANGES 108 $I->logOut()->loginAsSubscriber(); 109 $dashboardPage->visit()->canSeeHelpOptions(false); 110 111 112 $I->logOut()->loginAsAdmin(); 113 114 $page->visit(); 115 116 //Return to default capability value 117 $page->prepareAgcaOptions([ 118 GeneralPage::$capabilityField => [ 119 'type' => 'select', 120 'value' => GeneralPage::$capabilityEditDashboard 121 ] 122 ]); 123 } 124 125 public function test_exclude_administrator(AcceptanceTester $I) 126 { 127 // Initialization ----------------------------------------- 128 129 $dashboardPage = new WPDashboardPage($I); 130 $page = $this->generalPage->visit(); 131 132 $option = GeneralPage::$excludeAdministratorOption; 133 $label = GeneralPage::$excludeAdministratorOptionLabel; 134 135 136 // Prerequisites ------------------------------------------- 137 138 $page->prepareAgcaOptions([ 139 GeneralPage::$helpMenuOption => true, 140 GeneralPage::$capabilityField => [ 141 'type' => 'select', 142 'value' => GeneralPage::$capabilityEditDashboard 143 ] 144 ]); 145 146 // Assertions ------------------------------------------------ 92 147 93 148 //Assert label is correct 94 149 $I->assertEquals($label, $I->getAGCAOptionLabel($option)); 95 150 96 //Toggle hiding OFF 97 $I->uncheckAgcaOption($option); 98 $page->saveSettings(); 99 100 $page->amOnGeneralPage(); 101 $I->assertFalse($I->isAgcaOptionChecked($option)); 102 103 $dashboardPage = new WPDashboardPage($I); 104 $dashboardPage->amOnDashboardPage(); 105 $dashboardPage->canSeeHelpOptions(); 106 107 //Toggle hiding ON; 108 $page->amOnGeneralPage(); 109 $I->checkAgcaOption($option); 110 $page->saveSettings(); 111 $page->amOnGeneralPage(); 112 $I->assertTrue($I->isAgcaOptionChecked($option)); 113 114 $dashboardPage->amOnDashboardPage(); 115 $dashboardPage->canSeeHelpOptions(false); 116 } 117 118 public function test_screen_options(AcceptanceTester $I){ 119 $page = new GeneralPage($I); 120 $page->amOnGeneralPage(); 121 122 $option = 'agca_screen_options_menu'; 123 $label = '"Screen Options" menu'; 151 //Toggle OFF: Administrator is not excluded, he should see customizations 152 $page->prepareAgcaOptions([ $option => false ]); 153 $dashboardPage->visit()->canSeeHelpOptions(false); 154 155 $page->visit(); 156 157 //Toggle ON: Administrator is excluded, customizations should not affect him 158 $page->prepareAgcaOptions([ $option => true ]); 159 $dashboardPage->visit()->canSeeHelpOptions(); 160 161 //Revert back this option to defaults: 162 $page->visit(); 163 $page->prepareAgcaOptions([ $option => false ]); 164 } 165 166 public function test_help_menu(AcceptanceTester $I) 167 { 168 // Initialization ----------------------------------------- 169 170 $dashboardPage = new WPDashboardPage($I); 171 $page = $this->generalPage->visit(); 172 173 $option = GeneralPage::$helpMenuOption; 174 $label = GeneralPage::$helpMenuOptionLabel; 175 176 // Assertions ------------------------------------------------ 124 177 125 178 //Assert label is correct 126 179 $I->assertEquals($label, $I->getAGCAOptionLabel($option)); 127 180 181 //Toggle OFF 182 $page->prepareAgcaOptions([ $option => false ]); 183 $dashboardPage->visit()->canSeeHelpOptions(); 184 185 //Toggle ON; 186 $page->visit(); 187 188 $page->prepareAgcaOptions([ $option => true ]); 189 $dashboardPage->visit()->canSeeHelpOptions(false); 190 } 191 192 public function test_screen_options(AcceptanceTester $I) 193 { 194 // Initialization ----------------------------------------- 195 196 $dashboardPage = new WPDashboardPage($I); 197 $page = $this->generalPage->visit(); 198 199 $option = GeneralPage::$screenOption; 200 $label = GeneralPage::$screenOptionLabel; 201 202 // Assertions ------------------------------------------------ 203 204 //Assert label is correct 205 $I->assertEquals($label, $I->getAGCAOptionLabel($option)); 206 128 207 //Toggle hiding OFF 129 $I->uncheckAgcaOption($option); 130 $page->saveSettings(); 131 132 $page->amOnGeneralPage(); 133 $I->assertFalse($I->isAgcaOptionChecked($option)); 134 135 $dashboardPage = new WPDashboardPage($I); 136 $dashboardPage->amOnDashboardPage(); 137 $dashboardPage->canSeeScreenOptions(); 208 $page->prepareAgcaOptions([ $option => false ]); 209 $dashboardPage->visit()->canSeeScreenOptions(); 210 211 $page->visit(); 138 212 139 213 //Toggle hiding ON; 140 $page->amOnGeneralPage(); 141 $I->checkAgcaOption($option); 142 $page->saveSettings(); 143 $page->amOnGeneralPage(); 144 $I->assertTrue($I->isAgcaOptionChecked($option)); 145 146 $dashboardPage->amOnDashboardPage(); 147 $dashboardPage->canSeeScreenOptions(false); 214 $page->prepareAgcaOptions([ $option => true ]); 215 $dashboardPage->visit()->canSeeScreenOptions(false); 148 216 } 149 217 }
Note: See TracChangeset
for help on using the changeset viewer.