/** * 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 fetchUrl method. * * @param integer $limit The number of objects per page. * @param integer $offset The object's number on the page. * @param timestamp $until A unix timestamp or any date accepted by strtotime. * @param timestamp $since A unix timestamp or any date accepted by strtotime. * @param string $expected The expected result. * * @return void * * @dataProvider seedFetchUrl * * @since 1.0 */ public function testFetchUrl($limit, $offset, $until, $since, $expected) { $apiUrl = 'https://graph.facebook.com/'; $path = '456431243/likes?access_token=235twegsdgsdhtry3tgwgf'; TestHelper::setValue($this->object, 'options', array('api.url' => $apiUrl)); $this->assertThat($this->object->fetchUrl($path, $limit, $offset, $until, $since), $this->equalTo($expected)); }
/** * 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__); }
/** * Creates and instance of a mock Joomla\Cache\Item object. * * @return object * * @since 1.0 */ public function createMockItem() { // Collect all the relevant methods in JDatabase. $methods = array('getKey', 'getValue', 'isHit', 'setValue'); // Create the mock. $mockObject = $this->test->getMock('Joomla\\Cache\\Item', $methods, array(), '', false); TestHelper::assignMockCallbacks($mockObject, $this->test, array('getValue' => array(is_callable(array($this->test, 'mockCacheItemGetValue')) ? $this->test : $this, 'mockCacheItemGetValue'), 'isHit' => array(is_callable(array($this->test, 'mockCacheItemIsHit')) ? $this->test : $this, 'mockCacheItemIsHit'))); return $mockObject; }
/** * 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')); }
/** * Creates and instance of the mock JDatabase object. * * @param \PHPUnit_Framework_TestCase $test A test object. * @param string $nullDate A null date string for the driver. * @param string $dateFormat A date format for the driver. * * @return object * * @since 1.0 */ public static function create(\PHPUnit_Framework_TestCase $test, $nullDate = '0000-00-00 00:00:00', $dateFormat = 'Y-m-d H:i:s') { // Collect all the relevant methods in JDatabase. $methods = array('connect', 'connected', 'disconnect', 'dropTable', 'escape', 'execute', 'fetchArray', 'fetchAssoc', 'fetchObject', 'freeResult', 'getAffectedRows', 'getCollation', 'getConnectors', 'getDateFormat', 'getInstance', 'getLog', 'getNullDate', 'getNumRows', 'getPrefix', 'getQuery', 'getTableColumns', 'getTableCreate', 'getTableKeys', 'getTableList', 'getUtfSupport', 'getVersion', 'insertId', 'insertObject', 'loadAssoc', 'loadAssocList', 'loadColumn', 'loadObject', 'loadObjectList', 'loadResult', 'loadRow', 'loadRowList', 'lockTable', 'query', 'quote', 'quoteName', 'renameTable', 'replacePrefix', 'select', 'setQuery', 'setUTF', 'splitSql', 'test', 'isSupported', 'transactionCommit', 'transactionRollback', 'transactionStart', 'unlockTables', 'updateObject'); // Create the mock. $mockObject = $test->getMockBuilder('\\Joomla\\Database\\DatabaseDriver')->setConstructorArgs(array(array()))->setMethods($methods)->getMock(); // Mock selected methods. TestHelper::assignMockReturns($mockObject, $test, array('getNullDate' => $nullDate, 'getDateFormat' => $dateFormat)); TestHelper::assignMockCallbacks($mockObject, $test, array('escape' => array(is_callable(array($test, 'mockEscape')) ? $test : __CLASS__, 'mockEscape'), 'getQuery' => array(is_callable(array($test, 'mockGetQuery')) ? $test : __CLASS__, 'mockGetQuery'), 'quote' => array(is_callable(array($test, 'mockQuote')) ? $test : __CLASS__, 'mockQuote'), 'quoteName' => array(is_callable(array($test, 'mockQuoteName')) ? $test : __CLASS__, 'mockQuoteName'), 'setQuery' => array(is_callable(array($test, 'mockSetQuery')) ? $test : __CLASS__, 'mockSetQuery'))); return $mockObject; }
/** * 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 __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()); }
/** * Test the Joomla\Input\Files::decodeData method. * * @return void * * @covers Joomla\Input\Files::decodeData * @since 1.1.4 */ public function testDecodeData() { $instance = new Files(); $data = array('n', 'ty', 'tm', 'e', 's'); $decoded = TestHelper::invoke($instance, 'decodeData', $data); $expected = array('name' => 'n', 'type' => 'ty', 'tmp_name' => 'tm', 'error' => 'e', 'size' => 's'); $this->assertEquals($expected, $decoded); $dataArr = array('first', 'second'); $data = array($dataArr, $dataArr, $dataArr, $dataArr, $dataArr); $decoded = TestHelper::invoke($instance, 'decodeData', $data); $expectedFirst = array('name' => 'first', 'type' => 'first', 'tmp_name' => 'first', 'error' => 'first', 'size' => 'first'); $expectedSecond = array('name' => 'second', 'type' => 'second', 'tmp_name' => 'second', 'error' => 'second', 'size' => 'second'); $expected = array($expectedFirst, $expectedSecond); $this->assertEquals($expected, $decoded); }
/** * 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')); }
/** * This method is called before the first test of this test class is run. * * @return void * * @since 1.0 */ public static function setUpBeforeClass() { // We always want the default database test case to use an SQLite memory database. $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'jos_'); try { // Attempt to instantiate the driver. self::$driver = DatabaseDriver::getInstance($options); // Create a new PDO instance for an SQLite memory database and load the test schema into it. $pdo = new \PDO('sqlite::memory:'); $pdo->exec(file_get_contents(__DIR__ . '/Schema/ddl.sql')); // Set the PDO instance to the driver using reflection whizbangery. TestHelper::setValue(self::$driver, 'connection', $pdo); } catch (\RuntimeException $e) { self::$driver = null; } // If for some reason an exception object was returned set our database object to null. if (self::$driver instanceof \Exception) { self::$driver = null; } }
/** * Tests the Joomla\Data\DataSet::valid method. * * @return void * * @covers Joomla\Data\DataSet::valid * @since 1.0 */ public function testValid() { $this->assertTrue($this->instance->valid()); TestHelper::setValue($this->instance, 'current', null); $this->assertFalse($this->instance->valid()); }
/** * 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\Database\DatabaseDriver::getDatabase method. * * @return void * * @since 1.0 */ public function testGetDatabase() { $this->assertEquals('europa', TestHelper::invoke($this->instance, 'getDatabase')); }
/** * 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.'); }
/** * @testdox Tests the system URIs are correctly loaded when a relative media URI is set in the application configuration * * @covers Joomla\Application\AbstractWebApplication::loadSystemUris * @uses Joomla\Application\AbstractApplication::get */ public function testLoadSystemUrisWithoutSiteUriWithRelativeMediaUriSet() { $mockInput = $this->getMock('Joomla\\Input\\Input', array('get', 'getString'), array(), '', true, true, true, false, true); $mockConfig = $this->getMock('Joomla\\Registry\\Registry', array('get', 'set'), array(array('media_uri' => '/media/')), '', true, true, true, false, true); // Mock the Input object internals $mockServerInput = $this->getMock('Joomla\\Input\\Input', array('get', 'set'), array(array('SCRIPT_NAME' => '/index.php')), '', true, true, true, false, true); $inputInternals = array('server' => $mockServerInput); TestHelper::setValue($mockInput, 'inputs', $inputInternals); $object = $this->getMockForAbstractClass('Joomla\\Application\\AbstractWebApplication', array($mockInput, $mockConfig)); TestHelper::invoke($object, 'loadSystemUris', 'http://joom.la/application'); $this->assertSame('http://joom.la/', $object->get('uri.base.full')); $this->assertSame('http://joom.la', $object->get('uri.base.host')); $this->assertSame('/', $object->get('uri.base.path')); $this->assertSame('http://joom.la/media/', $object->get('uri.media.full')); $this->assertSame('/media/', $object->get('uri.media.path')); }
/** * Test the getInput method where the field is disabled * * @return void * * @since 1.0 */ public function testGetInputDisabled() { $formField = new Field_Checkbox(); // Test with checked element $element = simplexml_load_string('<field name="color" type="checkbox" value="red" disabled="true" />'); TestHelper::setValue($formField, 'element', $element); TestHelper::setValue($formField, 'id', 'myTestId'); TestHelper::setValue($formField, 'name', 'myTestName'); $this->assertEquals('<input type="checkbox" name="myTestName" id="myTestId" value="red" disabled="disabled" />', TestHelper::invoke($formField, 'getInput'), 'The field set to disabled did not produce the right html'); }
/** * 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__); }
/** * 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)); }
/** * 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 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 _generateRequestToken method - failure * * @return void * * @since 1.0 * @expectedException \DomainException */ public function testGenerateRequestTokenFailure() { $this->object->setOption('requestTokenURL', 'https://example.com/request_token'); $returnData = new \stdClass(); $returnData->code = 200; $returnData->body = 'oauth_token=token&oauth_token_secret=secret&oauth_callback_confirmed=false'; $this->client->expects($this->at(0))->method('post')->with($this->object->getOption('requestTokenURL'))->will($this->returnValue($returnData)); TestHelper::invoke($this->object, '_generateRequestToken'); }
/** * Test the cleanPath method. * * @return void * * @since __DEPLOY_VERSION__ * @covers Joomla\Uri\Uri::cleanPath */ public function testcleanPath() { $this->assertThat(TestHelper::invoke($this->object, 'cleanPath', '/foo/bar/../boo.php'), $this->equalTo('/foo/boo.php')); $this->assertThat(TestHelper::invoke($this->object, 'cleanPath', '/foo/bar/../../boo.php'), $this->equalTo('/boo.php')); $this->assertThat(TestHelper::invoke($this->object, 'cleanPath', '/foo/bar/.././/boo.php'), $this->equalTo('/foo/boo.php')); }
/** * Tet the Joomla\Registry\Registry::bindData method. * * @return void * * @covers Joomla\Registry\Registry::bindData * @since 1.0 */ public function testBindData() { $a = new Registry(); $parent = new stdClass(); TestHelper::invoke($a, 'bindData', $parent, 'foo'); $this->assertThat($parent->{0}, $this->equalTo('foo'), 'Line: ' . __LINE__ . ' The input value should exist in the parent object.'); TestHelper::invoke($a, 'bindData', $parent, array('foo' => 'bar')); $this->assertThat($parent->{'foo'}, $this->equalTo('bar'), 'Line: ' . __LINE__ . ' The input value should exist in the parent object.'); TestHelper::invoke($a, 'bindData', $parent, array('level1' => array('level2' => 'value2'))); $this->assertThat($parent->{'level1'}->{'level2'}, $this->equalTo('value2'), 'Line: ' . __LINE__ . ' The input value should exist in the parent object.'); TestHelper::invoke($a, 'bindData', $parent, array('intarray' => array(0, 1, 2))); $this->assertThat($parent->{'intarray'}, $this->equalTo(array(0, 1, 2)), 'Line: ' . __LINE__ . ' The un-associative array should bind natively.'); }
/** * 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.'); }
/** * 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'); }