Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: thibaud-rohmer/PhotoShow
base: 56b06db25f
...
head fork: thibaud-rohmer/PhotoShow
compare: 1cd4ebbeea
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
View
40 src/classes/GuestToken.php
@@ -160,10 +160,11 @@ public static function delete($key){
*/
public static function exist($key){
- // Check if the accounts file exists
+ // Check if the tokens file exists
if(!file_exists(CurrentUser::$tokens_file)){
return false;
}
+
$xml = simplexml_load_file(CurrentUser::$tokens_file);
foreach( $xml as $token ){
@@ -178,11 +179,16 @@ public static function exist($key){
/**
* Returns an array containing all tokens
*
- * @return array $tokens
+ * @return array $tokens, False if not found
* @author Franck Royer
*/
public static function findAll(){
$tokens = array();
+
+ // Check if the tokens file exists
+ if(!file_exists(CurrentUser::$tokens_file)){
+ return false;
+ }
$xml = simplexml_load_file(CurrentUser::$tokens_file);
@@ -202,11 +208,16 @@ public static function findAll(){
* which has access to the given path
*
* @param string $path
- * @return array $tokens
+ * @return array $tokens, False if not found
* @author Franck Royer
*/
public static function find_for_path($path, $exact_path = false){
$tokens = array();
+
+ // Check if the tokens file exists
+ if(!file_exists(CurrentUser::$tokens_file)){
+ return false;
+ }
foreach( self::findAll() as $token ){
if ($exact_path){
@@ -226,11 +237,17 @@ public static function find_for_path($path, $exact_path = false){
* Returns the allowed path of a guest token
*
* @param string $key
- * @return path
+ * @return path, False if not found
* @author Franck Royer
*/
public static function get_path($key){
$path = "";
+
+ // Check if the tokens file exists
+ if(!file_exists(CurrentUser::$tokens_file)){
+ return false;
+ }
+
$xml = simplexml_load_file(CurrentUser::$tokens_file);
foreach( self::findAll() as $token ){
@@ -247,11 +264,16 @@ public static function get_path($key){
* Returns the url to use a token
*
* @param string $key
- * @return path
+ * @return url, False if not found
* @author Franck Royer
*/
public static function get_url($key){
$url = "";
+
+ // Check if the tokens file exists
+ if(!file_exists(CurrentUser::$tokens_file)){
+ return false;
+ }
if (self::exist($key)){
$url = Settings::$site_address."?f=".urlencode(self::get_path($key))."&token=".$key;
@@ -272,6 +294,11 @@ public static function get_url($key){
public static function view($key,$path){
$rpath = File::a2r($path);
$apath = self::get_path($key);
+
+ // Check if the tokens file exists
+ if(!file_exists(CurrentUser::$tokens_file)){
+ return false;
+ }
if (!$apath || !$rpath){
return false;
@@ -302,10 +329,11 @@ public static function generate_key(){
*
*/
public function toHTML(){
- if (!CurrentUser::$admin){
+ if (!CurrentUser::$admin || !file_exists(CurrentUser::$tokens_file)){
// Only admin can see the tokens for now
return false;
}
+
echo "<div id='tokensblock' class='adminblock'>";
echo "<h3>".Settings::_("token","tokens")."</h3>\n";
echo "<div>";
View
11 src/classes/Judge.php
@@ -419,15 +419,18 @@ public function toHTML(){
// Token creation
echo "<h3>".Settings::_("token","tokens")."</h3>\n";
- foreach(GuestToken::find_for_path($this->file) as $token){
- echo "<a href='".GuestToken::get_url($token['key'])."' >".$token['key']."<\a><br />\n";
+ $tokens = GuestToken::find_for_path($this->file);
+ if ($tokens && !empty($tokens)){
+ foreach($tokens as $token){
+ echo "<a href='".GuestToken::get_url($token['key'])."' >".$token['key']."<\a><br />\n";
+ }
}
echo "<form action='?t=CTk&f=$this->webpath' method='post'>\n";
echo "<input type='submit' class='button blue' value='".Settings::_("token","createtoken")."' />";
echo "</form>";
- echo "</div>\n";
- }
+ echo "</div>\n";
+ }
}
View
23 src/tests/CurrentUserTest.php
@@ -46,31 +46,22 @@ class CurrentUserTest extends TestUnit
{
/**
- * Test login
+ * Test login & logout
* @test
*/
- public function test_login(){
- session_unset();
- CurrentUser::logout();
- self::login_as_user();
+ public function test_login_logout(){
+
+ CurrentUser::login("testuser", "testpassword");
$this->assertEquals("testuser", $_SESSION['login']);
$this->assertNull($_SESSION['token']);
$this->assertNotNull(CurrentUser::$account);
+ $this->assertEquals("testuser", CurrentUser::$account->login);
$this->assertFalse(CurrentUser::$admin);
- }
- /**
- * Test logout
- * @test
- * @depends test_login
- */
- public function test_logout(){
- session_unset();
- self::login_as_user();
CurrentUser::logout();
-
- //TODO: I guess we need to read the doc to use phpunit, _SESSION and session_unset()
+
+ //TODO: Failure because I do require_once. Autoload may solve the issue
$this->assertNull($_SESSION['login']);
$this->assertNull(CurrentUser::$account);
$this->assertNull($_SESSION['token']);
View
33 src/tests/TestUnit.php
@@ -51,21 +51,35 @@ class TestUnit extends PHPUnit_Framework_TestCase
/**************************************************/
/**
- * Constructor
+ * General setupbeforeClasse
* @author Franck Royer
*/
-
- function __construct()
+ public static function setUpBeforeClass()
{
- parent::__construct();
self::include_all();
- $this->config_file = realpath(dirname(__FILE__)."/test_config.php");
+ $GLOBALS['config_file'] = realpath(dirname(__FILE__))."/test_config.php";
self::prepare_files();
self::init_config();
self::create_accounts();
}
/**
+ * General setup
+ * @author Franck Royer
+ */
+ protected function setUp()
+ {
+ //always reset the session before a method
+ session_unset();
+ }
+
+ function __construct()
+ {
+ require_once('PHPUnit'.DIRECTORY_SEPARATOR.'Framework'.DIRECTORY_SEPARATOR.'TestCase.php');
+ parent::__construct();
+ }
+
+ /**
* includes all PhotoShow classes
* TODO: autoload
* @author Franck Royer
@@ -74,7 +88,6 @@ function __construct()
static public function include_all()
{
$toinclude = array(
- 'PHPUnit'.DIRECTORY_SEPARATOR.'Framework'.DIRECTORY_SEPARATOR.'TestCase.php',
realpath(dirname(__FILE__)."/../classes/HTMLObject.php"),
realpath(dirname(__FILE__)."/../classes/Page.php"),
realpath(dirname(__FILE__)."/../classes/File.php"),
@@ -98,8 +111,8 @@ static public function include_all()
/**
* Load the config
*/
- public function init_config(){
- Settings::init(false,$this->config_file);
+ public static function init_config(){
+ Settings::init(false,$GLOBALS['config_file']);
try {
CurrentUser::init();
} catch(Exception $e){
@@ -110,8 +123,8 @@ public function init_config(){
/**
* Function to prepare the files
*/
- public function prepare_files(){
- if (!include($this->config_file)){
+ public static function prepare_files(){
+ if (!include($GLOBALS['config_file'])){
throw new Exception("Cannot include config file!\n");
}
View
4 src/tests/phpunit.xml
@@ -1,8 +1,4 @@
<phpunit>
- <php>
- <includePath>.</includePath>
- <includePath>../classes/</includePath>
- </php>
<testsuites>
<testsuite name="PhotoShow">
<directory>.</directory>

No commit comments for this range

Something went wrong with that request. Please try again.