/**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     $View = new View(null);
     $this->Common = new CommonHelper($View);
 }
Exemplo n.º 2
0
 /**
  * @return void
  */
 public function testBuildResetWithPlugin()
 {
     Router::connect('/:controller/:action/*');
     $result = $this->Url->buildReset(['controller' => 'foobar', 'action' => 'test']);
     $expected = '/foobar/test';
     $this->assertSame($expected, $result);
     $this->Url->request->here = '/admin/foo/bar/baz/test';
     $this->Url->request->params['prefix'] = 'admin';
     $this->Url->request->params['plugin'] = 'Foo';
     Router::reload();
     Router::connect('/:controller/:action/*');
     Router::plugin('Foo', function ($routes) {
         $routes->fallbacks();
     });
     Router::prefix('admin', function ($routes) {
         $routes->plugin('Foo', function ($routes) {
             $routes->fallbacks();
         });
     });
     Plugin::routes();
     Router::pushRequest($this->Url->request);
     $result = $this->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']);
     $expected = '/admin/foo/bar/baz/x';
     $this->assertSame($expected, $result);
     $result = $this->Url->buildReset(['controller' => 'bar', 'action' => 'baz', 'x']);
     $expected = '/bar/baz/x';
     $this->assertSame($expected, $result);
 }
Exemplo n.º 3
0
 /**
  * test setting parameters in beforeDispatch method
  *
  * @return void
  */
 public function testQueryStringAndCustomTime()
 {
     $folder = CACHE . 'views' . DS;
     $file = $folder . 'posts-home-coffee-life-sleep-sissies-coffee-life-sleep-sissies.html';
     $content = '<!--cachetime:' . (time() + WEEK) . ';ext:html-->Foo bar';
     file_put_contents($file, $content);
     Router::reload();
     Router::connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
     Router::connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
     Router::connect('/:controller/:action/*');
     $_GET = ['coffee' => 'life', 'sleep' => 'sissies'];
     $filter = new CacheFilter();
     $request = new Request('posts/home/?coffee=life&sleep=sissies');
     $response = new Response();
     $event = new Event(__CLASS__, $this, compact('request', 'response'));
     $filter->beforeDispatch($event);
     $result = $response->body();
     $expected = '<!--created:';
     $this->assertTextStartsWith($expected, $result);
     $expected = '-->Foo bar';
     $this->assertTextEndsWith($expected, $result);
     $result = $response->type();
     $expected = 'text/html';
     $this->assertEquals($expected, $result);
     $result = $response->header();
     $this->assertNotEmpty($result['Expires']);
     // + 1 week
     unlink($file);
 }
Exemplo n.º 4
0
 /**
  * Tests
  *
  * @return void
  */
 public function testResetLink()
 {
     Router::connect('/:controller/:action/*');
     $result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']);
     $expected = '<a href="/foobar/test">Foo</a>';
     $this->assertEquals($expected, $result);
     $this->Html->request->here = '/admin/foobar/test';
     $this->Html->request->params['admin'] = true;
     $this->Html->request->params['prefix'] = 'admin';
     Router::reload();
     Router::connect('/:controller/:action/*');
     Router::prefix('admin', function ($routes) {
         $routes->connect('/:controller/:action/*');
     });
     $result = $this->Html->link('Foo', ['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
     $expected = '<a href="/admin/foobar/test">Foo</a>';
     $this->assertEquals($expected, $result);
     $result = $this->Html->link('Foo', ['controller' => 'foobar', 'action' => 'test']);
     $expected = '<a href="/admin/foobar/test">Foo</a>';
     //debug($result);
     //$this->assertEquals($expected, $result);
     $result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']);
     $expected = '<a href="/foobar/test">Foo</a>';
     $this->assertEquals($expected, $result);
 }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     Router::connect('/:controller', ['action' => 'index']);
     Router::connect('/:controller/:action/*');
 }
 /**
  * Loads routes and resets if the test case dictates it should
  *
  * @return void
  */
 protected function _loadRoutes()
 {
     parent::_loadRoutes();
     if (!$this->loadRoutes) {
         Router::reload();
     }
 }
Exemplo n.º 7
0
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     $View = new View(null);
     $this->Flash = new FlashHelper($View);
 }
Exemplo n.º 8
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     $this->View = new View();
     $this->Helper = new Helper($this->View);
     $this->Helper->request = new Request();
 }
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     Configure::write('App.namespace', 'Spekkoek\\Test\\TestApp');
     $this->dispatcher = new ActionDispatcher();
     $this->dispatcher->addFilter(new ControllerFactoryFilter());
 }
 /**
  * reset environment.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('App.namespace', 'TestApp');
     Plugin::load(array('TestPlugin', 'TestPluginTwo'));
     $this->Case = $this->getMockForAbstractClass('Cake\\TestSuite\\ControllerTestCase');
     Router::reload();
     TableRegistry::clear();
 }
Exemplo n.º 11
0
 /**
  * setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('Routing.prefixes', []);
     Router::reload();
     $this->Acl = $this->getMockBuilder('Acl\\Controller\\Component\\AclComponent')->disableOriginalConstructor()->getMock();
     $this->Components = $this->getMockBuilder('Cake\\Controller\\ComponentRegistry')->getMock();
     $this->auth = new CrudAuthorize($this->Components);
 }
Exemplo n.º 12
0
 /**
  * setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('Routing.prefixes', array());
     Router::reload();
     $this->Acl = $this->getMock('Acl\\Controller\\Component\\AclComponent', array(), array(), '', false);
     $this->Components = $this->getMock('Cake\\Controller\\ComponentRegistry');
     $this->auth = new CrudAuthorize($this->Components);
 }
Exemplo n.º 13
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     $this->View = new View();
     $this->Helper = new UrlHelper($this->View);
     $this->Helper->request = new Request();
     Configure::write('App.namespace', 'TestApp');
     Plugin::load(['TestTheme']);
 }
 /**
  * Test initial setup
  *
  * @return void
  */
 public function testGetRelationLink()
 {
     $userId = '481fc6d0-b920-43e0-a40d-6d1740cf8562';
     $articlesId = '99dbcad7-21d5-4dd1-b193-e00543c0224c';
     $article = $this->Articles->newEntity(['title' => 'title', 'content' => 'content']);
     $fieldValue = 123;
     Router::reload();
     $relationLink = $this->Articles->getRelationLink('foobar', $fieldValue);
     $this->assertEquals($fieldValue, $relationLink);
 }
Exemplo n.º 15
0
 /**
  * setup create a request object to get out of router later.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     $request = new Request();
     $request->base = '';
     Router::setRequestInfo($request);
     Configure::write('debug', true);
     $this->_logger = $this->getMock('Psr\\Log\\LoggerInterface');
     Log::reset();
     Log::config('error_test', ['engine' => $this->_logger]);
 }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->View = new View();
     $this->View->Html = new BootstrapHtmlHelper($this->View);
     $this->Paginator = new BootstrapPaginatorHelper($this->View);
     $this->Paginator->request = new Request();
     $this->Paginator->request->addParams(['paging' => ['Article' => ['page' => 1, 'current' => 9, 'count' => 62, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 7, 'sort' => null, 'direction' => null, 'limit' => null]]]);
     Configure::write('Routing.prefixes', []);
     Router::reload();
     Router::connect('/:controller/:action/*');
     Router::connect('/:plugin/:controller/:action/*');
 }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('Captcha', ['debug' => false]);
     Router::reload();
     $this->request = new Request();
     //$this->getMockBuilder(Request::class)->setMethods([''])->getMock([]);
     $this->session = $this->getMockBuilder(Session::class)->setMethods(['id'])->getMock();
     $this->request->session($this->session);
     $this->session->expects($this->once())->method('id')->willReturn(1);
     $this->View = new View($this->request);
     $this->Captcha = new CaptchaHelper($this->View);
 }
 /**
  * (non-PHPdoc)
  * @see cake/tests/lib/TestCase#startTest($method)
  */
 public function setUp()
 {
     parent::setUp();
     $this->request = new Request();
     $this->Controller = new Controller();
     $this->View = new View($this->request);
     $this->Rating = new RatingHelper($this->View);
     //$this->Rating->Form = new FormHelper($this->View);
     //$this->Rating->Html = new HtmlHelper($this->View);
     //$this->Rating->Form->Html = $this->Rating->Html;
     //$this->Rating->Form->params['action'] = 'add';
     //ClassRegistry::addObject('view', $this->View);
     Router::reload();
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('Captcha', ['debug' => false]);
     $this->request = new Request();
     $this->request->env('REMOTE_ADDR', '127.0.0.1');
     $this->session = $this->getMockBuilder(Session::class)->setMethods(['id'])->getMock();
     $this->session->expects($this->once())->method('id')->willReturn(1);
     $this->request->session($this->session);
     Router::pushRequest($this->request);
     Router::reload();
     $this->Captchas = TableRegistry::get('Captcha.Captchas');
     $this->Comments = TableRegistry::get('Captcha.Comments');
     $this->Comments->addBehavior('Captcha.Captcha');
 }
Exemplo n.º 20
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('Config.language', 'eng');
     $this->View = new View();
     $this->Paginator = new PaginatorHelper($this->View);
     $this->Paginator->Js = $this->getMock('Cake\\View\\Helper\\PaginatorHelper', [], [$this->View]);
     $this->Paginator->request = new Request();
     $this->Paginator->request->addParams(['paging' => ['Article' => ['page' => 1, 'current' => 9, 'count' => 62, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 7, 'sort' => null, 'direction' => null, 'limit' => null]]]);
     Configure::write('Routing.prefixes', []);
     Router::reload();
     Router::connect('/:controller/:action/*');
     Router::connect('/:plugin/:controller/:action/*');
     $this->locale = I18n::locale();
 }
Exemplo n.º 21
0
 public function setUp()
 {
     parent::setUp();
     Router::reload();
     if ($this->defaultLocale === null) {
         $this->defaultLocale = ini_get('intl.default_locale');
     }
     ini_set('intl.default_locale', 'de_DE');
     Configure::delete('Meta');
     $request = new Request();
     $request->params['controller'] = 'ControllerName';
     $request->params['action'] = 'actionName';
     $View = new View($request);
     $this->Meta = new MetaHelper($View);
 }
Exemplo n.º 22
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->backupUsersConfig = Configure::read('Users');
     Router::reload();
     Plugin::routes('CakeDC/Users');
     Router::connect('/route/*', ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'requestResetPassword']);
     Security::salt('YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
     Configure::write('App.namespace', 'Users');
     $this->request = $this->getMock('Cake\\Network\\Request', ['is', 'method']);
     $this->request->expects($this->any())->method('is')->will($this->returnValue(true));
     $this->response = $this->getMock('Cake\\Network\\Response', ['stop']);
     $this->Controller = new Controller($this->request, $this->response);
     $this->Registry = $this->Controller->components();
     $this->Controller->UsersAuth = new UsersAuthComponent($this->Registry);
 }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     TableRegistry::clear();
     Cache::disable();
     Router::reload();
     //Router::fullBaseUrl('http://test.local');
     Router::scope('/', function ($routes) {
         $routes->fallbacks('DashedRoute');
     });
     $this->Articles = TableRegistry::get('Articles', ['className' => 'Seo\\Test\\TestCase\\Model\\Behavior\\ArticlesTable']);
     $this->Articles->addBehavior('Seo.Seo', $this->defaultConfig);
     $this->SeoBehavior = new SeoBehavior($this->Articles, $this->defaultConfig);
     $this->setReflectionClassInstance($this->SeoBehavior);
     //$this->defaultReflectionTarget = $this->SeoBehavior; // (optional)
     $this->defaultEntity = $this->Articles->find()->first();
     $this->locale = I18n::locale();
 }
Exemplo n.º 24
0
 /**
  * test setting parameters in beforeDispatch method
  *
  * @return void
  * @triggers __CLASS__ $this, compact(request)
  * @triggers __CLASS__ $this, compact(request)
  */
 public function testQueryStringOnRoot()
 {
     Router::reload();
     Router::connect('/', ['controller' => 'pages', 'action' => 'display', 'home']);
     Router::connect('/pages/*', ['controller' => 'pages', 'action' => 'display']);
     Router::connect('/:controller/:action/*');
     $_GET = ['coffee' => 'life', 'sleep' => 'sissies'];
     $filter = new RoutingFilter();
     $request = new Request('posts/home/?coffee=life&sleep=sissies');
     $event = new Event(__CLASS__, $this, compact('request'));
     $filter->beforeDispatch($event);
     $this->assertRegExp('/posts/', $request['controller']);
     $this->assertRegExp('/home/', $request['action']);
     $this->assertTrue(isset($request['url']['sleep']));
     $this->assertTrue(isset($request['url']['coffee']));
     $request = new Request('/?coffee=life&sleep=sissy');
     $event = new Event(__CLASS__, $this, compact('request'));
     $filter->beforeDispatch($event);
     $this->assertRegExp('/pages/', $request['controller']);
     $this->assertRegExp('/display/', $request['action']);
     $this->assertTrue(isset($request['url']['sleep']));
     $this->assertTrue(isset($request['url']['coffee']));
     $this->assertEquals('life', $request['url']['coffee']);
 }
Exemplo n.º 25
0
$loader->addNamespace('App', APP);
//@codingStandardsIgnoreStart
@mkdir(LOGS);
@mkdir(SESSIONS);
@mkdir(CACHE);
@mkdir(CACHE . 'views');
@mkdir(CACHE . 'models');
//@codingStandardsIgnoreEnd
require_once CORE_PATH . 'config/bootstrap.php';
date_default_timezone_set('UTC');
mb_internal_encoding('UTF-8');
Configure::write('debug', true);
Configure::write('App', ['namespace' => 'App', 'encoding' => 'UTF-8', 'base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => 'webroot', 'wwwRoot' => WWW_ROOT, 'fullBaseUrl' => 'http://localhost', 'imageBaseUrl' => 'img/', 'jsBaseUrl' => 'js/', 'cssBaseUrl' => 'css/', 'paths' => ['plugins' => [TEST_APP . 'Plugin' . DS], 'templates' => [APP . 'Template' . DS], 'locales' => [APP . 'Locale' . DS]]]);
Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true]]);
// Ensure default test connection is defined
if (!getenv('db_dsn')) {
    putenv('db_dsn=sqlite:///:memory:');
}
ConnectionManager::config('test', ['url' => getenv('db_dsn')]);
ConnectionManager::config('test_custom_i18n_datasource', ['url' => getenv('db_dsn')]);
Configure::write('Session', ['defaults' => 'php']);
Configure::write('EmailTransport', ['default' => ['className' => 'Debug']]);
Configure::write('Email', ['default' => ['transport' => 'default', 'from' => 'you@localhost']]);
Email::configTransport(Configure::consume('EmailTransport'));
Email::config(Configure::consume('Email'));
Log::config(['debug' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['notice', 'info', 'debug'], 'file' => 'debug'], 'error' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], 'file' => 'error']]);
Router::reload();
Cake\Routing\DispatcherFactory::add('Routing');
Cake\Routing\DispatcherFactory::add('ControllerFactory');
Plugin::load('Users', ['path' => ROOT . DS, 'routes' => true]);
Cake\Utility\Security::salt('8b61f851d8cb3dfcf3b447dc67bd7bf9fe2ed91a916d4457f4969a05a637473d');
Exemplo n.º 26
0
 /**
  * test that the returned URL doesn't contain the base URL.
  *
  * @see https://cakephp.lighthouseapp.com/projects/42648/tickets/3922-authcomponentredirecturl-prepends-appbaseurl
  *
  * @return void This test method doesn't return anything.
  */
 public function testRedirectUrlWithBaseSet()
 {
     $App = Configure::read('App');
     Configure::write('App', ['dir' => APP_DIR, 'webroot' => 'webroot', 'base' => false, 'baseUrl' => '/cake/index.php']);
     $url = '/users/login';
     $this->Auth->request = $this->Controller->request = new Request($url);
     $this->Auth->request->addParams(Router::parse($url));
     $this->Auth->request->url = Router::normalize($url);
     Router::setRequestInfo($this->Auth->request);
     $this->Auth->config('loginAction', ['controller' => 'users', 'action' => 'login']);
     $this->Auth->config('loginRedirect', ['controller' => 'users', 'action' => 'home']);
     $result = $this->Auth->redirectUrl();
     $this->assertEquals('/users/home', $result);
     $this->assertFalse($this->Auth->session->check('Auth.redirect'));
     Configure::write('App', $App);
     Router::reload();
 }
Exemplo n.º 27
0
 /**
  * Setup the test case, backup the static object values so they can be restored.
  * Specifically backs up the contents of Configure and paths in App if they have
  * not already been backed up.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     if (empty($this->_configure)) {
         $this->_configure = Configure::read();
     }
     if (class_exists('Cake\\Routing\\Router', false)) {
         Router::reload();
     }
 }
Exemplo n.º 28
0
 /**
  * reset environment.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('App.namespace', 'TestApp');
     Router::reload();
 }
Exemplo n.º 29
0
 /**
  * test reversing parameter arrays back into strings.
  *
  * Mark the router as initialized so it doesn't auto-load routes
  *
  * @return void
  */
 public function testReverse()
 {
     Router::connect('/:controller/:action/*');
     $params = array('controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'url' => [], 'autoRender' => 1, 'bare' => 1, 'return' => 1, 'requested' => 1, '_Token' => array('key' => 'sekret'));
     $result = Router::reverse($params);
     $this->assertEquals('/posts/view/1', $result);
     Router::reload();
     Router::connect('/:lang/:controller/:action/*', [], array('lang' => '[a-z]{3}'));
     $params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'url' => array('url' => 'eng/posts/view/1'));
     $result = Router::reverse($params);
     $this->assertEquals('/eng/posts/view/1', $result);
     $params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 1, '?' => ['foo' => 'bar']);
     $result = Router::reverse($params);
     $this->assertEquals('/eng/posts/view/1?foo=bar', $result);
     $params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'url' => array('url' => 'eng/posts/view/1', 'foo' => 'bar', 'baz' => 'quu'), 'paging' => [], 'models' => []);
     $result = Router::reverse($params);
     $this->assertEquals('/eng/posts/view/1?foo=bar&baz=quu', $result);
     $request = new Request('/eng/posts/view/1');
     $request->addParams(array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1)));
     $request->query = array('url' => 'eng/posts/view/1', 'test' => 'value');
     $result = Router::reverse($request);
     $expected = '/eng/posts/view/1?test=value';
     $this->assertEquals($expected, $result);
     $params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'url' => array('url' => 'eng/posts/view/1'));
     $result = Router::reverse($params, true);
     $this->assertRegExp('/^http(s)?:\\/\\//', $result);
 }
Exemplo n.º 30
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('Routing', ['admin' => null, 'prefixes' => []]);
     Router::reload();
 }