/**
     * Test the Windwalker\IO\Json::__construct method.
     *
     * @return  void
     *
     * @covers  Windwalker\IO\Json::__construct
     * @since   2.0
     */
    public function test__construct()
    {
        $this->assertInstanceOf('Windwalker\\Filter\\InputFilter', TestHelper::getValue($this->instance, 'filter'));
        $this->assertEmpty(TestHelper::getValue($this->instance, 'data'));
        // Given Source & filter
        $src = array('foo' => 'bar');
        $input = new FormDataInput($src);
        $this->assertEquals($src, TestHelper::getValue($input, 'data'));
        // Src from GLOBAL
        FormDataInput::setRawData(null);
        $_SERVER['CONTENT_TYPE'] = 'multipart/form-data; boundary=----WebKitFormBoundary8zi5vcW6H9OgqKSj';
        $GLOBALS['HTTP_RAW_POST_DATA'] = <<<DATA
------WebKitFormBoundary8zi5vcW6H9OgqKSj
Content-Disposition: form-data; name="flower"

SAKURA
------WebKitFormBoundary8zi5vcW6H9OgqKSj
Content-Disposition: form-data; name="tree"

Marabutan
------WebKitFormBoundary8zi5vcW6H9OgqKSj
Content-Disposition: form-data; name="fruit"

Apple
------WebKitFormBoundary8zi5vcW6H9OgqKSj--
DATA;
        $input = new FormDataInput();
        $this->assertEquals(array('flower' => 'SAKURA', 'tree' => 'Marabutan', 'fruit' => 'Apple'), TestHelper::getValue($input, 'data'));
    }
 /**
  * test__construct
  *
  * @return  void
  */
 public function test__construct()
 {
     $this->assertInstanceOf('Windwalker\\IO\\Input', $this->instance->input, 'Input property wrong type');
     $this->assertInstanceOf('Windwalker\\Registry\\Registry', TestHelper::getValue($this->instance, 'config'), 'Config property wrong type');
     $this->assertInstanceOf('Windwalker\\Application\\Web\\Response', $this->instance->getResponse(), 'Response property wrong type');
     $this->assertInstanceOf('Windwalker\\Environment\\Web\\WebEnvironment', $this->instance->getEnvironment(), 'Environment property wrong type');
 }
Esempio n. 3
0
 /**
  * Test the Windwalker\IO\Cookie::set method.
  *
  * @return  void
  *
  * @covers  Windwalker\IO\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);
 }
Esempio n. 4
0
 /**
  * Method to test add().
  *
  * @return void
  *
  * @covers Windwalker\Middleware\Chain\ChainBuilder::add
  */
 public function testAdd()
 {
     $builder = new ChainBuilder();
     $builder->add(new StubCaesarMiddleware())->add(new StubOthelloMiddleware());
     $wares = TestHelper::getValue($builder, 'stack');
     $this->assertTrue($wares[0] instanceof StubCaesarMiddleware);
     $this->assertTrue($wares[1] instanceof StubOthelloMiddleware);
 }
 /**
  * Method to test removeInstance().
  *
  * @return void
  *
  * @covers Windwalker\DataMapper\DataMapperContainer::removeInstance
  */
 public function testRemoveInstance()
 {
     $mapperBackup = DataMapperContainer::getInstance('#__content');
     DataMapperContainer::removeInstance('#__content');
     $mappers = TestHelper::getValue('Windwalker\\DataMapper\\DataMapperContainer', 'instances');
     $this->assertArrayNotHasKey('#__content', $mappers);
     $this->assertNotSame($mapperBackup, DataMapperContainer::getInstance('#__content'));
 }
Esempio n. 6
0
 /**
  * testConstruct
  *
  * @return  void
  */
 public function testConstruct()
 {
     $stringObject = $this->getMockBuilder('stdClass')->setMethods(array('__toString'))->getMock();
     $stringObject->expects($this->once())->method('__toString')->willReturn('FOO');
     $stream = new StringStream($stringObject);
     $this->assertEquals('FOO', TestHelper::getValue($stream, 'resource'));
     $this->assertInternalType('object', TestHelper::getValue($stream, 'stream'));
 }
Esempio n. 7
0
 public function testConstruct()
 {
     $resource = fopen('php://memory', Stream::MODE_READ_WRITE_RESET);
     $stream = new Stream($resource);
     $this->assertInstanceOf('Asika\\Http\\Stream\\Stream', $stream);
     $stream = new Stream();
     $this->assertInternalType('resource', TestHelper::getValue($stream, 'resource'));
     $this->assertEquals('php://memory', TestHelper::getValue($stream, 'stream'));
 }
Esempio n. 8
0
 /**
  * prepareRecord
  *
  * @param Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     /** @var NestedRecord $record */
     parent::prepareRecord($record);
     // Auto set location for batch copy
     $key = $record->getKeyName();
     if (!$record->{$key} && !TestHelper::getValue($record, 'locationId')) {
         $record->setLocation($record->parent_id, $record::LOCATION_LAST_CHILD);
     }
 }
 /**
  * Method to test __construct().
  *
  * @return void
  *
  * @covers Windwalker\Provider\SystemProvider::__construct
  */
 public function test__construct()
 {
     $provider = new SystemProvider(true);
     $this->assertTrue(TestHelper::getValue($provider, 'isConsole'));
     $provider = new SystemProvider(false);
     $this->assertFalse(TestHelper::getValue($provider, 'isConsole'));
     $provider = new SystemProvider();
     $this->assertFalse(TestHelper::getValue($provider, 'isConsole'));
     $provider = new SystemProvider('foo');
     $this->assertTrue(TestHelper::getValue($provider, 'isConsole'));
     $provider = new SystemProvider(null);
     $this->assertFalse(TestHelper::getValue($provider, 'isConsole'));
 }
 /**
  * Method to test __construct().
  *
  * @return void
  *
  * @covers Windwalker\Table\TableHelper::__construct
  */
 public function test__construct()
 {
     $tableName = '#__test_table';
     $helper = new TableHelper($tableName);
     $this->assertEquals($tableName, TestHelper::getValue($helper, 'table'));
     $this->assertEquals('id', TestHelper::getValue($helper, 'pkName'));
     $this->assertSame(\JFactory::getDbo(), $helper->getDb());
     $tableName = '#__test_table2';
     $helper = new TableHelper($tableName, null, 'pk');
     $this->assertEquals($tableName, TestHelper::getValue($helper, 'table'));
     $this->assertEquals('pk', TestHelper::getValue($helper, 'pkName'));
     $this->assertSame(\JFactory::getDbo(), $helper->getDb());
 }
Esempio n. 11
0
 /**
  * Test the Windwalker\IO\Json::__construct method.
  *
  * @return  void
  *
  * @covers  Windwalker\IO\Json::__construct
  * @since   1.0
  */
 public function test__construct()
 {
     $this->assertInstanceOf('Windwalker\\Filter\\InputFilter', TestHelper::getValue($this->instance, 'filter'));
     $this->assertEmpty(TestHelper::getValue($this->instance, 'data'));
     // Given Source & filter
     $src = array('foo' => 'bar');
     $json = new JsonInput($src);
     $this->assertEquals($src, TestHelper::getValue($json, 'data'));
     // Src from GLOBAL
     $GLOBALS['HTTP_RAW_POST_DATA'] = '{"a":1,"b":2}';
     $json = new JsonInput();
     $this->assertEquals(array('a' => 1, 'b' => 2), TestHelper::getValue($json, 'data'));
 }
Esempio n. 12
0
 /**
  * uploadFromController
  *
  * @param AbstractSaveController $controller
  * @param string                 $field
  * @param DataInterface          $data
  * @param string                 $uri
  *
  * @return  boolean|string
  */
 public static function uploadFromController(AbstractSaveController $controller, $field, DataInterface $data, $uri)
 {
     // formControl is protected, we get it by TestHelper
     $base64 = $controller->input->post->getRaw('input-' . TestHelper::getValue($controller, 'formControl') . '-' . $field . '-data');
     $delete = $controller->input->post->get('input-' . TestHelper::getValue($controller, 'formControl') . '-' . $field . '-delete-image');
     if ($base64 && ($url = Base64Image::quickUpload($base64, $uri))) {
         $data->{$field} = $url;
         return $url;
     } elseif ($delete) {
         $data->{$field} = '';
         return true;
     }
     return false;
 }
 /**
  * Method to test __construct().
  *
  * @return void
  *
  * @covers \Windwalker\Component\Component::__construct
  * @covers \Windwalker\Component\Component::init
  */
 public function testConstructor()
 {
     $component = new Component($this->componentName);
     $this->assertInstanceOf('Windwalker\\Test\\Application\\TestApplication', $component->getApplication());
     $this->assertInstanceOf('Windwalker\\DI\\Container', $component->getContainer());
     $this->assertInstanceOf('JInput', $component->getInput());
     $this->assertNull($component->getDefaultController());
     $name = TestHelper::getValue($component, 'name');
     $option = TestHelper::getValue($component, 'option');
     $path = TestHelper::getValue($component, 'path');
     $this->assertEquals($this->componentName, $name);
     $this->assertEquals('com_' . $this->componentName, $option);
     $this->assertEquals(array('self' => JPATH_ROOT . '/components/com_' . strtolower($this->componentName), 'site' => JPATH_ROOT . '/components/com_' . strtolower($this->componentName), 'administrator' => JPATH_ROOT . '/administrator/components/com_' . strtolower($this->componentName)), $path);
 }
Esempio n. 14
0
 /**
  * Method to test __set().
  *
  * @return void
  *
  * @covers Windwalker\Record\Record::__set
  */
 public function test__set()
 {
     $record = new Record('#__flower');
     $record->set('catid', 1);
     $data = TestHelper::getValue($record, 'data');
     $this->assertEquals(1, $data->catid);
     $record->catid = 3;
     $data = TestHelper::getValue($record, 'data');
     $this->assertEquals(3, $data->catid);
     // Alias
     $record->setAlias('foo', 'catid');
     $record->foo = 6;
     $data = TestHelper::getValue($record, 'data');
     $this->assertEquals(6, $data->catid);
 }
Esempio n. 15
0
 /**
  * Method to test __construct().
  *
  * @return void
  *
  * @covers Windwalker\Table\Table::__construct
  */
 public function test__construct()
 {
     $tableName = '#__test_table';
     $table = new Table($tableName);
     $this->assertEquals($tableName, TestHelper::getValue($table, '_tbl'));
     $this->assertEquals(array('id'), TestHelper::getValue($table, '_tbl_keys'));
     $this->assertSame(\JFactory::getDbo(), $table->getDbo());
     $tableName = '#__test_table2';
     $db = $this->getMockBuilder(get_class(\JFactory::getDbo()))->disableOriginalConstructor()->getMock();
     // Just return something to make getFields() no crash.
     $db->expects($this->once())->method('getTableColumns')->willReturn(array('#__test_table2' => true));
     $table = new Table($tableName, 'pk', $db);
     $this->assertEquals($tableName, TestHelper::getValue($table, '_tbl'));
     $this->assertEquals(array('pk'), TestHelper::getValue($table, '_tbl_keys'));
     $this->assertSame($db, $table->getDbo());
 }
Esempio n. 16
0
 /**
  * Method to test __set().
  *
  * @return void
  *
  * @covers Windwalker\Record\Record::__set
  */
 public function test__set()
 {
     $record = new Record('#__flower');
     $record->set('catid', 1);
     $data = TestHelper::getValue($record, 'data');
     $this->assertEquals(1, $data->catid);
     $record->catid = 3;
     $data = TestHelper::getValue($record, 'data');
     $this->assertEquals(3, $data->catid);
     $this->assertExpectedException(function () use($record) {
         $record->foo = 'bar';
     }, new \InvalidArgumentException());
     // Alias
     $record->setAlias('foo', 'catid');
     $record->foo = 6;
     $data = TestHelper::getValue($record, 'data');
     $this->assertEquals(6, $data->catid);
 }
Esempio n. 17
0
 /**
  * testConstruct
  *
  * @return  void
  */
 public function testConstruct()
 {
     $server = array('foo' => 'bar', 'baz' => 'bat');
     $server['server'] = true;
     $files = array('files' => new UploadedFile('php://temp', 0));
     $uri = new PsrUri('http://example.com');
     $method = 'POST';
     $headers = array('Host' => array('example.com'));
     $request = new ServerRequest($server, $files, $uri, $method, 'php://memory', $headers);
     $this->assertEquals($server, $request->getServerParams());
     $this->assertEquals($files, $request->getUploadedFiles());
     $this->assertSame($uri, $request->getUri());
     $this->assertEquals($method, $request->getMethod());
     $this->assertEquals($headers, $request->getHeaders());
     $body = $request->getBody();
     $stream = TestHelper::getValue($body, 'stream');
     $this->assertEquals('php://memory', $stream);
 }
Esempio n. 18
0
 /**
  * Method to test loadAllInputs().
  *
  * @return void
  *
  * @covers Windwalker\IO\Input::loadAllInputs
  */
 public function testLoadAllInputs()
 {
     // Remove the following lines when you implement this test.
     $this->markTestSkipped('A bug that the static $loaded variable has benn set to true.....');
     $instance = $this->newInstance(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));
 }
Esempio n. 19
0
 /**
  * Test the JInput::parseArguments method.
  *
  * @dataProvider provider_parseArguments
  */
 public function testParseArguments($inputArgv, $expectedData, $expectedArgs)
 {
     $_SERVER['argv'] = $inputArgv;
     $this->instance = new CliInput();
     $this->assertThat(TestHelper::getValue($this->instance, 'data'), $this->identicalTo($expectedData));
     $this->assertThat($this->instance->args, $this->identicalTo($expectedArgs));
 }
 /**
  * testNormalizeContentType
  *
  * @return  void
  * 
  * @covers \Windwalker\Http\Response\AbstractContentTypeResponse::normalizeContentType
  */
 public function testNormalizeContentType()
 {
     $this->assertEquals('text/plain', TestHelper::invoke($this->instance, 'normalizeContentType', 'Text/Plain'));
 }
 /**
  * Method to test getContainer().
  *
  * @return void
  *
  * @covers \Windwalker\Controller\Controller::getContainer
  */
 public function testGetContainer()
 {
     // Test case #1: Get container with empty "container" property
     $controller = new \StubControllerFoo();
     $option = TestHelper::getValue($controller, 'option');
     $this->assertSame(Container::getInstance($option), $controller->getContainer());
     // Test case #2: Get container with an assigned "container" property
     $controller = new \StubControllerFoo();
     $container = new Container();
     $controller->setContainer($container);
     $this->assertSame($container, $controller->getContainer());
 }
Esempio n. 22
0
 /**
  * Translates an internal Joomla URL to a humanly readable URL.
  *
  * @param   string   $url    Absolute or Relative URI to Joomla resource.
  * @param   boolean  $xhtml  Replace & by &amp; for XML compliance.
  * @param   integer  $ssl    Secure state for the resolved URI.
  *                             0: (default) No change, use the protocol currently used in the request
  *                             1: Make URI secure using global secure site URI.
  *                             2: Make URI unsecure using the global unsecure site URI.
  *
  * @return string The translated humanly readable URL.
  */
 public static function jroute($url, $xhtml = true, $ssl = null)
 {
     if (!static::$router) {
         static::$router = static::getRouter();
     }
     if (!is_array($url) && strpos($url, '&') !== 0 && strpos($url, 'index.php') !== 0) {
         return $url;
     }
     // Backup base with frontend root
     $base = TestHelper::getValue('JUri', 'base');
     TestHelper::setValue('JUri', 'base', TestHelper::getValue('JUri', 'root'));
     // Build route.
     /** @var Uri $uri */
     $uri = static::$router->build($url);
     // Restore base
     TestHelper::setValue('JUri', 'base', $base);
     $scheme = array('path', 'query', 'fragment');
     /*
      * Get the secure/unsecure URLs.
      *
      * If the first 5 characters of the BASE are 'https', then we are on an ssl connection over
      * https and need to set our secure URL to the current request URL, if not, and the scheme is
      * 'http', then we need to do a quick string manipulation to switch schemes.
      */
     if ((int) $ssl || $uri->isSSL()) {
         static $host_port;
         if (!is_array($host_port)) {
             $uri2 = \JUri::getInstance();
             $host_port = array($uri2->getHost(), $uri2->getPort());
         }
         // Determine which scheme we want.
         $uri->setScheme((int) $ssl === 1 || $uri->isSSL() ? 'https' : 'http');
         $uri->setHost($host_port[0]);
         $uri->setPort($host_port[1]);
         $scheme = array_merge($scheme, array('host', 'port', 'scheme'));
     }
     $url = $uri->toString($scheme);
     // Replace spaces.
     $url = preg_replace('/\\s/u', '%20', $url);
     if ($xhtml) {
         $url = htmlspecialchars($url);
     }
     return $url;
 }
Esempio n. 23
0
 /**
  * Method to test setRenderer().
  *
  * @return void
  *
  * @covers Windwalker\Profiler\Profiler::setRenderer
  */
 public function testGetAndSetRenderer()
 {
     // Reset the property.
     TestHelper::setValue($this->instance, 'renderer', null);
     $renderer = new DefaultRenderer();
     $this->instance->setRenderer($renderer);
     $this->assertSame($renderer, $this->instance->getRenderer());
 }
 /**
  * testGetCategoryWithAssignedProperty
  *
  * @return  void
  */
 public function testGetCategoryWithAssignedProperty()
 {
     $model = new StubModelAdvanced();
     $category = new Data(array('id' => 30001, 'title' => 'foobar'));
     TestHelper::setValue($model, 'category', $category);
     $this->assertSame($category, $model->getCategory());
 }
    /**
     * Method to test backbone().
     *
     * @return void
     *
     * @covers Windwalker\Script\CoreScript::backbone
     */
    public function testBackbone()
    {
        $bakDoc = \JFactory::getDocument();
        \JFactory::$document = $this->doc;
        TestHelper::setValue('JHtmlJquery', 'loaded', array());
        CoreScript::backbone(false);
        $url = \JUri::root(true) . '/libraries/windwalker/resource/asset/js/core/backbone.js';
        $this->assertEquals($url, $this->doc->getLastScript());
        $this->assertEquals(5, count($this->doc->_scripts));
        $js = <<<JS
;
_.templateSettings = { interpolate: /\\{\\{(.+?)\\}\\}/g };;
;
var underscore = _.noConflict();;
JS;
        $this->assertStringDataEquals($js, $this->doc->_script['text/javascript']);
        CoreScript::backbone(true);
        $url = \JUri::root(true) . '/libraries/windwalker/resource/asset/js/core/backbone.js';
        $this->assertEquals($url, $this->doc->getLastScript());
        $this->assertEquals(5, count($this->doc->_scripts));
        $js = <<<JS
;
_.templateSettings = { interpolate: /\\{\\{(.+?)\\}\\}/g };;
;
var underscore = _.noConflict();;
;
var backbone = Backbone.noConflict();;
JS;
        $this->assertStringDataEquals($js, $this->doc->_script['text/javascript']);
        \JFactory::$document = $bakDoc;
    }
Esempio n. 26
0
 /**
  * test construct.
  *
  * @return void
  *
  * @since  2.0
  */
 public function testConstruct()
 {
     $console = new Console(new MockIO());
     $this->assertInstanceOf('Windwalker\\Console\\IO\\IO', $console->io);
     $this->assertInstanceOf('Windwalker\\Structure\\Structure', TestHelper::getValue($console, 'config'));
 }
 /**
  * Method to test __construct().
  *
  * @return void
  *
  * @covers Windwalker\Model\Provider\GridProvider::__construct
  */
 public function test__construct()
 {
     $provider = new GridProvider('FooBar');
     $this->assertEquals('foobar', TestHelper::getValue($provider, 'name'));
 }
 /**
  * Method to test setContainer().
  *
  * @return void
  *
  * @covers Windwalker\View\Engine\AbstractEngine::setContainer
  */
 public function testSetContainer()
 {
     $engine = new StubEngine();
     $container = new Container();
     $engine->setContainer($container);
     $this->assertSame($container, TestHelper::getValue($engine, 'container'));
 }
Esempio n. 29
0
 /**
  * Method to test clear().
  *
  * @return void
  *
  * @covers Windwalker\Query\Query::clear
  */
 public function testClearType()
 {
     $q = $this->getQuery();
     $types = array('select', 'delete', 'update', 'insert');
     $clauses = array('from', 'join', 'set', 'where', 'group', 'having', 'union', 'order', 'columns', 'values');
     // Set the clauses
     foreach ($clauses as $clause) {
         $q->{$clause}('foo', 'bar', 'yoo', 'goo');
     }
     // Check that all properties have been cleared
     foreach ($types as $type) {
         $query = clone $q;
         // Set the type.
         $query->{$type}('foo', 'bar');
         // Clear the type.
         $query->clear($type);
         // Check the type has been cleared.
         $this->assertNull(TestHelper::getValue($query, 'type'), 'Query property: ' . $type . ' should be null.');
         $this->assertNull(TestHelper::getValue($query, $type), $type . ' should be null.');
         // Now check the claues have not been affected.
         foreach ($clauses as $clause) {
             $this->assertNotNull(TestHelper::getValue($query, $clause), $clause . ' should exists if we clear ' . $type);
         }
     }
 }
 /**
  * Method to test __construct().
  *
  * @return void
  *
  * @covers Windwalker\Component\Component::__construct
  */
 public function test__construct()
 {
     // Test no constants
     $this->createComponent();
     $this->assertFalse(defined('STUB_ADMIN'));
     // Create with no params
     $component = new StubComponent();
     $this->assertEquals('stub', $component->getName());
     $container = Container::getInstance('com_stub');
     $this->assertSame($container, $component->getContainer());
     $this->assertSame($container->get('app'), $component->getApplication());
     $this->assertSame($container->get('app')->input, $component->getInput());
     $this->assertEquals('com_stub', $component->getOption());
     $this->assertEquals(STUB_ADMIN, $component->getAdminPath());
     $this->assertEquals(STUB_SITE, $component->getSitePath());
     $this->assertEquals(STUB_SELF, $component->getPath());
     // Create with manually set params
     $app = new TestApplication();
     $input = new \JInput();
     $container = new Container();
     $container->registerServiceProvider(new SystemProvider());
     // Mock Event
     $event = $this->getMock('JEventDispatcher', array('trigger'), array('eventName'), 'MockDispatcher');
     $event->expects($this->at(0))->method('trigger')->with('onComponentBeforeInit');
     $event->expects($this->at(1))->method('trigger')->with('onComponentAfterInit');
     $container->share('JEventDispatcher', $event)->alias('event.dispatcher', 'JEventDispatcher');
     $component = new StubComponent('flower', $input, $app, $container);
     $this->assertSame($container, $component->getContainer());
     $this->assertSame($app, $component->getApplication());
     $this->assertSame($input, $component->getInput());
     $this->assertEquals('com_flower', $component->getOption());
     $this->assertEquals('flower', $component->getName());
     // Other test
     $this->assertEquals('foo', $input->get('controller'));
     $this->assertEquals('foo', $input->get('task'));
     $paths = TestHelper::getValue('JFormHelper', 'paths');
     $this->assertTrue(in_array(WINDWALKER_SOURCE . '/Form/Fields', $paths['field']));
     $this->assertTrue(in_array(WINDWALKER_SOURCE . '/Form/Forms', $paths['form']));
 }