/** * group accountconf **/ function testThatAccountConfirmationProcessRejectsNinjaNamesOfTheWrongFormat() { // Same requirements as above, here we test that bad names are rejected. $bad_names = array('xz', 'bo', '69numfirst', 'underscorelast_', 'specialChar##', '@!#$#$^#$@#', 'double__underscore', 'double--dash'); foreach ($bad_names as $name) { $this->assertFalse((bool) username_is_valid($name)); } }
<?php // there is no session if (!session_id()) { session_start(); } $cart = array(); $data = json_decode(file_get_contents('php://input'), true); if (is_array($data) && count($data) > 0) { try { // valid the data foreach ($data as $developer) { if (!username_is_valid(trim($developer['username']))) { throw new Exception('Invalid username: "******".'); } elseif (!price_is_valid(trim($developer['price']))) { throw new Exception('Invalid price: "' . trim($developer['price']) . '".'); } elseif (!hours_is_valid(trim($developer['hours']))) { throw new Exception('Invalid hours: "' . trim($developer['hours']) . '".'); } else { $_SESSION['cart'][] = $developer; } } $success = array('success' => array('message' => 'cart updated!')); echo json_encode($success); } catch (Exception $e) { $errors = array('error' => array('message' => array())); $errors['error']['message'][] = $e->getMessage(); echo json_encode($errors); } } elseif ($_GET['remove'] == 'true') { foreach ($_SESSION['cart'] as $k => $developer) {