Ejemplo n.º 1
0
 /**
  * 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));
 }
Ejemplo n.º 2
0
 /**
  * Test the Joomla\Input\Files::get method.
  *
  * @return  void
  *
  * @covers  Joomla\Input\Files::get
  * @since   1.0
  */
 public function testGet()
 {
     $instance = new Files();
     $this->assertEquals('foobar', $instance->get('myfile', 'foobar'));
     $data = array('myfile' => array('name' => 'n', 'type' => 'ty', 'tmp_name' => 'tm', 'error' => 'e', 'size' => 's'), 'myfile2' => array('name' => 'nn', 'type' => 'ttyy', 'tmp_name' => 'ttmm', 'error' => 'ee', 'size' => 'ss'));
     $decoded = TestHelper::setValue($instance, 'data', $data);
     $expected = array('name' => 'n', 'type' => 'ty', 'tmp_name' => 'tm', 'error' => 'e', 'size' => 's');
     $this->assertEquals($expected, $instance->get('myfile'));
 }
Ejemplo n.º 3
0
 /**
  * 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;
     }
 }
Ejemplo n.º 4
0
 /**
  * Tests the setOption method
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testSetOption()
 {
     TestHelper::setValue($this->object, 'options', array('testKey' => 'testValue'));
     $this->assertThat($this->object->getOption('testKey'), $this->equalTo('testValue'));
 }
Ejemplo n.º 5
0
 /**
  * Test the Joomla\Input\Input::serialize method.
  *
  * @return  void
  *
  * @covers  Joomla\Input\Input::serialize
  * @since   1.0
  */
 public function testSerialize()
 {
     $instance = $this->getInputObject(array());
     // Load the inputs so that the static $loaded is set to true.
     TestHelper::invoke($instance, 'loadAllInputs');
     // Adjust the values so they are easier to handle.
     TestHelper::setValue($instance, 'inputs', array('server' => 'remove', 'env' => 'remove', 'request' => 'keep'));
     TestHelper::setValue($instance, 'options', 'options');
     TestHelper::setValue($instance, 'data', 'data');
     $this->assertThat($instance->serialize(), $this->equalTo('a:3:{i:0;s:7:"options";i:1;s:4:"data";i:2;a:1:{s:7:"request";s:4:"keep";}}'));
 }
Ejemplo n.º 6
0
 /**
  * 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');
     }
 }
Ejemplo n.º 7
0
 /**
  * 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 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');
 }
Ejemplo n.º 9
0
 /**
  * Method to test Inflector::getInstance().
  *
  * @return  void
  *
  * @covers  Joomla\String\Inflector::getInstance
  * @since   1.0
  */
 public function testGetInstance()
 {
     $this->assertInstanceOf('Joomla\\String\\Inflector', Inflector::getInstance(), 'Check getInstance returns the right class.');
     // Inject an instance an test.
     TestHelper::setValue($this->inflector, 'instance', new \stdClass());
     $this->assertThat(Inflector::getInstance(), $this->equalTo(new \stdClass()), 'Checks singleton instance is returned.');
     $this->assertInstanceOf('Joomla\\String\\Inflector', Inflector::getInstance(true), 'Check getInstance a fresh object with true argument even though the instance is set to something else.');
 }
Ejemplo n.º 10
0
 /**
  * Tests the getProcessor method for a RuntimeException
  *
  * @return  void
  *
  * @since   1.1.2
  * @expectedException  \RuntimeException
  */
 public function testGetProcessorException()
 {
     TestHelper::setValue($this->object, 'processor', null);
     $this->object->getProcessor();
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 protected function tearDown()
 {
     // Reset the internal cache
     TestHelper::setValue('Joomla\\Registry\\Factory', 'formatInstances', array());
     parent::tearDown();
 }
Ejemplo n.º 12
0
 /**
  * Tests the getPaths method.
  *
  * @return  void
  *
  * @covers  Joomla\View\AbstractHtmlView::getPaths
  * @since   1.0
  */
 public function testGetPaths()
 {
     // Inject a known value into the property.
     TestHelper::setValue($this->instance, 'paths', 'paths');
     // Check dirty path.
     $this->assertEquals('paths', $this->instance->getPaths());
 }
Ejemplo n.º 13
0
 /**
  * Tests the getScope method
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testGetScope()
 {
     TestHelper::setValue($this->object, 'options', array('scope' => 'read_stream'));
     $this->assertThat($this->object->getScope(), $this->equalTo('read_stream'));
 }
    /**
     * Test the getOptions method.
     *
     * @since   1.0
     *
     * @return  void
     */
    public function testGetOptions()
    {
        $formFieldCheckboxes = new Field_Checkboxes();
        $option1 = new \stdClass();
        $option1->value = 'yellow';
        $option1->text = 'yellow';
        $option1->disable = false;
        $option1->class = '';
        $option1->onclick = '';
        $option2 = new \stdClass();
        $option2->value = 'green';
        $option2->text = 'green';
        $option2->disable = false;
        $option2->class = '';
        $option2->onclick = '';
        $optionsExpected = array($option1, $option2);
        // Test with two values checked, no checked element
        TestHelper::setValue($formFieldCheckboxes, 'element', simplexml_load_string('<field name="color" type="checkboxes">
			<option value="yellow">yellow</option>
			<option value="green">green</option>
			</field>'));
        $this->assertEquals($optionsExpected, TestHelper::invoke($formFieldCheckboxes, 'getOptions'), 'The field with two values did not produce the right options');
    }
Ejemplo n.º 15
0
 /**
  * Tests the getRenderer method.
  *
  * @return  void
  *
  * @covers  \Joomla\Profiler\Profiler::getRenderer
  * @since   1.0
  */
 public function testGetRenderer()
 {
     TestHelper::setValue($this->instance, 'renderer', true);
     $this->assertTrue($this->instance->getRenderer());
 }
Ejemplo n.º 16
0
 /**
  * Test for FOR SHARE clause.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testForShare()
 {
     $q = new PgsqlQuery($this->dbo);
     $this->assertThat($q->forShare('#__foo'), $this->identicalTo($q), 'Tests chaining.');
     $this->assertThat(trim($q->forShare), $this->equalTo('FOR SHARE OF #__foo'), 'Tests rendered value.');
     $q->forShare('#__bar');
     $this->assertThat(trim($q->forShare), $this->equalTo('FOR SHARE OF #__foo, #__bar'), 'Tests rendered value.');
     // Testing glue
     TestHelper::setValue($q, 'forShare', null);
     $q->forShare('#__foo', ';');
     $q->forShare('#__bar');
     $this->assertThat(trim($q->forShare), $this->equalTo('FOR SHARE OF #__foo; #__bar'), 'Tests rendered value.');
 }
Ejemplo n.º 17
0
 /**
  * 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));
 }
Ejemplo n.º 18
0
 /**
  * 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.');
 }
 /**
  * @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'));
 }
Ejemplo n.º 20
0
 /**
  * Tests the getOption method
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testGetOption()
 {
     TestHelper::setValue($this->object, 'options', array('api.url' => 'https://example.com/gettest'));
     $this->assertThat($this->object->getOption('api.url'), $this->equalTo('https://example.com/gettest'));
 }
Ejemplo n.º 21
0
 /**
  * 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());
 }
Ejemplo n.º 22
0
 /**
  * Setup the tests.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function setUp()
 {
     parent::setUp();
     try {
         $this->instance = new Cache\Runtime();
         // Clear the internal store.
         TestHelper::setValue($this->instance, 'store', array());
     } catch (\Exception $e) {
         $this->markTestSkipped();
     }
 }
Ejemplo n.º 23
0
 /**
  * Test for WHERE clause using a simple condition and with glue for second one.
  *
  * @return  void
  *
  * @since   1.1
  */
 public function testWhere()
 {
     $q = new SqliteQuery($this->dbo);
     $this->assertThat($q->where('foo = 1'), $this->identicalTo($q), 'Tests chaining.');
     $this->assertThat(trim($q->where), $this->equalTo('WHERE foo = 1'), 'Tests rendered value.');
     // Add another column.
     $q->where(array('bar = 2', 'goo = 3'));
     $this->assertThat(trim($q->where), $this->equalTo('WHERE foo = 1 AND bar = 2 AND goo = 3'), 'Tests rendered value after second use and array input.');
     // Clear the where
     TestHelper::setValue($q, 'where', null);
     $q->where(array('bar = 2', 'goo = 3'), 'OR');
     $this->assertThat(trim($q->where), $this->equalTo('WHERE bar = 2 OR goo = 3'), 'Tests rendered value with glue.');
 }
 /**
  * Test...
  *
  * @covers  Joomla\Language\Language::getFirstDay
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testGetFirstDay()
 {
     TestHelper::setValue($this->object, 'metadata', array('firstDay' => null));
     $this->assertEquals(0, $this->object->getFirstDay());
     TestHelper::setValue($this->object, 'metadata', array('firstDay' => 1));
     $this->assertEquals(1, $this->object->getFirstDay());
 }