Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
QA
  • Loading branch information
jakoch committed Sep 26, 2012
1 parent 1b9b364 commit 38cad6b
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 159 deletions.
2 changes: 1 addition & 1 deletion framework/Koch/Debug/XDebug.php
Expand Up @@ -359,7 +359,7 @@ public static function showConstants()

public static function showBrowserInfo()
{
$ua = new \Koch\Http\UserAgent();
$ua = new \Koch\Http\UserAgent();
$browser = $ua->getBrowserInfo();

echo self::getSectionHeadlineHTML('Browserinfo');
Expand Down
264 changes: 132 additions & 132 deletions framework/Koch/Files/Directory.php
@@ -1,132 +1,132 @@
<?php

/**
* Koch Framework
* Jens-André Koch © 2005 - onwards
*
* This file is part of "Koch Framework".
*
* License: GNU/GPL v2 or any later version, see LICENSE file.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace Koch\Files;

class Directory
{
private $filtername = 'ImagesOnly';
private $directory = '';

public function __construct($directory = null)
{
if ($directory !== null) {
$this->setDirectory($directory);
}

return $this;
}

/**
* Available Filter types: image
*/
public function setFilter($filtername)
{
$this->filtername = $filtername;

return $this;
}

public function setDirectory($directory)
{
// slash fix
$directory = str_replace('/', DS, $directory);
$directory = str_replace('\\', DS, $directory);

// prefix directory with ROOT for security purposes
if (stristr($directory, ROOT) == false) {
$directory = ROOT . $directory;
}

$this->directory = $directory;

return $this;
}

public function getDirectory()
{
if (empty($this->directory) === false) {
return $this->directory;
} else { // default path

return ROOT . 'uploads/images/gallery';
}
}

public function getFiles($return_as_array = false)
{
// compose the full name of the filter class
$classname = 'Koch_' . $this->filtername . 'FilterIterator';

// wrap the iterator in a filter class, when looking for a specific file type, like imagesOnly'
$iterator = new $classname(new \DirectoryIterator($this->getDirectory()));

// return objects
if ($return_as_array === false) {
// create new array to take the SPL FileInfo Objects
$data = new \ArrayObject();

// while iterating
foreach ($iterator as $file) {
/**
* push the SPL FileInfo Objects into the array
* @see http://www.php.net/~helly/php/ext/spl/classSplFileInfo.html
*/
$data[$file->getFilename()] = $file->getFileInfo();
}

$data->ksort();
} else { // return array
// create array
$data = array();

// while iterating
foreach ($iterator as $file) {
$wwwpath = WWW_ROOT . DIRECTORY_SEPARATOR . $this->getDirectory() . DIRECTORY_SEPARATOR . $file->getFilename();
$wwwpath = str_replace('//', '/', $wwwpath);
$data[$wwwpath] = $file->getFilename();
}
}

// return the array with SPL FileInfo Objects
return $data;
}

/**
*
* @author: Lostindream at atlas dot cz
* @link http://de.php.net/manual/de/function.pathinfo.php#85196
*/
public function filePath($filePath)
{
$fileParts = pathinfo($filePath);

if (!isset($fileParts['filename'])) {
$fileParts['filename'] = mb_substr($fileParts['basename'], 0, mb_strrpos($fileParts['basename'], '.'));
}

return $fileParts;
}
}
<?php

/**
* Koch Framework
* Jens-André Koch © 2005 - onwards
*
* This file is part of "Koch Framework".
*
* License: GNU/GPL v2 or any later version, see LICENSE file.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace Koch\Files;

class Directory
{
private $filtername = 'ImagesOnly';
private $directory = '';

public function __construct($directory = null)
{
if ($directory !== null) {
$this->setDirectory($directory);
}

return $this;
}

/**
* Available Filter types: image
*/
public function setFilter($filtername)
{
$this->filtername = $filtername;

return $this;
}

public function setDirectory($directory)
{
// slash fix
$directory = str_replace('/', DS, $directory);
$directory = str_replace('\\', DS, $directory);

// prefix directory with ROOT for security purposes
if (stristr($directory, ROOT) == false) {
$directory = ROOT . $directory;
}

$this->directory = $directory;

return $this;
}

public function getDirectory()
{
if (empty($this->directory) === false) {
return $this->directory;
} else { // default path

return ROOT . 'uploads/images/gallery';
}
}

public function getFiles($return_as_array = false)
{
// compose the full name of the filter class
$classname = 'Koch_' . $this->filtername . 'FilterIterator';

// wrap the iterator in a filter class, when looking for a specific file type, like imagesOnly'
$iterator = new $classname(new \DirectoryIterator($this->getDirectory()));

// return objects
if ($return_as_array === false) {
// create new array to take the SPL FileInfo Objects
$data = new \ArrayObject();

// while iterating
foreach ($iterator as $file) {
/**
* push the SPL FileInfo Objects into the array
* @see http://www.php.net/~helly/php/ext/spl/classSplFileInfo.html
*/
$data[$file->getFilename()] = $file->getFileInfo();
}

$data->ksort();
} else { // return array
// create array
$data = array();

// while iterating
foreach ($iterator as $file) {
$wwwpath = WWW_ROOT . DIRECTORY_SEPARATOR . $this->getDirectory() . DIRECTORY_SEPARATOR . $file->getFilename();
$wwwpath = str_replace('//', '/', $wwwpath);
$data[$wwwpath] = $file->getFilename();
}
}

// return the array with SPL FileInfo Objects
return $data;
}

/**
*
* @author: Lostindream at atlas dot cz
* @link http://de.php.net/manual/de/function.pathinfo.php#85196
*/
public function filePath($filePath)
{
$fileParts = pathinfo($filePath);

if (!isset($fileParts['filename'])) {
$fileParts['filename'] = mb_substr($fileParts['basename'], 0, mb_strrpos($fileParts['basename'], '.'));
}

return $fileParts;
}
}
1 change: 0 additions & 1 deletion framework/Koch/Files/File.php
Expand Up @@ -269,4 +269,3 @@ public function accept()
}
}
}

2 changes: 1 addition & 1 deletion framework/Koch/View/Renderer/Smarty.php
Expand Up @@ -167,7 +167,7 @@ public function configureEngine()
/**
* ENGINE SETTINGS
*/

/**
* Smarty Template Directories
*
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/Clansuite/VersionTest.php
Expand Up @@ -35,7 +35,7 @@ public function tearDown()
public function testSetVersionInformation()
{
$this->object->setVersionInformation();

$this->assertTrue(
defined('CLANSUITE_VERSION') &&
defined('CLANSUITE_VERSION_NAME') &&
Expand Down
6 changes: 5 additions & 1 deletion tests/unittests/framework/Koch/Config/Adapter/INITest.php
Expand Up @@ -42,7 +42,7 @@ public function getIniArray()

public function getFile()
{
return dirname(__DIR__) . '/fixtures/file.ini';
return dirname(__DIR__) . '/fixtures/writeTest.ini';
}

public function testReadConfig_throwsException_IfFileNotFound()
Expand All @@ -57,6 +57,10 @@ public function testReadConfig_throwsException_IfFileNotFound()
public function testWriteConfig()
{
$ini_array = $this->object->writeConfig($this->getFile(), $this->getIniArray());

$this->assertEqual($ini_array, $this->getIniArray());

unlink($this->getFile());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/framework/Koch/Config/Adapter/JSONTest.php
Expand Up @@ -35,7 +35,7 @@ public function tearDown()

public function getFile()
{
return __DIR__ . '/file.json';
return dirname(__DIR__) . '/fixtures/file.json';
}

public function testReadConfig_throwsException_IfFileNotFound()
Expand All @@ -47,7 +47,7 @@ public function testReadConfig_throwsException_IfFileNotFound()
public function testReadConfig_throwsException_JsonError()
{
$this->expectException();
$this->object->readConfig(__DIR__ . 'error.json');
$this->object->readConfig('not-existant-file.json');
}

/**
Expand All @@ -69,7 +69,7 @@ public function testReadConfig()
public function testWriteConfig()
{
$array = array( 'section-1' => array( 'key1' => 'value1' ) );
$file = __DIR__.'/writeTest.json';
$file = dirname(__DIR__) . '/fixtures/writeTest.json';

$int_or_bool = $this->object->writeConfig($file, $array);

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/framework/Koch/Config/Adapter/XMLTest.php
Expand Up @@ -27,7 +27,7 @@ public function setUp()
public function tearDown()
{
}

public function getFile()
{
return dirname(__DIR__) . '/fixtures/data.xml';
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/framework/Koch/Config/Adapter/YAMLTest.php
Expand Up @@ -21,7 +21,7 @@ public function setUp()
$this->markTestSkipped('The no yaml reader available. Install SYCK extensions or Spyc library.');
$this->expectException();
}

$this->object = new YAML($this->getFile());
}

Expand All @@ -32,7 +32,7 @@ public function setUp()
public function tearDown()
{
}

public function getFile()
{
return dirname(__DIR__) . '/fixtures/data.yml';
Expand Down
16 changes: 8 additions & 8 deletions tests/unittests/framework/Koch/Config/fixtures/data.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data>
<one>Content 1</one>
<two>
<three>Content 3</three>
<four>Content 4</four>
</two>
</data>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data>
<one>Content 1</one>
<two>
<three>Content 3</three>
<four>Content 4</four>
</two>
</data>

0 comments on commit 38cad6b

Please sign in to comment.