Exemplo n.º 1
0
 public function test_get_element_include()
 {
     $request = midgardmvc_core_request::get_for_intent('/subdir');
     $routes = midgardmvc_core::get_instance()->component->get_routes($request);
     $request->set_route($routes['index']);
     midgardmvc_core::get_instance()->context->create($request);
     $original_element = file_get_contents(midgardmvc_core::get_component_path('midgardmvc_core') . '/templates/ROOT.xhtml');
     $element = midgardmvc_core::get_instance()->templating->get_element($this->_core->context->get_request(), 'ROOT');
     $this->assertNotEquals($original_element, $element, 'Template returned by templating service should not be the same as the template file because of includes');
     $this->assertTrue(strpos($element, '<h1 property="mgd:title" tal:content="current_component/object/title">Title</h1>') !== false);
     midgardmvc_core::get_instance()->context->delete();
 }
Exemplo n.º 2
0
 public function test_get_routes()
 {
     $request = midgardmvc_core_request::get_for_intent('/');
     $routes = midgardmvc_core::get_instance()->component->get_routes($request);
     $this->assertTrue(is_array($routes));
     $this->assertTrue(isset($routes['index']));
     $this->assertTrue($routes['index'] instanceof midgardmvc_core_route);
     $this->assertTrue(isset($routes['login']), 'Root node should provide login route');
     $request = midgardmvc_core_request::get_for_intent('/subdir');
     $routes = midgardmvc_core::get_instance()->component->get_routes($request);
     $this->assertTrue(is_array($routes));
     $this->assertTrue(isset($routes['index']));
     $this->assertTrue($routes['index'] instanceof midgardmvc_core_route);
     $this->assertFalse(isset($routes['login']), 'Subnode should not provide login route');
 }
Exemplo n.º 3
0
 /**
  * Call a route of a component with given arguments and display its content entry point
  *
  * Dynamic loads may be called for either a specific page that has a component assigned to it
  * by specifying a page GUID or path as the first argument, or to a static instance of a component
  * by specifying component name as the first argument.
  *
  * In a TAL template dynamic load can be used in the following way:
  *
  * <code>
  * <div class="news" tal:content="structure php:midgardmvc.templating.dynamic_load('/newsfolder', 'latest', array('number' => 4))"></div>
  * </code>
  *
  * @param string $intent Component name or page GUID
  * @param string $route_id     Route identifier
  * @param array $arguments  Arguments to give to the route
  * @return $array data
  */
 public function dynamic_load($intent, $route_id, array $arguments, $return_html = false)
 {
     $request = midgardmvc_core_request::get_for_intent($intent);
     $this->midgardmvc->context->create($request);
     $data = $this->dynamic_call($request, $route_id, $arguments, false);
     $this->template($request, 'content');
     if ($return_html) {
         $output = $this->display($request, $return_html);
     } else {
         $this->display($request);
     }
     /*
      * Gettext is not context safe. Here we return the "original" textdomain
      * because in dynamic call the new component may change it
      */
     $this->midgardmvc->context->delete();
     $component = $this->midgardmvc->context->get_request()->get_component();
     if ($component) {
         $this->midgardmvc->i18n->set_translation_domain($component->name);
     }
     if ($return_html) {
         return $output;
     }
 }
Exemplo n.º 4
0
 /**
  * Generates an URL for given route_id with given arguments
  *
  * @param string $route_id the id of the route to generate a link for
  * @param array $args associative arguments array
  * @param mixed $intent Component name, node object, node GUID or node path
  * @return string url
  */
 public function generate_url($route_id, array $args, $intent)
 {
     // Create a request from the intent and assign it to a context
     $request = midgardmvc_core_request::get_for_intent($intent);
     $this->midgardmvc->context->create($request);
     $this->midgardmvc->component->inject($request, 'process');
     $routes = $this->midgardmvc->component->get_routes($request);
     if (!isset($routes[$route_id])) {
         if (empty($routes)) {
             throw new OutOfBoundsException("Route ID '{$route_id}' not found in routes of request. Routes configuration is also empty " . $request->get_identifier());
         }
         throw new OutOfBoundsException("Route ID '{$route_id}' not found in routes of request " . $request->get_identifier());
     }
     $route = $routes[$route_id];
     $request->set_arguments($route->set_variables($args));
     $this->midgardmvc->context->delete();
     return $request->get_path();
 }
Exemplo n.º 5
0
 /**
  * @expectedException midgardmvc_exception_httperror
  */
 public function test_dispatch_invalidmethod()
 {
     $request = midgardmvc_core_request::get_for_intent('/');
     $routes = midgardmvc_core::get_instance()->component->get_routes($request);
     $request->set_route($routes['index']);
     $request->set_method('TRACE');
     midgardmvc_core::get_instance()->dispatcher->dispatch($request);
 }
Exemplo n.º 6
0
 /**
  * Process application comments and ratings
  *
  * It intercepts the POST and checks if multiple rating is allowed
  * and the user can rate the object
  * If the user has already rated an object and multiple rating is not allowed
  * then it takes away rating from the POST and passes on the request
  * to the proper controller that will process it.
  *
  */
 public function post_comment_application(array $args)
 {
     if (!self::can_rate($args['to'])) {
         unset($_POST['rating']);
     }
     $route_id = 'rating_create';
     $request = midgardmvc_core_request::get_for_intent('com_meego_ratings_caching', false);
     $request->add_component_to_chain($this->mvc->component->get('com_meego_ratings_caching'));
     $routes = $this->mvc->component->get_routes($request);
     $request->set_arguments($routes[$route_id]->set_variables($args));
     $request->set_route($routes[$route_id]);
     $request->set_method('post');
     $this->mvc->dispatcher->dispatch($request);
 }
Exemplo n.º 7
0
 public function test_intent_path()
 {
     $newreq = midgardmvc_core_request::get_for_intent('/subdir');
     $this->assertEquals('/subdir/', $newreq->get_path());
 }
Exemplo n.º 8
0
 public function test_serve()
 {
     $_ENV['MIDGARD_ENV_GLOBAL_CACHEDIR'] = '/tmp';
     $request = midgardmvc_core_request::get_for_intent('/');
     $routes = midgardmvc_core::get_instance()->component->get_routes($request);
     $request->set_route($routes['index']);
     midgardmvc_core::get_instance()->dispatcher->set_request($request);
     $request = midgardmvc_core::get_instance()->process();
     ob_start();
     midgardmvc_core::get_instance()->serve($request);
     $content = ob_get_clean();
     $this->assertTrue(strpos($content, '<h1 property="mgd:title">Midgard MVC</h1>') !== false);
 }