function getManager() { if (is_null(static::$db)) { static::$db = makeDB(); } return static::$db; }
<h1>SubmissionsDB tests</h1> <?php include_once "../models/Database.class.php"; include_once "../models/Messages.class.php"; include_once "../models/Submission.class.php"; include_once "../models/SubmissionsDB.class.php"; include_once "../models/User.class.php"; include_once "../models/UsersDB.class.php"; include_once "./makeDB.php"; ?> <h2>It should get all submissions from a test database</h2> <?php makeDB('ptest'); Database::clearDB(); $db = Database::getDB('ptest'); $submissions = SubmissionsDB::getAllSubmissions(); $submissionCount = count($submissions); echo "Number of submissions in db is: {$submissionCount} <br>"; foreach ($submissions as $submission) { echo "{$submission} <br>"; } ?> </body> </html>
<h1>Submission controller tests</h1> <?php include_once "../controllers/SubmissionController.class.php"; include_once "../models/Database.class.php"; include_once "../models/Messages.class.php"; include_once "../models/Submission.class.php"; include_once "../models/User.class.php"; include_once "../models/UsersDB.class.php"; include_once "../views/HomeView.class.php"; include_once "../views/MasterView.class.php"; include_once "../views/SubmissionView.class.php"; include_once "./makeDB.php"; ?> <h2>It should call the run method for valid input during $POST</h2> <?php $myDb = makeDB('ptest'); $_SERVER["REQUEST_METHOD"] = "POST"; $_POST = array("userName" => "Kay"); SubmissionController::run(); ?> <h2>It should call show the submission page for a $GET request</h2> <?php $_SERVER["REQUEST_METHOD"] = "GET"; SubmissionController::run(); ?> </body> </html>
} /* load Pear. */ require_once 'DB.php'; if (!class_exists('DB')) { die("<b>Error:</b> Unable to load PEAR-DB! It is a requirement. Please add this package, and try again."); } /* Config file compatible with this release? */ if (!isset($_SESSION["initdone"]) || $_SESSION['initdone'] != true) { if ("{$CONF_VER}" != "{$CONFIGVER}") { die("Your etc/config." . $DOMAIN . ".php file is out of date. Please update it."); } elseif ($HAVE_READ != true) { die("Please edit the configuration file ./etc/config." . $DOMAIN . ".php!"); } } /* Create the database - needed before auth! */ $DB = makeDB(); /* Create empty user object */ $MySelf = new user(false, false); /* Lets check if we have the right SQL version */ if (!isset($_SESSION["initdone"]) || $_SESSION["initdone"] != true) { global $SQLVER; // Check the Version information of the Database. $CURRENT = $DB->getCol("SELECT value FROM config WHERE name = 'version' LIMIT 1"); // NO schema found! if ($DB->isError($CURRENT)) { print "<br><center><body bgcolor=\"#2E2E2E\"><font color= white><body link=\"#00FF00\" vlink=\"##00FF00\" alink=\"#FF0000\">"; print "<br><br><br><br><br><br><br><br><br><br><br><br>"; die("<CENTER><H1>Mining Buddy Tables need to be Created<BR><a href=\"./buildDatabase.php\">Click to Continue</H1></a></CENTER>"); } // Version number incorrect. if ("{$CURRENT['0']}" < "{$SQLVER}") {
<h2>It should get all user data from a test database</h2> <?php makeDB('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest'); $userData = UserDataDB::getUserDataBy(); $userDataCount = count($userData); echo "Number of user data in db is: {$userDataCount} <br>"; foreach ($userData as $userData) { echo "{$userData} <br>"; } ?> <h2>It should allow a new valid user data to be added for a new user</h2> <?php makeDB('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest'); echo "Number of user data in db before adding is: " . count(UserDataDB::getUserDataBy()) . "<br>"; $validTestUser = array("email" => "*****@*****.**", "password" => "validpassword"); $user = new User($validTestUser); $userId = UsersDB::addUser($user); $validTestUserData = array("user_name" => "newbie-user", "skill_level" => "novice", "skill_areas" => array("computer-vision", "soldering", "circuit-design"), "profile_pic" => "no-picture.jpg", "started_hobby" => "2015-10", "fav_color" => "#ff8000", "url" => "http://www.wired.com", "phone" => "210-555-1234"); $userData = new UserData($validTestUserData); $userData->setUserId($userId); $userDataId = UserDataDB::addUserData($userData); echo "Number of user data in db after adding is: " . count(UserDataDB::getUserDataBy()) . "<br>"; echo "UserData ID of new user is: {$userDataId}"; ?> <h2>It should not allow invalid user data to be added</h2>
protected function setUp() { if (!$this->db) { $this->db = makeDB(); } if (!$this->db) { $this->markTestSkipped('Не настроено подключение к БД'); } $this->db->drop('test')->execute(); $this->db->create('test')->addId()->addChar('name')->addTimeCreated()->execute(); for ($i = 1; $i <= 20; $i++) { $this->db->insert('test')->setArray(array('name' => 'Item #' . $i))->execute(); } }