class TestRequestPath

Public Instance Methods

test_all() click to toggle source
# File vendor/qwik/lib/qwik/request-path.rb, line 200
    def test_all
      config = Qwik::Config.new
      req = Qwik::Request.new(config)

      # test_parse_path
#      t_make_public(Qwik::Request, :parse_path)
      ok_eq(['www', 'FrontPage', 'html'], req.parse_path('/'))
      ok_eq(['www', 'FrontPage', 'html'],
            req.parse_path('/FrontPage.html'))
      ok_eq(['test', 't', 'html'], req.parse_path('/test/t.html'))
      ok_eq(['test', 'FrontPage', 'html'], req.parse_path('/test/'))
      ok_eq(['www', 'test', ''], req.parse_path('/test'))
      ok_eq(['test', 'FrontPage', 'html'],
            req.parse_path('/test/FrontPage.html'))
      ok_eq(['example.com', 'FrontPage', 'html'],
            req.parse_path('/example.com/'))
      ok_eq(['www.example.com', 'FrontPage', 'html'],
            req.parse_path('/www.example.com/'))

      # test_theme_plugin
      req.parse_path('/.theme/all.css')
      ok_eq(['theme', ['all.css']], [req.plugin, req.path_args])
      ok_eq(['www', 'FrontPage', 'html'],
            req.parse_path('/.theme/all.css'))

      req.parse_path('/.theme/qwikgreen/qwikgreen.css')
      ok_eq(['theme', ['qwikgreen', 'qwikgreen.css']],
            [req.plugin, req.path_args])

      req.parse_path('/.login')
      ok_eq(['login', []], [req.plugin, req.path_args])

      req.parse_path('/.login/user@e.com/44484125/')
      ok_eq(['login', ['user@e.com', '44484125']],
            [req.plugin, req.path_args])

      ok_eq(['www', 'FrontPage', 'html'],
            req.parse_path('/FrontPage.html/sid=000/'))
      ok_eq(['sid=000'], req.path_args)
      ok_eq({'sid'=>'000'}, req.path_query)

      # test_parse_plugin
      assert_raise(RuntimeError){ req.parse_path('test/') }
      ok_eq(['test', 'FrontPage', 'html'],
            req.parse_path('/test/.attach/t.txt'))
      ok_eq(['attach', ['t.txt']], [req.plugin, req.path_args])
      ok_eq(['www', 'FrontPage', 'html'],
            req.parse_path('/.attach/s.jpg'))
      ok_eq(['attach', ['s.jpg']], [req.plugin, req.path_args])

      ok_eq(['www', 'FrontPage', 'html'], req.parse_path('/.new'))
      ok_eq(['new', []], [req.plugin, req.path_args])

      ok_eq(['test', 'test', 'zip'], req.parse_path('/test/test.zip'))
      ok_eq('zip', req.ext)

      ok_eq(['www', 'test', 'zip'], req.parse_path('/test.zip'))
      ok_eq('zip', req.ext)

      ok_eq(['e.com', 'FrontPage', 'html'],
            req.parse_path('/e.com/.attach/t.png'))
      ok_eq(['attach', ['t.png']],
            [req.plugin, req.path_args])

      ok_eq(['www', 'www', 'zip'], req.parse_path('/www.zip'))
      ok_eq(['www', 'www', 'rss'], req.parse_path('/www.rss'))

      ok_eq(['www', 'favicon', 'ico'], req.parse_path('/favicon.ico'))

      # test_attach
      ok_eq(['www', 'FrontPage', 'html'],
            req.parse_path('/.attach/s.jpg'))
      ok_eq(['attach', ['s.jpg']], [req.plugin, req.path_args])

      ok_eq(['www', 'FrontPage', 'html'],
            req.parse_path('/.attach/thumb/s.jpg'))
      ok_eq(['attach', ['thumb', 's.jpg']],
            [req.plugin, req.path_args])

      # test_parse_sitename
      c = Qwik::Request
      ok_eq(true,  c.sitename?('test'))
      ok_eq(true,  c.sitename?('e.com'))
      ok_eq(true,  c.sitename?('www.e.com'))
      ok_eq(false, c.sitename?('www.new'))
      ok_eq(false, c.sitename?('www.zip'))
      ok_eq(false, c.sitename?('www.rss'))
      ok_eq(false, c.sitename?('hoge.1.backup'))

      # test_ext_args
      ok_eq(['www', 'hoge', 'backup'],
            req.parse_path('/hoge.backup'))
      ok_eq([], req.ext_args)

      ok_eq(['www', 'hoge', 'backup'],
            req.parse_path('/hoge.1.backup'))
      ok_eq(['1'], req.ext_args)

      ok_eq(['test', 'hoge', 'backup'],
            req.parse_path('/test/hoge.1.backup'))
      ok_eq(['1'], req.ext_args)

    end
test_class_method() click to toggle source
# File vendor/qwik/lib/qwik/request-path.rb, line 192
def test_class_method
  c = Qwik::Request
  ok_eq('a',   c.remove_quote('a'))
  ok_eq("\"a\"", c.remove_quote("\"a\""))
  ok_eq('ab',  c.remove_quote("a\"b\""))
  ok_eq("'a'", c.remove_quote("'a'"))
end