├── .gitignore ├── .gitlab-ci.yml ├── Makefile ├── README.md ├── codeception.yml ├── composer.json ├── src ├── AssetHash.php ├── AuthenticatedRule.php ├── Html.php ├── ImageProxy.php ├── Metadata.php ├── RbacController.php ├── RouteAccess.php └── SettingsAsset.php └── tests ├── _bootstrap.php ├── _config └── test.php ├── _support ├── AcceptanceTester.php ├── FunctionalTester.php ├── Helper │ ├── Acceptance.php │ ├── Functional.php │ └── Unit.php ├── UnitTester.php └── _generated │ ├── AcceptanceTesterActions.php │ ├── FunctionalTesterActions.php │ └── UnitTesterActions.php ├── acceptance.suite.yml ├── acceptance └── _bootstrap.php ├── docker-compose.yml ├── functional.suite.yml ├── functional └── _bootstrap.php ├── unit.suite.yml └── unit ├── MetaDataTest.php └── _bootstrap.php /.gitignore: -------------------------------------------------------------------------------- 1 | tests/_output 2 | _artifacts 3 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | before_script: 2 | - export BUILD_PREFIX=buildref${CI_BUILD_REF}$(echo ${CI_BUILD_REF_NAME} | tr -dc '[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]')yii2pages 3 | - export COMPOSE_PROJECT_NAME=${BUILD_PREFIX} 4 | - cd tests 5 | 6 | stages: 7 | - test 8 | - report 9 | - cleanup 10 | 11 | test: 12 | stage: test 13 | script: 14 | - set +e 15 | - docker-compose up -d 16 | - docker-compose run --rm phpfpm setup.sh 17 | - docker-compose run --rm -e YII_ENV=test phpfpm codecept run; TESTS_EXIT_CODE=$? 18 | - set -e 19 | - mv _output /tmp/${BUILD_PREFIX} 20 | - exit $TESTS_EXIT_CODE 21 | 22 | report: 23 | stage: report 24 | script: 25 | - mv /tmp/${BUILD_PREFIX} _output 26 | artifacts: 27 | paths: 28 | - tests/_output/ 29 | when: always 30 | 31 | cleanup: 32 | stage: cleanup 33 | script: 34 | - docker-compose kill && docker-compose rm -fv 35 | - docker-compose down --rmi local --volumes 36 | when: always 37 | 38 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | lint: 2 | mkdir -p _artifacts/lint && chmod -R 777 _artifacts/lint 3 | docker run --rm -v "${PWD}:/project" jolicode/phaudit php-cs-fixer fix --format=txt -v --dry-run src || export ERROR=1; \ 4 | docker run --rm -v "${PWD}:/project" jolicode/phaudit phpmetrics --report-html=_artifacts/lint/metrics.html src/ || ERROR=1; \ 5 | docker run --rm -v "${PWD}:/project" jolicode/phaudit phpmd src html cleancode,codesize,controversial,design,unusedcode,tests/phpmd/naming.xml > _artifacts/lint/mess.html || ERROR=1; \ 6 | exit ${ERROR} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Yii2 Helpers 2 | ============ 3 | 4 | [![Latest Stable Version](https://poser.pugx.org/dmstr/yii2-helpers/v/stable.svg)](https://packagist.org/packages/dmstr/yii2-helpers) 5 | [![Total Downloads](https://poser.pugx.org/dmstr/yii2-helpers/downloads.svg)](https://packagist.org/packages/dmstr/yii2-helpers) 6 | [![License](https://poser.pugx.org/dmstr/yii2-helpers/license.svg)](https://packagist.org/packages/dmstr/yii2-helpers) 7 | 8 | Yii2 Helpers 9 | 10 | Installation 11 | ------------ 12 | 13 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 14 | 15 | Either run 16 | 17 | ``` 18 | php composer.phar require --prefer-dist dmstr/yii2-helpers "*" 19 | ``` 20 | 21 | or add 22 | 23 | ``` 24 | "dmstr/yii2-helpers": "*" 25 | ``` 26 | 27 | to the require section of your `composer.json` file. 28 | 29 | 30 | Usage 31 | ----- 32 | 33 | ### Metadata 34 | 35 | Retrieve application meta-information, such as module or controller routes. 36 | 37 | 38 | 39 | Testing 40 | ------- 41 | 42 | Run the tests with phd testing-stack 43 | 44 | cd tests 45 | docker-compose up -d 46 | 47 | Setup application 48 | 49 | docker-compose run --rm phpfpm setup.sh 50 | 51 | Run test suites 52 | 53 | docker-compose run --rm -e YII_ENV=test phpfpm codecept run 54 | 55 | or start a bash for 56 | 57 | docker-compose run --rm -e YII_ENV=test phpfpm bash 58 | -------------------------------------------------------------------------------- /codeception.yml: -------------------------------------------------------------------------------- 1 | actor: Tester 2 | paths: 3 | tests: tests 4 | log: tests/_output 5 | data: tests/_data 6 | support: tests/_support 7 | envs: tests/_envs 8 | settings: 9 | bootstrap: _bootstrap.php 10 | colors: true 11 | memory_limit: 1024M 12 | config: 13 | test_entry_url: http://nginx:80/index.php 14 | extensions: 15 | enabled: 16 | - Codeception\Extension\RunFailed 17 | modules: 18 | config: 19 | Db: 20 | dsn: '' 21 | user: '' 22 | password: '' 23 | dump: tests/_data/dump.sql 24 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dmstr/yii2-helpers", 3 | "description": "Yii2 Helpers", 4 | "type": "yii2-extension", 5 | "keywords": ["yii2","extension"], 6 | "license": "BSD-3-Clause", 7 | "authors": [ 8 | { 9 | "name": "Sergej Kunz", 10 | "email": "s.kunz@herzogkommunikation.de" 11 | }, 12 | { 13 | "name": "Tobias Munk", 14 | "email": "t.munk@herzogkommunikation.de" 15 | } 16 | ], 17 | "require": { 18 | "yiisoft/yii2": "~2.0.0", 19 | "pheme/yii2-settings": "^0.5.0 || ^0.7.0" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "dmstr\\helpers\\": "src/" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/AssetHash.php: -------------------------------------------------------------------------------- 1 | ['*.js', '*.css', '*.less']]); 29 | } 30 | 31 | 32 | $max = 0; 33 | foreach ($files as $file) { 34 | $max = max($max, filemtime($file), filectime($file)); 35 | } 36 | 37 | $hash = substr(hash('sha256', $path . $max), 0, 6) . 38 | '-' . APP_VERSION . '-c' . \Yii::$app->cache->get('prototype.less.changed_at'); 39 | Yii::trace(['byFileTimeAndLess', $path, count($files), Yii::$app->formatter->asRelativeTime($max), $hash], 40 | __METHOD__); 41 | 42 | return $hash; 43 | }; 44 | } 45 | 46 | /** 47 | * Returns asset hashes for development 48 | * 49 | * Format: version git less path time 50 | * 51 | * dev-v1.0.0-ga1b2c3e-l123456/path|to|asset-tf6e5d3 52 | * 53 | * @return \Closure 54 | */ 55 | static public function byFileTimeAndLessDevelopment() 56 | { 57 | return function ($path) { 58 | if (is_file($path)) { 59 | $files[] = $path; 60 | } else { 61 | $files = \yii\helpers\FileHelper::findFiles($path, ['only' => ['*.js', '*.css', '*.less']]); 62 | } 63 | 64 | $max = 0; 65 | foreach ($files as $file) { 66 | $max = max($max, filemtime($file), filectime($file)); 67 | } 68 | 69 | $modificationHash = substr(hash('sha256', $max), 0, 6); 70 | 71 | $hash = 'dev' . 72 | '-v' . APP_VERSION . 73 | '-p' . strtr($path, ['/' => '|']) . 74 | '-t' . $modificationHash; 75 | Yii::trace(['byFileTimeAndLessDevelopment', $path, count($files), Yii::$app->formatter->asRelativeTime($max), $hash], 76 | __METHOD__); 77 | 78 | return $hash; 79 | }; 80 | } 81 | 82 | /** 83 | * Returns asset hashes for production 84 | * 85 | * Checks mtime, ctime by folder 86 | * 87 | * @return \Closure 88 | */ 89 | static public function byFileTime($obfuscateHash = true) 90 | { 91 | return function ($path) use ($obfuscateHash) { 92 | if (is_file($path)) { 93 | $files[] = $path; 94 | } else { 95 | $files = \yii\helpers\FileHelper::findFiles($path, ['only' => ['*.js', '*.css', '*.less']]); 96 | } 97 | 98 | 99 | $max = 0; 100 | foreach ($files as $file) { 101 | $max = max($max, filemtime($file), filectime($file)); 102 | } 103 | 104 | $hash = YII_ENV . 105 | '-r' . PROJECT_VERSION . 106 | '-v' . APP_VERSION . 107 | '-p' . strtr($path, ['/' => '_']) . 108 | '-t' . $max; 109 | Yii::trace(['byFileTime', $path, count($files), Yii::$app->formatter->asRelativeTime($max), $hash], 110 | __METHOD__); 111 | 112 | if ($obfuscateHash) { 113 | return md5($hash); 114 | } 115 | 116 | return $hash; 117 | }; 118 | } 119 | } -------------------------------------------------------------------------------- /src/AuthenticatedRule.php: -------------------------------------------------------------------------------- 1 | user->isGuest; 12 | } 13 | } -------------------------------------------------------------------------------- /src/Html.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | class Html extends \yii\helpers\Html 19 | { 20 | /** 21 | * Use case: 22 | * \dmstr\helpers\Html::a("test link", ['create']). 23 | * 24 | * @param string $text 25 | * @param null $url 26 | * @param array $options 27 | * 28 | * @return string|null 29 | */ 30 | public static function a($text, $url = null, $options = []) 31 | { 32 | return RouteAccess::can($url, function () use ($text, $url, $options) { 33 | return parent::a($text, $url, $options); 34 | }, function () { 35 | return; 36 | }, [ 37 | $text, 38 | $options, 39 | ]); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ImageProxy.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | class ImageProxy 19 | { 20 | 21 | public static function getFile($imageSource, $preset = null) 22 | { 23 | // check if settings components is set 24 | if (isset(\Yii::$app->settings)) { 25 | // preset example, when using imageproxy, https://github.com/willnorris/imageproxy#examples 26 | return \Yii::$app->settings->get('imgBaseUrl', 'app.frontend') . 27 | $preset . 28 | \Yii::$app->settings->get('imgHostPrefix', 'app.frontend') . 29 | $imageSource . 30 | \Yii::$app->settings->get('imgHostSuffix', 'app.frontend'); 31 | } 32 | return $imageSource; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Metadata.php: -------------------------------------------------------------------------------- 1 | getModules(); 19 | if ($sorted) { 20 | ksort($modules); 21 | } 22 | 23 | return $modules; 24 | } 25 | 26 | /** 27 | * @param null $module 28 | * @param null $directory 29 | * @param array $blacklist List of blacklisted controllers (e.g. abstract controllers) 30 | * @return array 31 | */ 32 | public static function getModuleControllers($module = null, $directory = null, $blacklist = ['abstract-auth-item']) 33 | { 34 | if ($module === null) { 35 | $module = \Yii::$app; 36 | } elseif ($module instanceof Module) { 37 | //$module = $module; 38 | } else { 39 | $module = \Yii::$app->getModule($module); 40 | } 41 | 42 | $controllers = []; 43 | $controllerDir = $module->getControllerPath().'/'.$directory; 44 | if (is_dir($controllerDir)) { 45 | foreach (scandir($controllerDir) as $i => $name) { 46 | if (substr($name, 0, 1) == '.') { 47 | continue; 48 | } 49 | if (substr($name, -14) != 'Controller.php') { 50 | continue; 51 | } 52 | $controller = Inflector::camel2id(str_replace('Controller.php', '', $name),'-',true); 53 | 54 | if (!\in_array($controller,$blacklist,true)) { 55 | $route = ($module->id == 'app') ? '' : '/'.$module->id; 56 | $route .= (!$directory) ? '' : '/'.$directory; 57 | $route .= '/' . $controller; 58 | 59 | // check if controller not is abstract 60 | try { 61 | $c = Yii::$app->createController($route); 62 | } catch (NotInstantiableException $exception) { 63 | $c = false; 64 | } 65 | 66 | if ($c === false) { 67 | continue; 68 | } 69 | 70 | $controllers[] = [ 71 | 'name' => $controller, 72 | 'module' => $module->id, 73 | 'route' => $route, 74 | 'url' => Yii::$app->urlManager->createUrl($route), 75 | 'actions' => self::getControllerActions($c[0]), 76 | ]; 77 | } 78 | 79 | } 80 | } 81 | 82 | return $controllers; 83 | } 84 | 85 | public static function getAllControllers() 86 | { 87 | $controllers = self::getModuleControllers(); 88 | foreach (\Yii::$app->getModules() as $id => $module) { 89 | #var_dump($module); 90 | $controllers = ArrayHelper::merge($controllers, self::getModuleControllers($id)); 91 | } 92 | 93 | return $controllers; 94 | } 95 | 96 | /** 97 | * Returns all available actions of the specified controller. 98 | * Taken from Yii2 HelpController. 99 | * 100 | * @param Controller $controller the controller instance 101 | * 102 | * @return array all available action IDs. 103 | */ 104 | public static function getControllerActions($controller) 105 | { 106 | if (!$controller) { 107 | return []; 108 | } 109 | $actions = []; 110 | $prefix = ($controller->module->id === Yii::$app->id) ? '/'.$controller->id.'/' : 111 | $controller->module->id.'/'.$controller->id.'/'; 112 | foreach ($controller->actions() as $name => $importedActions) { 113 | $actions[] = [ 114 | 'name' => $name, 115 | 'route' => Yii::$app->urlManager->createUrl($prefix.$name), 116 | ]; 117 | } 118 | $class = new \ReflectionClass($controller); 119 | foreach ($class->getMethods() as $method) { 120 | $name = $method->getName(); 121 | if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') { 122 | $action = Inflector::camel2id(substr($name, 6), '-', true); 123 | $actions[] = [ 124 | 'name' => $action, 125 | 'route' => Yii::$app->urlManager->createUrl($prefix.$action), 126 | ]; 127 | } 128 | } 129 | //sort($actions); 130 | return $actions; 131 | #return array_unique($actions); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/RbacController.php: -------------------------------------------------------------------------------- 1 | user->identityClass; 25 | $user = $userModel::find()->where(['username' => $userName])->one(); 26 | $manager = \Yii::$app->authManager; 27 | if (\in_array($user->id, $manager->getUserIdsByRole($roleName))) { 28 | $this->stdout('Role is already assigned to this user'.PHP_EOL); 29 | $this->stdout(PHP_EOL.PHP_EOL.'Aborted.'.PHP_EOL); 30 | } else { 31 | $role = $manager->getRole($roleName); 32 | $manager->assign($role, $user->id); 33 | $this->stdout('Role has been assigned'); 34 | $this->stdout(PHP_EOL.PHP_EOL.'Done.'.PHP_EOL); 35 | } 36 | } 37 | 38 | /** 39 | * Revoke role from user 40 | * 41 | * @param $roleName 42 | * @param $userName 43 | */ 44 | public function actionRevoke($roleName, $userName) 45 | { 46 | $userModel = new \Yii::$app->user->identityClass; 47 | $user = $userModel::find()->where(['username' => $userName])->one(); 48 | $manager = \Yii::$app->authManager; 49 | $role = $manager->getRole($roleName); 50 | $manager->revoke($role, $user->id); 51 | $this->stdout('Role has been revoked'); 52 | $this->stdout(PHP_EOL.PHP_EOL.'Done.'.PHP_EOL); 53 | } 54 | } -------------------------------------------------------------------------------- /src/RouteAccess.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | class RouteAccess 24 | { 25 | protected static $_accessCache = []; 26 | 27 | /** 28 | * @param $route 29 | * @param callable $callback 30 | * 31 | * @return null|mixed 32 | */ 33 | public static function can($route, \Closure $callback = null, \Closure $failCallback = null, $attributes = []) 34 | { 35 | if (is_array($route)) { 36 | $route = (array) $route; 37 | $key = json_encode($route); 38 | $route = static::normalizeRoute($route[0]); 39 | } else { 40 | $key = $route; 41 | } 42 | 43 | if (isset($callback)) { 44 | $key .= spl_object_hash($callback); 45 | } 46 | 47 | if (isset($failCallback)) { 48 | $key .= spl_object_hash($failCallback); 49 | } 50 | 51 | $key .= json_encode($attributes); 52 | $key = md5($key); 53 | 54 | if (!isset(static::$_accessCache[$key])) { 55 | self::$_accessCache[$key] = false; 56 | $parts = \Yii::$app->createController($route); 57 | if ($parts) { 58 | /* 59 | * @var Controller 60 | */ 61 | list($controller, $actionID) = $parts; 62 | if (!$actionID) { 63 | $actionID = 'index'; 64 | } 65 | 66 | $tmpLoginUrl = Yii::$app->user->loginUrl; 67 | Yii::$app->user->loginUrl = null; 68 | try { 69 | $modules = $controller->getModules(); 70 | if ($modules && !$modules[count($modules) - 1]->beforeAction(new Action($actionID, $controller))) { 71 | throw new \Exception('not valid'); 72 | } 73 | 74 | if ($controller->beforeAction(new Action($actionID, $controller))) { 75 | if (isset($callback)) { 76 | self::$_accessCache[$key] = $callback(); 77 | } else { 78 | self::$_accessCache[$key] = true; 79 | } 80 | } 81 | } catch (\Exception $e) { 82 | if (isset($failCallback)) { 83 | self::$_accessCache[$key] = $failCallback(); 84 | } 85 | } 86 | 87 | Yii::$app->user->loginUrl = $tmpLoginUrl; 88 | } 89 | } 90 | 91 | return self::$_accessCache[$key]; 92 | } 93 | 94 | /** 95 | * @param $route 96 | * 97 | * @return string 98 | */ 99 | protected static function normalizeRoute($route) 100 | { 101 | $route = Yii::getAlias((string) $route); 102 | if (strncmp($route, '/', 1) === 0) { 103 | // absolute route 104 | return ltrim($route, '/'); 105 | } 106 | 107 | // relative route 108 | if (Yii::$app->controller === null) { 109 | throw new InvalidParamException("Unable to resolve the relative route: $route. No active controller is available."); 110 | } 111 | 112 | if (strpos($route, '/') === false) { 113 | // empty or an action ID 114 | return $route === '' ? Yii::$app->controller->getRoute() : Yii::$app->controller->getUniqueId().'/'.$route; 115 | } else { 116 | // relative to module 117 | return ltrim(Yii::$app->controller->module->getUniqueId().'/'.$route, '/'); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/SettingsAsset.php: -------------------------------------------------------------------------------- 1 | settings->getOrSet('settingsAssetList', 'app\\assets\\AppAsset', 'app.assets', 'string') 20 | ); 21 | 22 | foreach ($bundles as $bundle) { 23 | $bundle = trim($bundle); 24 | // ignore empty lines 25 | if ($bundle === '') { 26 | continue; 27 | } 28 | if (class_exists($bundle)) { 29 | $bundle::register($view); 30 | } else { 31 | \Yii::warning("Asset bundle '{$bundle}' from settings does not exist"); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/_bootstrap.php: -------------------------------------------------------------------------------- 1 | 'app\controllers', 9 | ] 10 | ); 11 | -------------------------------------------------------------------------------- /tests/_support/AcceptanceTester.php: -------------------------------------------------------------------------------- 1 | setHeader('X-Requested-With', 'Codeception'); 29 | * $I->amOnPage('test-headers.php'); 30 | * ?> 31 | * ``` 32 | * 33 | * @param string $name the name of the request header 34 | * @param string $value the value to set it to for subsequent 35 | * requests 36 | * @see \Codeception\Module\PhpBrowser::setHeader() 37 | */ 38 | public function setHeader($name, $value) { 39 | return $this->getScenario()->runStep(new \Codeception\Step\Action('setHeader', func_get_args())); 40 | } 41 | 42 | 43 | /** 44 | * [!] Method is generated. Documentation taken from corresponding module. 45 | * 46 | * Deletes the header with the passed name. Subsequent requests 47 | * will not have the deleted header in its request. 48 | * 49 | * Example: 50 | * ```php 51 | * setHeader('X-Requested-With', 'Codeception'); 53 | * $I->amOnPage('test-headers.php'); 54 | * // ... 55 | * $I->deleteHeader('X-Requested-With'); 56 | * $I->amOnPage('some-other-page.php'); 57 | * ?> 58 | * ``` 59 | * 60 | * @param string $name the name of the header to delete. 61 | * @see \Codeception\Module\PhpBrowser::deleteHeader() 62 | */ 63 | public function deleteHeader($name) { 64 | return $this->getScenario()->runStep(new \Codeception\Step\Action('deleteHeader', func_get_args())); 65 | } 66 | 67 | 68 | /** 69 | * [!] Method is generated. Documentation taken from corresponding module. 70 | * 71 | * Authenticates user for HTTP_AUTH 72 | * 73 | * @param $username 74 | * @param $password 75 | * @see \Codeception\Module\PhpBrowser::amHttpAuthenticated() 76 | */ 77 | public function amHttpAuthenticated($username, $password) { 78 | return $this->getScenario()->runStep(new \Codeception\Step\Condition('amHttpAuthenticated', func_get_args())); 79 | } 80 | 81 | 82 | /** 83 | * [!] Method is generated. Documentation taken from corresponding module. 84 | * 85 | * Open web page at the given absolute URL and sets its hostname as the base host. 86 | * 87 | * ``` php 88 | * amOnUrl('http://codeception.com'); 90 | * $I->amOnPage('/quickstart'); // moves to http://codeception.com/quickstart 91 | * ?> 92 | * ``` 93 | * @see \Codeception\Module\PhpBrowser::amOnUrl() 94 | */ 95 | public function amOnUrl($url) { 96 | return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnUrl', func_get_args())); 97 | } 98 | 99 | 100 | /** 101 | * [!] Method is generated. Documentation taken from corresponding module. 102 | * 103 | * Changes the subdomain for the 'url' configuration parameter. 104 | * Does not open a page; use `amOnPage` for that. 105 | * 106 | * ``` php 107 | * amOnSubdomain('user'); 113 | * $I->amOnPage('/'); 114 | * // moves to http://user.mysite.com/ 115 | * ?> 116 | * ``` 117 | * 118 | * @param $subdomain 119 | * 120 | * @return mixed 121 | * @see \Codeception\Module\PhpBrowser::amOnSubdomain() 122 | */ 123 | public function amOnSubdomain($subdomain) { 124 | return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnSubdomain', func_get_args())); 125 | } 126 | 127 | 128 | /** 129 | * [!] Method is generated. Documentation taken from corresponding module. 130 | * 131 | * Low-level API method. 132 | * If Codeception commands are not enough, use [Guzzle HTTP Client](http://guzzlephp.org/) methods directly 133 | * 134 | * Example: 135 | * 136 | * ``` php 137 | * executeInGuzzle(function (\GuzzleHttp\Client $client) { 139 | * $client->get('/get', ['query' => ['foo' => 'bar']]); 140 | * }); 141 | * ?> 142 | * ``` 143 | * 144 | * It is not recommended to use this command on a regular basis. 145 | * If Codeception lacks important Guzzle Client methods, implement them and submit patches. 146 | * 147 | * @param callable $function 148 | * @see \Codeception\Module\PhpBrowser::executeInGuzzle() 149 | */ 150 | public function executeInGuzzle($function) { 151 | return $this->getScenario()->runStep(new \Codeception\Step\Action('executeInGuzzle', func_get_args())); 152 | } 153 | 154 | 155 | /** 156 | * [!] Method is generated. Documentation taken from corresponding module. 157 | * 158 | * Opens the page for the given relative URI. 159 | * 160 | * ``` php 161 | * amOnPage('/'); 164 | * // opens /register page 165 | * $I->amOnPage('/register'); 166 | * ``` 167 | * 168 | * @param $page 169 | * @see \Codeception\Lib\InnerBrowser::amOnPage() 170 | */ 171 | public function amOnPage($page) { 172 | return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnPage', func_get_args())); 173 | } 174 | 175 | 176 | /** 177 | * [!] Method is generated. Documentation taken from corresponding module. 178 | * 179 | * Perform a click on a link or a button, given by a locator. 180 | * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. 181 | * For buttons, the "value" attribute, "name" attribute, and inner text are searched. 182 | * For links, the link text is searched. 183 | * For images, the "alt" attribute and inner text of any parent links are searched. 184 | * 185 | * The second parameter is a context (CSS or XPath locator) to narrow the search. 186 | * 187 | * Note that if the locator matches a button of type `submit`, the form will be submitted. 188 | * 189 | * ``` php 190 | * click('Logout'); 193 | * // button of form 194 | * $I->click('Submit'); 195 | * // CSS button 196 | * $I->click('#form input[type=submit]'); 197 | * // XPath 198 | * $I->click('//form/*[@type=submit]'); 199 | * // link in context 200 | * $I->click('Logout', '#nav'); 201 | * // using strict locator 202 | * $I->click(['link' => 'Login']); 203 | * ?> 204 | * ``` 205 | * 206 | * @param $link 207 | * @param $context 208 | * @see \Codeception\Lib\InnerBrowser::click() 209 | */ 210 | public function click($link, $context = null) { 211 | return $this->getScenario()->runStep(new \Codeception\Step\Action('click', func_get_args())); 212 | } 213 | 214 | 215 | /** 216 | * [!] Method is generated. Documentation taken from corresponding module. 217 | * 218 | * Checks that the current page contains the given string (case insensitive). 219 | * 220 | * You can specify a specific HTML element (via CSS or XPath) as the second 221 | * parameter to only search within that element. 222 | * 223 | * ``` php 224 | * see('Logout'); // I can suppose user is logged in 226 | * $I->see('Sign Up', 'h1'); // I can suppose it's a signup page 227 | * $I->see('Sign Up', '//body/h1'); // with XPath 228 | * ``` 229 | * 230 | * Note that the search is done after stripping all HTML tags from the body, 231 | * so `$I->see('strong')` will return true for strings like: 232 | * 233 | * - `

I am Stronger than thou

` 234 | * - `` 235 | * 236 | * But will *not* be true for strings like: 237 | * 238 | * - `Home` 239 | * - `
Home` 240 | * - `` 241 | * 242 | * For checking the raw source code, use `seeInSource()`. 243 | * 244 | * @param $text 245 | * @param null $selector 246 | * Conditional Assertion: Test won't be stopped on fail 247 | * @see \Codeception\Lib\InnerBrowser::see() 248 | */ 249 | public function canSee($text, $selector = null) { 250 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('see', func_get_args())); 251 | } 252 | /** 253 | * [!] Method is generated. Documentation taken from corresponding module. 254 | * 255 | * Checks that the current page contains the given string (case insensitive). 256 | * 257 | * You can specify a specific HTML element (via CSS or XPath) as the second 258 | * parameter to only search within that element. 259 | * 260 | * ``` php 261 | * see('Logout'); // I can suppose user is logged in 263 | * $I->see('Sign Up', 'h1'); // I can suppose it's a signup page 264 | * $I->see('Sign Up', '//body/h1'); // with XPath 265 | * ``` 266 | * 267 | * Note that the search is done after stripping all HTML tags from the body, 268 | * so `$I->see('strong')` will return true for strings like: 269 | * 270 | * - `

I am Stronger than thou

` 271 | * - `` 272 | * 273 | * But will *not* be true for strings like: 274 | * 275 | * - `Home` 276 | * - `
Home` 277 | * - `` 278 | * 279 | * For checking the raw source code, use `seeInSource()`. 280 | * 281 | * @param $text 282 | * @param null $selector 283 | * @see \Codeception\Lib\InnerBrowser::see() 284 | */ 285 | public function see($text, $selector = null) { 286 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('see', func_get_args())); 287 | } 288 | 289 | 290 | /** 291 | * [!] Method is generated. Documentation taken from corresponding module. 292 | * 293 | * Checks that the current page doesn't contain the text specified (case insensitive). 294 | * Give a locator as the second parameter to match a specific region. 295 | * 296 | * ```php 297 | * dontSee('Login'); // I can suppose user is already logged in 299 | * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page 300 | * $I->dontSee('Sign Up','//body/h1'); // with XPath 301 | * ``` 302 | * 303 | * Note that the search is done after stripping all HTML tags from the body, 304 | * so `$I->dontSee('strong')` will fail on strings like: 305 | * 306 | * - `

I am Stronger than thou

` 307 | * - `` 308 | * 309 | * But will ignore strings like: 310 | * 311 | * - `Home` 312 | * - `
Home` 313 | * - `` 314 | * 315 | * For checking the raw source code, use `seeInSource()`. 316 | * 317 | * @param $text 318 | * @param null $selector 319 | * Conditional Assertion: Test won't be stopped on fail 320 | * @see \Codeception\Lib\InnerBrowser::dontSee() 321 | */ 322 | public function cantSee($text, $selector = null) { 323 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSee', func_get_args())); 324 | } 325 | /** 326 | * [!] Method is generated. Documentation taken from corresponding module. 327 | * 328 | * Checks that the current page doesn't contain the text specified (case insensitive). 329 | * Give a locator as the second parameter to match a specific region. 330 | * 331 | * ```php 332 | * dontSee('Login'); // I can suppose user is already logged in 334 | * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page 335 | * $I->dontSee('Sign Up','//body/h1'); // with XPath 336 | * ``` 337 | * 338 | * Note that the search is done after stripping all HTML tags from the body, 339 | * so `$I->dontSee('strong')` will fail on strings like: 340 | * 341 | * - `

I am Stronger than thou

` 342 | * - `` 343 | * 344 | * But will ignore strings like: 345 | * 346 | * - `Home` 347 | * - `
Home` 348 | * - `` 349 | * 350 | * For checking the raw source code, use `seeInSource()`. 351 | * 352 | * @param $text 353 | * @param null $selector 354 | * @see \Codeception\Lib\InnerBrowser::dontSee() 355 | */ 356 | public function dontSee($text, $selector = null) { 357 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSee', func_get_args())); 358 | } 359 | 360 | 361 | /** 362 | * [!] Method is generated. Documentation taken from corresponding module. 363 | * 364 | * Checks that the current page contains the given string in its 365 | * raw source code. 366 | * 367 | * ``` php 368 | * seeInSource('

Green eggs & ham

'); 370 | * ``` 371 | * 372 | * @param $raw 373 | * Conditional Assertion: Test won't be stopped on fail 374 | * @see \Codeception\Lib\InnerBrowser::seeInSource() 375 | */ 376 | public function canSeeInSource($raw) { 377 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInSource', func_get_args())); 378 | } 379 | /** 380 | * [!] Method is generated. Documentation taken from corresponding module. 381 | * 382 | * Checks that the current page contains the given string in its 383 | * raw source code. 384 | * 385 | * ``` php 386 | * seeInSource('

Green eggs & ham

'); 388 | * ``` 389 | * 390 | * @param $raw 391 | * @see \Codeception\Lib\InnerBrowser::seeInSource() 392 | */ 393 | public function seeInSource($raw) { 394 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInSource', func_get_args())); 395 | } 396 | 397 | 398 | /** 399 | * [!] Method is generated. Documentation taken from corresponding module. 400 | * 401 | * Checks that the current page contains the given string in its 402 | * raw source code. 403 | * 404 | * ```php 405 | * dontSeeInSource('

Green eggs & ham

'); 407 | * ``` 408 | * 409 | * @param $raw 410 | * Conditional Assertion: Test won't be stopped on fail 411 | * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() 412 | */ 413 | public function cantSeeInSource($raw) { 414 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInSource', func_get_args())); 415 | } 416 | /** 417 | * [!] Method is generated. Documentation taken from corresponding module. 418 | * 419 | * Checks that the current page contains the given string in its 420 | * raw source code. 421 | * 422 | * ```php 423 | * dontSeeInSource('

Green eggs & ham

'); 425 | * ``` 426 | * 427 | * @param $raw 428 | * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() 429 | */ 430 | public function dontSeeInSource($raw) { 431 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInSource', func_get_args())); 432 | } 433 | 434 | 435 | /** 436 | * [!] Method is generated. Documentation taken from corresponding module. 437 | * 438 | * Checks that there's a link with the specified text. 439 | * Give a full URL as the second parameter to match links with that exact URL. 440 | * 441 | * ``` php 442 | * seeLink('Logout'); // matches Logout 444 | * $I->seeLink('Logout','/logout'); // matches Logout 445 | * ?> 446 | * ``` 447 | * 448 | * @param $text 449 | * @param null $url 450 | * Conditional Assertion: Test won't be stopped on fail 451 | * @see \Codeception\Lib\InnerBrowser::seeLink() 452 | */ 453 | public function canSeeLink($text, $url = null) { 454 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeLink', func_get_args())); 455 | } 456 | /** 457 | * [!] Method is generated. Documentation taken from corresponding module. 458 | * 459 | * Checks that there's a link with the specified text. 460 | * Give a full URL as the second parameter to match links with that exact URL. 461 | * 462 | * ``` php 463 | * seeLink('Logout'); // matches Logout 465 | * $I->seeLink('Logout','/logout'); // matches Logout 466 | * ?> 467 | * ``` 468 | * 469 | * @param $text 470 | * @param null $url 471 | * @see \Codeception\Lib\InnerBrowser::seeLink() 472 | */ 473 | public function seeLink($text, $url = null) { 474 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeLink', func_get_args())); 475 | } 476 | 477 | 478 | /** 479 | * [!] Method is generated. Documentation taken from corresponding module. 480 | * 481 | * Checks that the page doesn't contain a link with the given string. 482 | * If the second parameter is given, only links with a matching "href" attribute will be checked. 483 | * 484 | * ``` php 485 | * dontSeeLink('Logout'); // I suppose user is not logged in 487 | * $I->dontSeeLink('Checkout now', '/store/cart.php'); 488 | * ?> 489 | * ``` 490 | * 491 | * @param $text 492 | * @param null $url 493 | * Conditional Assertion: Test won't be stopped on fail 494 | * @see \Codeception\Lib\InnerBrowser::dontSeeLink() 495 | */ 496 | public function cantSeeLink($text, $url = null) { 497 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeLink', func_get_args())); 498 | } 499 | /** 500 | * [!] Method is generated. Documentation taken from corresponding module. 501 | * 502 | * Checks that the page doesn't contain a link with the given string. 503 | * If the second parameter is given, only links with a matching "href" attribute will be checked. 504 | * 505 | * ``` php 506 | * dontSeeLink('Logout'); // I suppose user is not logged in 508 | * $I->dontSeeLink('Checkout now', '/store/cart.php'); 509 | * ?> 510 | * ``` 511 | * 512 | * @param $text 513 | * @param null $url 514 | * @see \Codeception\Lib\InnerBrowser::dontSeeLink() 515 | */ 516 | public function dontSeeLink($text, $url = null) { 517 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeLink', func_get_args())); 518 | } 519 | 520 | 521 | /** 522 | * [!] Method is generated. Documentation taken from corresponding module. 523 | * 524 | * Checks that current URI contains the given string. 525 | * 526 | * ``` php 527 | * seeInCurrentUrl('home'); 530 | * // to match: /users/1 531 | * $I->seeInCurrentUrl('/users/'); 532 | * ?> 533 | * ``` 534 | * 535 | * @param $uri 536 | * Conditional Assertion: Test won't be stopped on fail 537 | * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() 538 | */ 539 | public function canSeeInCurrentUrl($uri) { 540 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInCurrentUrl', func_get_args())); 541 | } 542 | /** 543 | * [!] Method is generated. Documentation taken from corresponding module. 544 | * 545 | * Checks that current URI contains the given string. 546 | * 547 | * ``` php 548 | * seeInCurrentUrl('home'); 551 | * // to match: /users/1 552 | * $I->seeInCurrentUrl('/users/'); 553 | * ?> 554 | * ``` 555 | * 556 | * @param $uri 557 | * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() 558 | */ 559 | public function seeInCurrentUrl($uri) { 560 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInCurrentUrl', func_get_args())); 561 | } 562 | 563 | 564 | /** 565 | * [!] Method is generated. Documentation taken from corresponding module. 566 | * 567 | * Checks that the current URI doesn't contain the given string. 568 | * 569 | * ``` php 570 | * dontSeeInCurrentUrl('/users/'); 572 | * ?> 573 | * ``` 574 | * 575 | * @param $uri 576 | * Conditional Assertion: Test won't be stopped on fail 577 | * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() 578 | */ 579 | public function cantSeeInCurrentUrl($uri) { 580 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInCurrentUrl', func_get_args())); 581 | } 582 | /** 583 | * [!] Method is generated. Documentation taken from corresponding module. 584 | * 585 | * Checks that the current URI doesn't contain the given string. 586 | * 587 | * ``` php 588 | * dontSeeInCurrentUrl('/users/'); 590 | * ?> 591 | * ``` 592 | * 593 | * @param $uri 594 | * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() 595 | */ 596 | public function dontSeeInCurrentUrl($uri) { 597 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInCurrentUrl', func_get_args())); 598 | } 599 | 600 | 601 | /** 602 | * [!] Method is generated. Documentation taken from corresponding module. 603 | * 604 | * Checks that the current URL is equal to the given string. 605 | * Unlike `seeInCurrentUrl`, this only matches the full URL. 606 | * 607 | * ``` php 608 | * seeCurrentUrlEquals('/'); 611 | * ?> 612 | * ``` 613 | * 614 | * @param $uri 615 | * Conditional Assertion: Test won't be stopped on fail 616 | * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() 617 | */ 618 | public function canSeeCurrentUrlEquals($uri) { 619 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCurrentUrlEquals', func_get_args())); 620 | } 621 | /** 622 | * [!] Method is generated. Documentation taken from corresponding module. 623 | * 624 | * Checks that the current URL is equal to the given string. 625 | * Unlike `seeInCurrentUrl`, this only matches the full URL. 626 | * 627 | * ``` php 628 | * seeCurrentUrlEquals('/'); 631 | * ?> 632 | * ``` 633 | * 634 | * @param $uri 635 | * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() 636 | */ 637 | public function seeCurrentUrlEquals($uri) { 638 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlEquals', func_get_args())); 639 | } 640 | 641 | 642 | /** 643 | * [!] Method is generated. Documentation taken from corresponding module. 644 | * 645 | * Checks that the current URL doesn't equal the given string. 646 | * Unlike `dontSeeInCurrentUrl`, this only matches the full URL. 647 | * 648 | * ``` php 649 | * dontSeeCurrentUrlEquals('/'); 652 | * ?> 653 | * ``` 654 | * 655 | * @param $uri 656 | * Conditional Assertion: Test won't be stopped on fail 657 | * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() 658 | */ 659 | public function cantSeeCurrentUrlEquals($uri) { 660 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlEquals', func_get_args())); 661 | } 662 | /** 663 | * [!] Method is generated. Documentation taken from corresponding module. 664 | * 665 | * Checks that the current URL doesn't equal the given string. 666 | * Unlike `dontSeeInCurrentUrl`, this only matches the full URL. 667 | * 668 | * ``` php 669 | * dontSeeCurrentUrlEquals('/'); 672 | * ?> 673 | * ``` 674 | * 675 | * @param $uri 676 | * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() 677 | */ 678 | public function dontSeeCurrentUrlEquals($uri) { 679 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCurrentUrlEquals', func_get_args())); 680 | } 681 | 682 | 683 | /** 684 | * [!] Method is generated. Documentation taken from corresponding module. 685 | * 686 | * Checks that the current URL matches the given regular expression. 687 | * 688 | * ``` php 689 | * seeCurrentUrlMatches('~$/users/(\d+)~'); 692 | * ?> 693 | * ``` 694 | * 695 | * @param $uri 696 | * Conditional Assertion: Test won't be stopped on fail 697 | * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() 698 | */ 699 | public function canSeeCurrentUrlMatches($uri) { 700 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCurrentUrlMatches', func_get_args())); 701 | } 702 | /** 703 | * [!] Method is generated. Documentation taken from corresponding module. 704 | * 705 | * Checks that the current URL matches the given regular expression. 706 | * 707 | * ``` php 708 | * seeCurrentUrlMatches('~$/users/(\d+)~'); 711 | * ?> 712 | * ``` 713 | * 714 | * @param $uri 715 | * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() 716 | */ 717 | public function seeCurrentUrlMatches($uri) { 718 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlMatches', func_get_args())); 719 | } 720 | 721 | 722 | /** 723 | * [!] Method is generated. Documentation taken from corresponding module. 724 | * 725 | * Checks that current url doesn't match the given regular expression. 726 | * 727 | * ``` php 728 | * dontSeeCurrentUrlMatches('~$/users/(\d+)~'); 731 | * ?> 732 | * ``` 733 | * 734 | * @param $uri 735 | * Conditional Assertion: Test won't be stopped on fail 736 | * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() 737 | */ 738 | public function cantSeeCurrentUrlMatches($uri) { 739 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlMatches', func_get_args())); 740 | } 741 | /** 742 | * [!] Method is generated. Documentation taken from corresponding module. 743 | * 744 | * Checks that current url doesn't match the given regular expression. 745 | * 746 | * ``` php 747 | * dontSeeCurrentUrlMatches('~$/users/(\d+)~'); 750 | * ?> 751 | * ``` 752 | * 753 | * @param $uri 754 | * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() 755 | */ 756 | public function dontSeeCurrentUrlMatches($uri) { 757 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCurrentUrlMatches', func_get_args())); 758 | } 759 | 760 | 761 | /** 762 | * [!] Method is generated. Documentation taken from corresponding module. 763 | * 764 | * Executes the given regular expression against the current URI and returns the first match. 765 | * If no parameters are provided, the full URI is returned. 766 | * 767 | * ``` php 768 | * grabFromCurrentUrl('~$/user/(\d+)/~'); 770 | * $uri = $I->grabFromCurrentUrl(); 771 | * ?> 772 | * ``` 773 | * 774 | * @param null $uri 775 | * 776 | * @return mixed 777 | * @see \Codeception\Lib\InnerBrowser::grabFromCurrentUrl() 778 | */ 779 | public function grabFromCurrentUrl($uri = null) { 780 | return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromCurrentUrl', func_get_args())); 781 | } 782 | 783 | 784 | /** 785 | * [!] Method is generated. Documentation taken from corresponding module. 786 | * 787 | * Checks that the specified checkbox is checked. 788 | * 789 | * ``` php 790 | * seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms 792 | * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. 793 | * $I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); 794 | * ?> 795 | * ``` 796 | * 797 | * @param $checkbox 798 | * Conditional Assertion: Test won't be stopped on fail 799 | * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() 800 | */ 801 | public function canSeeCheckboxIsChecked($checkbox) { 802 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCheckboxIsChecked', func_get_args())); 803 | } 804 | /** 805 | * [!] Method is generated. Documentation taken from corresponding module. 806 | * 807 | * Checks that the specified checkbox is checked. 808 | * 809 | * ``` php 810 | * seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms 812 | * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. 813 | * $I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); 814 | * ?> 815 | * ``` 816 | * 817 | * @param $checkbox 818 | * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() 819 | */ 820 | public function seeCheckboxIsChecked($checkbox) { 821 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCheckboxIsChecked', func_get_args())); 822 | } 823 | 824 | 825 | /** 826 | * [!] Method is generated. Documentation taken from corresponding module. 827 | * 828 | * Check that the specified checkbox is unchecked. 829 | * 830 | * ``` php 831 | * dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms 833 | * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. 834 | * ?> 835 | * ``` 836 | * 837 | * @param $checkbox 838 | * Conditional Assertion: Test won't be stopped on fail 839 | * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() 840 | */ 841 | public function cantSeeCheckboxIsChecked($checkbox) { 842 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCheckboxIsChecked', func_get_args())); 843 | } 844 | /** 845 | * [!] Method is generated. Documentation taken from corresponding module. 846 | * 847 | * Check that the specified checkbox is unchecked. 848 | * 849 | * ``` php 850 | * dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms 852 | * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. 853 | * ?> 854 | * ``` 855 | * 856 | * @param $checkbox 857 | * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() 858 | */ 859 | public function dontSeeCheckboxIsChecked($checkbox) { 860 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCheckboxIsChecked', func_get_args())); 861 | } 862 | 863 | 864 | /** 865 | * [!] Method is generated. Documentation taken from corresponding module. 866 | * 867 | * Checks that the given input field or textarea contains the given value. 868 | * For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath. 869 | * 870 | * ``` php 871 | * seeInField('Body','Type your comment here'); 873 | * $I->seeInField('form textarea[name=body]','Type your comment here'); 874 | * $I->seeInField('form input[type=hidden]','hidden_value'); 875 | * $I->seeInField('#searchform input','Search'); 876 | * $I->seeInField('//form/*[@name=search]','Search'); 877 | * $I->seeInField(['name' => 'search'], 'Search'); 878 | * ?> 879 | * ``` 880 | * 881 | * @param $field 882 | * @param $value 883 | * Conditional Assertion: Test won't be stopped on fail 884 | * @see \Codeception\Lib\InnerBrowser::seeInField() 885 | */ 886 | public function canSeeInField($field, $value) { 887 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInField', func_get_args())); 888 | } 889 | /** 890 | * [!] Method is generated. Documentation taken from corresponding module. 891 | * 892 | * Checks that the given input field or textarea contains the given value. 893 | * For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath. 894 | * 895 | * ``` php 896 | * seeInField('Body','Type your comment here'); 898 | * $I->seeInField('form textarea[name=body]','Type your comment here'); 899 | * $I->seeInField('form input[type=hidden]','hidden_value'); 900 | * $I->seeInField('#searchform input','Search'); 901 | * $I->seeInField('//form/*[@name=search]','Search'); 902 | * $I->seeInField(['name' => 'search'], 'Search'); 903 | * ?> 904 | * ``` 905 | * 906 | * @param $field 907 | * @param $value 908 | * @see \Codeception\Lib\InnerBrowser::seeInField() 909 | */ 910 | public function seeInField($field, $value) { 911 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInField', func_get_args())); 912 | } 913 | 914 | 915 | /** 916 | * [!] Method is generated. Documentation taken from corresponding module. 917 | * 918 | * Checks that an input field or textarea doesn't contain the given value. 919 | * For fuzzy locators, the field is matched by label text, CSS and XPath. 920 | * 921 | * ``` php 922 | * dontSeeInField('Body','Type your comment here'); 924 | * $I->dontSeeInField('form textarea[name=body]','Type your comment here'); 925 | * $I->dontSeeInField('form input[type=hidden]','hidden_value'); 926 | * $I->dontSeeInField('#searchform input','Search'); 927 | * $I->dontSeeInField('//form/*[@name=search]','Search'); 928 | * $I->dontSeeInField(['name' => 'search'], 'Search'); 929 | * ?> 930 | * ``` 931 | * 932 | * @param $field 933 | * @param $value 934 | * Conditional Assertion: Test won't be stopped on fail 935 | * @see \Codeception\Lib\InnerBrowser::dontSeeInField() 936 | */ 937 | public function cantSeeInField($field, $value) { 938 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInField', func_get_args())); 939 | } 940 | /** 941 | * [!] Method is generated. Documentation taken from corresponding module. 942 | * 943 | * Checks that an input field or textarea doesn't contain the given value. 944 | * For fuzzy locators, the field is matched by label text, CSS and XPath. 945 | * 946 | * ``` php 947 | * dontSeeInField('Body','Type your comment here'); 949 | * $I->dontSeeInField('form textarea[name=body]','Type your comment here'); 950 | * $I->dontSeeInField('form input[type=hidden]','hidden_value'); 951 | * $I->dontSeeInField('#searchform input','Search'); 952 | * $I->dontSeeInField('//form/*[@name=search]','Search'); 953 | * $I->dontSeeInField(['name' => 'search'], 'Search'); 954 | * ?> 955 | * ``` 956 | * 957 | * @param $field 958 | * @param $value 959 | * @see \Codeception\Lib\InnerBrowser::dontSeeInField() 960 | */ 961 | public function dontSeeInField($field, $value) { 962 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInField', func_get_args())); 963 | } 964 | 965 | 966 | /** 967 | * [!] Method is generated. Documentation taken from corresponding module. 968 | * 969 | * Checks if the array of form parameters (name => value) are set on the form matched with the 970 | * passed selector. 971 | * 972 | * ``` php 973 | * seeInFormFields('form[name=myform]', [ 975 | * 'input1' => 'value', 976 | * 'input2' => 'other value', 977 | * ]); 978 | * ?> 979 | * ``` 980 | * 981 | * For multi-select elements, or to check values of multiple elements with the same name, an 982 | * array may be passed: 983 | * 984 | * ``` php 985 | * seeInFormFields('.form-class', [ 987 | * 'multiselect' => [ 988 | * 'value1', 989 | * 'value2', 990 | * ], 991 | * 'checkbox[]' => [ 992 | * 'a checked value', 993 | * 'another checked value', 994 | * ], 995 | * ]); 996 | * ?> 997 | * ``` 998 | * 999 | * Additionally, checkbox values can be checked with a boolean. 1000 | * 1001 | * ``` php 1002 | * seeInFormFields('#form-id', [ 1004 | * 'checkbox1' => true, // passes if checked 1005 | * 'checkbox2' => false, // passes if unchecked 1006 | * ]); 1007 | * ?> 1008 | * ``` 1009 | * 1010 | * Pair this with submitForm for quick testing magic. 1011 | * 1012 | * ``` php 1013 | * 'value', 1016 | * 'field2' => 'another value', 1017 | * 'checkbox1' => true, 1018 | * // ... 1019 | * ]; 1020 | * $I->submitForm('//form[@id=my-form]', $form, 'submitButton'); 1021 | * // $I->amOnPage('/path/to/form-page') may be needed 1022 | * $I->seeInFormFields('//form[@id=my-form]', $form); 1023 | * ?> 1024 | * ``` 1025 | * 1026 | * @param $formSelector 1027 | * @param $params 1028 | * Conditional Assertion: Test won't be stopped on fail 1029 | * @see \Codeception\Lib\InnerBrowser::seeInFormFields() 1030 | */ 1031 | public function canSeeInFormFields($formSelector, $params) { 1032 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInFormFields', func_get_args())); 1033 | } 1034 | /** 1035 | * [!] Method is generated. Documentation taken from corresponding module. 1036 | * 1037 | * Checks if the array of form parameters (name => value) are set on the form matched with the 1038 | * passed selector. 1039 | * 1040 | * ``` php 1041 | * seeInFormFields('form[name=myform]', [ 1043 | * 'input1' => 'value', 1044 | * 'input2' => 'other value', 1045 | * ]); 1046 | * ?> 1047 | * ``` 1048 | * 1049 | * For multi-select elements, or to check values of multiple elements with the same name, an 1050 | * array may be passed: 1051 | * 1052 | * ``` php 1053 | * seeInFormFields('.form-class', [ 1055 | * 'multiselect' => [ 1056 | * 'value1', 1057 | * 'value2', 1058 | * ], 1059 | * 'checkbox[]' => [ 1060 | * 'a checked value', 1061 | * 'another checked value', 1062 | * ], 1063 | * ]); 1064 | * ?> 1065 | * ``` 1066 | * 1067 | * Additionally, checkbox values can be checked with a boolean. 1068 | * 1069 | * ``` php 1070 | * seeInFormFields('#form-id', [ 1072 | * 'checkbox1' => true, // passes if checked 1073 | * 'checkbox2' => false, // passes if unchecked 1074 | * ]); 1075 | * ?> 1076 | * ``` 1077 | * 1078 | * Pair this with submitForm for quick testing magic. 1079 | * 1080 | * ``` php 1081 | * 'value', 1084 | * 'field2' => 'another value', 1085 | * 'checkbox1' => true, 1086 | * // ... 1087 | * ]; 1088 | * $I->submitForm('//form[@id=my-form]', $form, 'submitButton'); 1089 | * // $I->amOnPage('/path/to/form-page') may be needed 1090 | * $I->seeInFormFields('//form[@id=my-form]', $form); 1091 | * ?> 1092 | * ``` 1093 | * 1094 | * @param $formSelector 1095 | * @param $params 1096 | * @see \Codeception\Lib\InnerBrowser::seeInFormFields() 1097 | */ 1098 | public function seeInFormFields($formSelector, $params) { 1099 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInFormFields', func_get_args())); 1100 | } 1101 | 1102 | 1103 | /** 1104 | * [!] Method is generated. Documentation taken from corresponding module. 1105 | * 1106 | * Checks if the array of form parameters (name => value) are not set on the form matched with 1107 | * the passed selector. 1108 | * 1109 | * ``` php 1110 | * dontSeeInFormFields('form[name=myform]', [ 1112 | * 'input1' => 'non-existent value', 1113 | * 'input2' => 'other non-existent value', 1114 | * ]); 1115 | * ?> 1116 | * ``` 1117 | * 1118 | * To check that an element hasn't been assigned any one of many values, an array can be passed 1119 | * as the value: 1120 | * 1121 | * ``` php 1122 | * dontSeeInFormFields('.form-class', [ 1124 | * 'fieldName' => [ 1125 | * 'This value shouldn\'t be set', 1126 | * 'And this value shouldn\'t be set', 1127 | * ], 1128 | * ]); 1129 | * ?> 1130 | * ``` 1131 | * 1132 | * Additionally, checkbox values can be checked with a boolean. 1133 | * 1134 | * ``` php 1135 | * dontSeeInFormFields('#form-id', [ 1137 | * 'checkbox1' => true, // fails if checked 1138 | * 'checkbox2' => false, // fails if unchecked 1139 | * ]); 1140 | * ?> 1141 | * ``` 1142 | * 1143 | * @param $formSelector 1144 | * @param $params 1145 | * Conditional Assertion: Test won't be stopped on fail 1146 | * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() 1147 | */ 1148 | public function cantSeeInFormFields($formSelector, $params) { 1149 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInFormFields', func_get_args())); 1150 | } 1151 | /** 1152 | * [!] Method is generated. Documentation taken from corresponding module. 1153 | * 1154 | * Checks if the array of form parameters (name => value) are not set on the form matched with 1155 | * the passed selector. 1156 | * 1157 | * ``` php 1158 | * dontSeeInFormFields('form[name=myform]', [ 1160 | * 'input1' => 'non-existent value', 1161 | * 'input2' => 'other non-existent value', 1162 | * ]); 1163 | * ?> 1164 | * ``` 1165 | * 1166 | * To check that an element hasn't been assigned any one of many values, an array can be passed 1167 | * as the value: 1168 | * 1169 | * ``` php 1170 | * dontSeeInFormFields('.form-class', [ 1172 | * 'fieldName' => [ 1173 | * 'This value shouldn\'t be set', 1174 | * 'And this value shouldn\'t be set', 1175 | * ], 1176 | * ]); 1177 | * ?> 1178 | * ``` 1179 | * 1180 | * Additionally, checkbox values can be checked with a boolean. 1181 | * 1182 | * ``` php 1183 | * dontSeeInFormFields('#form-id', [ 1185 | * 'checkbox1' => true, // fails if checked 1186 | * 'checkbox2' => false, // fails if unchecked 1187 | * ]); 1188 | * ?> 1189 | * ``` 1190 | * 1191 | * @param $formSelector 1192 | * @param $params 1193 | * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() 1194 | */ 1195 | public function dontSeeInFormFields($formSelector, $params) { 1196 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInFormFields', func_get_args())); 1197 | } 1198 | 1199 | 1200 | /** 1201 | * [!] Method is generated. Documentation taken from corresponding module. 1202 | * 1203 | * Submits the given form on the page, optionally with the given form 1204 | * values. Pass the form field's values as an array in the second 1205 | * parameter. 1206 | * 1207 | * Although this function can be used as a short-hand version of 1208 | * `fillField()`, `selectOption()`, `click()` etc. it has some important 1209 | * differences: 1210 | * 1211 | * * Only field *names* may be used, not CSS/XPath selectors nor field labels 1212 | * * If a field is sent to this function that does *not* exist on the page, 1213 | * it will silently be added to the HTTP request. This is helpful for testing 1214 | * some types of forms, but be aware that you will *not* get an exception 1215 | * like you would if you called `fillField()` or `selectOption()` with 1216 | * a missing field. 1217 | * 1218 | * Fields that are not provided will be filled by their values from the page, 1219 | * or from any previous calls to `fillField()`, `selectOption()` etc. 1220 | * You don't need to click the 'Submit' button afterwards. 1221 | * This command itself triggers the request to form's action. 1222 | * 1223 | * You can optionally specify which button's value to include 1224 | * in the request with the last parameter (as an alternative to 1225 | * explicitly setting its value in the second parameter), as 1226 | * button values are not otherwise included in the request. 1227 | * 1228 | * Examples: 1229 | * 1230 | * ``` php 1231 | * submitForm('#login', [ 1233 | * 'login' => 'davert', 1234 | * 'password' => '123456' 1235 | * ]); 1236 | * // or 1237 | * $I->submitForm('#login', [ 1238 | * 'login' => 'davert', 1239 | * 'password' => '123456' 1240 | * ], 'submitButtonName'); 1241 | * 1242 | * ``` 1243 | * 1244 | * For example, given this sample "Sign Up" form: 1245 | * 1246 | * ``` html 1247 | *
1248 | * Login: 1249 | *
1250 | * Password: 1251 | *
1252 | * Do you agree to our terms? 1253 | *
1254 | * Select pricing plan: 1255 | * 1259 | * 1260 | *
1261 | * ``` 1262 | * 1263 | * You could write the following to submit it: 1264 | * 1265 | * ``` php 1266 | * submitForm( 1268 | * '#userForm', 1269 | * [ 1270 | * 'user' => [ 1271 | * 'login' => 'Davert', 1272 | * 'password' => '123456', 1273 | * 'agree' => true 1274 | * ] 1275 | * ], 1276 | * 'submitButton' 1277 | * ); 1278 | * ``` 1279 | * Note that "2" will be the submitted value for the "plan" field, as it is 1280 | * the selected option. 1281 | * 1282 | * You can also emulate a JavaScript submission by not specifying any 1283 | * buttons in the third parameter to submitForm. 1284 | * 1285 | * ```php 1286 | * submitForm( 1288 | * '#userForm', 1289 | * [ 1290 | * 'user' => [ 1291 | * 'login' => 'Davert', 1292 | * 'password' => '123456', 1293 | * 'agree' => true 1294 | * ] 1295 | * ] 1296 | * ); 1297 | * ``` 1298 | * 1299 | * This function works well when paired with `seeInFormFields()` 1300 | * for quickly testing CRUD interfaces and form validation logic. 1301 | * 1302 | * ``` php 1303 | * 'value', 1306 | * 'field2' => 'another value', 1307 | * 'checkbox1' => true, 1308 | * // ... 1309 | * ]; 1310 | * $I->submitForm('#my-form', $form, 'submitButton'); 1311 | * // $I->amOnPage('/path/to/form-page') may be needed 1312 | * $I->seeInFormFields('#my-form', $form); 1313 | * ``` 1314 | * 1315 | * Parameter values can be set to arrays for multiple input fields 1316 | * of the same name, or multi-select combo boxes. For checkboxes, 1317 | * you can use either the string value or boolean `true`/`false` which will 1318 | * be replaced by the checkbox's value in the DOM. 1319 | * 1320 | * ``` php 1321 | * submitForm('#my-form', [ 1323 | * 'field1' => 'value', 1324 | * 'checkbox' => [ 1325 | * 'value of first checkbox', 1326 | * 'value of second checkbox', 1327 | * ], 1328 | * 'otherCheckboxes' => [ 1329 | * true, 1330 | * false, 1331 | * false 1332 | * ], 1333 | * 'multiselect' => [ 1334 | * 'first option value', 1335 | * 'second option value' 1336 | * ] 1337 | * ]); 1338 | * ``` 1339 | * 1340 | * Mixing string and boolean values for a checkbox's value is not supported 1341 | * and may produce unexpected results. 1342 | * 1343 | * Field names ending in `[]` must be passed without the trailing square 1344 | * bracket characters, and must contain an array for its value. This allows 1345 | * submitting multiple values with the same name, consider: 1346 | * 1347 | * ```php 1348 | * submitForm('#my-form', [ 1351 | * 'field[]' => 'value', 1352 | * 'field[]' => 'another value', // 'field[]' is already a defined key 1353 | * ]); 1354 | * ``` 1355 | * 1356 | * The solution is to pass an array value: 1357 | * 1358 | * ```php 1359 | * submitForm('#my-form', [ 1362 | * 'field' => [ 1363 | * 'value', 1364 | * 'another value', 1365 | * ] 1366 | * ]); 1367 | * ``` 1368 | * 1369 | * @param $selector 1370 | * @param $params 1371 | * @param $button 1372 | * @see \Codeception\Lib\InnerBrowser::submitForm() 1373 | */ 1374 | public function submitForm($selector, $params, $button = null) { 1375 | return $this->getScenario()->runStep(new \Codeception\Step\Action('submitForm', func_get_args())); 1376 | } 1377 | 1378 | 1379 | /** 1380 | * [!] Method is generated. Documentation taken from corresponding module. 1381 | * 1382 | * Fills a text field or textarea with the given string. 1383 | * 1384 | * ``` php 1385 | * fillField("//input[@type='text']", "Hello World!"); 1387 | * $I->fillField(['name' => 'email'], 'jon@mail.com'); 1388 | * ?> 1389 | * ``` 1390 | * 1391 | * @param $field 1392 | * @param $value 1393 | * @see \Codeception\Lib\InnerBrowser::fillField() 1394 | */ 1395 | public function fillField($field, $value) { 1396 | return $this->getScenario()->runStep(new \Codeception\Step\Action('fillField', func_get_args())); 1397 | } 1398 | 1399 | 1400 | /** 1401 | * [!] Method is generated. Documentation taken from corresponding module. 1402 | * 1403 | * Selects an option in a select tag or in radio button group. 1404 | * 1405 | * ``` php 1406 | * selectOption('form select[name=account]', 'Premium'); 1408 | * $I->selectOption('form input[name=payment]', 'Monthly'); 1409 | * $I->selectOption('//form/select[@name=account]', 'Monthly'); 1410 | * ?> 1411 | * ``` 1412 | * 1413 | * Provide an array for the second argument to select multiple options: 1414 | * 1415 | * ``` php 1416 | * selectOption('Which OS do you use?', array('Windows','Linux')); 1418 | * ?> 1419 | * ``` 1420 | * 1421 | * @param $select 1422 | * @param $option 1423 | * @see \Codeception\Lib\InnerBrowser::selectOption() 1424 | */ 1425 | public function selectOption($select, $option) { 1426 | return $this->getScenario()->runStep(new \Codeception\Step\Action('selectOption', func_get_args())); 1427 | } 1428 | 1429 | 1430 | /** 1431 | * [!] Method is generated. Documentation taken from corresponding module. 1432 | * 1433 | * Ticks a checkbox. For radio buttons, use the `selectOption` method instead. 1434 | * 1435 | * ``` php 1436 | * checkOption('#agree'); 1438 | * ?> 1439 | * ``` 1440 | * 1441 | * @param $option 1442 | * @see \Codeception\Lib\InnerBrowser::checkOption() 1443 | */ 1444 | public function checkOption($option) { 1445 | return $this->getScenario()->runStep(new \Codeception\Step\Action('checkOption', func_get_args())); 1446 | } 1447 | 1448 | 1449 | /** 1450 | * [!] Method is generated. Documentation taken from corresponding module. 1451 | * 1452 | * Unticks a checkbox. 1453 | * 1454 | * ``` php 1455 | * uncheckOption('#notify'); 1457 | * ?> 1458 | * ``` 1459 | * 1460 | * @param $option 1461 | * @see \Codeception\Lib\InnerBrowser::uncheckOption() 1462 | */ 1463 | public function uncheckOption($option) { 1464 | return $this->getScenario()->runStep(new \Codeception\Step\Action('uncheckOption', func_get_args())); 1465 | } 1466 | 1467 | 1468 | /** 1469 | * [!] Method is generated. Documentation taken from corresponding module. 1470 | * 1471 | * Attaches a file relative to the Codeception data directory to the given file upload field. 1472 | * 1473 | * ``` php 1474 | * attachFile('input[@type="file"]', 'prices.xls'); 1477 | * ?> 1478 | * ``` 1479 | * 1480 | * @param $field 1481 | * @param $filename 1482 | * @see \Codeception\Lib\InnerBrowser::attachFile() 1483 | */ 1484 | public function attachFile($field, $filename) { 1485 | return $this->getScenario()->runStep(new \Codeception\Step\Action('attachFile', func_get_args())); 1486 | } 1487 | 1488 | 1489 | /** 1490 | * [!] Method is generated. Documentation taken from corresponding module. 1491 | * 1492 | * If your page triggers an ajax request, you can perform it manually. 1493 | * This action sends a GET ajax request with specified params. 1494 | * 1495 | * See ->sendAjaxPostRequest for examples. 1496 | * 1497 | * @param $uri 1498 | * @param $params 1499 | * @see \Codeception\Lib\InnerBrowser::sendAjaxGetRequest() 1500 | */ 1501 | public function sendAjaxGetRequest($uri, $params = null) { 1502 | return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxGetRequest', func_get_args())); 1503 | } 1504 | 1505 | 1506 | /** 1507 | * [!] Method is generated. Documentation taken from corresponding module. 1508 | * 1509 | * If your page triggers an ajax request, you can perform it manually. 1510 | * This action sends a POST ajax request with specified params. 1511 | * Additional params can be passed as array. 1512 | * 1513 | * Example: 1514 | * 1515 | * Imagine that by clicking checkbox you trigger ajax request which updates user settings. 1516 | * We emulate that click by running this ajax request manually. 1517 | * 1518 | * ``` php 1519 | * sendAjaxPostRequest('/updateSettings', array('notifications' => true)); // POST 1521 | * $I->sendAjaxGetRequest('/updateSettings', array('notifications' => true)); // GET 1522 | * 1523 | * ``` 1524 | * 1525 | * @param $uri 1526 | * @param $params 1527 | * @see \Codeception\Lib\InnerBrowser::sendAjaxPostRequest() 1528 | */ 1529 | public function sendAjaxPostRequest($uri, $params = null) { 1530 | return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxPostRequest', func_get_args())); 1531 | } 1532 | 1533 | 1534 | /** 1535 | * [!] Method is generated. Documentation taken from corresponding module. 1536 | * 1537 | * If your page triggers an ajax request, you can perform it manually. 1538 | * This action sends an ajax request with specified method and params. 1539 | * 1540 | * Example: 1541 | * 1542 | * You need to perform an ajax request specifying the HTTP method. 1543 | * 1544 | * ``` php 1545 | * sendAjaxRequest('PUT', '/posts/7', array('title' => 'new title')); 1547 | * 1548 | * ``` 1549 | * 1550 | * @param $method 1551 | * @param $uri 1552 | * @param $params 1553 | * @see \Codeception\Lib\InnerBrowser::sendAjaxRequest() 1554 | */ 1555 | public function sendAjaxRequest($method, $uri, $params = null) { 1556 | return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxRequest', func_get_args())); 1557 | } 1558 | 1559 | 1560 | /** 1561 | * [!] Method is generated. Documentation taken from corresponding module. 1562 | * 1563 | * Finds and returns the text contents of the given element. 1564 | * If a fuzzy locator is used, the element is found using CSS, XPath, and by matching the full page source by regular expression. 1565 | * 1566 | * ``` php 1567 | * grabTextFrom('h1'); 1569 | * $heading = $I->grabTextFrom('descendant-or-self::h1'); 1570 | * $value = $I->grabTextFrom('~ 1572 | * ``` 1573 | * 1574 | * @param $cssOrXPathOrRegex 1575 | * 1576 | * @return mixed 1577 | * @see \Codeception\Lib\InnerBrowser::grabTextFrom() 1578 | */ 1579 | public function grabTextFrom($cssOrXPathOrRegex) { 1580 | return $this->getScenario()->runStep(new \Codeception\Step\Action('grabTextFrom', func_get_args())); 1581 | } 1582 | 1583 | 1584 | /** 1585 | * [!] Method is generated. Documentation taken from corresponding module. 1586 | * 1587 | * Grabs the value of the given attribute value from the given element. 1588 | * Fails if element is not found. 1589 | * 1590 | * ``` php 1591 | * grabAttributeFrom('#tooltip', 'title'); 1593 | * ?> 1594 | * ``` 1595 | * 1596 | * 1597 | * @param $cssOrXpath 1598 | * @param $attribute 1599 | * 1600 | * @return mixed 1601 | * @see \Codeception\Lib\InnerBrowser::grabAttributeFrom() 1602 | */ 1603 | public function grabAttributeFrom($cssOrXpath, $attribute) { 1604 | return $this->getScenario()->runStep(new \Codeception\Step\Action('grabAttributeFrom', func_get_args())); 1605 | } 1606 | 1607 | 1608 | /** 1609 | * [!] Method is generated. Documentation taken from corresponding module. 1610 | * 1611 | * Grabs either the text content, or attribute values, of nodes 1612 | * matched by $cssOrXpath and returns them as an array. 1613 | * 1614 | * ```html 1615 | * First 1616 | * Second 1617 | * Third 1618 | * ``` 1619 | * 1620 | * ```php 1621 | * grabMultiple('a'); 1624 | * 1625 | * // would return ['#first', '#second', '#third'] 1626 | * $aLinks = $I->grabMultiple('a', 'href'); 1627 | * ?> 1628 | * ``` 1629 | * 1630 | * @param $cssOrXpath 1631 | * @param $attribute 1632 | * @return string[] 1633 | * @see \Codeception\Lib\InnerBrowser::grabMultiple() 1634 | */ 1635 | public function grabMultiple($cssOrXpath, $attribute = null) { 1636 | return $this->getScenario()->runStep(new \Codeception\Step\Action('grabMultiple', func_get_args())); 1637 | } 1638 | 1639 | 1640 | /** 1641 | * [!] Method is generated. Documentation taken from corresponding module. 1642 | * 1643 | * @param $field 1644 | * 1645 | * @return array|mixed|null|string 1646 | * @see \Codeception\Lib\InnerBrowser::grabValueFrom() 1647 | */ 1648 | public function grabValueFrom($field) { 1649 | return $this->getScenario()->runStep(new \Codeception\Step\Action('grabValueFrom', func_get_args())); 1650 | } 1651 | 1652 | 1653 | /** 1654 | * [!] Method is generated. Documentation taken from corresponding module. 1655 | * 1656 | * Sets a cookie with the given name and value. 1657 | * You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. 1658 | * 1659 | * ``` php 1660 | * setCookie('PHPSESSID', 'el4ukv0kqbvoirg7nkp4dncpk3'); 1662 | * ?> 1663 | * ``` 1664 | * 1665 | * @param $name 1666 | * @param $val 1667 | * @param array $params 1668 | * 1669 | * @return mixed 1670 | * @see \Codeception\Lib\InnerBrowser::setCookie() 1671 | */ 1672 | public function setCookie($name, $val, $params = null) { 1673 | return $this->getScenario()->runStep(new \Codeception\Step\Action('setCookie', func_get_args())); 1674 | } 1675 | 1676 | 1677 | /** 1678 | * [!] Method is generated. Documentation taken from corresponding module. 1679 | * 1680 | * Grabs a cookie value. 1681 | * You can set additional cookie params like `domain`, `path` in array passed as last argument. 1682 | * 1683 | * @param $cookie 1684 | * 1685 | * @param array $params 1686 | * @return mixed 1687 | * @see \Codeception\Lib\InnerBrowser::grabCookie() 1688 | */ 1689 | public function grabCookie($cookie, $params = null) { 1690 | return $this->getScenario()->runStep(new \Codeception\Step\Action('grabCookie', func_get_args())); 1691 | } 1692 | 1693 | 1694 | /** 1695 | * [!] Method is generated. Documentation taken from corresponding module. 1696 | * 1697 | * Checks that a cookie with the given name is set. 1698 | * You can set additional cookie params like `domain`, `path` as array passed in last argument. 1699 | * 1700 | * ``` php 1701 | * seeCookie('PHPSESSID'); 1703 | * ?> 1704 | * ``` 1705 | * 1706 | * @param $cookie 1707 | * @param array $params 1708 | * @return mixed 1709 | * Conditional Assertion: Test won't be stopped on fail 1710 | * @see \Codeception\Lib\InnerBrowser::seeCookie() 1711 | */ 1712 | public function canSeeCookie($cookie, $params = null) { 1713 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCookie', func_get_args())); 1714 | } 1715 | /** 1716 | * [!] Method is generated. Documentation taken from corresponding module. 1717 | * 1718 | * Checks that a cookie with the given name is set. 1719 | * You can set additional cookie params like `domain`, `path` as array passed in last argument. 1720 | * 1721 | * ``` php 1722 | * seeCookie('PHPSESSID'); 1724 | * ?> 1725 | * ``` 1726 | * 1727 | * @param $cookie 1728 | * @param array $params 1729 | * @return mixed 1730 | * @see \Codeception\Lib\InnerBrowser::seeCookie() 1731 | */ 1732 | public function seeCookie($cookie, $params = null) { 1733 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCookie', func_get_args())); 1734 | } 1735 | 1736 | 1737 | /** 1738 | * [!] Method is generated. Documentation taken from corresponding module. 1739 | * 1740 | * Checks that there isn't a cookie with the given name. 1741 | * You can set additional cookie params like `domain`, `path` as array passed in last argument. 1742 | * 1743 | * @param $cookie 1744 | * 1745 | * @param array $params 1746 | * @return mixed 1747 | * Conditional Assertion: Test won't be stopped on fail 1748 | * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() 1749 | */ 1750 | public function cantSeeCookie($cookie, $params = null) { 1751 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCookie', func_get_args())); 1752 | } 1753 | /** 1754 | * [!] Method is generated. Documentation taken from corresponding module. 1755 | * 1756 | * Checks that there isn't a cookie with the given name. 1757 | * You can set additional cookie params like `domain`, `path` as array passed in last argument. 1758 | * 1759 | * @param $cookie 1760 | * 1761 | * @param array $params 1762 | * @return mixed 1763 | * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() 1764 | */ 1765 | public function dontSeeCookie($cookie, $params = null) { 1766 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCookie', func_get_args())); 1767 | } 1768 | 1769 | 1770 | /** 1771 | * [!] Method is generated. Documentation taken from corresponding module. 1772 | * 1773 | * Unsets cookie with the given name. 1774 | * You can set additional cookie params like `domain`, `path` in array passed as last argument. 1775 | * 1776 | * @param $cookie 1777 | * 1778 | * @param array $params 1779 | * @return mixed 1780 | * @see \Codeception\Lib\InnerBrowser::resetCookie() 1781 | */ 1782 | public function resetCookie($name, $params = null) { 1783 | return $this->getScenario()->runStep(new \Codeception\Step\Action('resetCookie', func_get_args())); 1784 | } 1785 | 1786 | 1787 | /** 1788 | * [!] Method is generated. Documentation taken from corresponding module. 1789 | * 1790 | * Checks that the given element exists on the page and is visible. 1791 | * You can also specify expected attributes of this element. 1792 | * 1793 | * ``` php 1794 | * seeElement('.error'); 1796 | * $I->seeElement('//form/input[1]'); 1797 | * $I->seeElement('input', ['name' => 'login']); 1798 | * $I->seeElement('input', ['value' => '123456']); 1799 | * 1800 | * // strict locator in first arg, attributes in second 1801 | * $I->seeElement(['css' => 'form input'], ['name' => 'login']); 1802 | * ?> 1803 | * ``` 1804 | * 1805 | * @param $selector 1806 | * @param array $attributes 1807 | * @return 1808 | * Conditional Assertion: Test won't be stopped on fail 1809 | * @see \Codeception\Lib\InnerBrowser::seeElement() 1810 | */ 1811 | public function canSeeElement($selector, $attributes = null) { 1812 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeElement', func_get_args())); 1813 | } 1814 | /** 1815 | * [!] Method is generated. Documentation taken from corresponding module. 1816 | * 1817 | * Checks that the given element exists on the page and is visible. 1818 | * You can also specify expected attributes of this element. 1819 | * 1820 | * ``` php 1821 | * seeElement('.error'); 1823 | * $I->seeElement('//form/input[1]'); 1824 | * $I->seeElement('input', ['name' => 'login']); 1825 | * $I->seeElement('input', ['value' => '123456']); 1826 | * 1827 | * // strict locator in first arg, attributes in second 1828 | * $I->seeElement(['css' => 'form input'], ['name' => 'login']); 1829 | * ?> 1830 | * ``` 1831 | * 1832 | * @param $selector 1833 | * @param array $attributes 1834 | * @return 1835 | * @see \Codeception\Lib\InnerBrowser::seeElement() 1836 | */ 1837 | public function seeElement($selector, $attributes = null) { 1838 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeElement', func_get_args())); 1839 | } 1840 | 1841 | 1842 | /** 1843 | * [!] Method is generated. Documentation taken from corresponding module. 1844 | * 1845 | * Checks that the given element is invisible or not present on the page. 1846 | * You can also specify expected attributes of this element. 1847 | * 1848 | * ``` php 1849 | * dontSeeElement('.error'); 1851 | * $I->dontSeeElement('//form/input[1]'); 1852 | * $I->dontSeeElement('input', ['name' => 'login']); 1853 | * $I->dontSeeElement('input', ['value' => '123456']); 1854 | * ?> 1855 | * ``` 1856 | * 1857 | * @param $selector 1858 | * @param array $attributes 1859 | * Conditional Assertion: Test won't be stopped on fail 1860 | * @see \Codeception\Lib\InnerBrowser::dontSeeElement() 1861 | */ 1862 | public function cantSeeElement($selector, $attributes = null) { 1863 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeElement', func_get_args())); 1864 | } 1865 | /** 1866 | * [!] Method is generated. Documentation taken from corresponding module. 1867 | * 1868 | * Checks that the given element is invisible or not present on the page. 1869 | * You can also specify expected attributes of this element. 1870 | * 1871 | * ``` php 1872 | * dontSeeElement('.error'); 1874 | * $I->dontSeeElement('//form/input[1]'); 1875 | * $I->dontSeeElement('input', ['name' => 'login']); 1876 | * $I->dontSeeElement('input', ['value' => '123456']); 1877 | * ?> 1878 | * ``` 1879 | * 1880 | * @param $selector 1881 | * @param array $attributes 1882 | * @see \Codeception\Lib\InnerBrowser::dontSeeElement() 1883 | */ 1884 | public function dontSeeElement($selector, $attributes = null) { 1885 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeElement', func_get_args())); 1886 | } 1887 | 1888 | 1889 | /** 1890 | * [!] Method is generated. Documentation taken from corresponding module. 1891 | * 1892 | * Checks that there are a certain number of elements matched by the given locator on the page. 1893 | * 1894 | * ``` php 1895 | * seeNumberOfElements('tr', 10); 1897 | * $I->seeNumberOfElements('tr', [0,10]); //between 0 and 10 elements 1898 | * ?> 1899 | * ``` 1900 | * @param $selector 1901 | * @param mixed $expected : 1902 | * - string: strict number 1903 | * - array: range of numbers [0,10] 1904 | * Conditional Assertion: Test won't be stopped on fail 1905 | * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() 1906 | */ 1907 | public function canSeeNumberOfElements($selector, $expected) { 1908 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberOfElements', func_get_args())); 1909 | } 1910 | /** 1911 | * [!] Method is generated. Documentation taken from corresponding module. 1912 | * 1913 | * Checks that there are a certain number of elements matched by the given locator on the page. 1914 | * 1915 | * ``` php 1916 | * seeNumberOfElements('tr', 10); 1918 | * $I->seeNumberOfElements('tr', [0,10]); //between 0 and 10 elements 1919 | * ?> 1920 | * ``` 1921 | * @param $selector 1922 | * @param mixed $expected : 1923 | * - string: strict number 1924 | * - array: range of numbers [0,10] 1925 | * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() 1926 | */ 1927 | public function seeNumberOfElements($selector, $expected) { 1928 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberOfElements', func_get_args())); 1929 | } 1930 | 1931 | 1932 | /** 1933 | * [!] Method is generated. Documentation taken from corresponding module. 1934 | * 1935 | * Checks that the given option is selected. 1936 | * 1937 | * ``` php 1938 | * seeOptionIsSelected('#form input[name=payment]', 'Visa'); 1940 | * ?> 1941 | * ``` 1942 | * 1943 | * @param $selector 1944 | * @param $optionText 1945 | * 1946 | * @return mixed 1947 | * Conditional Assertion: Test won't be stopped on fail 1948 | * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() 1949 | */ 1950 | public function canSeeOptionIsSelected($selector, $optionText) { 1951 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeOptionIsSelected', func_get_args())); 1952 | } 1953 | /** 1954 | * [!] Method is generated. Documentation taken from corresponding module. 1955 | * 1956 | * Checks that the given option is selected. 1957 | * 1958 | * ``` php 1959 | * seeOptionIsSelected('#form input[name=payment]', 'Visa'); 1961 | * ?> 1962 | * ``` 1963 | * 1964 | * @param $selector 1965 | * @param $optionText 1966 | * 1967 | * @return mixed 1968 | * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() 1969 | */ 1970 | public function seeOptionIsSelected($selector, $optionText) { 1971 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeOptionIsSelected', func_get_args())); 1972 | } 1973 | 1974 | 1975 | /** 1976 | * [!] Method is generated. Documentation taken from corresponding module. 1977 | * 1978 | * Checks that the given option is not selected. 1979 | * 1980 | * ``` php 1981 | * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); 1983 | * ?> 1984 | * ``` 1985 | * 1986 | * @param $selector 1987 | * @param $optionText 1988 | * 1989 | * @return mixed 1990 | * Conditional Assertion: Test won't be stopped on fail 1991 | * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() 1992 | */ 1993 | public function cantSeeOptionIsSelected($selector, $optionText) { 1994 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeOptionIsSelected', func_get_args())); 1995 | } 1996 | /** 1997 | * [!] Method is generated. Documentation taken from corresponding module. 1998 | * 1999 | * Checks that the given option is not selected. 2000 | * 2001 | * ``` php 2002 | * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); 2004 | * ?> 2005 | * ``` 2006 | * 2007 | * @param $selector 2008 | * @param $optionText 2009 | * 2010 | * @return mixed 2011 | * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() 2012 | */ 2013 | public function dontSeeOptionIsSelected($selector, $optionText) { 2014 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeOptionIsSelected', func_get_args())); 2015 | } 2016 | 2017 | 2018 | /** 2019 | * [!] Method is generated. Documentation taken from corresponding module. 2020 | * 2021 | * Asserts that current page has 404 response status code. 2022 | * Conditional Assertion: Test won't be stopped on fail 2023 | * @see \Codeception\Lib\InnerBrowser::seePageNotFound() 2024 | */ 2025 | public function canSeePageNotFound() { 2026 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seePageNotFound', func_get_args())); 2027 | } 2028 | /** 2029 | * [!] Method is generated. Documentation taken from corresponding module. 2030 | * 2031 | * Asserts that current page has 404 response status code. 2032 | * @see \Codeception\Lib\InnerBrowser::seePageNotFound() 2033 | */ 2034 | public function seePageNotFound() { 2035 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seePageNotFound', func_get_args())); 2036 | } 2037 | 2038 | 2039 | /** 2040 | * [!] Method is generated. Documentation taken from corresponding module. 2041 | * 2042 | * Checks that response code is equal to value provided. 2043 | * 2044 | * @param $code 2045 | * 2046 | * @return mixed 2047 | * Conditional Assertion: Test won't be stopped on fail 2048 | * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() 2049 | */ 2050 | public function canSeeResponseCodeIs($code) { 2051 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIs', func_get_args())); 2052 | } 2053 | /** 2054 | * [!] Method is generated. Documentation taken from corresponding module. 2055 | * 2056 | * Checks that response code is equal to value provided. 2057 | * 2058 | * @param $code 2059 | * 2060 | * @return mixed 2061 | * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() 2062 | */ 2063 | public function seeResponseCodeIs($code) { 2064 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIs', func_get_args())); 2065 | } 2066 | 2067 | 2068 | /** 2069 | * [!] Method is generated. Documentation taken from corresponding module. 2070 | * 2071 | * Checks that the page title contains the given string. 2072 | * 2073 | * ``` php 2074 | * seeInTitle('Blog - Post #1'); 2076 | * ?> 2077 | * ``` 2078 | * 2079 | * @param $title 2080 | * 2081 | * @return mixed 2082 | * Conditional Assertion: Test won't be stopped on fail 2083 | * @see \Codeception\Lib\InnerBrowser::seeInTitle() 2084 | */ 2085 | public function canSeeInTitle($title) { 2086 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInTitle', func_get_args())); 2087 | } 2088 | /** 2089 | * [!] Method is generated. Documentation taken from corresponding module. 2090 | * 2091 | * Checks that the page title contains the given string. 2092 | * 2093 | * ``` php 2094 | * seeInTitle('Blog - Post #1'); 2096 | * ?> 2097 | * ``` 2098 | * 2099 | * @param $title 2100 | * 2101 | * @return mixed 2102 | * @see \Codeception\Lib\InnerBrowser::seeInTitle() 2103 | */ 2104 | public function seeInTitle($title) { 2105 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInTitle', func_get_args())); 2106 | } 2107 | 2108 | 2109 | /** 2110 | * [!] Method is generated. Documentation taken from corresponding module. 2111 | * 2112 | * Checks that the page title does not contain the given string. 2113 | * 2114 | * @param $title 2115 | * 2116 | * @return mixed 2117 | * Conditional Assertion: Test won't be stopped on fail 2118 | * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() 2119 | */ 2120 | public function cantSeeInTitle($title) { 2121 | return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInTitle', func_get_args())); 2122 | } 2123 | /** 2124 | * [!] Method is generated. Documentation taken from corresponding module. 2125 | * 2126 | * Checks that the page title does not contain the given string. 2127 | * 2128 | * @param $title 2129 | * 2130 | * @return mixed 2131 | * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() 2132 | */ 2133 | public function dontSeeInTitle($title) { 2134 | return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInTitle', func_get_args())); 2135 | } 2136 | 2137 | 2138 | /** 2139 | * [!] Method is generated. Documentation taken from corresponding module. 2140 | * 2141 | * Switch to iframe or frame on the page. 2142 | * 2143 | * Example: 2144 | * ``` html 2145 | *