idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
1,700
public function updateChangelog ( string $ version ) { $ changelog = sprintf ( self :: TEMPLATE , $ version ) ; $ contents = file_get_contents ( $ this -> changelogFile ) ; $ contents = preg_replace ( "/^(\# Changelog\n\n.*?)(\n\n\#\# )/s" , '$1' . $ changelog . '## ' , $ contents ) ; file_put_contents ( $ this -> changelogFile , $ contents ) ; }
Update the CHANGELOG with the new version information .
1,701
private function getChangelogEntry ( $ filename ) : ? stdClass { $ contents = file ( $ filename ) ; if ( false === $ contents ) { throw Exception \ ChangelogFileNotFoundException :: at ( $ filename ) ; } $ data = ( object ) [ 'contents' => '' , 'index' => null , 'length' => 0 , ] ; foreach ( $ contents as $ index => $ line ) { if ( preg_match ( '/^## \d+\.\d+\.\d+/' , $ line ) ) { if ( $ data -> index ) { break ; } $ data -> contents = $ line ; $ data -> index = $ index ; $ data -> length = 1 ; continue ; } if ( ! $ data -> index ) { continue ; } $ data -> contents .= $ line ; $ data -> length += 1 ; } return $ data -> index !== null ? $ data : null ; }
Retrieves the first changelog entry in the file .
1,702
private function createTempFileWithContents ( string $ contents ) : string { $ filename = sprintf ( '%s.md' , uniqid ( 'KAC' , true ) ) ; $ path = sprintf ( '%s/%s' , sys_get_temp_dir ( ) , $ filename ) ; file_put_contents ( $ path , $ contents ) ; return $ path ; }
Creates a temporary file with the changelog contents .
1,703
private function discoverEditor ( ) : string { $ editor = getenv ( 'EDITOR' ) ; if ( $ editor ) { return $ editor ; } return isset ( $ _SERVER [ 'OS' ] ) && false !== strpos ( $ _SERVER [ 'OS' ] , 'indows' ) ? 'notepad' : 'vi' ; }
Determines the system editor command and returns it .
1,704
public function spawnEditor ( OutputInterface $ output , string $ editor , string $ filename ) : int { $ descriptorspec = [ STDIN , STDOUT , STDERR ] ; $ command = sprintf ( '%s %s' , $ editor , escapeshellarg ( $ filename ) ) ; $ output -> writeln ( sprintf ( '<info>Executing "%s"</info>' , $ command ) ) ; $ process = proc_open ( $ command , $ descriptorspec , $ pipes ) ; return proc_close ( $ process ) ; }
Spawn an editor to edit the given filename .
1,705
public function extractPsr0ClassName ( ) { $ shortName = $ this -> parseFileForPsr0ClassShortName ( ) ; return new PhpName ( ltrim ( $ this -> parseFileForPsr0NamespaceName ( ) . '\\' . $ shortName , '\\' ) , $ shortName ) ; }
Extract the PhpName for the class contained in this file assuming PSR - 0 naming .
1,706
public function changeToken ( $ originalLine , $ oldToken , $ newToken ) { $ newLine = $ this -> buffer -> getLine ( $ this -> createLineNumber ( $ originalLine ) ) ; $ newLine = preg_replace ( '!(^|[^a-z0-9])(' . preg_quote ( $ oldToken ) . ')([^a-z0-9]|$)!' , '\1' . $ newToken . '\3' , $ newLine ) ; $ this -> buffer -> replace ( $ this -> createSingleLineRange ( $ originalLine ) , array ( $ newLine ) ) ; }
Change Token in given line from old to new .
1,707
public function appendToLine ( $ originalLine , array $ lines ) { $ originalLine ++ ; $ this -> buffer -> insert ( $ this -> createLineNumber ( $ originalLine ) , $ lines ) ; }
Append new lines to an original line of the file .
1,708
public function changeLines ( $ originalLine , array $ newLines ) { $ this -> buffer -> replace ( $ this -> createSingleLineRange ( $ originalLine ) , $ newLines ) ; }
Change one line by replacing it with one or many new lines .
1,709
public function replaceLines ( $ startOriginalLine , $ endOriginalLine , array $ newLines ) { $ this -> buffer -> replace ( $ this -> createLineRange ( $ startOriginalLine , $ endOriginalLine ) , $ newLines ) ; }
Replace a range of lines with a set of new lines .
1,710
public function generateUnifiedDiff ( ) { $ builder = new PhpDiffBuilder ( ) ; return $ builder -> buildPatch ( 'a/' . $ this -> path , 'b/' . $ this -> path , $ this -> buffer ) ; }
Generate a unified diff of all operations performed on the current file .
1,711
public function contains ( Variable $ variable ) { return ( isset ( $ this -> readAccess [ $ variable -> getName ( ) ] ) || isset ( $ this -> changeAccess [ $ variable -> getName ( ) ] ) ) ; }
Does list contain the given variable?
1,712
public function isAffectedByChangesTo ( PhpName $ other ) { return $ this -> fullyQualifiedName === $ other -> fullyQualifiedName || $ this -> overlaps ( $ other ) ; }
Would this name be affected by a change to the given name?
1,713
public function add ( $ item ) { if ( $ item instanceof Hashable ) { $ this -> items [ $ item -> hashCode ( ) ] = $ item ; return ; } $ this -> items [ ( string ) $ item ] = $ item ; }
Add a new item to the set .
1,714
public function findMethodRange ( File $ file , LineRange $ range ) { $ methodStartLine = $ this -> getMethodStartLine ( $ file , $ range ) ; $ methodEndLine = $ this -> getMethodEndLine ( $ file , $ range ) ; return LineRange :: fromLines ( $ methodStartLine , $ methodEndLine ) ; }
From a range within a method find the start and end range of that method .
1,715
protected function setMessengerModels ( ) { $ config = $ this -> app -> make ( 'config' ) ; Models :: setMessageModel ( $ config -> get ( 'chatmessenger.message_model' , Message :: class ) ) ; Models :: setThreadModel ( $ config -> get ( 'chatmessenger.thread_model' , Thread :: class ) ) ; Models :: setParticipantModel ( $ config -> get ( 'chatmessenger.participant_model' , Participant :: class ) ) ; Models :: setTables ( [ 'messages' => $ config -> get ( 'chatmessenger.messages_table' , Models :: message ( ) -> getTable ( ) ) , 'participants' => $ config -> get ( 'chatmessenger.participants_table' , Models :: participant ( ) -> getTable ( ) ) , 'threads' => $ config -> get ( 'chatmessenger.threads_table' , Models :: thread ( ) -> getTable ( ) ) , ] ) ; }
Define Messenger s models in registry
1,716
protected function setUserModel ( ) { $ config = $ this -> app -> make ( 'config' ) ; $ model = $ config -> get ( 'auth.providers.users.model' , function ( ) use ( $ config ) { return $ config -> get ( 'auth.model' , $ config -> get ( 'chatmessenger.user_model' ) ) ; } ) ; Models :: setUserModel ( $ model ) ; Models :: setTables ( [ 'users' => ( new $ model ) -> getTable ( ) , ] ) ; }
Define User model in Messenger s model registry .
1,717
public function participantsUserIds ( $ userId = null ) { $ users = $ this -> participants ( ) -> select ( 'user_id' ) -> get ( ) -> map ( function ( $ participant ) { return $ participant -> user_id ; } ) ; if ( $ userId ) { $ users -> push ( $ userId ) ; } return $ users -> toArray ( ) ; }
Returns an array of user ids that are associated with the thread . Deleted participants from a thread will not be returned
1,718
public function hasMaxParticipants ( ) { $ participants = $ this -> participants ( ) ; if ( $ participants -> count ( ) > $ this -> max_participants ) { return true ; } return false ; }
Checks if the max number of participants in a thread has been reached .
1,719
protected function oooPushIt ( Message $ message , $ html = '' ) { $ thread = $ message -> thread ; $ sender = $ message -> user ; $ data = [ 'thread_id' => $ thread -> id , 'div_id' => 'thread_' . $ thread -> id , 'sender_name' => $ sender -> name , 'thread_url' => route ( 'messages.show' , [ 'id' => $ thread -> id ] ) , 'thread_subject' => $ thread -> subject , 'message' => $ message -> body , 'html' => $ html , 'text' => str_limit ( $ message -> body , 50 ) , ] ; $ recipients = $ thread -> participantsUserIds ( ) ; if ( count ( $ recipients ) > 0 ) { foreach ( $ recipients as $ recipient ) { if ( $ recipient == $ sender -> id ) { continue ; } $ pusher_resp = Pusher :: trigger ( [ 'for_user_' . $ recipient ] , 'new_message' , $ data ) ; } } return $ pusher_resp ; }
Send the new message to Pusher in order to notify users .
1,720
public function read ( $ id ) { $ thread = Thread :: find ( $ id ) ; if ( ! $ thread ) { abort ( 404 ) ; } $ thread -> markAsRead ( Auth :: id ( ) ) ; }
Mark a specific thread as read for ajax use .
1,721
public function scopeUnreadForUser ( Builder $ query , $ userId ) { return $ query -> has ( 'thread' ) -> where ( 'user_id' , '!=' , $ userId ) -> whereHas ( 'participants' , function ( Builder $ query ) use ( $ userId ) { $ query -> where ( 'user_id' , $ userId ) -> whereNull ( 'deleted_at' ) -> where ( function ( Builder $ q ) { $ q -> where ( 'last_read' , '<' , $ this -> getConnection ( ) -> raw ( $ this -> getConnection ( ) -> getTablePrefix ( ) . $ this -> getTable ( ) . '.created_at' ) ) -> orWhereNull ( 'last_read' ) ; } ) ; } ) ; }
Returns unread messages given the userId .
1,722
public function iSelectPostContentEditorMode ( string $ mode ) { $ content_editor = $ this -> edit_post_page -> getContentEditor ( ) ; $ content_editor -> setMode ( strtoupper ( $ mode ) ) ; }
Switch the mode of the post content editor .
1,723
public function iEnterContentIntoPostContentEditor ( PyStringNode $ content ) { $ content_editor = $ this -> edit_post_page -> getContentEditor ( ) ; $ content_editor -> setContent ( $ content -> getRaw ( ) ) ; }
Enter the content into the content editor .
1,724
public function postContentEditorIsInMode ( string $ mode ) { $ content_editor = $ this -> edit_post_page -> getContentEditor ( ) ; if ( strtoupper ( $ mode ) !== $ content_editor -> getMode ( ) ) { throw new ExpectationException ( sprintf ( '[W808] Content editor is in "%1$s" mode. Expected "%2$s".' , $ content_editor -> getMode ( ) , $ mode ) , $ this -> getSession ( ) -> getDriver ( ) ) ; } }
Assert the mode that the content editor is in .
1,725
public function iAmOnEditScreenForPostType ( string $ post_type , string $ post_title ) { $ post = $ this -> getContentFromTitle ( $ post_title , $ post_type ) ; $ this -> edit_post_page -> isOpen ( array ( 'id' => $ post [ 'id' ] , ) ) ; }
Assert that the edit screen for the given post and post type is displayed
1,726
public function iShouldNotSeeTheMetabox ( string $ title ) { try { $ this -> edit_post_page -> getMetaBox ( $ title ) ; } catch ( ExpectationException $ e ) { return ; } throw new ExpectationException ( sprintf ( '[W809] Metabox "%s" was found on the page, but it should not be there.' , $ title ) , $ this -> getSession ( ) -> getDriver ( ) ) ; }
Assert that the referenced metabox is not visible .
1,727
public function update ( $ id , $ args = [ ] ) { if ( $ args [ 'status' ] === 'activate' ) { activate_plugin ( $ id , '' , false , true ) ; } elseif ( $ args [ 'status' ] === 'deactivate' ) { deactivate_plugins ( $ id , true , false ) ; } }
Activate or deactivate specified plugin .
1,728
public function getPage ( string $ name ) : Page { if ( $ this -> page_object_factory === null ) { throw new RuntimeException ( '[W406] To create pages you need to pass a factory with setPageObjectFactory()' ) ; } return $ this -> page_object_factory -> createPage ( $ name ) ; }
Creates a page object from its name .
1,729
public function getElement ( string $ name ) : Element { if ( $ this -> page_object_factory === null ) { throw new RuntimeException ( '[W406] To create elements you need to pass a factory with setPageObjectFactory()' ) ; } return $ this -> page_object_factory -> createElement ( $ name ) ; }
Creates a page object element from its name .
1,730
public function wpcli ( string $ command , string $ subcommand , array $ raw_arguments = [ ] ) : array { $ arguments = implode ( ' ' , $ raw_arguments ) ; $ config = sprintf ( '--url=%s' , escapeshellarg ( $ this -> url ) ) ; if ( $ this -> path ) { $ config .= sprintf ( ' --path=%s' , escapeshellarg ( $ this -> path ) ) ; } if ( $ this -> alias ) { $ config = "@{$this->alias}" ; } $ command = "{$this->binary} {$config} --no-color {$command} {$subcommand} {$arguments}" ; $ proc = proc_open ( $ command , array ( 1 => [ 'pipe' , 'w' ] , 2 => [ 'pipe' , 'w' ] , ) , $ pipes ) ; $ stdout = trim ( stream_get_contents ( $ pipes [ 1 ] ) ) ; $ stderr = trim ( stream_get_contents ( $ pipes [ 2 ] ) ) ; fclose ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 2 ] ) ; $ exit_code = proc_close ( $ proc ) ; if ( ! $ stdout && $ stderr ) { $ stdout = $ stderr ; } if ( $ exit_code || strpos ( $ stdout , 'Warning: ' ) === 0 || strpos ( $ stdout , 'Error: ' ) === 0 ) { if ( $ exit_code === 255 && ! $ stdout ) { $ stdout = 'Unable to connect to server via SSH. Is it on?' ; } throw new UnexpectedValueException ( sprintf ( "[W102] WP-CLI driver failure in method %1\$s():\n\n%2\$s.\n\nTried to run: %3\$s\n(%4\$s)" , debug_backtrace ( ) [ 1 ] [ 'function' ] , $ stdout , $ command , $ exit_code ) ) ; } return compact ( 'stdout' , 'exit_code' ) ; }
Execute a WP - CLI command .
1,731
protected function verifyPage ( ) { $ url = $ this -> getSession ( ) -> getCurrentUrl ( ) ; if ( strrpos ( $ url , $ this -> path ) !== false ) { return ; } throw new ExpectationException ( sprintf ( '[W401] Expected screen is the wp-admin dashboard, instead on "%1$s".' , $ url ) , $ this -> getDriver ( ) ) ; }
Asserts the current screen is the Dashboard .
1,732
public function getSidebar ( $ sidebar_name ) { $ registered_sidebars = json_decode ( $ this -> drivers -> getDriver ( ) -> wpcli ( 'sidebar' , 'list' , [ '--format=json' , ] ) [ 'stdout' ] ) ; $ sidebar_id = null ; foreach ( $ registered_sidebars as $ sidebar ) { if ( $ sidebar_name === $ sidebar -> name ) { $ sidebar_id = $ sidebar -> id ; break ; } } if ( $ sidebar_id === null ) { throw new UnexpectedValueException ( sprintf ( '[W506] Sidebar "%s" does not exist' , $ sidebar_name ) ) ; } return $ sidebar_id ; }
Gets a sidebar ID from its human - readable name
1,733
public function getPlugin ( $ name ) { foreach ( array_keys ( get_plugins ( ) ) as $ file ) { if ( $ file === "{$name}.php" || ( $ name && $ file === $ name ) || ( dirname ( $ file ) === $ name && $ name !== '.' ) ) { return $ file ; } } return '' ; }
Get information about a plugin .
1,734
public function update ( $ id , $ args = [ ] ) { $ bin = '' ; $ command_args = sprintf ( '--no-defaults --no-auto-rehash --host=%1$s --user=%2$s --database=%3$s --execute=%4$s' , DB_HOST , DB_USER , DB_NAME , escapeshellarg ( sprintf ( 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %1$s; COMMIT;' , $ args [ 'path' ] ) ) ) ; $ old_pwd = getenv ( 'MYSQL_PWD' ) ; putenv ( 'MYSQL_PWD=' . DB_PASSWORD ) ; if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) === 'WIN' ) { $ bin = '/usr/bin/env ' ; } $ proc = proc_open ( "{$bin}mysql {$command_args}" , array ( 1 => [ 'pipe' , 'w' ] , 2 => [ 'pipe' , 'w' ] , ) , $ pipes ) ; $ stdout = trim ( stream_get_contents ( $ pipes [ 1 ] ) ) ; $ stderr = trim ( stream_get_contents ( $ pipes [ 2 ] ) ) ; fclose ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 2 ] ) ; $ exit_code = proc_close ( $ proc ) ; putenv ( 'MYSQL_PWD=' . $ old_pwd ) ; if ( ! $ stdout && $ stderr ) { $ stdout = $ stderr ; } if ( $ exit_code || strpos ( $ stdout , 'Warning: ' ) === 0 || strpos ( $ stdout , 'Error: ' ) === 0 ) { throw new RuntimeException ( sprintf ( "[W607] Could not import database in method %1\$s(): \n\n%2\$s.\n(%3\$s)" , debug_backtrace ( ) [ 1 ] [ 'function' ] , $ stdout , $ exit_code ) ) ; } \ wp_cache_flush ( ) ; }
Import site database .
1,735
public function update ( $ id , $ args = [ ] ) { $ theme = wp_get_theme ( $ id ) ; if ( ! $ theme -> exists ( ) ) { throw new UnexpectedValueException ( sprintf ( '[W612] Could not find theme %s' , $ id ) ) ; } switch_theme ( $ theme -> get_template ( ) ) ; }
Switch active theme .
1,736
public function locatePath ( $ path ) { if ( stripos ( $ path , 'http' ) === 0 ) { return $ path ; } $ url = $ this -> getMinkParameter ( 'base_url' ) ; if ( strpos ( $ path , 'wp-admin' ) !== false || strpos ( $ path , '.php' ) !== false ) { $ url = $ this -> getWordpressParameter ( 'site_url' ) ; } return rtrim ( $ url , '/' ) . '/' . ltrim ( $ path , '/' ) ; }
Build URL based on provided path .
1,737
public function getWordpressParameter ( string $ name ) { return ! empty ( $ this -> wordpress_parameters [ $ name ] ) ? $ this -> wordpress_parameters [ $ name ] : null ; }
Get a specific WordPress parameter .
1,738
public function clickToolbarLink ( string $ link ) { $ link_parts = array_map ( 'trim' , preg_split ( '/(?<!\\\\)>/' , $ link ) ) ; $ click_node = false ; $ first_level_items = $ this -> findAll ( 'css' , '.ab-top-menu > li' ) ; foreach ( $ first_level_items as $ first_level_item ) { if ( ! $ this -> elementIsTargetLink ( $ first_level_item , $ link_parts [ 0 ] ) ) { continue ; } if ( count ( $ link_parts ) > 1 ) { $ click_node = $ this -> getSubmenuLinkNode ( $ first_level_item , $ link_parts [ 1 ] ) ; } else { $ click_node = $ first_level_item -> find ( 'css' , 'a' ) ; } break ; } if ( false === $ click_node ) { throw new ExpectationException ( sprintf ( '[W403] Toolbar link "%s" could not be found' , $ link ) , $ this -> getDriver ( ) ) ; } $ click_node -> click ( ) ; }
Click a specific item in the toolbar .
1,739
protected function elementIsTargetLink ( NodeElement $ element , string $ link_text ) : bool { $ current_item_name = strtolower ( $ element -> find ( 'css' , '.ab-item' ) -> getText ( ) ) ; switch ( strtolower ( $ link_text ) ) { case 'wordpress' : $ is_link = $ element -> getAttribute ( 'id' ) === 'wp-admin-bar-wp-logo' ; break ; case 'updates' : $ is_link = $ element -> getAttribute ( 'id' ) === 'wp-admin-bar-updates' ; break ; case 'comments' : $ is_link = $ element -> getAttribute ( 'id' ) === 'wp-admin-bar-comments' ; break ; default : $ is_link = strtolower ( $ link_text ) === $ current_item_name ; } return $ is_link ; }
Determines whether the link name refers to the given NodeElement .
1,740
protected function getSubmenuLinkNode ( NodeElement $ first_level_item , string $ link_text ) { $ second_level_items = $ first_level_item -> findAll ( 'css' , 'ul li a' ) ; $ submenu_link_node = null ; foreach ( $ second_level_items as $ second_level_item ) { $ current_item_name = Util \ stripTagsAndContent ( $ second_level_item -> getHtml ( ) ) ; if ( strtolower ( $ link_text ) !== strtolower ( $ current_item_name ) ) { continue ; } $ id = $ first_level_item -> getAttribute ( 'id' ) ; try { $ element_exists = $ this -> getSession ( ) -> evaluateScript ( 'return document.getElementById("' . $ id . '");' ) ; if ( $ element_exists !== null ) { $ this -> getSession ( ) -> executeScript ( 'document.getElementById("' . $ id . '").classList.add("hover");' ) ; } } catch ( UnsupportedDriverActionException $ e ) { } $ submenu_link_node = $ second_level_item ; break ; } return $ submenu_link_node ; }
Returns a second - level toolbar NodeElement corresponding to the link text under the given first - level toolbar NodeElement .
1,741
public function search ( string $ text ) { $ search = $ this -> find ( 'css' , '#adminbarsearch' ) ; if ( ! $ search ) { throw new ExpectationException ( '[W404] Search field in the toolbar could not be found' , $ this -> getDriver ( ) ) ; } try { $ search -> find ( 'css' , '#adminbar-search' ) -> press ( ) ; $ search -> find ( 'css' , '#adminbar-search' ) -> focus ( ) ; $ search -> fillField ( 'adminbar-search' , $ text ) ; $ search -> find ( 'css' , '#adminbar-search' ) -> focus ( ) ; } catch ( UnsupportedDriverActionException $ e ) { $ search -> fillField ( 'adminbar-search' , $ text ) ; } $ search -> submit ( ) ; }
Searches for the given text using the toolbar search field .
1,742
public function logOut ( ) { try { $ element_exists = $ this -> getSession ( ) -> evaluateScript ( 'return document.getElementById("wp-admin-bar-my-account");' ) ; if ( $ element_exists !== null ) { $ this -> getSession ( ) -> executeScript ( 'document.getElementById("wp-admin-bar-my-account").classList.add("hover");' ) ; $ this -> find ( 'css' , '#wp-admin-bar-logout a' ) -> click ( ) ; } } catch ( UnsupportedDriverActionException $ e ) { $ this -> find ( 'css' , '#wp-admin-bar-logout a' ) -> click ( ) ; } }
Logs - out using the toolbar log - out link .
1,743
protected function verifyLoginPage ( ) { $ session = $ this -> verifySession ( ) ; $ url = $ session -> getCurrentUrl ( ) ; if ( false === strrpos ( $ url , $ this -> path ) ) { throw new ExpectationException ( sprintf ( 'Expected screen is the wp-login form, instead on "%1$s".' , $ url ) , $ this -> getDriver ( ) ) ; } $ page = $ session -> getPage ( ) ; $ login_form_selector = '#loginform' ; $ login_form = $ page -> find ( 'css' , $ login_form_selector ) ; if ( null === $ login_form ) { throw new ExpectationException ( sprintf ( 'Expected to find the login form with the selector "%1$s" at the current URL "%2$s".' , $ login_form_selector , $ url ) , $ this -> getDriver ( ) ) ; } }
Asserts the current screen is the login page .
1,744
public function setUserName ( string $ username ) { $ session = $ this -> verifySession ( ) ; $ this -> verifyLoginPage ( ) ; $ page = $ session -> getPage ( ) ; $ user_login_field = $ page -> find ( 'css' , '#user_login' ) ; try { $ user_login_field -> focus ( ) ; } catch ( UnsupportedDriverActionException $ e ) { } $ user_login_field -> setValue ( $ username ) ; $ page -> fillField ( 'user_login' , $ username ) ; try { $ session -> executeScript ( "document.getElementById('user_login').value='$username'" ) ; } catch ( UnsupportedDriverActionException $ e ) { } $ username_actual = $ user_login_field -> getValue ( ) ; if ( $ username_actual !== $ username ) { throw new ExpectationException ( sprintf ( 'Expected the username field to be "%1$s", found "%2$s".' , $ username , $ $ username_actual ) , $ this -> getDriver ( ) ) ; } }
Fills the user_login field of the login form with a given username .
1,745
public function setUserPassword ( string $ password ) { $ session = $ this -> verifySession ( ) ; $ this -> verifyLoginPage ( ) ; $ page = $ session -> getPage ( ) ; $ user_pass_field = $ page -> find ( 'css' , '#user_pass' ) ; try { $ user_pass_field -> focus ( ) ; } catch ( UnsupportedDriverActionException $ e ) { } $ user_pass_field -> setValue ( $ password ) ; $ page -> fillField ( 'user_pass' , $ password ) ; try { $ session -> executeScript ( "document.getElementById('user_pass').value='$password'" ) ; } catch ( UnsupportedDriverActionException $ e ) { } $ password_actual = $ user_pass_field -> getValue ( ) ; if ( $ password_actual !== $ password ) { throw new ExpectationException ( sprintf ( 'Expected the password field to be "%1$s", found "%2$s".' , $ password , $ $ password_actual ) , $ this -> getDriver ( ) ) ; } }
Fills the user_pass field of the login form with a given password .
1,746
public function submitLoginForm ( ) { $ session = $ this -> verifySession ( ) ; $ this -> verifyLoginPage ( ) ; $ page = $ session -> getPage ( ) ; $ submit_button = $ page -> find ( 'css' , '#wp-submit' ) ; try { $ submit_button -> focus ( ) ; } catch ( UnsupportedDriverActionException $ e ) { } $ submit_button -> click ( ) ; }
Submit the WordPress login form
1,747
protected function verifySession ( ) { $ session = $ this -> getSession ( ) ; if ( ! $ session -> isStarted ( ) ) { $ session -> start ( ) ; } if ( 'about:blank' === $ session -> getCurrentUrl ( ) ) { $ session -> visit ( '/' ) ; } return $ session ; }
Verify and return a properly started Mink session
1,748
public function clickMenuItem ( string $ item ) { $ click_node = false ; $ first_level_items = $ this -> findAll ( 'css' , 'li.menu-top' ) ; $ items = array_map ( 'trim' , preg_split ( '/(?<!\\\\)>/' , $ item ) ) ; foreach ( $ first_level_items as $ first_level_item ) { $ item_name = Util \ stripTagsAndContent ( $ first_level_item -> find ( 'css' , '.wp-menu-name' ) -> getHtml ( ) ) ; if ( strtolower ( $ items [ 0 ] ) !== strtolower ( $ item_name ) ) { continue ; } if ( isset ( $ items [ 1 ] ) ) { $ second_level_items = $ first_level_item -> findAll ( 'css' , 'ul li a' ) ; foreach ( $ second_level_items as $ second_level_item ) { $ item_name = Util \ stripTagsAndContent ( $ second_level_item -> getHtml ( ) ) ; if ( strtolower ( $ items [ 1 ] ) !== strtolower ( $ item_name ) ) { continue ; } try { $ first_level_item -> find ( 'css' , 'a.menu-top' ) -> focus ( ) ; } catch ( UnsupportedDriverActionException $ e ) { } $ click_node = $ second_level_item ; break ; } } else { $ click_node = $ first_level_item -> find ( 'css' , 'a' ) ; } break ; } if ( false === $ click_node ) { throw new RuntimeException ( '[W405] Menu item could not be found' ) ; } $ click_node -> click ( ) ; }
Click a specific item in the admin menu .
1,749
public function registerDriverElement ( string $ name , ElementInterface $ element , string $ driver_name ) { $ this -> getDriver ( $ driver_name , 'skip bootstrap' ) -> registerElement ( $ name , $ element ) ; }
Register a new driver element .
1,750
public function getSetting ( $ name ) { return ! empty ( $ this -> settings [ $ name ] ) ? $ this -> settings [ $ name ] : null ; }
Return the value of an internal setting .
1,751
public function loggedIn ( ) : bool { $ session = $ this -> getSession ( ) ; if ( ! $ session -> isStarted ( ) ) { $ session -> start ( ) ; return false ; } $ page = $ session -> getPage ( ) ; try { $ body_element = $ page -> find ( 'css' , 'body' ) ; if ( null === $ body_element ) { return false ; } $ is_logged_in = ( $ body_element -> hasClass ( 'logged-in' ) || $ body_element -> hasClass ( 'wp-admin' ) ) ; return $ is_logged_in ; } catch ( DriverException $ e ) { } return false ; }
Determine if the current user is logged in or not .
1,752
protected function getExistingMatchingUser ( array $ args ) { $ user_id = $ this -> getUserIdFromLogin ( $ args [ 'user_login' ] ) ; $ user = $ this -> getDriver ( ) -> user -> get ( $ user_id ) ; if ( array_key_exists ( 'role' , $ args ) ) { $ this -> checkUserHasRole ( $ user , $ args [ 'role' ] ) ; } foreach ( $ args as $ parameter => $ value ) { if ( $ parameter === 'password' ) { continue ; } if ( $ this -> isValidUserParameter ( $ parameter ) && $ user -> $ parameter !== $ args [ $ parameter ] ) { throw new UnexpectedValueException ( '[W804] User with login: ' . $ user -> user_login . 'exists, but ' . $ parameter . ' is ' . $ user -> $ parameter . ' not ' . $ args [ $ parameter ] . 'which was specified' ) ; } } return $ user ; }
Get a user which matches all parameters .
1,753
protected function checkUserHasRole ( $ user , string $ role ) : bool { if ( ! in_array ( $ role , $ user -> roles , true ) ) { $ message = sprintf ( '[W804] User with login: %s exists, but role %s is not in the list of applied roles: %s' , $ user -> user_login , $ role , $ user -> roles ) ; throw new \ UnexpectedValueException ( $ message ) ; } return true ; }
Checks to see if the user has an assigned role or not .
1,754
protected function isValidUserParameter ( string $ user_parameter ) : bool { $ validUserParameters = array ( 'id' , 'user_login' , 'display_name' , 'user_email' , 'user_registered' , 'roles' , 'user_nicename' , 'user_url' , 'user_activation_key' , 'user_status' , 'url' ) ; return in_array ( strtolower ( $ user_parameter ) , $ validUserParameters , true ) ; }
Checks to see if the passed in parameter applies to a user or not .
1,755
public function getUserIdFromLogin ( string $ username ) : int { return ( int ) $ this -> getDriver ( ) -> user -> get ( $ username , [ 'by' => 'login' ] ) -> ID ; }
Get a user s ID from their username .
1,756
public function getUserDataFromUsername ( string $ data , string $ username ) { return $ this -> getDriver ( ) -> user -> get ( $ username , [ 'by' => 'login' ] ) -> { $ data } ; }
Get a piece of user data from their username .
1,757
public function configure ( ArrayNodeDefinition $ builder ) { $ builder -> children ( ) -> enumNode ( 'default_driver' ) -> values ( [ 'wpcli' , 'wpapi' , 'wpphp' , 'blackbox' ] ) -> defaultValue ( 'wpcli' ) -> end ( ) -> scalarNode ( 'path' ) -> defaultValue ( '' ) -> end ( ) -> scalarNode ( 'site_url' ) -> defaultValue ( '%mink.base_url%' ) -> end ( ) -> arrayNode ( 'users' ) -> prototype ( 'array' ) -> children ( ) -> variableNode ( 'roles' ) -> defaultValue ( [ 'administrator' ] ) -> end ( ) -> scalarNode ( 'username' ) -> defaultValue ( 'admin' ) -> end ( ) -> scalarNode ( 'password' ) -> defaultValue ( 'admin' ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> arrayNode ( 'wpcli' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> scalarNode ( 'alias' ) -> end ( ) -> scalarNode ( 'binary' ) -> defaultValue ( 'wp' ) -> end ( ) -> end ( ) -> end ( ) -> arrayNode ( 'wpphp' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> end ( ) -> end ( ) -> arrayNode ( 'blackbox' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> end ( ) -> end ( ) -> arrayNode ( 'database' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> booleanNode ( 'restore_after_test' ) -> defaultFalse ( ) -> end ( ) -> scalarNode ( 'backup_path' ) -> end ( ) -> end ( ) -> end ( ) -> arrayNode ( 'permalinks' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> scalarNode ( 'author_archive' ) -> defaultValue ( 'author/%s/' ) -> end ( ) -> end ( ) -> end ( ) -> arrayNode ( 'internal' ) -> addDefaultsIfNotSet ( ) -> end ( ) -> end ( ) -> end ( ) ; }
Declare configuration options for the extension .
1,758
public function load ( ContainerBuilder $ container , array $ config ) { $ loader = new YamlFileLoader ( $ container , new FileLocator ( __DIR__ . '/config' ) ) ; $ loader -> load ( 'services.yml' ) ; if ( $ config [ 'default_driver' ] === 'wpapi' ) { $ config [ 'default_driver' ] = 'wpphp' ; } $ container -> setParameter ( 'wordpress.wordpress.default_driver' , $ config [ 'default_driver' ] ) ; $ container -> setParameter ( 'wordpress.path' , $ config [ 'path' ] ) ; $ container -> setParameter ( 'wordpress.parameters' , $ config ) ; $ this -> setupWpcliDriver ( $ loader , $ container , $ config ) ; $ this -> setupWpphpDriver ( $ loader , $ container , $ config ) ; $ this -> setupBlackboxDriver ( $ loader , $ container , $ config ) ; }
Load extension services into ServiceContainer .
1,759
protected function setupWpcliDriver ( FileLoader $ loader , ContainerBuilder $ container , array $ config ) { if ( ! isset ( $ config [ 'wpcli' ] ) ) { return ; } $ loader -> load ( 'drivers/wpcli.yml' ) ; $ config [ 'wpcli' ] [ 'alias' ] = isset ( $ config [ 'wpcli' ] [ 'alias' ] ) ? $ config [ 'wpcli' ] [ 'alias' ] : '' ; $ container -> setParameter ( 'wordpress.driver.wpcli.alias' , $ config [ 'wpcli' ] [ 'alias' ] ) ; $ config [ 'wpcli' ] [ 'path' ] = isset ( $ config [ 'path' ] ) ? $ config [ 'path' ] : '' ; $ container -> setParameter ( 'wordpress.driver.wpcli.path' , $ config [ 'path' ] ) ; $ config [ 'wpcli' ] [ 'binary' ] = isset ( $ config [ 'wpcli' ] [ 'binary' ] ) ? $ config [ 'wpcli' ] [ 'binary' ] : null ; $ container -> setParameter ( 'wordpress.driver.wpcli.binary' , $ config [ 'wpcli' ] [ 'binary' ] ) ; }
Load settings for the WP - CLI driver .
1,760
protected function setupWpphpDriver ( FileLoader $ loader , ContainerBuilder $ container , array $ config ) { if ( ! isset ( $ config [ 'wpphp' ] ) ) { return ; } $ loader -> load ( 'drivers/wpphp.yml' ) ; $ config [ 'wpphp' ] [ 'path' ] = isset ( $ config [ 'path' ] ) ? $ config [ 'path' ] : '' ; $ container -> setParameter ( 'wordpress.driver.wpphp.path' , $ config [ 'wpphp' ] [ 'path' ] ) ; }
Load settings for the WordPress PHP driver .
1,761
protected function setupBlackboxDriver ( FileLoader $ loader , ContainerBuilder $ container , array $ config ) { if ( ! isset ( $ config [ 'blackbox' ] ) ) { return ; } $ loader -> load ( 'drivers/blackbox.yml' ) ; }
Load settings for the blackbox driver .
1,762
protected function setPageObjectNamespaces ( ContainerBuilder $ container ) { $ pages = $ container -> getParameter ( 'sensio_labs.page_object_extension.namespaces.page' ) ; $ pages [ ] = 'PaulGibbs\WordpressBehatExtension\PageObject' ; $ elements = $ container -> getParameter ( 'sensio_labs.page_object_extension.namespaces.element' ) ; $ elements [ ] = 'PaulGibbs\WordpressBehatExtension\PageObject\Element' ; $ container -> setParameter ( 'sensio_labs.page_object_extension.namespaces.page' , $ pages ) ; $ container -> setParameter ( 'sensio_labs.page_object_extension.namespaces.element' , $ elements ) ; }
Tell Page Object Extension the namespace of our page objects
1,763
protected function injectSiteUrlIntoPageObjects ( ContainerBuilder $ container ) { $ page_parameters = $ container -> getParameter ( 'sensio_labs.page_object_extension.page_factory.page_parameters' ) ; $ page_parameters = $ container -> getParameterBag ( ) -> resolveValue ( $ page_parameters ) ; $ page_parameters [ 'site_url' ] = $ container -> getParameter ( 'wordpress.parameters' ) [ 'site_url' ] ; $ container -> setParameter ( 'sensio_labs.page_object_extension.page_factory.page_parameters' , $ page_parameters ) ; }
Adds the WordPress site url as a page parameter into page objects .
1,764
public function initializeContext ( Context $ context ) { if ( ! $ context instanceof WordpressAwareInterface ) { return ; } $ context -> setWordpress ( $ this -> wordpress ) ; $ context -> setWordpressParameters ( $ this -> parameters ) ; }
Prepare everything that the Context needs .
1,765
public function maybeBackupDatabase ( BeforeScenarioScope $ scope ) { $ db = $ this -> getWordpressParameter ( 'database' ) ; if ( ! $ db [ 'restore_after_test' ] ) { return ; } $ backup_file = $ this -> getWordpress ( ) -> getSetting ( 'database_backup_file' ) ; if ( $ backup_file ) { return ; } $ file = ! empty ( $ db [ 'backup_path' ] ) ? $ db [ 'backup_path' ] : '' ; if ( ! $ file || ! is_file ( $ file ) || ! is_readable ( $ file ) ) { $ file = $ this -> exportDatabase ( [ 'path' => $ file ] ) ; } $ this -> getWordpress ( ) -> setSetting ( 'database_backup_file' , $ file ) ; }
If database . restore_after_test is set and a scenario is tagged db create a database backup .
1,766
public function fixToolbar ( ) { $ driver = $ this -> getSession ( ) -> getDriver ( ) ; if ( ! $ driver instanceof Selenium2Driver || ! $ driver -> getWebDriverSession ( ) ) { return ; } try { $ this -> getSession ( ) -> getDriver ( ) -> executeScript ( 'if (document.getElementById("wpadminbar")) { document.getElementById("wpadminbar").style.position="absolute"; if (document.getElementsByTagName("body")[0].className.match(/wp-admin/)) { document.getElementById("wpadminbar").style.top="-32px"; } };' ) ; } catch ( \ Exception $ e ) { } }
When using the Selenium driver position the admin bar to the top of the page not fixed to the screen . Otherwise the admin toolbar can hide clickable elements .
1,767
public function maybeRestoreDatabase ( AfterScenarioScope $ scope ) { $ db = $ this -> getWordpressParameter ( 'database' ) ; if ( ! $ db [ 'restore_after_test' ] ) { return ; } $ file = $ this -> getWordpress ( ) -> getSetting ( 'database_backup_file' ) ; if ( ! $ file ) { return ; } $ this -> importDatabase ( [ 'path' => $ file ] ) ; }
If database . restore_after_test is set and scenario is tagged db restore the database from a backup .
1,768
public function createTerm ( string $ term , string $ taxonomy , array $ args = [ ] ) : array { $ args [ 'taxonomy' ] = $ taxonomy ; $ args [ 'term' ] = $ term ; $ term = $ this -> getDriver ( ) -> term -> create ( $ args ) ; return array ( 'id' => $ term -> term_id , 'slug' => $ term -> slug ) ; }
Create a term in a taxonomy .
1,769
public function deleteTerm ( int $ term_id , string $ taxonomy ) { $ this -> getDriver ( ) -> term -> delete ( $ term_id , compact ( $ taxonomy ) ) ; }
Delete a term from a taxonomy .
1,770
public function getHeaderText ( ) : string { $ header = $ this -> getHeaderElement ( ) ; $ header_text = $ header -> getText ( ) ; $ header_link = $ header -> find ( 'css' , 'a' ) ; if ( $ header_link ) { $ header_text = trim ( str_replace ( $ header_link -> getText ( ) , '' , $ header_text ) ) ; } return $ header_text ; }
Returns the text in the header tag .
1,771
public function assertHasHeader ( string $ expected ) { $ actual = $ this -> getHeaderText ( ) ; if ( $ expected === $ actual ) { return ; } throw new ExpectationException ( sprintf ( '[W402] Expected screen header "%1$s", found "%2$s".' , $ expected , $ actual ) , $ this -> getDriver ( ) ) ; }
Asserts the text in the header tag matches the given text .
1,772
protected function getHeaderElement ( ) { $ header2 = $ this -> find ( 'css' , '.wrap > h2' ) ; $ header1 = $ this -> find ( 'css' , '.wrap > h1' ) ; if ( $ header1 ) { return $ header1 ; } elseif ( $ header2 ) { return $ header2 ; } throw new ExpectationException ( '[W402] Header could not be found' , $ this -> getDriver ( ) ) ; }
Get the text in the header tag .
1,773
public function clickLinkInHeader ( string $ link ) { $ header_link = $ this -> find ( 'css' , '.page-title-action' ) ; if ( $ header_link -> getText ( ) === $ link ) { $ header_link -> click ( ) ; } else { $ this -> getHeaderElement ( ) -> clickLink ( $ link ) ; } }
Click a link within the page header tag .
1,774
protected function makeSurePathIsAbsolute ( $ path ) : string { $ site_url = rtrim ( $ this -> getParameter ( 'site_url' ) , '/' ) . '/' ; if ( 0 !== strpos ( $ path , 'http' ) ) { return $ site_url . ltrim ( $ path , '/' ) ; } else { return $ path ; } }
We use WordHat s site_url property rather than Mink s base_url property to get the correct URL to wp - admin wp - login . php etc .
1,775
protected function unmaskUrl ( array $ url_parameters ) : string { $ url = $ this -> getPath ( ) ; foreach ( $ url_parameters as $ parameter => $ value ) { $ url = str_replace ( sprintf ( '{%s}' , $ parameter ) , $ value , $ url ) ; } return $ url ; }
Insert values for placeholders in the page s path .
1,776
public function deleteComment ( int $ comment_id , array $ args = [ ] ) { $ this -> getDriver ( ) -> comment -> delete ( $ comment_id , $ args ) ; }
Delete specified comment .
1,777
public function iShouldSeeTextInToolbar ( string $ text ) { $ toolbar = $ this -> getElement ( 'Toolbar' ) ; $ actual = $ toolbar -> getText ( ) ; $ regex = '/' . preg_quote ( $ text , '/' ) . '/ui' ; if ( ! preg_match ( $ regex , $ actual ) ) { $ message = sprintf ( '[W806] The text "%s" was not found in the toolbar' , $ text ) ; throw new ElementTextException ( $ message , $ this -> getSession ( ) -> getDriver ( ) , $ toolbar ) ; } }
Clicks the specified link in the toolbar .
1,778
public function theUsernameShouldBe ( string $ username ) { $ toolbar = $ this -> getElement ( 'Toolbar' ) ; $ actual = $ toolbar -> getAuthenticatedUserText ( ) ; if ( $ username !== $ actual ) { $ message = sprintf ( '[W807] Toolbar shows authenticated user is "%1$s", not "%2$s"' , $ actual , $ username ) ; throw new ElementTextException ( $ message , $ this -> getSession ( ) -> getDriver ( ) , $ toolbar ) ; } }
Checks the authenticated user show in the toolbar .
1,779
public function createContent ( array $ args ) : array { $ post = $ this -> getDriver ( ) -> content -> create ( $ args ) ; return array ( 'id' => ( int ) $ post -> ID , 'slug' => $ post -> post_name , 'url' => $ post -> url , ) ; }
Create content .
1,780
public function getContentFromTitle ( string $ title , string $ post_type = '' ) : array { $ post = $ this -> getDriver ( ) -> content -> get ( $ title , [ 'by' => 'title' , 'post_type' => $ post_type ] ) ; return array ( 'id' => ( int ) $ post -> ID , 'slug' => $ post -> post_name , 'url' => $ post -> url , ) ; }
Get content from its title .
1,781
public function deleteContent ( int $ content_id , array $ args = [ ] ) { $ this -> getDriver ( ) -> content -> delete ( $ content_id , $ args ) ; }
Delete specified content .
1,782
public function iGoToMenuItem ( string $ item ) { $ adminMenu = $ this -> admin_page -> getMenu ( ) ; $ adminMenu -> clickMenuItem ( $ item ) ; }
Go to a given screen on the admin menu .
1,783
public function iShouldSeeMessageThatSays ( string $ type , string $ message ) { $ selector = 'div.notice' ; if ( $ type === 'error' ) { $ selector .= '.error' ; } else { $ selector .= '.updated' ; } $ this -> assertSession ( ) -> elementTextContains ( 'css' , $ selector , $ message ) ; }
Check the specified notification is on - screen .
1,784
public function addWidgetToSidebar ( string $ widget_name , string $ sidebar_id , array $ args ) { $ this -> getDriver ( ) -> widget -> addToSidebar ( $ widget_name , $ sidebar_id , $ args ) ; }
Adds a widget to the sidebar with the specified arguments .
1,785
public function generateClass ( Suite $ suite , $ context_class ) { $ fqn = $ context_class ; $ namespace = '' ; $ pos = strrpos ( $ fqn , '\\' ) ; if ( $ pos ) { $ context_class = substr ( $ fqn , $ pos + 1 ) ; $ namespace = sprintf ( 'namespace %s;%s' , substr ( $ fqn , 0 , $ pos ) , PHP_EOL . PHP_EOL ) ; } return strtr ( static :: $ template , array ( '{namespace}' => $ namespace , '{class_name}' => $ context_class , ) ) ; }
Generate context class code .
1,786
public function thereArePosts ( TableNode $ posts ) { foreach ( $ posts -> getHash ( ) as $ post ) { $ this -> createContent ( $ this -> parseArgs ( $ post ) ) ; } }
Create content of the given type .
1,787
public function iAmViewingBlogPost ( $ post_data_or_title ) { if ( $ post_data_or_title instanceof TableNode ) { $ post_data_hash = $ post_data_or_title -> getHash ( ) ; if ( count ( $ post_data_hash ) > 1 ) { throw new UnexpectedValueException ( '[W810] "Given I am viewing a post:" step must only contain one post' ) ; } $ post = $ this -> createContent ( $ this -> parseArgs ( $ post_data_hash [ 0 ] ) ) ; } else { $ post = $ this -> getContentFromTitle ( $ post_data_or_title ) ; } $ this -> visitPath ( $ post [ 'url' ] ) ; }
Create content and go to it in the browser .
1,788
public function setMode ( string $ mode ) { if ( self :: VISUAL === $ mode ) { $ this -> find ( 'css' , '#content-tmce' ) -> press ( ) ; } else { $ this -> find ( 'css' , '#content-html' ) -> press ( ) ; } }
Sets the mode of the WYSIWYG editor .
1,789
public function setContent ( string $ content ) { if ( self :: VISUAL === $ this -> getMode ( ) ) { $ this -> getDriver ( ) -> switchToIFrame ( self :: $ wysiwyg_iframe_id ) ; $ this -> getDriver ( ) -> executeScript ( ';document.body.innerHTML = \'<p>' . addslashes ( htmlspecialchars ( $ content ) ) . '</p>\';' ) ; $ this -> getDriver ( ) -> switchToIFrame ( ) ; } else { $ this -> fillField ( self :: $ textarea_id , $ content ) ; } }
Enter the given content into the WYSIWYG editor
1,790
public function prepareWordpressDriver ( $ event ) { $ drivers = array_keys ( $ this -> wordpress -> getDrivers ( ) ) ; $ driver = $ this -> parameters [ 'default_driver' ] ; $ tags = array_merge ( $ event -> getFeature ( ) -> getTags ( ) , $ event -> getScenario ( ) -> getTags ( ) ) ; foreach ( $ tags as $ tag ) { if ( ! in_array ( $ tag , $ drivers , true ) ) { continue ; } $ driver = $ tag ; break ; } $ this -> wordpress -> setDefaultDriverName ( $ driver ) ; }
Configures the driver to use before each scenario or outline .
1,791
protected function getUserByName ( string $ username ) { $ found_user = null ; $ users = $ this -> getWordpressParameter ( 'users' ) ; foreach ( $ users as $ user ) { if ( $ username === $ user [ 'username' ] ) { $ found_user = $ user ; break ; } } if ( $ found_user === null ) { throw new RuntimeException ( "[W801] User not found for name \"{$username}\"" ) ; } return $ found_user ; }
Verify a username is valid and get the matching user information .
1,792
public function thereAreUsers ( TableNode $ users ) { $ params = $ this -> getWordpressParameters ( ) ; foreach ( $ users -> getHash ( ) as $ user ) { if ( ! isset ( $ user [ 'user_pass' ] ) ) { $ user [ 'user_pass' ] = $ this -> getRandomString ( ) ; } $ this -> createUser ( $ user [ 'user_login' ] , $ user [ 'user_email' ] , $ user ) ; $ params [ 'users' ] [ ] = array ( 'roles' => $ this -> getUserDataFromUsername ( 'roles' , $ user [ 'user_login' ] ) , 'username' => $ user [ 'user_login' ] , 'password' => $ user [ 'user_pass' ] , ) ; } $ this -> setWordpressParameters ( $ params ) ; }
Add specified user accounts .
1,793
public function iAmViewingAuthorArchive ( string $ username ) { $ found_user = $ this -> getUserByName ( $ username ) ; $ this -> visitPath ( sprintf ( $ this -> getWordpressParameters ( ) [ 'permalinks' ] [ 'author_archive' ] , $ this -> getUserDataFromUsername ( 'user_nicename' , $ found_user [ 'username' ] ) ) ) ; }
Go to a user s author archive page .
1,794
public function getSidebar ( $ sidebar_name ) { global $ wp_registered_sidebars ; $ sidebar_id = null ; foreach ( $ wp_registered_sidebars as $ registered_sidebar_id => $ registered_sidebar ) { if ( $ sidebar_name === $ registered_sidebar [ 'name' ] ) { $ sidebar_id = $ registered_sidebar_id ; break ; } } if ( $ sidebar_id === null ) { throw new UnexpectedValueException ( sprintf ( '[W614] Sidebar "%s" does not exist' , $ sidebar_name ) ) ; } return $ sidebar_id ; }
Gets a sidebar ID from its human - readable name .
1,795
public function getMetaBox ( string $ title ) : NodeElement { $ metaboxes = $ this -> findAll ( 'css' , '.postbox' ) ; if ( $ metaboxes ) { foreach ( $ metaboxes as $ metabox ) { if ( $ metabox -> find ( 'css' , 'h2' ) -> getText ( ) === $ title ) { return $ metabox ; } } } throw new ExpectationException ( sprintf ( '[W400] Metabox "%s" not found on the screen.' , $ title ) , $ this -> getDriver ( ) ) ; }
Get the node element for the specified metabox .
1,796
public static function convertPingppObjectToArray ( $ values , $ keep_object = false ) { $ results = array ( ) ; foreach ( $ values as $ k => $ v ) { if ( $ k [ 0 ] == '_' ) { continue ; } if ( $ v instanceof PingppObject ) { $ results [ $ k ] = $ keep_object ? $ v -> __toStdObject ( true ) : $ v -> __toArray ( true ) ; } else if ( is_array ( $ v ) ) { $ results [ $ k ] = self :: convertPingppObjectToArray ( $ v , $ keep_object ) ; } else { $ results [ $ k ] = $ v ; } } return $ results ; }
Recursively converts the PHP Pingpp object to an array .
1,797
public static function convertPingppObjectToStdObject ( $ values ) { $ results = new stdClass ; foreach ( $ values as $ k => $ v ) { if ( $ k [ 0 ] == '_' ) { continue ; } if ( $ v instanceof PingppObject ) { $ results -> $ k = $ v -> __toStdObject ( true ) ; } else if ( is_array ( $ v ) ) { $ results -> $ k = self :: convertPingppObjectToArray ( $ v , true ) ; } else { $ results -> $ k = $ v ; } } return $ results ; }
Recursively converts the PHP Pingpp object to an stdObject .
1,798
public function replaceWith ( $ properties ) { $ removed = array_diff ( array_keys ( $ this -> _values ) , array_keys ( $ properties ) ) ; foreach ( $ removed as $ k ) { unset ( $ this -> $ k ) ; } foreach ( $ properties as $ k => $ v ) { $ this -> $ k = $ v ; } }
Updates this object .
1,799
public function withError ( $ message , $ errorCode , array $ headers = [ ] ) { return $ this -> withArray ( [ 'error' => [ 'code' => $ errorCode , 'http_code' => $ this -> statusCode , 'message' => $ message ] ] , $ headers ) ; }
Response for errors