Updated all tests to pass on PHP 7.1.

This commit is contained in:
Abel Hoogeveen 2017-07-14 16:14:47 +02:00
parent e08765246b
commit 8296f6a00b
24 changed files with 407 additions and 80 deletions

View File

@ -38,7 +38,7 @@ use FuzeWorks\Logger;
$container = require('bootstrap.php');
// Load the test abstract
require_once 'abstract.coreTestAbstract.php';
require_once 'core/abstract.coreTestAbstract.php';
// Reset error and exception handlers
ob_start();

View File

@ -12,6 +12,7 @@ $parameters = array(
$configurator->setParameters($parameters);
$configurator->setDebugMode(true);
//$configurator->setDebugEmail('example@mail.com');
$configurator->setTimeZone('Europe/Amsterdam');
$configurator->setTempDirectory(__DIR__ . '/temp');
$configurator->setLogDirectory(__DIR__ . '/temp');

View File

@ -29,6 +29,7 @@
*
* @version Version 1.0.1
*/
use PHPUnit\Framework\TestCase;
use FuzeWorks\Events;
use FuzeWorks\Layout;
use FuzeWorks\Factory;
@ -39,7 +40,7 @@ use FuzeWorks\LoggerTracyBridge;
*
* Provides the event tests with some basic functionality
*/
abstract class CoreTestAbstract extends PHPUnit_Framework_TestCase
abstract class CoreTestAbstract extends TestCase
{
/**
* Remove all listeners before the next test starts.
@ -55,7 +56,7 @@ abstract class CoreTestAbstract extends PHPUnit_Framework_TestCase
LoggerTracyBridge::register();
// Reset the layout manager
Layout::reset();
Factory::getInstance()->layout->reset();
// Re-enable events, in case they have been disabled
Events::enable();

View File

@ -0,0 +1,77 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2017 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://techfuze.net/fuzeworks
* @since Version 1.0.4
*
* @version Version 1.0.4
*/
use FuzeWorks\EventPriority;
/**
* Class EventPriorityTest.
*
* This test will test the EventPriority class
*/
class eventPriorityTest extends CoreTestAbstract
{
public function testPriorities()
{
$this->assertEquals(EventPriority::LOWEST, 5);
$this->assertEquals(EventPriority::LOW, 4);
$this->assertEquals(EventPriority::NORMAL, 3);
$this->assertEquals(EventPriority::HIGH, 2);
$this->assertEquals(EventPriority::HIGHEST, 1);
$this->assertEquals(EventPriority::MONITOR, 0);
}
public function testGetPriority()
{
$this->assertEquals(EventPriority::getPriority(5), 'EventPriority::LOWEST');
$this->assertEquals(EventPriority::getPriority(4), 'EventPriority::LOW');
$this->assertEquals(EventPriority::getPriority(3), 'EventPriority::NORMAL');
$this->assertEquals(EventPriority::getPriority(2), 'EventPriority::HIGH');
$this->assertEquals(EventPriority::getPriority(1), 'EventPriority::HIGHEST');
$this->assertEquals(EventPriority::getPriority(0), 'EventPriority::MONITOR');
}
public function testGetInvalidPriority()
{
$this->assertFalse(EventPriority::getPriority(99));
}
public function testHighestPriority()
{
$this->assertEquals(EventPriority::getHighestPriority(), EventPriority::MONITOR);
}
public function testLowestPriority()
{
$this->assertEquals(EventPriority::getLowestPriority(), EventPriority::LOWEST);
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2017 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://techfuze.net/fuzeworks
* @since Version 1.0.4
*
* @version Version 1.0.4
*/
use FuzeWorks\Events;
use FuzeWorks\Event;
use FuzeWorks\EventPriority;
/**
* Class EventTest.
*
* This test will test the Event class
*/
class eventTest extends CoreTestAbstract
{
public function testFireEvent()
{
$event = Events::fireEvent('testEvent');
$this->assertInstanceOf('FuzeWorks\Event', $event);
}
public function testCancelEvent()
{
Events::addListener(array($this, 'listener_cancel'), 'testCancelEvent', EventPriority::NORMAL);
$event = Events::fireEvent('testCancelEvent');
$this->assertTrue($event->isCancelled());
}
public function testUncancelEvent()
{
Events::addListener(array($this, 'listener_cancel'), 'testUncancelEvent', EventPriority::HIGH);
Events::addListener(array($this, 'listener_uncancel'), 'testUncancelEvent', EventPriority::LOW);
$event = Events::fireEvent('testUncancelEvent');
$this->assertFalse($event->isCancelled());
}
public function listener_cancel($event)
{
$event->setCancelled(true);
return $event;
}
public function listener_uncancel($event)
{
$this->assertTrue($event->isCancelled());
$event->setCancelled(false);
return $event;
}
}

View File

@ -27,9 +27,10 @@
* @link http://techfuze.net/fuzeworks
* @since Version 0.0.1
*
* @version Version 1.0.0
* @version Version 1.0.4
*/
use FuzeWorks\Router;
use FuzeWorks\Event;
use FuzeWorks\Events;
use FuzeWorks\EventPriority;
@ -42,7 +43,7 @@ class eventsTest extends CoreTestAbstract
{
public function testFireEvent()
{
$mock = $this->getMock('MockEventListener', array('mockMethod'));
$mock = $this->getMockBuilder(Observer::class)->setMethods(['mockMethod'])->getMock();
$mock->expects($this->once())->method('mockMethod');
Events::addListener(array($mock, 'mockMethod'), 'mockEvent', EventPriority::NORMAL);
@ -54,9 +55,9 @@ class eventsTest extends CoreTestAbstract
*/
public function testObjectEvent()
{
$event = $this->getMock('MockEvent');
$event = $this->getMockBuilder(MockEvent::class)->getMock();
$listener = $this->getMock('MockEventListener', array('mockListener'));
$listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock();
$listener->expects($this->once())->method('mockListener')->with($this->equalTo($event));
Events::addListener(array($listener, 'mockListener'), get_class($event), EventPriority::NORMAL);
@ -68,7 +69,7 @@ class eventsTest extends CoreTestAbstract
*/
public function testVariablePassing()
{
$event = $this->getMock('MockEvent');
$event = $this->getMockBuilder(MockEvent::class)->getMock();
$event->key = 'value';
$eventName = get_class($event);
@ -87,7 +88,7 @@ class eventsTest extends CoreTestAbstract
public function testVariableChanging()
{
// First prepare the event
$event = $this->getMock('MockEvent');
$event = $this->getMockBuilder(MockEvent::class)->getMock();
$event->key = 1;
$eventName = get_class($event);
@ -115,11 +116,29 @@ class eventsTest extends CoreTestAbstract
/**
* @depends testFireEvent
* @expectedException FuzeWorks\Exception\EventException
*/
public function testRemoveListener()
public function testInvalidTypeEvent()
{
Events::fireEvent(array('x', 'y', 'z'));
}
/**
* @depends testFireEvent
* @expectedException FuzeWorks\Exception\EventException
*/
public function testInvalidClassEvent()
{
Events::fireEvent('nonExistingEvent', 'x', 'y', 'z');
}
/**
* @depends testFireEvent
*/
public function testAddAndRemoveListener()
{
// First add the listener, expect it to be never called
$listener = $this->getMock('MockEventListener', array('mockListener'));
$listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock();
$listener->expects($this->never())->method('mockListener');
Events::addListener(array($listener, 'mockListener'), 'mockEvent', EventPriority::NORMAL);
@ -130,10 +149,63 @@ class eventsTest extends CoreTestAbstract
Events::fireEvent('mockEvent');
}
/**
* @depends testAddAndRemoveListener
* @expectedException FuzeWorks\Exception\EventException
*/
public function testAddInvalidPriorityListener()
{
Events::addListener('fakeCallable', 'mockEvent', 99);
}
/**
* @depends testAddAndRemoveListener
* @expectedException FuzeWorks\Exception\EventException
*/
public function testAddInvalidCallableListener()
{
Events::addListener(array('nonExistingClass', 'nonExistingMethod'), 'mockEvent', EventPriority::NORMAL);
}
/**
* @depends testAddAndRemoveListener
* @expectedException FuzeWorks\Exception\EventException
*/
public function testAddInvalidNameListener()
{
Events::addListener(function($e) {}, '', EventPriority::NORMAL);
}
/**
* @depends testAddAndRemoveListener
* @expectedException FuzeWorks\Exception\EventException
*/
public function testRemoveInvalidPriorityListener()
{
Events::removeListener('fakeCallable', 'mockEvent', 99);
}
/**
* @depends testAddAndRemoveListener
*/
public function testRemoveUnsetEventListener()
{
$this->assertNull(Events::removeListener('fakeCallable', 'emptyListenerArray', EventPriority::NORMAL));
}
/**
* @depends testAddAndRemoveListener
*/
public function testRemoveUnsetListener()
{
Events::addListener(function($e) {}, 'mockEvent', EventPriority::NORMAL);
$this->assertNull(Events::removeListener(function($x) {echo "Called"; }, 'mockEvent', EventPriority::NORMAL));
}
public function testDisable()
{
// First add the listener, expect it to be never called
$listener = $this->getMock('MockEventListener', array('mockListener'));
$listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock();
$listener->expects($this->never())->method('mockListener');
Events::addListener(array($listener, 'mockListener'), 'mockEvent', EventPriority::NORMAL);
@ -147,7 +219,7 @@ class eventsTest extends CoreTestAbstract
public function testReEnable()
{
// First add the listener, expect it to be never called
$listener = $this->getMock('MockEventListener', array('mockListener'));
$listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock();
$listener->expects($this->once())->method('mockListener');
Events::addListener(array($listener, 'mockListener'), 'mockEvent', EventPriority::NORMAL);
@ -164,3 +236,14 @@ class eventsTest extends CoreTestAbstract
Events::fireEvent('mockEvent');
}
}
class Observer
{
public function mockMethod() {}
public function mockListener($event) {}
}
class MockEvent extends Event
{
}

View File

@ -43,7 +43,6 @@ use FuzeWorks\Exception\LayoutException;
use FuzeWorks\Exception\LibraryException;
use FuzeWorks\Exception\LoggerException;
use FuzeWorks\Exception\ModelException;
use FuzeWorks\Exception\ModuleException;
use FuzeWorks\Exception\RouterException;
use FuzeWorks\Exception\SecurityException;
use FuzeWorks\Exception\UriException;
@ -160,14 +159,6 @@ class exceptionTestTest extends CoreTestAbstract
throw new ModelException("Exception Test Run", 1);
}
/**
* @expectedException FuzeWorks\Exception\ModuleException
*/
public function testModuleException()
{
throw new ModuleException("Exception Test Run", 1);
}
/**
* @expectedException FuzeWorks\Exception\RouterException
*/

View File

@ -70,7 +70,7 @@ class factoryTest extends CoreTestAbstract
public function testObjectsSameInstance()
{
// Create mock
$mock = $this->getMock('MockInstance');
$mock = $this->getMockBuilder(MockFactory::class)->setMethods(['mockListener'])->getMock();
// Test not set
$this->assertNull(Factory::getInstance()->mock);
@ -96,7 +96,7 @@ class factoryTest extends CoreTestAbstract
public function testObjectsDifferentInstance()
{
// Create mock
$mock = $this->getMock('MockInstance');
$mock = $this->getMockBuilder(MockFactory::class)->getMock();
// Test not set
$this->assertNull(Factory::getInstance()->mock);
@ -175,3 +175,7 @@ class factoryTest extends CoreTestAbstract
}
}
class MockFactory {
}

View File

@ -178,6 +178,7 @@ class inputTest extends CoreTestAbstract
$this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $harm);
$this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless);
unset($_POST['foo']);
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['foo']['bar'] = 'baz';
$barArray = array('bar' => 'baz');

View File

@ -39,12 +39,21 @@ use FuzeWorks\Factory;
*/
class layoutTest extends CoreTestAbstract
{
protected $factory;
public function setUp()
{
// Load the factory first
$this->factory = Factory::getInstance();
}
public function testGetFileExtensions()
{
// Test getting php files
$this->assertEquals('php', Layout::getExtensionFromFile('class.test.php'));
$this->assertEquals('php', Layout::getExtensionFromFile('class.test.org.php'));
$this->assertEquals('random', Layout::getExtensionFromFile('class.test.something.random'));
$this->assertEquals('php', $this->factory->layout->getExtensionFromFile('class.test.php'));
$this->assertEquals('php', $this->factory->layout->getExtensionFromFile('class.test.org.php'));
$this->assertEquals('random', $this->factory->layout->getExtensionFromFile('class.test.something.random'));
}
/**
@ -56,19 +65,19 @@ class layoutTest extends CoreTestAbstract
$extensions = array('php', 'json');
// Basic path
Layout::setFileFromString('test', 'tests/layout/testGetFilePath/', $extensions);
$this->assertEquals('tests/layout/testGetFilePath/view.test.php', Layout::getFile());
$this->assertEquals('tests/layout/testGetFilePath/', Layout::getDirectory());
$this->factory->layout->setFileFromString('test', 'tests/layout/testGetFilePath/', $extensions);
$this->assertEquals('tests/layout/testGetFilePath/view.test.php', $this->factory->layout->getFile());
$this->assertEquals('tests/layout/testGetFilePath/', $this->factory->layout->getDirectory());
// Alternate file extension
Layout::setFileFromString('JSON', 'tests/layout/testGetFilePath/', $extensions);
$this->assertEquals('tests/layout/testGetFilePath/view.JSON.json', Layout::getFile());
$this->assertEquals('tests/layout/testGetFilePath/', Layout::getDirectory());
$this->factory->layout->setFileFromString('JSON', 'tests/layout/testGetFilePath/', $extensions);
$this->assertEquals('tests/layout/testGetFilePath/view.JSON.json', $this->factory->layout->getFile());
$this->assertEquals('tests/layout/testGetFilePath/', $this->factory->layout->getDirectory());
// Complex deeper path
Layout::setFileFromString('Deeper/test', 'tests/layout/testGetFilePath/', $extensions);
$this->assertEquals('tests/layout/testGetFilePath/Deeper/view.test.php', Layout::getFile());
$this->assertEquals('tests/layout/testGetFilePath/', Layout::getDirectory());
$this->factory->layout->setFileFromString('Deeper/test', 'tests/layout/testGetFilePath/', $extensions);
$this->assertEquals('tests/layout/testGetFilePath/Deeper/view.test.php', $this->factory->layout->getFile());
$this->assertEquals('tests/layout/testGetFilePath/', $this->factory->layout->getDirectory());
}
/**
@ -80,7 +89,7 @@ class layoutTest extends CoreTestAbstract
// Extensions to be used in this test
$extensions = array('php', 'json');
Layout::setFileFromString('test?\/<>', 'test|?/*<>', $extensions);
$this->factory->layout->setFileFromString('test?\/<>', 'test|?/*<>', $extensions);
}
/**
@ -89,7 +98,7 @@ class layoutTest extends CoreTestAbstract
public function testMissingDirectory()
{
// Directory that does not exist
Layout::setFileFromString('test', 'tests/layout/doesNotExist/', array('php'));
$this->factory->layout->setFileFromString('test', 'tests/layout/doesNotExist/', array('php'));
}
/**
@ -97,7 +106,7 @@ class layoutTest extends CoreTestAbstract
*/
public function testMissingFile()
{
Layout::setFileFromString('test', 'tests/layout/testMissingFile/', array('php'));
$this->factory->layout->setFileFromString('test', 'tests/layout/testMissingFile/', array('php'));
}
/**
@ -105,7 +114,7 @@ class layoutTest extends CoreTestAbstract
*/
public function testUnknownFileExtension()
{
Layout::setFileFromString('test', 'tests/layout/testUnknownFileExtension/', array('php'));
$this->factory->layout->setFileFromString('test', 'tests/layout/testUnknownFileExtension/', array('php'));
}
public function testLayoutGet()
@ -113,7 +122,7 @@ class layoutTest extends CoreTestAbstract
// Directory of these tests
$directory = 'tests/layout/testLayoutGet/';
$this->assertEquals('Retrieved Data', Layout::get('test', $directory));
$this->assertEquals('Retrieved Data', $this->factory->layout->get('test', $directory));
}
public function testLayoutView()
@ -122,7 +131,7 @@ class layoutTest extends CoreTestAbstract
$directory = 'tests/layout/testLayoutGet/';
ob_start();
Layout::view('test', $directory);
$this->factory->layout->view('test', $directory);
Factory::getInstance()->output->_display();
$output = ob_get_contents();
ob_end_clean();
@ -133,29 +142,29 @@ class layoutTest extends CoreTestAbstract
public function testReset()
{
// First the the variables
Layout::setTitle('Test Title');
Layout::setDirectory('tests/layout/testLayoutGet');
$this->factory->layout->setTitle('Test Title');
$this->factory->layout->setDirectory('tests/layout/testLayoutGet');
// Test if they are actually set
$this->assertEquals('Test Title', Layout::getTitle());
$this->assertEquals('tests/layout/testLayoutGet', Layout::getDirectory());
$this->assertEquals('Test Title', $this->factory->layout->getTitle());
$this->assertEquals('tests/layout/testLayoutGet', $this->factory->layout->getDirectory());
// Reset the layout system
Layout::reset();
$this->factory->layout->reset();
// Test for default values
$this->assertFalse(Layout::getTitle());
$this->assertTrue(strpos(Layout::getDirectory(), 'application/Views') !== false);
$this->assertFalse($this->factory->layout->getTitle());
$this->assertTrue(strpos($this->factory->layout->getDirectory(), 'application/Views') !== false);
}
public function testGetEngineFromExtension()
{
Layout::loadTemplateEngines();
$this->factory->layout->loadTemplateEngines();
// Test all the default engines
$this->assertInstanceOf('FuzeWorks\TemplateEngine\PHPEngine', Layout::getEngineFromExtension('php'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\JsonEngine', Layout::getEngineFromExtension('json'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\SmartyEngine', Layout::getEngineFromExtension('tpl'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\PHPEngine', $this->factory->layout->getEngineFromExtension('php'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\JsonEngine', $this->factory->layout->getEngineFromExtension('json'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\SmartyEngine', $this->factory->layout->getEngineFromExtension('tpl'));
}
/**
@ -164,7 +173,7 @@ class layoutTest extends CoreTestAbstract
*/
public function testGetEngineFromExtensionFail()
{
Layout::getEngineFromExtension('faulty');
$this->factory->layout->getEngineFromExtension('faulty');
}
/**
@ -182,10 +191,10 @@ class layoutTest extends CoreTestAbstract
$mock->expects($this->once())->method('get')->with('tests/layout/testCustomEngine/view.test.test');
// Register the engine
Layout::registerEngine($mock, 'Custom', array('test'));
$this->factory->layout->registerEngine($mock, 'Custom', array('test'));
// And run the engine
$this->assertEquals('output', Layout::get('test', 'tests/layout/testCustomEngine/'));
$this->assertEquals('output', $this->factory->layout->get('test', 'tests/layout/testCustomEngine/'));
}
/**
@ -194,10 +203,10 @@ class layoutTest extends CoreTestAbstract
*/
public function testInvalidCustomEngine()
{
$mock = $this->getMock('MockEngine');
$mock = $this->getMockBuilder(MockEngine::class)->getMock();
// Does not implement FuzeWorks\TemplateEngine\TemplateEngine, this should fail
Layout::registerEngine($mock, 'Custom', array('test'));
$this->factory->layout->registerEngine($mock, 'Custom', array('test'));
}
public function testEnginesLoadView()
@ -206,15 +215,15 @@ class layoutTest extends CoreTestAbstract
$directory = 'tests/layout/testEngines/';
// First the PHP Engine
$this->assertEquals('PHP Template Check', Layout::get('php', $directory));
Layout::reset();
$this->assertEquals('PHP Template Check', $this->factory->layout->get('php', $directory));
$this->factory->layout->reset();
// Then the JSON Engine
$this->assertEquals('JSON Template Check', json_decode(Layout::get('json', $directory), true)[0]);
Layout::reset();
$this->assertEquals('JSON Template Check', json_decode($this->factory->layout->get('json', $directory), true)[0]);
$this->factory->layout->reset();
// And the Smarty Engine
$this->assertEquals('Smarty Template Check', Layout::get('smarty', $directory));
$this->assertEquals('Smarty Template Check', $this->factory->layout->get('smarty', $directory));
}
public function testEngineVariables()
@ -223,17 +232,21 @@ class layoutTest extends CoreTestAbstract
$directory = 'tests/layout/testEngineVariables/';
// First the PHP Engine
Layout::assign('key', 'value');
$this->assertEquals('value', Layout::get('php', $directory));
Layout::reset();
$this->factory->layout->assign('key', 'value');
$this->assertEquals('value', $this->factory->layout->get('php', $directory));
$this->factory->layout->reset();
// Then the JSON Engine
Layout::assign('key', 'value');
$this->assertEquals('value', json_decode(Layout::get('json', $directory), true)['data']['key']);
Layout::reset();
$this->factory->layout->assign('key', 'value');
$this->assertEquals('value', json_decode($this->factory->layout->get('json', $directory), true)['data']['key']);
$this->factory->layout->reset();
// And the Smarty Engine
Layout::assign('key', 'value');
$this->assertEquals('value', Layout::get('smarty', $directory));
$this->factory->layout->assign('key', 'value');
$this->assertEquals('value', $this->factory->layout->get('smarty', $directory));
}
}
class MockEngine {
}

View File

@ -137,7 +137,7 @@ class securityTest extends CoreTestAbstract
$xss_clean_return = $this->security->xss_clean($harm_string, TRUE);
// $this->assertTrue($xss_clean_return);
$this->assertTrue($xss_clean_return);
}
// --------------------------------------------------------------------

View File

@ -51,7 +51,7 @@ class uriTest extends CoreTestAbstract {
$this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-');
$str = 'abc01239~%.:_-';
$this->uri->filter_uri($str);
$this->assertTrue($this->uri->filter_uri($str));
}
// --------------------------------------------------------------------

View File

@ -0,0 +1,59 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2017 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 - 2017, 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://techfuze.net/fuzeworks
* @since Version 1.0.4
*
* @version Version 1.0.4
*/
use FuzeWorks\Factory;
use FuzeWorks\Exception\DatabaseException;
/**
* Class databaseTest.
*
* Core testing suite. Will test databases, querybuilders and frequently used drivers.
*/
class databaseTest extends CoreTestAbstract
{
protected $factory;
public function setUp()
{
$this->factory = Factory::getInstance();
}
/**
* @expectedException FuzeWorks\Exception\DatabaseException
*/
public function testInvalidDb()
{
$this->factory->database->get('unknown://unknown:password@unknown/database');
}
}

View File

@ -43,10 +43,14 @@ class coreStartEventTest extends CoreTestAbstract
*/
public function testCoreStartEvent()
{
$mock = $this->getMock('MockEvent', array('mockMethod'));
$mock = $this->getMockBuilder(MockStartEvent::class)->setMethods(['mockMethod'])->getMock();
$mock->expects($this->once())->method('mockMethod');
Events::addListener(array($mock, 'mockMethod'), 'coreStartEvent', EventPriority::NORMAL);
Core::init();
}
}
class MockStartEvent {
public function mockMethod() {}
}

View File

@ -30,7 +30,7 @@
* @version Version 1.0.0
*/
use FuzeWorks\Events;
use FuzeWorks\Layout;
use FuzeWorks\Factory;
use FuzeWorks\EventPriority;
/**
@ -38,18 +38,27 @@ use FuzeWorks\EventPriority;
*/
class layoutLoadViewEventTest extends CoreTestAbstract
{
protected $factory;
public function setUp()
{
// Load the factory first
$this->factory = Factory::getInstance();
}
/**
* Check if the event is fired when it should be.
*/
public function test_basic()
{
$mock = $this->getMock('MockEvent', array('mockMethod'));
$mock = $this->getMockBuilder(MockLayoutViewEventTest::class)->setMethods(['mockMethod'])->getMock();
$mock->expects($this->once())->method('mockMethod');
Events::addListener(array($mock, 'mockMethod'), 'layoutLoadViewEvent', EventPriority::NORMAL);
// And run the test
Layout::get('home');
$this->factory->layout->get('home');
}
/**
@ -60,7 +69,7 @@ class layoutLoadViewEventTest extends CoreTestAbstract
public function test_change()
{
Events::addListener(array($this, 'listener_change'), 'layoutLoadViewEvent', EventPriority::NORMAL);
Layout::get('home');
$this->factory->layout->get('home');
}
// Change title from new to other
@ -85,7 +94,7 @@ class layoutLoadViewEventTest extends CoreTestAbstract
// Listen for the event and cancel it
Events::addListener(array($this, 'listener_cancel'), 'layoutLoadViewEvent', EventPriority::NORMAL);
$this->assertFalse(Layout::get('home'));
$this->assertFalse($this->factory->layout->get('home'));
}
// Cancel all calls
@ -94,3 +103,7 @@ class layoutLoadViewEventTest extends CoreTestAbstract
$event->setCancelled(true);
}
}
class MockLayoutViewEventTest {
public function MockMethod() {}
}