public function testAjax() { $this->module->sendAjaxGetRequest('/info'); $this->assertNotNull(data::get('ajax')); $this->module->sendAjaxPostRequest('/form/complex', array('show' => 'author')); $this->assertNotNull(data::get('ajax')); $post = data::get('form'); $this->assertEquals('author', $post['show']); }
public function get_helper($key) { $ret = null; $in_helper = false; if (isset($this->helper[$key])) { $ret = $this->helper[$key]; $in_helper = true; } else { $class = 'view_helper_' . $key; if (class_exists($class)) { $this->helper[$key] = new $class(); $ret = $this->helper[$key]; $in_helper = true; } else { $ret = parent::get($key); } } if ($in_helper) { $ret->view = $this; } return $ret; }
public function testFillFieldWithAmpersand() { $this->module->amOnPage('/form/field'); $this->module->fillField('Name', 'this & that'); $this->module->click('Submit'); $form = data::get('form'); $this->assertEquals('this & that', $form['name']); }
public function testFileFieldByLabel() { $this->module->amOnPage('/form/file'); $this->module->attachFile('Avatar', 'app/avatar.jpg'); $this->module->click('Submit'); $this->assertNotEmpty(data::get('files')); }
/** * @Issue https://github.com/Codeception/Codeception/issues/933 */ public function testSubmitFormWithQueries() { $this->module->amOnPage('/form/example3'); $this->module->seeElement('form'); $this->module->submitForm('form', array('name' => 'jon')); $form = data::get('form'); $this->assertEquals('jon', $form['name']); $this->module->seeCurrentUrlEquals('/form/example3?validate=yes'); }
public static function getUser() { if (self::$session && self::$session['logged_in'] == 1 && !isset(self::$user)) { $res = data::get('user', 'get', array('users_id')); self::$user = false; if (!$res['error']) { self::$user = $res['data']; } } return self::$user; }
/** * parse the rendered view for {{placeholders}} and replace them * @param string $view the rendered view (typically html) possibly containing {{placeholders}} * @return string */ private function parse_view($view) { $v = view::getInstance(); $app = \maverick\maverick::getInstance(); // check for the use of multi-lingual gettext stuff if ($app->get_config('lang.active') !== false) { // match the format of {{_('string to translate')}} - the quote style can be either single or double, // and the text to translate must start with a letter \p{L} if (preg_match_all('/\\{\\{_\\(([\'"]\\p{L}[^\'"]+[\'"])\\)\\}\\}/', $view, $matches) && !empty($matches[1])) { $find = $replace = array(); foreach ($matches[1] as $match) { $find[] = "{{_({$match})}}"; $replace[] = _(trim($match, "\"'")); } $view = str_replace($find, $replace, $view); } } // run any custom handlers that have been added - the callback will pass up to three matched parameters in the form // {{handler_namespacee:param1:param2:param3}} with each matched parameter being in an array with // param1 being array index 1, param2 being array index 3, and param3 being array index5 // the callback method must be a static method, and the return must be a string if (count($v->parse_handlers)) { foreach ($v->parse_handlers as $parse_handler) { list($controller, $method) = explode('->', $parse_handler[1]); $view = preg_replace_callback("/\\{\\{{$parse_handler[0]}:([\\p{L}\\p{N}_]+)(:([\\p{L}\\p{N}_]+))?(:([\\p{L}\\p{N}_]+))?\\}\\}/", array($controller, $method), $view); } } // match simple placeholder formats - this check should always be last if (preg_match_all('/\\{\\{(\\p{L}[\\p{L}\\p{N}_\\.]+)/', $view, $matches) && !empty($matches[1])) { $find = $replace = array(); foreach ($matches[1] as $match) { $find[] = "{{{$match}}}"; $r = \data::get($match); if (is_array($r)) { $r = implode($r); } $replace[] = $r; } $view = str_replace($find, $replace, $view); } return $view; }
/** * @Issue https://github.com/Codeception/Codeception/issues/1585 * @Issue https://github.com/Codeception/Codeception/issues/1602 */ public function testUnreachableField() { $this->module->amOnPage('/form/bug1585'); $this->module->fillField('textarea[name="captions[]"]', 'test2'); $this->module->fillField('items[1][]', 'test3'); $this->module->fillField('input[name="users[]"]', 'davert'); $this->module->attachFile('input[name="files[]"]', 'app/avatar.jpg'); $this->module->click('Submit'); $data = data::get('form'); $this->assertContains('test3', $data['items'][1]); $this->assertContains('test2', $data['captions']); $this->assertContains('davert', $data['users']); }
<?php include MAVERICK_VIEWSDIR . 'includes/header.php'; include MAVERICK_VIEWSDIR . '' . data::get('page') . '.php'; include MAVERICK_VIEWSDIR . 'includes/footer.php';
public function testSelectOptionValueSelector() { $this->module->amOnPage('/form/select_selectors'); $this->module->selectOption('age', ['value' => '20']); $this->module->click('Submit'); $data = data::get('form'); $this->assertEquals('20', $data['age']); }
public function testFormWithFileSpecialCharNames() { $this->module->amOnPage('/form/example14'); $this->module->attachFile('foo bar', 'app/avatar.jpg'); $this->module->attachFile('foo.baz', 'app/avatar.jpg'); $this->module->click('Submit'); $this->assertNotEmpty(data::get('files')); $files = data::get('files'); $this->assertNotEmpty($files); $this->assertArrayHasKey('foo_bar', $files); $this->assertArrayHasKey('foo_baz', $files); }
/** * @issue https://github.com/Codeception/Codeception/issues/2841 */ public function testSubmitFormDoesNotKeepGetParameters() { $this->module->amOnPage('/form/bug2841?stuff=other'); $this->module->fillField('#texty', 'thingshjere'); $this->module->click('#submit-registration'); $this->assertEmpty(data::get('query'), 'Query string is not empty'); }
public function testArrayFieldSubmitForm() { $this->module->amOnPage('/form/example17'); $this->module->submitForm('form', ['FooBar' => ['bar' => 'booze'], 'Food' => ['beer' => ['yum' => ['yeah' => 'crunked']]]]); $data = data::get('form'); $this->assertEquals('booze', $data['FooBar']['bar']); $this->assertEquals('crunked', $data['Food']['beer']['yum']['yeah']); }
public function testComplexSelectorsAndForms() { $this->module->amOnPage('/login'); $this->module->submitForm('form#user_form_login', array('email' => '*****@*****.**', 'password' => '111111')); $post = data::get('form'); $this->assertEquals('*****@*****.**', $post['email']); }
public function testComplexFormsAndXPath() { $this->module->amOnPage('/login'); $this->module->submitForm("descendant-or-self::form[@id='user_form_login']", array('email' => '*****@*****.**', 'password' => '111111')); $post = data::get('form'); $this->assertEquals('*****@*****.**', $post['email']); }
public function testLoadPageApi() { $this->module->_loadPage('POST', '/form/try', ['user' => 'davert']); $data = data::get('form'); $this->assertEquals('davert', $data['user']); $this->module->see('Welcome to test app'); $this->module->click('More info'); $this->module->seeInCurrentUrl('/info'); }
public function testSubmitAdjacentForms() { $this->module->amOnPage('/form/submit_adjacentforms'); $this->module->submitForm('#form-2', []); $data = data::get('form'); $this->assertTrue(isset($data['second-field'])); $this->assertFalse(isset($data['first-field'])); $this->assertEquals('Killgore Trout', $data['second-field']); }
<?php $app = \maverick\maverick::getInstance(); $nav = array('' => 'Home', '/tweets' => 'Tweets'); if (isset($_SESSION['maverick_login']) && $_SESSION['maverick_login']) { $nav['/logout'] = 'Logout'; } $params = data::get('params'); $request = isset($params[0]) ? $params[0] : ''; foreach ($nav as $uri => $name) { $active = trim($uri, '/') == $request ? 'active' : ''; $class = strtolower(str_replace('_', '', $name)); $uri = '/' . $app->get_config('tweed.admin_path') . $uri; echo <<<NAV \t<a href="{$uri}" class="{$class} {$active}">{$name}</a> NAV; }
<!--[if lt IE 7]> <html lang="en" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html lang="en" class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]> <html lang="en" class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html lang="en" class="no-js"> <!--<![endif]--> <head> <meta charset="UTF-8"/> <title>Tweed</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <link href="http://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext" rel="stylesheet" type="text/css"/> <link rel="stylesheet" href="/css/tweed.css"> <?php $scripts = data::get('scripts'); foreach ($scripts as $script => $priority) { echo "<script data-priority=\"{$priority}\" src=\"{$script}\"></script>"; } ?> </head> <body class=""> <header> <h1>Tweed</h1> <nav> <?php $var = "{{admin_nav}}"; echo $var; ?> </nav>
public function testExample1() { $this->module->amOnPage('/form/example1'); $this->module->see('Login', 'button'); $this->module->fillField('#LoginForm_username', 'davert'); $this->module->fillField('#LoginForm_password', '123456'); $this->module->checkOption('#LoginForm_rememberMe'); $this->module->click('Login'); $login = data::get('form'); $this->assertEquals('davert', $login['LoginForm']['username']); $this->assertEquals('123456', $login['LoginForm']['password']); $this->assertNotEmpty($login['LoginForm']['rememberMe']); }
public function testFillPasswordOnFormSubmit() { $this->module->amOnPage('/form/complex'); $this->module->submitForm('form', ['password' => '123456']); $form = data::get('form'); $this->assertEquals('123456', $form['password']); }
public function testSubmitFormWithoutButton() { $this->module->amOnPage('/form/empty'); $this->module->submitForm('form', array( 'text' => 'Hello!' )); $form = data::get('form'); $this->assertEquals('Hello!', $form['text']); }