コード例 #1
0
 public function testGetValidStatisticByStatisticName()
 {
     //count the numbers of rows and save
     $numRows = $this->getConnection()->getRowCount("statistic");
     //create a new Game and insert into mySQL
     $statistic = new Statistic(null, $this->VALID_STATISTICNAME);
     $statistic->insert($this->getPDO());
     //grab the data from mySQL and enforce the fields
     $results = Statistic::getStatisticByStatisticName($this->getPDO(), $this->VALID_STATISTICNAME);
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount('statistic'));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Sprots\\Statistic", $results);
     // grab the result from the array and validate it
     $pdoStatistic = $results[0];
     $this->assertEquals($pdoStatistic->getStatisticName(), $this->VALID_STATISTICNAME);
 }
コード例 #2
0
ファイル: index.php プロジェクト: chrispaul3625/sprots
    }
    //Sanitize and trim other fields
    $statisticId = filter_input(INPUT_GET, "statisticId", FILTER_VALIDATE_INT);
    $statisticName = filter_input(INPUT_GET, "statisticName", FILTER_SANITIZE_STRING);
    //handle REST calls, while only allowing administrators to access database-modifying methods
    if ($method === "GET") {
        //set XSRF cookie
        setXsrfCookie("/");
        if (empty($id) === false) {
            $statistic = Statistic::getStatisticByStatisticId($pdo, $id);
            if ($statistic !== null && $statistic->getStatisticId() === $_SESSION["statistic"]->getStatisticId()) {
                $reply->data = $statistic;
            }
        } else {
            if (empty($name) === false) {
                $statistic = Statistic::getStatisticByStatisticName($pdo, $statisticName);
                if ($statistic !== null && $statistic->getStatisticId() === $_SESSION["statistic"]->getStatisticId()) {
                    $reply->data = $statistic;
                }
            }
        }
    }
    if ($method === "GET") {
        setXsrfCookie("/");
        $statistics = Statistic::getAllStatistic($pdo)->toArray();
        $reply->data = $statistics;
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
}