Implemented Helper Tests
As more helpers get added, more tests will get added
This commit is contained in:
parent
84432bf9a1
commit
5aa165d4a4
|
@ -339,8 +339,8 @@ if ( ! function_exists('get_mime_by_extension'))
|
|||
|
||||
if ( ! is_array($mimes))
|
||||
{
|
||||
$factory = Factory::getInstance();
|
||||
$mimes = $factory->getConfig()->get('mimes');
|
||||
$factory = FuzeWorks\Factory::getInstance();
|
||||
$mimes = $factory->getConfig()->get('mimes')->toArray();
|
||||
|
||||
if (empty($mimes))
|
||||
{
|
||||
|
|
11
phpunit.xml
11
phpunit.xml
|
@ -3,23 +3,16 @@
|
|||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
forceCoversAnnotation="false"
|
||||
mapTestClassNameToCoveredClassName="false"
|
||||
printerClass="PHPUnit_TextUI_ResultPrinter"
|
||||
processIsolation="false"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
|
||||
timeoutForSmallTests="1"
|
||||
timeoutForMediumTests="10"
|
||||
timeoutForLargeTests="60"
|
||||
verbose="true">
|
||||
colors="true">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Core Functionality">
|
||||
<directory>tests</directory>
|
||||
<directory>tests/helpers</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use FuzeWorks\Factory;
|
||||
|
||||
/**
|
||||
* Class ArrayHelperTest.
|
||||
*
|
||||
* Helpers testing suite, will test specific helper
|
||||
*/
|
||||
class arrayHelperTest extends CoreTestAbstract
|
||||
{
|
||||
|
||||
public $my_array = array(
|
||||
'foo' => 'bar',
|
||||
'sally' => 'jim',
|
||||
'maggie' => 'bessie',
|
||||
'herb' => 'cook'
|
||||
);
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
// Load Helper
|
||||
Factory::getInstance()->getHelpers()->load('array');
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function test_element_with_existing_item()
|
||||
{
|
||||
$this->assertEquals(FALSE, element('testing', $this->my_array));
|
||||
$this->assertEquals('not set', element('testing', $this->my_array, 'not set'));
|
||||
$this->assertEquals('bar', element('foo', $this->my_array));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function test_random_element()
|
||||
{
|
||||
// Send a string, not an array to random_element
|
||||
$this->assertEquals('my string', random_element('my string'));
|
||||
|
||||
// Test sending an array
|
||||
$this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function test_elements()
|
||||
{
|
||||
$this->assertEquals(TRUE, is_array(elements('test', $this->my_array)));
|
||||
$this->assertEquals(TRUE, is_array(elements('foo', $this->my_array)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use FuzeWorks\Factory;
|
||||
|
||||
/**
|
||||
* Class CommonHelperTest.
|
||||
*
|
||||
* Helpers testing suite, will test specific helper
|
||||
*/
|
||||
class commonHelperTest extends CoreTestAbstract
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
// Load Helper
|
||||
Factory::getInstance()->getHelpers()->load('common');
|
||||
}
|
||||
|
||||
public function test_stringify_attributes()
|
||||
{
|
||||
$this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar')));
|
||||
|
||||
$atts = new stdClass;
|
||||
$atts->class = 'foo';
|
||||
$atts->id = 'bar';
|
||||
$this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts));
|
||||
|
||||
$atts = new stdClass;
|
||||
$this->assertEquals('', _stringify_attributes($atts));
|
||||
|
||||
$this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"'));
|
||||
|
||||
$this->assertEquals('', _stringify_attributes(array()));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function test_stringify_js_attributes()
|
||||
{
|
||||
$this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE));
|
||||
|
||||
$atts = new stdClass;
|
||||
$atts->width = 800;
|
||||
$atts->height = 600;
|
||||
$this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function test_html_escape()
|
||||
{
|
||||
$this->assertEquals(
|
||||
html_escape('Here is a string containing "quoted" text.'),
|
||||
'Here is a string containing "quoted" text.'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
html_escape(array('associative' => 'and', array('multi' => 'dimentional'))),
|
||||
array('associative' => 'and', array('multi' => 'dimentional'))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use FuzeWorks\Factory;
|
||||
|
||||
/**
|
||||
* Class FileHelperTest.
|
||||
*
|
||||
* Helpers testing suite, will test specific helper
|
||||
*/
|
||||
class fileHelperTest extends CoreTestAbstract
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
// Load Helper
|
||||
Factory::getInstance()->getHelpers()->load('file');
|
||||
|
||||
vfsStreamWrapper::register();
|
||||
vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
|
||||
|
||||
$this->_test_dir = vfsStreamWrapper::getRoot();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function test_read_file()
|
||||
{
|
||||
$this->assertFalse(read_file('does_not_exist'));
|
||||
|
||||
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
|
||||
|
||||
$file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir);
|
||||
|
||||
$this->assertEquals($content, read_file(vfsStream::url('my_file.txt')));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function test_octal_permissions()
|
||||
{
|
||||
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
|
||||
|
||||
$file = vfsStream::newFile('my_file.txt', 0777)
|
||||
->withContent($content)
|
||||
->lastModified(time() - 86400)
|
||||
->at($this->_test_dir);
|
||||
|
||||
$this->assertEquals('777', octal_permissions($file->getPermissions()));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* More tests should happen here, since I'm not hitting the whole function.
|
||||
*/
|
||||
public function test_symbolic_permissions()
|
||||
{
|
||||
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
|
||||
|
||||
$file = vfsStream::newFile('my_file.txt', 0777)
|
||||
->withContent($content)
|
||||
->lastModified(time() - 86400)
|
||||
->at($this->_test_dir);
|
||||
|
||||
$this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function test_get_mime_by_extension()
|
||||
{
|
||||
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
|
||||
|
||||
$file = vfsStream::newFile('my_file.txt', 0777)
|
||||
->withContent($content)
|
||||
->lastModified(time() - 86400)
|
||||
->at($this->_test_dir);
|
||||
|
||||
$this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt')));
|
||||
|
||||
// Test a mime with an array, such as png
|
||||
$file = vfsStream::newFile('foo.png')->at($this->_test_dir);
|
||||
|
||||
$this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
|
||||
|
||||
// Test a file not in the mimes array
|
||||
$file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir);
|
||||
|
||||
$this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar')));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function test_get_file_info()
|
||||
{
|
||||
// Test Bad File
|
||||
$this->assertFalse(get_file_info('i_am_bad_boo'));
|
||||
|
||||
// Test the rest
|
||||
|
||||
// First pass in an array
|
||||
$vals = array(
|
||||
'name', 'server_path', 'size', 'date',
|
||||
'readable', 'writable', 'executable', 'fileperms'
|
||||
);
|
||||
|
||||
$this->_test_get_file_info($vals);
|
||||
|
||||
// Test passing in vals as a string.
|
||||
$this->_test_get_file_info(implode(', ', $vals));
|
||||
}
|
||||
|
||||
private function _test_get_file_info($vals)
|
||||
{
|
||||
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
|
||||
$last_modified = time() - 86400;
|
||||
|
||||
$file = vfsStream::newFile('my_file.txt', 0777)
|
||||
->withContent($content)
|
||||
->lastModified($last_modified)
|
||||
->at($this->_test_dir);
|
||||
|
||||
$ret_values = array(
|
||||
'name' => 'my_file.txt',
|
||||
'server_path' => 'vfs://my_file.txt',
|
||||
'size' => 57,
|
||||
'date' => $last_modified,
|
||||
'readable' => TRUE,
|
||||
'writable' => TRUE,
|
||||
'executable' => TRUE,
|
||||
'fileperms' => 33279
|
||||
);
|
||||
|
||||
$info = get_file_info(vfsStream::url('my_file.txt'), $vals);
|
||||
|
||||
foreach ($info as $k => $v)
|
||||
{
|
||||
$this->assertEquals($ret_values[$k], $v);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function test_write_file()
|
||||
{
|
||||
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
|
||||
|
||||
$file = vfsStream::newFile('write.txt', 0777)
|
||||
->withContent('')
|
||||
->lastModified(time() - 86400)
|
||||
->at($this->_test_dir);
|
||||
|
||||
$this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use FuzeWorks\Factory;
|
||||
|
||||
/**
|
||||
* Class XmlHelperTest.
|
||||
*
|
||||
* Helpers testing suite, will test specific helper
|
||||
*/
|
||||
class xmlHelperTest extends CoreTestAbstract
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
// Load Helper
|
||||
Factory::getInstance()->getHelpers()->load('xml');
|
||||
}
|
||||
|
||||
public function test_xml_convert()
|
||||
{
|
||||
$this->assertEquals('<tag>my & test - </tag>', xml_convert('<tag>my & test - </tag>'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue