Beispiel #1
0
 /**
  * Testing that a BO attached to a controller that contains tags will have those tags mapped to the controller's keywords.
  *
  * @since 1.0
  */
 public function testTagsMapToMetaKeywords()
 {
     ActiveRecord::begin();
     $this->article->save();
     ActiveRecord::commit();
     $tags = $this->article->getPropObject('tags')->getRelatedObjects();
     $found = false;
     foreach ($tags as $tag) {
         if ($tag->get('content') == 'unittestarticle') {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'Testing the Tag::tokenize method returns a tag called "unittestarticle"');
     $this->controller->setRecord($this->article);
     $this->assertEquals('unittestarticle,unittestarticletagone,unittestarticletagtwo', $this->controller->getKeywords(), 'Testing that a BO attached to a controller that contains tags will have those tags mapped to the controller\'s keywords');
 }
Beispiel #2
0
 /**
  * The constructor method.
  *
  * @throws Alpha\Exception\BadRequestException
  *
  * @since 1.0
  */
 public function __construct()
 {
     self::$logger = new Logger('FrontController');
     self::$logger->debug('>>__construct()');
     $config = ConfigProvider::getInstance();
     mb_internal_encoding('UTF-8');
     mb_http_output('UTF-8');
     mb_http_input('UTF-8');
     ini_set('default_charset', 'utf-8');
     if (!mb_check_encoding()) {
         throw new BadRequestException('Request character encoding does not match expected UTF-8');
     }
     $this->addRoute('/', function ($request) {
         $controller = new IndexController();
         return $controller->process($request);
     });
     $this->addRoute('/a/{title}/{view}', function ($request) {
         $controller = new ArticleController();
         return $controller->process($request);
     })->value('title', null)->value('view', 'detailed');
     $this->addRoute('/articles/{start}/{limit}', function ($request) {
         $controller = new ArticleController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/attach/{articleOID}/{filename}', function ($request) {
         $controller = new AttachmentController();
         return $controller->process($request);
     });
     $this->addRoute('/cache', function ($request) {
         $controller = new CacheController();
         return $controller->process($request);
     });
     $this->addRoute('/denum/{denumOID}', function ($request) {
         $controller = new DEnumController();
         return $controller->process($request);
     })->value('denumOID', null);
     $this->addRoute('/excel/{ActiveRecordType}/{ActiveRecordOID}', function ($request) {
         $controller = new ExcelController();
         return $controller->process($request);
     })->value('ActiveRecordOID', null);
     $this->addRoute('/feed/{ActiveRecordType}/{type}', function ($request) {
         $controller = new FeedController();
         return $controller->process($request);
     })->value('type', 'Atom');
     $this->addRoute('/gensecure', function ($request) {
         $controller = new GenSecureQueryStringController();
         return $controller->process($request);
     });
     $this->addRoute('/image/{source}/{width}/{height}/{type}/{quality}/{scale}/{secure}/{var1}/{var2}', function ($request) {
         $controller = new ImageController();
         return $controller->process($request);
     })->value('var1', null)->value('var2', null);
     $this->addRoute('/listactiverecords', function ($request) {
         $controller = new ListActiveRecordsController();
         return $controller->process($request);
     });
     $this->addRoute('/log/{logPath}', function ($request) {
         $controller = new LogController();
         return $controller->process($request);
     });
     $this->addRoute('/login', function ($request) {
         $controller = new LoginController();
         return $controller->process($request);
     });
     $this->addRoute('/logout', function ($request) {
         $controller = new LogoutController();
         return $controller->process($request);
     });
     $this->addRoute('/metric', function ($request) {
         $controller = new MetricController();
         return $controller->process($request);
     });
     $this->addRoute('/recordselector/12m/{ActiveRecordOID}/{field}/{relatedClass}/{relatedClassField}/{relatedClassDisplayField}/{relationType}', function ($request) {
         $controller = new RecordSelectorController();
         return $controller->process($request);
     })->value('relationType', 'ONE-TO-MANY');
     $this->addRoute('/recordselector/m2m/{ActiveRecordOID}/{field}/{relatedClassLeft}/{relatedClassLeftDisplayField}/{relatedClassRight}/{relatedClassRightDisplayField}/{accessingClassName}/{lookupOIDs}/{relationType}', function ($request) {
         $controller = new RecordSelectorController();
         return $controller->process($request);
     })->value('relationType', 'MANY-TO-MANY');
     $this->addRoute('/search/{query}/{start}/{limit}', function ($request) {
         $controller = new SearchController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/sequence/{start}/{limit}', function ($request) {
         $controller = new SequenceController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/tag/{ActiveRecordType}/{ActiveRecordOID}', function ($request) {
         $controller = new TagController();
         return $controller->process($request);
     });
     $this->addRoute('/install', function ($request) {
         $controller = new InstallController();
         return $controller->process($request);
     });
     $this->addRoute('/record/{ActiveRecordType}/{ActiveRecordOID}/{view}', function ($request) {
         $controller = new ActiveRecordController();
         return $controller->process($request);
     })->value('ActiveRecordOID', null)->value('view', 'detailed');
     $this->addRoute('/records/{ActiveRecordType}/{start}/{limit}', function ($request) {
         $controller = new ActiveRecordController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/tk/{token}', function ($request) {
         $params = self::getDecodeQueryParams($request->getParam('token'));
         if (isset($params['act'])) {
             $className = $params['act'];
             if (class_exists($className)) {
                 $controller = new $className();
                 if (isset($params['ActiveRecordType']) && $params['act'] == 'Alpha\\Controller\\ActiveRecordController') {
                     $customController = $controller->getCustomControllerName($params['ActiveRecordType']);
                     if ($customController != null) {
                         $controller = new $customController();
                     }
                 }
                 $request->setParams(array_merge($params, $request->getParams()));
                 return $controller->process($request);
             }
         }
         self::$logger->warn('Bad params [' . print_r($params, true) . '] provided on a /tk/ request');
         return new Response(404, 'Resource not found');
     });
     $this->addRoute('/alpha/service', function ($request) {
         $controller = new LoginController();
         $controller->setUnitOfWork(array('Alpha\\Controller\\LoginController', 'Alpha\\Controller\\ListActiveRecordsController'));
         return $controller->process($request);
     });
     $this->addRoute('/phpinfo', function ($request) {
         $controller = new PhpinfoController();
         return $controller->process($request);
     });
     self::$logger->debug('<<__construct');
 }
Beispiel #3
0
 /**
  * Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD.
  */
 public function testHTTPMethodOverride()
 {
     $front = new FrontController();
     $front->addRoute('/image', function ($request) {
         $controller = new ImageController();
         return $controller->process($request);
     });
     $request = new Request(array('method' => 'DELETE', 'URI' => '/image'));
     try {
         $response = $front->process($request);
         $this->fail('Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
     } catch (\Exception $e) {
         $this->assertEquals('The DELETE method is not supported by this controller', $e->getMessage(), 'Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
     }
     $_POST['_METHOD'] = 'OPTIONS';
     $request = new Request(array('method' => 'DELETE', 'URI' => '/image'));
     $response = $front->process($request);
     $this->assertEquals(200, $response->getStatus(), 'Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
     $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'OPTIONS';
     $request = new Request(array('method' => 'DELETE', 'URI' => '/image'));
     $response = $front->process($request);
     $this->assertEquals(200, $response->getStatus(), 'Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD');
 }