コード例 #1
0
ファイル: FilesInputTest.php プロジェクト: rokite/windwalker
 /**
  * Test the Windwalker\Input\Files::get method.
  *
  * @return  void
  *
  * @covers  Windwalker\Input\Files::get
  * @since   1.0
  */
 public function testGet()
 {
     $this->assertEquals('foobar', $this->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'));
     TestHelper::setValue($this->instance, 'data', $data);
     $expected = array('name' => 'n', 'type' => 'ty', 'tmp_name' => 'tm', 'error' => 'e', 'size' => 's');
     $this->assertEquals($expected, $this->instance->get('myfile'));
 }
コード例 #2
0
 /**
  * Test the Windwalker\Input\Files::get method.
  *
  * @return  void
  *
  * @covers  Windwalker\Input\Files::get
  * @since   2.0
  */
 public function testGet()
 {
     $this->assertEquals('foobar', $this->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'));
     TestHelper::setValue($this->instance, 'data', $data);
     $expected = array('name' => 'n', 'type' => 'ty', 'tmp_name' => 'tm', 'error' => 'e', 'size' => 's');
     $this->assertEquals($expected, $this->instance->get('myfile'));
     $data2 = array('foo' => array('name' => array('myfile' => 'n', 'myfile2' => 'nn'), 'type' => array('myfile' => 'ty', 'myfile2' => 'ttyy'), 'tmp_name' => array('myfile' => 'tm', 'myfile2' => 'ttmm'), 'error' => array('myfile' => 'e', 'myfile2' => 'ee'), 'size' => array('myfile' => 's', 'myfile2' => 'ss')));
     TestHelper::setValue($this->instance, 'data', $data2);
     $this->assertEquals($data, $this->instance->get('foo'));
     // We don't convert data structure for getByPath() now.
     $this->assertEquals('n', $this->instance->getByPath('foo.name.myfile'));
 }
コード例 #3
0
ファイル: ProfilerTest.php プロジェクト: im286er/windwalker
 /**
  * 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());
 }
コード例 #4
0
    /**
     * 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;
    }
コード例 #5
0
 /**
  * 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());
 }
コード例 #6
0
ファイル: InputTest.php プロジェクト: rokite/windwalker
 /**
  * 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));
 }
コード例 #7
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;
 }
コード例 #8
0
 /**
  * Method to test getLayoutTemplate().
  *
  * @return void
  *
  * @covers Windwalker\View\Engine\AbstractEngine::getLayoutTemplate
  */
 public function testGetLayoutTemplate()
 {
     $engine = new StubEngine();
     $layoutTemplate = 'template';
     TestHelper::setValue($engine, 'layoutTemplate', $layoutTemplate);
     $this->assertEquals($layoutTemplate, $engine->getLayoutTemplate());
 }
コード例 #9
0
 /**
  * Method to test getFilterForm().
  *
  * @return void
  *
  * @covers Windwalker\Model\ListModel::getFilterForm
  */
 public function testGetFilterForm()
 {
     $listModel = new WindwalkerModelStubList();
     $form = new \JForm('stublistmodel');
     TestHelper::setValue($listModel, 'context', 'model.foo.bar');
     $listModel->setLoadedForm($form);
     $this->assertSame($form, $listModel->getFilterForm());
     $listModel->setLoadedForm(new \RuntimeException('test runtime exception'));
     $this->assertEquals(new \JForm('model.foo.bar.filter'), $listModel->getFilterForm());
 }
コード例 #10
0
 /**
  * testGetStoreId
  *
  * @return  void
  *
  * @covers Windwalker\Model\Model::getStoreId
  */
 public function testGetStoreId()
 {
     TestHelper::setValue($this->instance, 'context', 'com_test.item');
     $this->assertEquals(md5('com_test.item:' . 123 . ':' . json_encode($this->instance->getState()->toArray())), TestHelper::invoke($this->instance, 'getStoreId', 123));
 }
コード例 #11
0
ファイル: InflectorTest.php プロジェクト: rokite/windwalker
 /**
  * Method to test StringInflector::getInstance().
  *
  * @return  void
  *
  * @covers  Windwalker\String\StringInflector::getInstance
  * @since   1.0
  */
 public function testGetInstance()
 {
     $this->assertInstanceOf('Windwalker\\String\\StringInflector', StringInflector::getInstance(), 'Check getInstance returns the right class.');
     // Inject an instance an test.
     TestHelper::setValue($this->StringInflector, 'instance', new \stdClass());
     $this->assertThat(StringInflector::getInstance(), $this->equalTo(new \stdClass()), 'Checks singleton instance is returned.');
     $this->assertInstanceOf('Windwalker\\String\\StringInflector', StringInflector::getInstance(true), 'Check getInstance a fresh object with true argument even though the instance is set to something else.');
 }
コード例 #12
0
 /**
  * setUpBeforeClass
  *
  * @return  void
  */
 public static function setUpBeforeClass()
 {
     TestHelper::setValue('JUri', 'base', array());
     \JFactory::getConfig()->set('live_site', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
 }
コード例 #13
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  *
  * @return void
  */
 protected function tearDown()
 {
     TestHelper::setValue('Juri', 'base', array());
     TestHelper::setValue('JUri', 'root', array());
     \JFactory::getConfig()->set('live_site', null);
 }