/** * Tests the Image::__construct method. * * @return void * * @since 1.0 */ public function testConstructor() { // Create an image handle of the correct size. $imageHandle = imagecreatetruecolor(100, 100); $filter = new FilterBrightness($imageHandle); $this->assertEquals(TestHelper::getValue($filter, 'handle'), $imageHandle); }
/** * Test the Joomla\Input\Cookie::set method. * * @return void * * @todo Figure out out to tests w/o ob_start() in bootstrap. setcookie() prevents this. * * @covers Joomla\Input\Cookie::set * @since 1.0 */ public function testSet() { $instance = new Cookie(); $instance->set('foo', 'bar'); $data = TestHelper::getValue($instance, 'data'); $this->assertArrayHasKey('foo', $data); $this->assertContains('bar', $data); }
/** * Test... * * @covers Joomla\Language\Language::getInstance * @covers Joomla\Language\Language::getLanguage * * @return void */ public function testGetInstanceAndLanguage() { $instance = Language::getInstance(null); $this->assertInstanceOf('Joomla\\Language\\Language', $instance); $this->assertEquals(TestHelper::getValue($instance, 'default'), $instance->getLanguage(), 'Asserts that getInstance when called with a null language returns the default language. Line: ' . __LINE__); $instance = Language::getInstance('es-ES'); $this->assertEquals('es-ES', $instance->getLanguage(), 'Asserts that getInstance when called with a specific language returns that language. Line: ' . __LINE__); }
/** * Test the Joomla\Input\Cookie::set method. * * @return void * * @todo Figure out out to tests w/o ob_start() in bootstrap. setcookie() prevents this. * * @covers Joomla\Input\Cookie::set * @since 1.0 */ public function testSet() { if (headers_sent()) { $this->markTestSkipped(); } else { $this->instance->set('foo', 'bar'); $data = TestHelper::getValue($this->instance, 'data'); $this->assertTrue(array_key_exists('foo', $data)); $this->assertTrue(in_array('bar', $data)); } }
/** * Tests the constructor. * * @return void * * @covers \Joomla\Profiler\ProfilePoint::__construct * @since 1.0 */ public function test__construct() { $point = new ProfilePoint('test'); $this->assertEquals('test', TestHelper::getValue($point, 'name')); $this->assertSame(0.0, TestHelper::getValue($point, 'time')); $this->assertSame(0, TestHelper::getValue($point, 'memoryBytes')); $point = new ProfilePoint('foo', '1', '1048576'); $this->assertEquals('foo', TestHelper::getValue($point, 'name')); $this->assertSame(1.0, TestHelper::getValue($point, 'time')); $this->assertSame(1048576, TestHelper::getValue($point, 'memoryBytes')); }
/** * Test the Joomla\Input\Files::__construct method. * * @return void * * @covers Joomla\Input\Files::__construct * @since 1.1.4 */ public function test__construct() { // Default constructor call $instance = new Files(); $this->assertInstanceOf('Joomla\\Filter\\InputFilter', TestHelper::getValue($instance, 'filter')); $this->assertEmpty(TestHelper::getValue($instance, 'options')); $this->assertEquals($_FILES, TestHelper::getValue($instance, 'data')); // Given Source & filter $src = array('foo' => 'bar'); $instance = new Files($src, array('filter' => new FilterInputMock())); $this->assertArrayHasKey('filter', TestHelper::getValue($instance, 'options')); }
/** * Tests the __construct method. * * @return void * * @covers Joomla\Application\AbstractCliApplication::__construct * @since 1.0 */ public function test__construct() { // @TODO Test that configuration data loaded. $this->assertGreaterThan(2001, $this->instance->get('execution.datetime'), 'Tests execution.datetime was set.'); $this->assertGreaterThan(1, $this->instance->get('execution.timestamp'), 'Tests execution.timestamp was set.'); // Test dependancy injection. $mockInput = $this->getMock('Joomla\\Input\\Cli', array('test'), array(), '', false); $mockInput->expects($this->any())->method('test')->will($this->returnValue('ok')); $mockConfig = $this->getMock('Joomla\\Registry\\Registry', array('test'), array(null), '', true); $instance = new ConcreteCli($mockInput, $mockConfig); $input = TestHelper::getValue($instance, 'input'); $this->assertEquals('ok', $input->test()); }
/** * Tests the __construct method. * * @return void * * @covers Joomla\Controller\AbstractController::__construct * @covers Joomla\Controller\AbstractController::getInput * @covers Joomla\Controller\AbstractController::getApplication * @since 1.0 */ public function test__construct() { $app = TestHelper::getValue($this->instance, 'app'); // New controller with no dependancies. $this->assertAttributeEmpty('input', $this->instance); $this->assertAttributeEmpty('app', $this->instance); // New controller with dependancies $appMocker = new ApplicationMocker($this); $mockApp = $appMocker->createMockBase(); $mockInput = $this->getMock('Joomla\\Input\\Input'); $instance = new BaseController($mockInput, $mockApp); $this->assertSame($mockInput, $instance->getInput()); $this->assertSame($mockApp, $instance->getApplication()); }
/** * Tests the __construct method. * * @return void * * @covers Joomla\Application\AbstractApplication::__construct * @since 1.0 */ public function test__construct() { $this->assertInstanceOf('Joomla\\Input\\Input', $this->instance->input, 'Input property wrong type'); $this->assertInstanceOf('Joomla\\Registry\\Registry', TestHelper::getValue($this->instance, 'config'), 'Config property wrong type'); // Test dependancy injection. $mockInput = $this->getMock('Joomla\\Input\\Input', array('test'), array(), '', false); $mockInput->expects($this->any())->method('test')->will($this->returnValue('ok')); $mockConfig = $this->getMock('Joomla\\Registry\\Registry', array('test'), array(null), '', true); $mockConfig->expects($this->any())->method('test')->will($this->returnValue('ok')); $instance = new ConcreteBase($mockInput, $mockConfig); $input = TestHelper::getValue($instance, 'input'); $this->assertEquals('ok', $input->test()); $config = TestHelper::getValue($instance, 'config'); $this->assertEquals('ok', $config->test()); }
/** * Tests the constructor. * * @return void * * @covers \Joomla\Profiler\Profiler::__construct * @since 1.0 */ public function test__construct() { $this->assertEquals('test', TestHelper::getValue($this->instance, 'name')); $this->assertInstanceOf('\\Joomla\\Profiler\\Renderer\\DefaultRenderer', TestHelper::getValue($this->instance, 'renderer')); $this->assertEmpty(TestHelper::getValue($this->instance, 'points')); $this->assertFalse(TestHelper::getValue($this->instance, 'memoryRealUsage')); $renderer = new DefaultRenderer(); $pointOne = new ProfilePoint('start'); $pointTwo = new ProfilePoint('two', 1, 1); $points = array($pointOne, $pointTwo); $profiler = new Profiler('bar', $renderer, $points, true); $this->assertEquals('bar', TestHelper::getValue($profiler, 'name')); $this->assertSame($renderer, TestHelper::getValue($profiler, 'renderer')); $this->assertEquals($points, TestHelper::getValue($profiler, 'points')); $this->assertTrue(TestHelper::getValue($profiler, 'memoryRealUsage')); }
/** * Test the Joomla\Input\Json::__construct method. * * @return void * * @covers Joomla\Input\Json::__construct * @since 1.0 */ public function test__construct() { // Default constructor call $instance = new Json(); $this->assertInstanceOf('Joomla\\Filter\\InputFilter', TestHelper::getValue($instance, 'filter')); $this->assertEmpty(TestHelper::getValue($instance, 'options')); $this->assertEmpty(TestHelper::getValue($instance, 'data')); // Given Source & filter $src = array('foo' => 'bar'); $instance = new Json($src, array('filter' => new FilterInputMock())); $this->assertArrayHasKey('filter', TestHelper::getValue($instance, 'options')); $this->assertEquals($src, TestHelper::getValue($instance, 'data')); // Src from GLOBAL $GLOBALS['HTTP_RAW_POST_DATA'] = '{"a":1,"b":2}'; $instance = new Json(); $this->assertEquals(array('a' => 1, 'b' => 2), TestHelper::getValue($instance, 'data')); }
/** * Test the Joomla\Log\Logger\W3c::addEntry method. * * @return void * * @since 1.0 */ public function testAddEntry() { // Setup the basic configuration. $config = array('text_file_path' => __DIR__ . '/tmp'); $logger = new W3c($config); // Remove the log file if it exists. @unlink(TestHelper::getValue($logger, 'path')); $logger->addEntry(new LogEntry('Testing Entry 01', Log::INFO, null, '1980-04-18')); $this->assertEquals($this->getLastLine(TestHelper::getValue($logger, 'path')), '1980-04-18 00:00:00 INFO - - Testing Entry 01', 'Line: ' . __LINE__); $_SERVER['REMOTE_ADDR'] = '192.168.0.1'; $logger->addEntry(new LogEntry('Testing 02', Log::ERROR, null, '1982-12-15')); $this->assertEquals($this->getLastLine(TestHelper::getValue($logger, 'path')), '1982-12-15 00:00:00 ERROR 192.168.0.1 - Testing 02', 'Line: ' . __LINE__); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $logger->addEntry(new LogEntry('Testing3', Log::EMERGENCY, 'deprecated', '1980-04-18')); $this->assertEquals($this->getLastLine(TestHelper::getValue($logger, 'path')), '1980-04-18 00:00:00 EMERGENCY 127.0.0.1 deprecated Testing3', 'Line: ' . __LINE__); // Remove the log file if it exists. @unlink(TestHelper::getValue($logger, 'path')); }
/** * Tests the authenticate method * * @param array $token The passed token. * @param boolean $fail Mark if should fail or not. * @param string $version Specify oauth version 1.0 or 1.0a. * * @return void * * @dataProvider seedAuthenticate * @since 1.0 */ public function testAuthenticate($token, $fail, $version) { // Already got some credentials stored? if (!is_null($token)) { $this->object->setToken($token); $result = $this->object->authenticate(); $this->assertEquals($result, $token); } else { $this->object->setOption('requestTokenURL', 'https://example.com/request_token'); $this->object->setOption('authoriseURL', 'https://example.com/authorize'); $this->object->setOption('accessTokenURL', 'https://example.com/access_token'); // Request token. $returnData = new \stdClass(); $returnData->code = 200; $returnData->body = 'oauth_token=token&oauth_token_secret=secret&oauth_callback_confirmed=true'; $this->client->expects($this->at(0))->method('post')->with($this->object->getOption('requestTokenURL'))->will($this->returnValue($returnData)); $input = TestHelper::getValue($this->object, 'input'); $input->set('oauth_verifier', null); TestHelper::setValue($this->object, 'input', $input); if (strcmp($version, '1.0a') === 0) { $this->object->setOption('callback', 'TEST_URL'); } $this->object->authenticate(); $token = $this->object->getToken(); $this->assertEquals($token['key'], 'token'); $this->assertEquals($token['secret'], 'secret'); // Access token. $input = TestHelper::getValue($this->object, 'input'); if (strcmp($version, '1.0a') === 0) { TestHelper::setValue($this->object, 'version', $version); $data = array('oauth_verifier' => 'verifier', 'oauth_token' => 'token'); } else { TestHelper::setValue($this->object, 'version', $version); $data = array('oauth_token' => 'token'); } TestHelper::setValue($input, 'data', $data); // Get mock session $mockSession = $this->getMock('Joomla\\Session\\Session', array('_start', 'get')); if ($fail) { $mockSession->expects($this->at(0))->method('get')->with('key', null, 'oauth_token')->will($this->returnValue('bad')); $mockSession->expects($this->at(1))->method('get')->with('secret', null, 'oauth_token')->will($this->returnValue('session')); $this->application->setSession($mockSession); $this->setExpectedException('DomainException'); $result = $this->object->authenticate(); } $mockSession->expects($this->at(0))->method('get')->with('key', null, 'oauth_token')->will($this->returnValue('token')); $mockSession->expects($this->at(1))->method('get')->with('secret', null, 'oauth_token')->will($this->returnValue('secret')); $this->application->setSession($mockSession); $returnData = new \stdClass(); $returnData->code = 200; $returnData->body = 'oauth_token=token_key&oauth_token_secret=token_secret'; $this->client->expects($this->at(0))->method('post')->with($this->object->getOption('accessTokenURL'))->will($this->returnValue($returnData)); $result = $this->object->authenticate(); $this->assertEquals($result['key'], 'token_key'); $this->assertEquals($result['secret'], 'token_secret'); } }
/** * Test the Joomla\Log\Logger\Database::__construct method. * * @return void * * @since 1.0 */ public function testConstructor01() { $config = array('db' => self::$driver); $logger = new Database($config); $this->assertInstanceOf('Joomla\\Database\\DatabaseDriver', TestHelper::getValue($logger, 'db'), 'The $db property of a properly configured Database storage must be an instance of Joomla\\Database\\DatabaseDriver'); }
/** * Tests the Joomla\Data\DataSet::offsetUnset method. * * @return void * * @covers Joomla\Data\DataSet::OffsetUnset * @since 1.0 */ public function testOffsetUnset() { $this->instance->offsetUnset(0); $objects = TestHelper::getValue($this->instance, 'objects'); $this->assertFalse(isset($objects[0])); }
/** * Test the Joomla\Log\Logger\Callback::__construct method. * * @return null * * @since 1.0 */ public function testConstructor06() { // Use a defined object method $obj = new CallbackHelper(); $callback = array($obj, 'callback02'); // Setup the basic configuration. $config = array('callback' => $callback); $logger = new Callback($config); // Callback was set. $this->assertEquals(TestHelper::getValue($logger, 'callback'), $callback, 'Line: ' . __LINE__); // Callback is callable $this->assertTrue(is_callable(TestHelper::getValue($logger, 'callback')), 'Line: ' . __LINE__); }
/** * Tests the \Joomla\Database\DatabaseQuery::unionDistinct method. * * @return void * * @covers \Joomla\Database\DatabaseQuery::unionDistinct * @since 1.0 */ public function testUnionDistinctArray() { TestHelper::setValue($this->instance, 'union', null); $this->instance->unionDistinct(array('SELECT name FROM foo', 'SELECT name FROM bar')); $teststring = (string) TestHelper::getValue($this->instance, 'union'); $this->assertThat($teststring, $this->equalTo(PHP_EOL . "UNION DISTINCT (SELECT name FROM foo)" . PHP_EOL . "UNION DISTINCT (SELECT name FROM bar)"), 'Tests rendered query with two unions distinct.'); }
/** * Test the Joomla\Input\Input::loadAllInputs method. * * @return void * * @covers Joomla\Input\Input::loadAllInputs * @since 1.1.4 */ public function testLoadAllInputs() { $instance = $this->getInputObject(array()); TestHelper::setValue($instance, 'loaded', false); $inputs = TestHelper::getValue($instance, 'inputs'); $this->assertCount(0, $inputs); TestHelper::invoke($instance, 'loadAllInputs'); $inputs = TestHelper::getValue($instance, 'inputs'); $this->assertGreaterThan(0, count($inputs)); }
/** * Test the Joomla\Log\Logger\FormattedText::addEntry method. * * @return void */ public function testAddEntry() { // Setup the basic configuration. $config = array('text_file_path' => __DIR__ . '/tmp', 'text_file' => '', 'text_entry_format' => '{PRIORITY} {CATEGORY} {MESSAGE}'); $logger = new Formattedtext($config); // Remove the log file if it exists. @unlink(TestHelper::getValue($logger, 'path')); $logger->addEntry(new LogEntry('Testing Entry 01')); $this->assertEquals($this->getLastLine(TestHelper::getValue($logger, 'path')), 'INFO - Testing Entry 01', 'Line: ' . __LINE__); $logger->addEntry(new LogEntry('Testing 02', Log::ERROR)); $this->assertEquals($this->getLastLine(TestHelper::getValue($logger, 'path')), 'ERROR - Testing 02', 'Line: ' . __LINE__); $logger->addEntry(new LogEntry('Testing3', Log::EMERGENCY, 'deprecated')); $this->assertEquals($this->getLastLine(TestHelper::getValue($logger, 'path')), 'EMERGENCY deprecated Testing3', 'Line: ' . __LINE__); // Remove the log file if it exists. @unlink(TestHelper::getValue($logger, 'path')); }
/** * Test getExpire() * * @covers JSession::getExpire * * @return void */ public function testGetExpire() { $this->assertEquals(TestHelper::getValue($this->object, '_expire'), $this->object->getExpire(), 'Session expire time should be the same'); }
/** * Tests the Joomla\Data\DataObject::setProperty method. * * @return void * * @covers Joomla\Data\DataObject::setProperty * @expectedException InvalidArgumentException * @since 1.0 */ public function testSetProperty_exception() { // Get the reflection property. This should throw an exception. $property = TestHelper::getValue($this->instance, 'set_test'); }
/** * Test for the Joomla\Database\DatabaseFactory::getImporter method. * * @return void * * @since 1.0 */ public function testGetImporter() { $object = static::$instance; $this->assertThat($object->getImporter('mysqli'), $this->isInstanceOf('\\Joomla\\Database\\Mysqli\\MysqliImporter'), 'Tests that getImporter with "mysqli" param returns an instance of MysqliImporter.'); try { $object->getImporter('mariadb'); } catch (\RuntimeException $e) { $this->assertThat($e->getMessage(), $this->equalTo('Database importer not found.'), 'Tests that getImporter with "mariadb" param throws an exception due to a class not existing.'); } $importer = $object->getImporter('mysqli', static::$driver); $this->assertThat(TestHelper::getValue($importer, 'db'), $this->isInstanceOf('\\Joomla\\Database\\Sqlite\\SqliteDriver'), 'Tests that getImporter with the test database driver returns an instance of SqliteDriver.'); }
/** * Tests the setOption method * * @return void * * @since 1.0 */ public function testSetOption() { $this->object->setOption('api.url', 'https://example.com/settest'); $value = TestHelper::getValue($this->object, 'options'); $this->assertThat($value['api.url'], $this->equalTo('https://example.com/settest')); }
/** * Test the output setter * * @return void * * @since 1.0 * * @covers Joomla\Console\Command\AbstractCommand::setOutput */ public function testSetOutput() { // Using mock to make sure we get same object. $mockOutput = $this->getMock('Joomla\\Application\\Cli\\Output\\Stdout', array('test'), array(), '', false); $mockOutput->expects($this->any())->method('test')->will($this->returnValue('ok')); $this->instance->setOutput($mockOutput); $output = TestHelper::getValue($this->instance, 'output'); $this->assertEquals('ok', $output->test()); }
/** * Tests the Joomla\Application\AbstractWebApplication::setHeader method. * * @return void * * @since 1.0 */ public function testSetHeader() { // Fill the header body with an arbitrary value. TestHelper::setValue($this->instance, 'response', (object) array('cachable' => null, 'headers' => array(array('name' => 'foo', 'value' => 'bar')), 'body' => null)); $this->instance->setHeader('foo', 'car'); $this->assertThat(TestHelper::getValue($this->instance, 'response')->headers, $this->equalTo(array(array('name' => 'foo', 'value' => 'bar'), array('name' => 'foo', 'value' => 'car'))), 'Tests that a header is added.'); $this->instance->setHeader('foo', 'car', true); $this->assertThat(TestHelper::getValue($this->instance, 'response')->headers, $this->equalTo(array(array('name' => 'foo', 'value' => 'car'))), 'Tests that headers of the same name are replaced.'); }
/** * Tests the Joomla\Data\DataSet::offsetUnset method. * * @return void * * @covers Joomla\Data\DataSet::OffsetUnset * @since 1.0 */ public function testOffsetUnset() { TestHelper::setValue($this->instance, 'current', 1); $this->instance->offsetUnset(1); $objects = TestHelper::getValue($this->instance, 'objects'); $this->assertFalse(isset($objects[1])); $this->instance->offsetUnset(0); $objects = TestHelper::getValue($this->instance, 'objects'); $this->assertFalse(isset($objects[0])); // Nonexistent offset $this->instance->offsetUnset(-1); }
/** * Tests the Joomla\Router\RestRouter::setHttpMethodSuffix method. * * @return void * * @covers Joomla\Router\RestRouter::setHttpMethodSuffix * @since 1.0 */ public function testSetHttpMethodSuffix() { $this->instance->setHttpMethodSuffix('FOO', 'Bar'); $s = TestHelper::getValue($this->instance, 'suffixMap'); $this->assertEquals('Bar', $s['FOO']); }
/** * Tests the getOption method * * @return void * * @since 1.0 */ public function testGetOption() { $this->object->setOption('testKey', 'testValue'); $value = TestHelper::getValue($this->object, 'options'); $this->assertThat($value['testKey'], $this->equalTo('testValue')); }
/** * Test for LIMIT and OFFSET clause. * * @return void * * @since 1.1 */ public function testSetLimitAndOffset() { $q = new SqliteQuery($this->dbo); $q->setLimit('5', '10'); $this->assertThat(trim(TestHelper::getValue($q, 'limit')), $this->equalTo('5'), 'Tests limit was set correctly.'); $this->assertThat(trim(TestHelper::getValue($q, 'offset')), $this->equalTo('10'), 'Tests offset was set correctly.'); }
/** * Tests the setDefaultType method. * * @param string $type The proposed default type * @param string $expectation The expected value of $this->defaultType * * @covers Joomla\Crypt\Password\Simple::setDefaultType * @dataProvider defaultTypeData * * @return void * * @since 1.0 */ public function testSetDefaultType($type, $expectation) { $test = new Simple(); $test->setDefaultType($type); $this->assertThat(TestHelper::getValue($test, 'defaultType'), $this->equalTo($expectation)); }