idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
6,200
public static function isBuggyIe ( ) { if ( empty ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) { return false ; } $ ua = $ _SERVER [ 'HTTP_USER_AGENT' ] ; if ( 0 !== strpos ( $ ua , 'Mozilla/4.0 (compatible; MSIE ' ) || false !== strpos ( $ ua , 'Opera' ) ) { return false ; } $ version = ( float ) substr ( $ ua , 30 ) ; return self :: $ encodeToIe6 ? ( $ version < 6 || ( $ version == 6 && false === strpos ( $ ua , 'SV1' ) ) ) : ( $ version < 7 ) ; }
Is the browser an IE version earlier than 6 SP2?
6,201
private function getCache ( ) { if ( isset ( $ this -> parsed ) ) { return $ this -> parsed ; } $ cache = null ; $ cacheId = $ this -> getCacheId ( ) ; if ( $ this -> cache -> isValid ( $ cacheId , 0 ) ) { if ( $ cache = $ this -> cache -> fetch ( $ cacheId ) ) { $ cache = unserialize ( $ cache ) ; } } $ input = $ cache ? $ cache : $ this -> filepath ; if ( $ this -> cacheIsStale ( $ cache ) ) { $ cache = $ this -> compile ( $ this -> filepath ) ; } if ( ! is_array ( $ input ) || $ cache [ 'updated' ] > $ input [ 'updated' ] ) { $ this -> cache -> store ( $ cacheId , serialize ( $ cache ) ) ; } return $ this -> parsed = $ cache ; }
Get SCSS cache object
6,202
public static function getUri ( $ keyOrFiles , $ opts = array ( ) ) { $ opts = array_merge ( array ( 'farExpires' => true , 'debug' => false , 'charset' => 'UTF-8' , 'minAppUri' => '/min' , 'rewriteWorks' => true , 'groupsConfigFile' => self :: app ( ) -> groupsConfigPath , ) , $ opts ) ; $ h = new self ; $ h -> minAppUri = $ opts [ 'minAppUri' ] ; $ h -> rewriteWorks = $ opts [ 'rewriteWorks' ] ; $ h -> groupsConfigFile = $ opts [ 'groupsConfigFile' ] ; if ( is_array ( $ keyOrFiles ) ) { $ h -> setFiles ( $ keyOrFiles , $ opts [ 'farExpires' ] ) ; } else { $ h -> setGroup ( $ keyOrFiles , $ opts [ 'farExpires' ] ) ; } $ uri = $ h -> getRawUri ( $ opts [ 'farExpires' ] , $ opts [ 'debug' ] ) ; return htmlspecialchars ( $ uri , ENT_QUOTES , $ opts [ 'charset' ] ) ; }
Get an HTML - escaped Minify URI for a group or set of files
6,203
public function getRawUri ( $ farExpires = true , $ debug = false ) { $ path = rtrim ( $ this -> minAppUri , '/' ) . '/' ; if ( ! $ this -> rewriteWorks ) { $ path .= '?' ; } if ( null === $ this -> _groupKey ) { $ path = self :: _getShortestUri ( $ this -> _filePaths , $ path ) ; } else { $ path .= "g=" . $ this -> _groupKey ; } if ( $ debug ) { $ path .= "&debug" ; } elseif ( $ farExpires && $ this -> _lastModified ) { $ path .= "&" . $ this -> _lastModified ; } return $ path ; }
Get non - HTML - escaped URI to minify the specified files
6,204
public function setFiles ( $ files , $ checkLastModified = true ) { $ this -> _groupKey = null ; if ( $ checkLastModified ) { $ this -> _lastModified = self :: getLastModified ( $ files ) ; } foreach ( $ files as $ k => $ file ) { if ( 0 === strpos ( $ file , '//' ) ) { $ file = substr ( $ file , 2 ) ; } elseif ( 0 === strpos ( $ file , '/' ) || 1 === strpos ( $ file , ':\\' ) ) { $ file = substr ( $ file , strlen ( self :: app ( ) -> env -> getDocRoot ( ) ) + 1 ) ; } $ file = strtr ( $ file , '\\' , '/' ) ; $ files [ $ k ] = $ file ; } $ this -> _filePaths = $ files ; }
Set the files that will comprise the URI we re building
6,205
public function setGroup ( $ key , $ checkLastModified = true ) { $ this -> _groupKey = $ key ; if ( $ checkLastModified ) { if ( ! $ this -> groupsConfigFile ) { $ this -> groupsConfigFile = self :: app ( ) -> groupsConfigPath ; } if ( is_file ( $ this -> groupsConfigFile ) ) { $ gc = ( require $ this -> groupsConfigFile ) ; $ keys = explode ( ',' , $ key ) ; foreach ( $ keys as $ key ) { if ( ! isset ( $ gc [ $ key ] ) ) { continue ; } $ this -> _lastModified = self :: getLastModified ( $ gc [ $ key ] , $ this -> _lastModified ) ; } } } }
Set the group of files that will comprise the URI we re building
6,206
protected static function _getCommonCharAtPos ( $ arr , $ pos ) { if ( ! isset ( $ arr [ 0 ] [ $ pos ] ) ) { return '' ; } $ c = $ arr [ 0 ] [ $ pos ] ; $ l = count ( $ arr ) ; if ( $ l === 1 ) { return $ c ; } for ( $ i = 1 ; $ i < $ l ; ++ $ i ) { if ( $ arr [ $ i ] [ $ pos ] !== $ c ) { return '' ; } } return $ c ; }
In a given array of strings find the character they all have at a particular index
6,207
public function getDefaultOptions ( ) { return array ( 'isPublic' => true , 'encodeOutput' => function_exists ( 'gzdeflate' ) , 'encodeMethod' => null , 'encodeLevel' => 9 , 'minifiers' => array ( Minify :: TYPE_JS => array ( 'JSMin\\JSMin' , 'minify' ) , Minify :: TYPE_CSS => array ( 'Minify_CSSmin' , 'minify' ) , Minify :: TYPE_HTML => array ( 'Minify_HTML' , 'minify' ) , ) , 'minifierOptions' => array ( ) , 'contentTypeCharset' => 'utf-8' , 'maxAge' => 1800 , 'rewriteCssUris' => true , 'bubbleCssImports' => false , 'quiet' => false , 'debug' => false , 'concatOnly' => false , 'badRequestHeader' => 'HTTP/1.0 400 Bad Request' , 'errorHeader' => 'HTTP/1.0 500 Internal Server Error' , 'postprocessor' => null , 'postprocessorRequire' => null , 'importWarning' => "/* See https://github.com/mrclay/minify/blob/master/docs/CommonProblems.wiki.md#imports-can-appear-in-invalid-locations-in-combined-css-files */\n" ) ; }
Get default Minify options .
6,208
public function combine ( $ sources , $ options = array ( ) ) { $ tmpCache = $ this -> cache ; $ this -> cache = new Minify_Cache_Null ( ) ; $ env = new Minify_Env ( ) ; $ sourceFactory = new Minify_Source_Factory ( $ env , array ( 'checkAllowDirs' => false , ) , $ this -> cache ) ; $ controller = new Minify_Controller_Files ( $ env , $ sourceFactory , $ this -> logger ) ; $ options = array_merge ( $ options , array ( 'files' => ( array ) $ sources , 'quiet' => true , 'encodeMethod' => '' , 'lastModifiedTime' => 0 , ) ) ; $ out = $ this -> serve ( $ controller , $ options ) ; $ this -> cache = $ tmpCache ; return $ out [ 'content' ] ; }
Return combined minified content for a set of sources
6,209
public function errorExit ( $ header , $ url = '' , $ msgHtml = '' ) { $ url = htmlspecialchars ( $ url , ENT_QUOTES ) ; list ( , $ h1 ) = explode ( ' ' , $ header , 2 ) ; $ h1 = htmlspecialchars ( $ h1 ) ; list ( , $ code ) = explode ( ' ' , $ header , 3 ) ; header ( $ header , true , $ code ) ; header ( 'Content-Type: text/html; charset=utf-8' ) ; echo "<h1>$h1</h1>" ; if ( $ msgHtml ) { echo $ msgHtml ; } if ( $ url ) { echo "<p>Please see <a href='$url'>$url</a>.</p>" ; } exit ; }
Show an error page
6,210
public static function nullMinifier ( $ content ) { if ( isset ( $ content [ 0 ] ) && $ content [ 0 ] === "\xef" ) { $ content = substr ( $ content , 3 ) ; } $ content = str_replace ( "\r\n" , "\n" , $ content ) ; return trim ( $ content ) ; }
Default minifier for . min or - min JS files .
6,211
protected function setupUriRewrites ( ) { foreach ( $ this -> sources as $ key => $ source ) { $ file = $ this -> env -> normalizePath ( $ source -> getFilePath ( ) ) ; $ minifyOptions = $ source -> getMinifierOptions ( ) ; if ( $ file && ! isset ( $ minifyOptions [ 'currentDir' ] ) && ! isset ( $ minifyOptions [ 'prependRelativePath' ] ) ) { $ minifyOptions [ 'currentDir' ] = dirname ( $ file ) ; $ source -> setMinifierOptions ( $ minifyOptions ) ; } } }
Setup CSS sources for URI rewriting
6,212
protected function setupDebug ( ) { foreach ( $ this -> sources as $ source ) { $ source -> setMinifier ( array ( 'Minify_Lines' , 'minify' ) ) ; $ id = $ source -> getId ( ) ; $ source -> setMinifierOptions ( array ( 'id' => ( is_file ( $ id ) ? basename ( $ id ) : $ id ) , ) ) ; } }
Set up sources to use Minify_Lines
6,213
protected function combineMinify ( ) { $ type = $ this -> options [ 'contentType' ] ; $ implodeSeparator = ( $ type === self :: TYPE_JS ) ? "\n;" : '' ; if ( isset ( $ this -> options [ 'minifierOptions' ] [ $ type ] ) ) { $ defaultOptions = $ this -> options [ 'minifierOptions' ] [ $ type ] ; } else { $ defaultOptions = array ( ) ; } if ( isset ( $ this -> options [ 'minifiers' ] [ $ type ] ) ) { $ defaultMinifier = $ this -> options [ 'minifiers' ] [ $ type ] ; } else { $ defaultMinifier = false ; } $ content = array ( ) ; $ i = 0 ; $ l = count ( $ this -> sources ) ; $ groupToProcessTogether = array ( ) ; $ lastMinifier = null ; $ lastOptions = null ; do { $ source = null ; if ( $ i < $ l ) { $ source = $ this -> sources [ $ i ] ; $ sourceContent = $ source -> getContent ( ) ; $ minifier = $ source -> getMinifier ( ) ; if ( ! $ minifier ) { $ minifier = $ defaultMinifier ; } $ options = array_merge ( $ defaultOptions , $ source -> getMinifierOptions ( ) ) ; } if ( $ i > 0 && ( ! $ source || $ type === self :: TYPE_CSS || $ minifier !== $ lastMinifier || $ options !== $ lastOptions ) ) { $ imploded = implode ( $ implodeSeparator , $ groupToProcessTogether ) ; $ groupToProcessTogether = array ( ) ; if ( $ lastMinifier ) { try { $ content [ ] = call_user_func ( $ lastMinifier , $ imploded , $ lastOptions ) ; } catch ( Exception $ e ) { throw new Exception ( "Exception in minifier: " . $ e -> getMessage ( ) ) ; } } else { $ content [ ] = $ imploded ; } } if ( $ source ) { $ groupToProcessTogether [ ] = $ sourceContent ; $ lastMinifier = $ minifier ; $ lastOptions = $ options ; } $ i ++ ; } while ( $ source ) ; $ content = implode ( $ implodeSeparator , $ content ) ; if ( $ type === self :: TYPE_CSS && false !== strpos ( $ content , '@import' ) ) { $ content = $ this -> handleCssImports ( $ content ) ; } if ( $ this -> options [ 'postprocessorRequire' ] ) { require_once $ this -> options [ 'postprocessorRequire' ] ; } if ( $ this -> options [ 'postprocessor' ] ) { $ content = call_user_func ( $ this -> options [ 'postprocessor' ] , $ content , $ type ) ; } return $ content ; }
Combines sources and minifies the result .
6,214
protected function _getCacheId ( $ prefix = 'minify' ) { $ name = preg_replace ( '/[^a-zA-Z0-9\\.=_,]/' , '' , $ this -> selectionId ) ; $ name = preg_replace ( '/\\.+/' , '.' , $ name ) ; $ name = substr ( $ name , 0 , 100 - 34 - strlen ( $ prefix ) ) ; $ md5 = md5 ( serialize ( array ( Minify_SourceSet :: getDigest ( $ this -> sources ) , $ this -> options [ 'minifiers' ] , $ this -> options [ 'minifierOptions' ] , $ this -> options [ 'postprocessor' ] , $ this -> options [ 'bubbleCssImports' ] , Minify :: VERSION , ) ) ) ; return "{$prefix}_{$name}_{$md5}" ; }
Make a unique cache id for for this request .
6,215
public function min ( $ js ) { $ postBody = $ this -> buildPostBody ( $ js ) ; if ( $ this -> maxBytes > 0 ) { $ bytes = ( function_exists ( 'mb_strlen' ) && ( ( int ) ini_get ( 'mbstring.func_overload' ) & 2 ) ) ? mb_strlen ( $ postBody , '8bit' ) : strlen ( $ postBody ) ; if ( $ bytes > $ this -> maxBytes ) { throw new Minify_JS_ClosureCompiler_Exception ( 'POST content larger than ' . $ this -> maxBytes . ' bytes' ) ; } } $ response = $ this -> getResponse ( $ postBody ) ; if ( preg_match ( '/^Error\(\d\d?\):/' , $ response ) ) { if ( is_callable ( $ this -> fallbackMinifier ) ) { $ response = "/* Received errors from Closure Compiler API:\n$response" . "\n(Using fallback minifier)\n*/\n" ; $ response .= call_user_func ( $ this -> fallbackMinifier , $ js ) ; } else { throw new Minify_JS_ClosureCompiler_Exception ( $ response ) ; } } if ( $ response === '' ) { $ errors = $ this -> getResponse ( $ this -> buildPostBody ( $ js , true ) ) ; throw new Minify_JS_ClosureCompiler_Exception ( $ errors ) ; } return $ response ; }
Call the service to perform the minification
6,216
protected function getResponse ( $ postBody ) { $ allowUrlFopen = preg_match ( '/1|yes|on|true/i' , ini_get ( 'allow_url_fopen' ) ) ; if ( $ allowUrlFopen ) { $ contents = file_get_contents ( $ this -> serviceUrl , false , stream_context_create ( array ( 'http' => array ( 'method' => 'POST' , 'compilation_level' => 'SIMPLE' , 'output_format' => 'text' , 'output_info' => 'compiled_code' , 'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close\r\n" , 'content' => $ postBody , 'max_redirects' => 0 , 'timeout' => 15 , ) ) ) ) ; } elseif ( defined ( 'CURLOPT_POST' ) ) { $ ch = curl_init ( $ this -> serviceUrl ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( 'Content-type: application/x-www-form-urlencoded' ) ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ postBody ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , false ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , 15 ) ; $ contents = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; } else { throw new Minify_JS_ClosureCompiler_Exception ( "Could not make HTTP request: allow_url_open is false and cURL not available" ) ; } if ( false === $ contents ) { throw new Minify_JS_ClosureCompiler_Exception ( "No HTTP response from server" ) ; } return trim ( $ contents ) ; }
Get the response for a given POST body
6,217
protected function buildPostBody ( $ js , $ returnErrors = false ) { return http_build_query ( array_merge ( self :: $ DEFAULT_OPTIONS , $ this -> additionalOptions , array ( 'js_code' => $ js , 'output_info' => ( $ returnErrors ? 'errors' : 'compiled_code' ) ) ) , null , '&' ) ; }
Build a POST request body
6,218
protected function extract ( $ archive ) { $ zip = new ZipArchive ; $ zip -> open ( $ archive ) ; $ zip -> extractTo ( $ this -> directory ) ; $ binary = $ zip -> getNameIndex ( 0 ) ; $ zip -> close ( ) ; unlink ( $ archive ) ; return $ binary ; }
Extract the ChromeDriver binary from the archive and delete the archive .
6,219
protected function rename ( $ binary , $ os ) { $ newName = str_replace ( 'chromedriver' , 'chromedriver-' . $ os , $ binary ) ; rename ( $ this -> directory . $ binary , $ this -> directory . $ newName ) ; chmod ( $ this -> directory . $ newName , 0755 ) ; }
Rename the ChromeDriver binary and make it executable .
6,220
public function whenAvailable ( $ selector , Closure $ callback , $ seconds = null ) { return $ this -> waitFor ( $ selector , $ seconds ) -> with ( $ selector , $ callback ) ; }
Execute the given callback in a scoped browser once the selector is available .
6,221
public function waitFor ( $ selector , $ seconds = null ) { $ message = $ this -> formatTimeOutMessage ( 'Waited %s seconds for selector' , $ selector ) ; return $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ selector ) { return $ this -> resolver -> findOrFail ( $ selector ) -> isDisplayed ( ) ; } , $ message ) ; }
Wait for the given selector to be visible .
6,222
public function waitUntilMissing ( $ selector , $ seconds = null ) { $ message = $ this -> formatTimeOutMessage ( 'Waited %s seconds for removal of selector' , $ selector ) ; return $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ selector ) { try { $ missing = ! $ this -> resolver -> findOrFail ( $ selector ) -> isDisplayed ( ) ; } catch ( NoSuchElementException $ e ) { $ missing = true ; } return $ missing ; } , $ message ) ; }
Wait for the given selector to be removed .
6,223
public function waitForText ( $ text , $ seconds = null ) { $ text = Arr :: wrap ( $ text ) ; $ message = $ this -> formatTimeOutMessage ( 'Waited %s seconds for text' , implode ( "', '" , $ text ) ) ; return $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ text ) { return Str :: contains ( $ this -> resolver -> findOrFail ( '' ) -> getText ( ) , $ text ) ; } , $ message ) ; }
Wait for the given text to be visible .
6,224
public function waitForLink ( $ link , $ seconds = null ) { $ message = $ this -> formatTimeOutMessage ( 'Waited %s seconds for link' , $ link ) ; return $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ link ) { return $ this -> seeLink ( $ link ) ; } , $ message ) ; }
Wait for the given link to be visible .
6,225
public function waitForLocation ( $ path , $ seconds = null ) { $ message = $ this -> formatTimeOutMessage ( 'Waited %s seconds for location' , $ path ) ; return $ this -> waitUntil ( "window.location.pathname == '{$path}'" , $ seconds , $ message ) ; }
Wait for the given location .
6,226
public function waitForRoute ( $ route , $ parameters = [ ] , $ seconds = null ) { return $ this -> waitForLocation ( route ( $ route , $ parameters , false ) , $ seconds ) ; }
Wait for the given location using a named route .
6,227
public function waitUntil ( $ script , $ seconds = null , $ message = null ) { if ( ! Str :: startsWith ( $ script , 'return ' ) ) { $ script = 'return ' . $ script ; } if ( ! Str :: endsWith ( $ script , ';' ) ) { $ script = $ script . ';' ; } return $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ script ) { return $ this -> driver -> executeScript ( $ script ) ; } , $ message ) ; }
Wait until the given script returns true .
6,228
public function waitUntilVue ( $ key , $ value , $ componentSelector = null , $ seconds = null ) { $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ key , $ value , $ componentSelector ) { return $ value == $ this -> vueAttribute ( $ componentSelector , $ key ) ; } ) ; return $ this ; }
Wait until the Vue component s attribute at the given key has the given value .
6,229
public function waitForDialog ( $ seconds = null ) { $ seconds = is_null ( $ seconds ) ? static :: $ waitSeconds : $ seconds ; $ this -> driver -> wait ( $ seconds , 100 ) -> until ( WebDriverExpectedCondition :: alertIsPresent ( ) , "Waited {$seconds} seconds for dialog." ) ; return $ this ; }
Wait for a JavaScript dialog to open .
6,230
public function waitForReload ( $ callback = null , $ seconds = null ) { $ token = Str :: random ( ) ; $ this -> driver -> executeScript ( "window['{$token}'] = {};" ) ; if ( $ callback ) { $ callback ( $ this ) ; } return $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ token ) { return $ this -> driver -> executeScript ( "return typeof window['{$token}'] === 'undefined';" ) ; } , 'Waited %s seconds for page reload.' ) ; }
Wait for the current page to reload .
6,231
public function waitUsing ( $ seconds , $ interval , Closure $ callback , $ message = null ) { $ seconds = is_null ( $ seconds ) ? static :: $ waitSeconds : $ seconds ; $ this -> pause ( $ interval ) ; $ started = Carbon :: now ( ) ; while ( true ) { try { if ( $ callback ( ) ) { break ; } } catch ( Exception $ e ) { } if ( $ started -> lt ( Carbon :: now ( ) -> subSeconds ( $ seconds ) ) ) { throw new TimeOutException ( $ message ? sprintf ( $ message , $ seconds ) : "Waited {$seconds} seconds for callback." ) ; } $ this -> pause ( $ interval ) ; } return $ this ; }
Wait for the given callback to be true .
6,232
public function loginAs ( $ userId , $ guard = null ) { $ userId = method_exists ( $ userId , 'getKey' ) ? $ userId -> getKey ( ) : $ userId ; return $ this -> visit ( rtrim ( '/_dusk/login/' . $ userId . '/' . $ guard , '/' ) ) ; }
Log into the application using a given user ID or email .
6,233
protected static function duskEnvironment ( $ options ) { if ( ! isset ( $ options [ 'environments' ] ) ) { return false ; } if ( is_string ( $ options [ 'environments' ] ) ) { $ options [ 'environments' ] = [ $ options [ 'environments' ] ] ; } if ( ! is_array ( $ options [ 'environments' ] ) ) { throw new InvalidArgumentException ( 'Dusk environments must be listed as an array.' ) ; } return app ( ) -> environment ( ... $ options [ 'environments' ] ) ; }
Determine if Dusk may run in this environment .
6,234
public function moveMouse ( $ xOffset , $ yOffset ) { ( new WebDriverActions ( $ this -> driver ) ) -> moveByOffset ( $ xOffset , $ yOffset ) -> perform ( ) ; return $ this ; }
Move the mouse by offset X and Y .
6,235
public function mouseover ( $ selector ) { $ element = $ this -> resolver -> findOrFail ( $ selector ) ; $ this -> driver -> getMouse ( ) -> mouseMove ( $ element -> getCoordinates ( ) ) ; return $ this ; }
Move the mouse over the given selector .
6,236
public function click ( $ selector = null ) { if ( is_null ( $ selector ) ) { ( new WebDriverActions ( $ this -> driver ) ) -> click ( ) -> perform ( ) ; } else { $ this -> resolver -> findOrFail ( $ selector ) -> click ( ) ; } return $ this ; }
Click the element at the given selector .
6,237
public function rightClick ( $ selector = null ) { if ( is_null ( $ selector ) ) { ( new WebDriverActions ( $ this -> driver ) ) -> contextClick ( ) -> perform ( ) ; } else { ( new WebDriverActions ( $ this -> driver ) ) -> contextClick ( $ this -> resolver -> findOrFail ( $ selector ) ) -> perform ( ) ; } return $ this ; }
Right click the element at the given selector .
6,238
public function browse ( Closure $ callback ) { $ browsers = $ this -> createBrowsersFor ( $ callback ) ; try { $ callback ( ... $ browsers -> all ( ) ) ; } catch ( Exception $ e ) { $ this -> captureFailuresFor ( $ browsers ) ; throw $ e ; } catch ( Throwable $ e ) { $ this -> captureFailuresFor ( $ browsers ) ; throw $ e ; } finally { $ this -> storeConsoleLogsFor ( $ browsers ) ; static :: $ browsers = $ this -> closeAllButPrimary ( $ browsers ) ; } }
Create a new browser instance .
6,239
protected function createBrowsersFor ( Closure $ callback ) { if ( count ( static :: $ browsers ) === 0 ) { static :: $ browsers = collect ( [ $ this -> newBrowser ( $ this -> createWebDriver ( ) ) ] ) ; } $ additional = $ this -> browsersNeededFor ( $ callback ) - 1 ; for ( $ i = 0 ; $ i < $ additional ; $ i ++ ) { static :: $ browsers -> push ( $ this -> newBrowser ( $ this -> createWebDriver ( ) ) ) ; } return static :: $ browsers ; }
Create the browser instances needed for the given callback .
6,240
protected function captureFailuresFor ( $ browsers ) { $ browsers -> each ( function ( $ browser , $ key ) { $ name = str_replace ( '\\' , '_' , get_class ( $ this ) ) . '_' . $ this -> getName ( false ) ; $ browser -> screenshot ( 'failure-' . $ name . '-' . $ key ) ; } ) ; }
Capture failure screenshots for each browser .
6,241
protected function storeConsoleLogsFor ( $ browsers ) { $ browsers -> each ( function ( $ browser , $ key ) { $ name = str_replace ( '\\' , '_' , get_class ( $ this ) ) . '_' . $ this -> getName ( false ) ; $ browser -> storeConsoleLog ( $ name . '-' . $ key ) ; } ) ; }
Store the console output for the given browsers .
6,242
public function toProcess ( array $ arguments = [ ] ) { if ( $ this -> driver ) { return $ this -> process ( $ arguments ) ; } if ( $ this -> onWindows ( ) ) { $ this -> driver = realpath ( __DIR__ . '/../../bin/chromedriver-win.exe' ) ; } elseif ( $ this -> onMac ( ) ) { $ this -> driver = realpath ( __DIR__ . '/../../bin/chromedriver-mac' ) ; } else { $ this -> driver = realpath ( __DIR__ . '/../../bin/chromedriver-linux' ) ; } return $ this -> process ( $ arguments ) ; }
Build the process to run Chromedriver .
6,243
protected function process ( array $ arguments = [ ] ) { return new Process ( array_merge ( [ realpath ( $ this -> driver ) ] , $ arguments ) , null , $ this -> chromeEnvironment ( ) ) ; }
Build the Chromedriver with Symfony Process .
6,244
protected function phpunitArguments ( $ options ) { $ options = array_values ( array_filter ( $ options , function ( $ option ) { return ! Str :: startsWith ( $ option , '--env=' ) ; } ) ) ; if ( ! file_exists ( $ file = base_path ( 'phpunit.dusk.xml' ) ) ) { $ file = base_path ( 'phpunit.dusk.xml.dist' ) ; } return array_merge ( [ '-c' , $ file ] , $ options ) ; }
Get the array of arguments for running PHPUnit .
6,245
protected function purgeScreenshots ( ) { $ path = base_path ( 'tests/Browser/screenshots' ) ; if ( ! is_dir ( $ path ) ) { return ; } $ files = Finder :: create ( ) -> files ( ) -> in ( $ path ) -> name ( 'failure-*' ) ; foreach ( $ files as $ file ) { @ unlink ( $ file -> getRealPath ( ) ) ; } }
Purge the failure screenshots .
6,246
protected function withDuskEnvironment ( $ callback ) { if ( file_exists ( base_path ( $ this -> duskFile ( ) ) ) ) { if ( file_get_contents ( base_path ( '.env' ) ) !== file_get_contents ( base_path ( $ this -> duskFile ( ) ) ) ) { $ this -> backupEnvironment ( ) ; } $ this -> refreshEnvironment ( ) ; } $ this -> writeConfiguration ( ) ; return tap ( $ callback ( ) , function ( ) { $ this -> removeConfiguration ( ) ; if ( file_exists ( base_path ( $ this -> duskFile ( ) ) ) && file_exists ( base_path ( '.env.backup' ) ) ) { $ this -> restoreEnvironment ( ) ; } } ) ; }
Run the given callback with the Dusk configuration files .
6,247
protected function refreshEnvironment ( ) { if ( ! method_exists ( Dotenv :: class , 'create' ) ) { ( new Dotenv ( base_path ( ) ) ) -> overload ( ) ; return ; } Dotenv :: create ( base_path ( ) ) -> overload ( ) ; }
Refresh the current environment variables .
6,248
protected function writeConfiguration ( ) { if ( ! file_exists ( $ file = base_path ( 'phpunit.dusk.xml' ) ) && ! file_exists ( base_path ( 'phpunit.dusk.xml.dist' ) ) ) { copy ( realpath ( __DIR__ . '/../../stubs/phpunit.xml' ) , $ file ) ; return ; } $ this -> hasPhpUnitConfiguration = true ; }
Write the Dusk PHPUnit configuration .
6,249
public function assertTitleContains ( $ title ) { PHPUnit :: assertTrue ( Str :: contains ( $ this -> driver -> getTitle ( ) , $ title ) , "Did not see expected value [{$title}] within title [{$this->driver->getTitle()}]." ) ; return $ this ; }
Assert that the page title contains the given value .
6,250
public function assertHasCookie ( $ name , $ decrypt = true ) { $ cookie = $ decrypt ? $ this -> cookie ( $ name ) : $ this -> plainCookie ( $ name ) ; PHPUnit :: assertTrue ( ! is_null ( $ cookie ) , "Did not find expected cookie [{$name}]." ) ; return $ this ; }
Assert that the given cookie is present .
6,251
public function assertCookieValue ( $ name , $ value , $ decrypt = true ) { $ actual = $ decrypt ? $ this -> cookie ( $ name ) : $ this -> plainCookie ( $ name ) ; PHPUnit :: assertEquals ( $ value , $ actual , "Cookie [{$name}] had value [{$actual}], but expected [{$value}]." ) ; return $ this ; }
Assert that an encrypted cookie has a given value .
6,252
public function assertSeeIn ( $ selector , $ text ) { $ fullSelector = $ this -> resolver -> format ( $ selector ) ; $ element = $ this -> resolver -> findOrFail ( $ selector ) ; PHPUnit :: assertTrue ( Str :: contains ( $ element -> getText ( ) , $ text ) , "Did not see expected text [{$text}] within element [{$fullSelector}]." ) ; return $ this ; }
Assert that the given text appears within the given selector .
6,253
public function assertDontSeeIn ( $ selector , $ text ) { $ fullSelector = $ this -> resolver -> format ( $ selector ) ; $ element = $ this -> resolver -> findOrFail ( $ selector ) ; PHPUnit :: assertFalse ( Str :: contains ( $ element -> getText ( ) , $ text ) , "Saw unexpected text [{$text}] within element [{$fullSelector}]." ) ; return $ this ; }
Assert that the given text does not appear within the given selector .
6,254
public function assertSourceHas ( $ code ) { PHPUnit :: assertTrue ( Str :: contains ( $ this -> driver -> getPageSource ( ) , $ code ) , "Did not find expected source code [{$code}]" ) ; return $ this ; }
Assert that the given source code is present on the page .
6,255
public function assertSourceMissing ( $ code ) { PHPUnit :: assertFalse ( Str :: contains ( $ this -> driver -> getPageSource ( ) , $ code ) , "Found unexpected source code [{$code}]" ) ; return $ this ; }
Assert that the given source code is not present on the page .
6,256
public function assertSeeLink ( $ link ) { if ( $ this -> resolver -> prefix ) { $ message = "Did not see expected link [{$link}] within [{$this->resolver->prefix}]." ; } else { $ message = "Did not see expected link [{$link}]." ; } PHPUnit :: assertTrue ( $ this -> seeLink ( $ link ) , $ message ) ; return $ this ; }
Assert that the given link is visible .
6,257
public function assertDontSeeLink ( $ link ) { if ( $ this -> resolver -> prefix ) { $ message = "Saw unexpected link [{$link}] within [{$this->resolver->prefix}]." ; } else { $ message = "Saw unexpected link [{$link}]." ; } PHPUnit :: assertFalse ( $ this -> seeLink ( $ link ) , $ message ) ; return $ this ; }
Assert that the given link is not visible .
6,258
public function seeLink ( $ link ) { $ this -> ensurejQueryIsAvailable ( ) ; $ selector = addslashes ( trim ( $ this -> resolver -> format ( "a:contains('{$link}')" ) ) ) ; $ script = <<<JS var link = jQuery.find("{$selector}"); return link.length > 0 && jQuery(link).is(':visible');JS ; return $ this -> driver -> executeScript ( $ script ) ; }
Determine if the given link is visible .
6,259
public function assertInputValue ( $ field , $ value ) { PHPUnit :: assertEquals ( $ value , $ this -> inputValue ( $ field ) , "Expected value [{$value}] for the [{$field}] input does not equal the actual value [{$this->inputValue($field)}]." ) ; return $ this ; }
Assert that the given input or text area contains the given value .
6,260
public function assertInputValueIsNot ( $ field , $ value ) { PHPUnit :: assertNotEquals ( $ value , $ this -> inputValue ( $ field ) , "Value [{$value}] for the [{$field}] input should not equal the actual value." ) ; return $ this ; }
Assert that the given input or text area does not contain the given value .
6,261
public function inputValue ( $ field ) { $ element = $ this -> resolver -> resolveForTyping ( $ field ) ; return in_array ( $ element -> getTagName ( ) , [ 'input' , 'textarea' ] ) ? $ element -> getAttribute ( 'value' ) : $ element -> getText ( ) ; }
Get the value of the given input or text area field .
6,262
public function assertChecked ( $ field , $ value = null ) { $ element = $ this -> resolver -> resolveForChecking ( $ field , $ value ) ; PHPUnit :: assertTrue ( $ element -> isSelected ( ) , "Expected checkbox [{$field}] to be checked, but it wasn't." ) ; return $ this ; }
Assert that the given checkbox field is checked .
6,263
public function assertNotChecked ( $ field , $ value = null ) { $ element = $ this -> resolver -> resolveForChecking ( $ field , $ value ) ; PHPUnit :: assertFalse ( $ element -> isSelected ( ) , "Checkbox [{$field}] was unexpectedly checked." ) ; return $ this ; }
Assert that the given checkbox field is not checked .
6,264
public function assertRadioSelected ( $ field , $ value ) { $ element = $ this -> resolver -> resolveForRadioSelection ( $ field , $ value ) ; PHPUnit :: assertTrue ( $ element -> isSelected ( ) , "Expected radio [{$field}] to be selected, but it wasn't." ) ; return $ this ; }
Assert that the given radio field is selected .
6,265
public function assertRadioNotSelected ( $ field , $ value = null ) { $ element = $ this -> resolver -> resolveForRadioSelection ( $ field , $ value ) ; PHPUnit :: assertFalse ( $ element -> isSelected ( ) , "Radio [{$field}] was unexpectedly selected." ) ; return $ this ; }
Assert that the given radio field is not selected .
6,266
public function assertSelected ( $ field , $ value ) { PHPUnit :: assertTrue ( $ this -> selected ( $ field , $ value ) , "Expected value [{$value}] to be selected for [{$field}], but it wasn't." ) ; return $ this ; }
Assert that the given select field has the given value selected .
6,267
public function assertNotSelected ( $ field , $ value ) { PHPUnit :: assertFalse ( $ this -> selected ( $ field , $ value ) , "Unexpected value [{$value}] selected for [{$field}]." ) ; return $ this ; }
Assert that the given select field does not have the given value selected .
6,268
public function assertSelectHasOptions ( $ field , array $ values ) { $ options = $ this -> resolver -> resolveSelectOptions ( $ field , $ values ) ; $ options = collect ( $ options ) -> unique ( function ( RemoteWebElement $ option ) { return $ option -> getAttribute ( 'value' ) ; } ) -> all ( ) ; PHPUnit :: assertCount ( count ( $ values ) , $ options , 'Expected options [' . implode ( ',' , $ values ) . "] for selection field [{$field}] to be available." ) ; return $ this ; }
Assert that the given array of values are available to be selected .
6,269
public function assertSelectMissingOptions ( $ field , array $ values ) { PHPUnit :: assertCount ( 0 , $ this -> resolver -> resolveSelectOptions ( $ field , $ values ) , 'Unexpected options [' . implode ( ',' , $ values ) . "] for selection field [{$field}]." ) ; return $ this ; }
Assert that the given array of values are not available to be selected .
6,270
public function selected ( $ field , $ value ) { $ options = $ this -> resolver -> resolveSelectOptions ( $ field , ( array ) $ value ) ; return collect ( $ options ) -> contains ( function ( RemoteWebElement $ option ) { return $ option -> isSelected ( ) ; } ) ; }
Determine if the given value is selected for the given select field .
6,271
public function assertValue ( $ selector , $ value ) { $ actual = $ this -> resolver -> findOrFail ( $ selector ) -> getAttribute ( 'value' ) ; PHPUnit :: assertEquals ( $ value , $ actual ) ; return $ this ; }
Assert that the element at the given selector has the given value .
6,272
public function assertVisible ( $ selector ) { $ fullSelector = $ this -> resolver -> format ( $ selector ) ; PHPUnit :: assertTrue ( $ this -> resolver -> findOrFail ( $ selector ) -> isDisplayed ( ) , "Element [{$fullSelector}] is not visible." ) ; return $ this ; }
Assert that the element with the given selector is visible .
6,273
public function assertPresent ( $ selector ) { $ fullSelector = $ this -> resolver -> format ( $ selector ) ; PHPUnit :: assertTrue ( ! is_null ( $ this -> resolver -> find ( $ selector ) ) , "Element [{$fullSelector}] is not present." ) ; return $ this ; }
Assert that the element with the given selector is present in the DOM .
6,274
public function assertMissing ( $ selector ) { $ fullSelector = $ this -> resolver -> format ( $ selector ) ; try { $ missing = ! $ this -> resolver -> findOrFail ( $ selector ) -> isDisplayed ( ) ; } catch ( NoSuchElementException $ e ) { $ missing = true ; } PHPUnit :: assertTrue ( $ missing , "Saw unexpected element [{$fullSelector}]." ) ; return $ this ; }
Assert that the element with the given selector is not on the page .
6,275
public function assertDialogOpened ( $ message ) { $ actualMessage = $ this -> driver -> switchTo ( ) -> alert ( ) -> getText ( ) ; PHPUnit :: assertEquals ( $ message , $ actualMessage , "Expected dialog message [{$message}] does not equal actual message [{$actualMessage}]." ) ; return $ this ; }
Assert that a JavaScript dialog with given message has been opened .
6,276
public function assertEnabled ( $ field ) { $ element = $ this -> resolver -> resolveForField ( $ field ) ; PHPUnit :: assertTrue ( $ element -> isEnabled ( ) , "Expected element [{$field}] to be enabled, but it wasn't." ) ; return $ this ; }
Assert that the given field is enabled .
6,277
public function assertDisabled ( $ field ) { $ element = $ this -> resolver -> resolveForField ( $ field ) ; PHPUnit :: assertFalse ( $ element -> isEnabled ( ) , "Expected element [{$field}] to be disabled, but it wasn't." ) ; return $ this ; }
Assert that the given field is disabled .
6,278
public function assertFocused ( $ field ) { $ element = $ this -> resolver -> resolveForField ( $ field ) ; PHPUnit :: assertTrue ( $ this -> driver -> switchTo ( ) -> activeElement ( ) -> equals ( $ element ) , "Expected element [{$field}] to be focused, but it wasn't." ) ; return $ this ; }
Assert that the given field is focused .
6,279
public function assertNotFocused ( $ field ) { $ element = $ this -> resolver -> resolveForField ( $ field ) ; PHPUnit :: assertFalse ( $ this -> driver -> switchTo ( ) -> activeElement ( ) -> equals ( $ element ) , "Expected element [{$field}] not to be focused, but it was." ) ; return $ this ; }
Assert that the given field is not focused .
6,280
public function assertVue ( $ key , $ value , $ componentSelector = null ) { PHPUnit :: assertEquals ( $ value , $ this -> vueAttribute ( $ componentSelector , $ key ) ) ; return $ this ; }
Assert that the Vue component s attribute at the given key has the given value .
6,281
public function assertVueIsNot ( $ key , $ value , $ componentSelector = null ) { PHPUnit :: assertNotEquals ( $ value , $ this -> vueAttribute ( $ componentSelector , $ key ) ) ; return $ this ; }
Assert that the Vue component s attribute at the given key does not have the given value .
6,282
public function assertVueContains ( $ key , $ value , $ componentSelector = null ) { $ attribute = $ this -> vueAttribute ( $ componentSelector , $ key ) ; PHPUnit :: assertIsArray ( $ attribute , "The attribute for key [$key] is not an array." ) ; PHPUnit :: assertContains ( $ value , $ attribute ) ; return $ this ; }
Assert that the Vue component s attribute at the given key is an array that contains the given value .
6,283
public function assertVueDoesNotContain ( $ key , $ value , $ componentSelector = null ) { $ attribute = $ this -> vueAttribute ( $ componentSelector , $ key ) ; PHPUnit :: assertIsArray ( $ attribute , "The attribute for key [$key] is not an array." ) ; PHPUnit :: assertNotContains ( $ value , $ attribute ) ; return $ this ; }
Assert that the Vue component s attribute at the given key is an array that does not contain the given value .
6,284
public function vueAttribute ( $ componentSelector , $ key ) { $ fullSelector = $ this -> resolver -> format ( $ componentSelector ) ; return $ this -> driver -> executeScript ( "return document.querySelector('" . $ fullSelector . "').__vue__." . $ key ) ; }
Retrieve the value of the Vue component s attribute at the given key .
6,285
public function clickLink ( $ link , $ element = 'a' ) { $ this -> ensurejQueryIsAvailable ( ) ; $ selector = addslashes ( trim ( $ this -> resolver -> format ( "{$element}:contains({$link}):visible" ) ) ) ; $ this -> driver -> executeScript ( "jQuery.find(\"{$selector}\")[0].click();" ) ; return $ this ; }
Click the link with the given text .
6,286
public function value ( $ selector , $ value = null ) { if ( is_null ( $ value ) ) { return $ this -> resolver -> findOrFail ( $ selector ) -> getAttribute ( 'value' ) ; } $ selector = $ this -> resolver -> format ( $ selector ) ; $ this -> driver -> executeScript ( "document.querySelector('{$selector}').value = '{$value}';" ) ; return $ this ; }
Directly get or set the value attribute of an input field .
6,287
public function keys ( $ selector , ... $ keys ) { $ this -> resolver -> findOrFail ( $ selector ) -> sendKeys ( $ this -> parseKeys ( $ keys ) ) ; return $ this ; }
Send the given keys to the element matching the given selector .
6,288
protected function parseKeys ( $ keys ) { return collect ( $ keys ) -> map ( function ( $ key ) { if ( is_string ( $ key ) && Str :: startsWith ( $ key , '{' ) && Str :: endsWith ( $ key , '}' ) ) { $ key = constant ( WebDriverKeys :: class . '::' . strtoupper ( trim ( $ key , '{}' ) ) ) ; } if ( is_array ( $ key ) && Str :: startsWith ( $ key [ 0 ] , '{' ) ) { $ key [ 0 ] = constant ( WebDriverKeys :: class . '::' . strtoupper ( trim ( $ key [ 0 ] , '{}' ) ) ) ; } return $ key ; } ) -> all ( ) ; }
Parse the keys before sending to the keyboard .
6,289
public function type ( $ field , $ value ) { $ this -> resolver -> resolveForTyping ( $ field ) -> clear ( ) -> sendKeys ( $ value ) ; return $ this ; }
Type the given value in the given field .
6,290
public function append ( $ field , $ value ) { $ this -> resolver -> resolveForTyping ( $ field ) -> sendKeys ( $ value ) ; return $ this ; }
Type the given value in the given field without clearing it .
6,291
public function select ( $ field , $ value = null ) { $ element = $ this -> resolver -> resolveForSelection ( $ field ) ; $ options = $ element -> findElements ( WebDriverBy :: cssSelector ( 'option:not([disabled])' ) ) ; if ( is_null ( $ value ) ) { $ options [ array_rand ( $ options ) ] -> click ( ) ; } else { foreach ( $ options as $ option ) { if ( ( string ) $ option -> getAttribute ( 'value' ) === ( string ) $ value ) { $ option -> click ( ) ; break ; } } } return $ this ; }
Select the given value or random value of a drop - down field .
6,292
public function radio ( $ field , $ value ) { $ this -> resolver -> resolveForRadioSelection ( $ field , $ value ) -> click ( ) ; return $ this ; }
Select the given value of a radio button field .
6,293
public function check ( $ field , $ value = null ) { $ element = $ this -> resolver -> resolveForChecking ( $ field , $ value ) ; if ( ! $ element -> isSelected ( ) ) { $ element -> click ( ) ; } return $ this ; }
Check the given checkbox .
6,294
public function attach ( $ field , $ path ) { $ element = $ this -> resolver -> resolveForAttachment ( $ field ) ; $ element -> setFileDetector ( new LocalFileDetector ) -> sendKeys ( $ path ) ; return $ this ; }
Attach the given file to the field .
6,295
public function pressAndWaitFor ( $ button , $ seconds = 5 ) { $ element = $ this -> resolver -> resolveForButtonPress ( $ button ) ; $ element -> click ( ) ; return $ this -> waitUsing ( $ seconds , 100 , function ( ) use ( $ element ) { return $ element -> isEnabled ( ) ; } ) ; }
Press the button with the given text or name .
6,296
public function drag ( $ from , $ to ) { ( new WebDriverActions ( $ this -> driver ) ) -> dragAndDrop ( $ this -> resolver -> findOrFail ( $ from ) , $ this -> resolver -> findOrFail ( $ to ) ) -> perform ( ) ; return $ this ; }
Drag an element to another element using selectors .
6,297
public function dragOffset ( $ selector , $ x = 0 , $ y = 0 ) { ( new WebDriverActions ( $ this -> driver ) ) -> dragAndDropBy ( $ this -> resolver -> findOrFail ( $ selector ) , $ x , $ y ) -> perform ( ) ; return $ this ; }
Drag an element by the given offset .
6,298
public function onWithoutAssert ( $ page ) { $ this -> page = $ page ; $ this -> resolver -> pageElements ( array_merge ( $ page :: siteElements ( ) , $ page -> elements ( ) ) ) ; return $ this ; }
Set the current page object without executing the assertions .
6,299
public function resize ( $ width , $ height ) { $ this -> driver -> manage ( ) -> window ( ) -> setSize ( new WebDriverDimension ( $ width , $ height ) ) ; return $ this ; }
Resize the browser window .