Inheritance: extends AppController
Ejemplo n.º 1
0
 public function onReceive($server, $fd, $fromId, $data)
 {
     //echo "receive \n";
     $tttt = new Schedule();
     $test = new TestController($server, $fd, $fromId, array());
     $tttt->add($test->test());
 }
Ejemplo n.º 2
0
 public function testOutput()
 {
     $obj = new TestController('id', Yii::$app);
     $this->assertEquals(0, $obj->outputInfo('info'));
     $this->assertEquals(0, $obj->outputSuccess('success'));
     $this->assertEquals(1, $obj->outputError('error'));
 }
 /**
  * @test
  */
 public function form_appears_and_saves()
 {
     Config::inst()->update('Controller', 'extensions', array('QuickFeedbackExtension'));
     $controller = new TestController();
     $result = $controller->handleRequest(new SS_HTTPRequest('GET', 'form_appears_and_saves'), DataModel::inst());
     $body = $result->getBody();
     $this->assertContains('Form_QuickFeedbackForm', $body);
     $this->assertContains('Form_QuickFeedbackForm_Rating', $body);
     $this->assertContains('Form_QuickFeedbackForm_Comment', $body);
     preg_match('/action="([^"]+)"/', $body, $action);
     if (!count($action)) {
         $this->fail('No form action');
     }
     preg_match('/name="SecurityID" value="([^"]+)"/', $body, $token);
     if (!count($action)) {
         $this->fail('No token');
     }
     $parts = explode('/', $action[1]);
     $action = end($parts);
     $time = time();
     $data = ['SecurityID' => $token[1], 'Rating' => '0', 'Comment' => 'comment at ' . $time];
     $controller->handleRequest(new SS_HTTPRequest('POST', $action, array(), $data), DataModel::inst());
     $existing = Feedback::get()->filter('Comment', 'comment at ' . $time)->first();
     if (!$existing) {
         $this->fail('Record missing');
     }
 }
Ejemplo n.º 4
0
 public function runIndex($searchValue, $formInput, $returnValue, $returnValue2 = null, $returnValue3 = null)
 {
     Input::replace($formInput);
     $controller = new TestController();
     $view = $controller->index();
     $tests = $view->getData()['testSet'];
     if (isset($returnValue3)) {
         $field3 = $returnValue3;
         $field2 = $returnValue2;
     } elseif (isset($returnValue2)) {
         $field2 = $returnValue2;
     }
     $field = $returnValue;
     if (is_numeric($searchValue) && $field == 'specimen_id' | $field == 'visit_id') {
         if ($searchValue == '0') {
             $this->assertEquals($searchValue, count($tests));
         } else {
             $this->assertGreaterThanOrEqual(1, count($tests));
         }
     } else {
         foreach ($tests as $key => $test) {
             if (isset($field3)) {
                 $this->assertEquals($searchValue, $test->{$field}->{$field2}->{$field3});
             } elseif (isset($field2)) {
                 $this->assertEquals($searchValue, $test->{$field}->{$field2});
             } else {
                 $this->assertEquals($searchValue, $test->{$field});
             }
         }
     }
 }
Ejemplo n.º 5
0
 public function onReceive($server, $fd, $fromId, $data)
 {
     $tttt = new Schedule();
     $test = new TestController($server, $fd, array());
     $tttt->add($test->test());
     $tttt->run();
     $this->server->send($fd, $data);
 }
Ejemplo n.º 6
0
 /**
  * Test cache key, no params
  * @TODO Possibly load the resulting markup as a DOM object and test various children in it; this would enforce valid markup
  */
 function testCacheKeyNoRequestParams()
 {
     $config = Config::getInstance();
     $config->setValue('cache_pages', true);
     $controller = new TestController(true);
     $results = $controller->go();
     $this->assertEqual($controller->getCacheKeyString(), '');
 }
Ejemplo n.º 7
0
 public function testDispatch()
 {
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $ctr = new TestController();
     $ctr->theme = $this->getMock('Theme', ['render']);
     $ctr->theme->expects($this->once())->method('render');
     $ctr->dispatch('test1');
     $this->assertEquals(1, $ctr->test1);
 }
Ejemplo n.º 8
0
 function testHeader()
 {
     ob_start();
     $test = new TestController();
     $test->update();
     $output = ob_get_contents();
     ob_end_clean();
     $this->assertTrue(in_array("Location: http://google.com", $test->header));
 }
Ejemplo n.º 9
0
 /**
  * Test that the Controller response object is working properly for get/set/unset of a controller property
  */
 public function testResponse()
 {
     $controller = new TestController();
     $response = new WikiaResponse('html');
     // setResponse and getResponse
     $controller->setResponse($response);
     $this->assertEquals($response, $controller->getResponse());
     // setVal and getVal
     $controller->foo = 'foo';
     $this->assertFalse(empty($controller->foo));
     $this->assertEquals($controller->foo, 'foo');
     // unset
     unset($controller->foo);
     $this->assertTrue(empty($controller->foo));
 }
 public function testRunAction()
 {
     $app = new TestApplication();
     $c = new TestController('test');
     $this->assertEquals($c->internal, 0);
     $this->assertEquals($c->external, 0);
     $this->assertEquals($c->internalFilter1, 0);
     $this->assertEquals($c->internalFilter2, 0);
     $this->assertEquals($c->internalFilter3, 0);
     $this->assertEquals($c->externalFilter, 0);
     $c->run('');
     $this->assertEquals($c->internal, 0);
     $this->assertEquals($c->external, 1);
     $this->assertEquals($c->internalFilter1, 1);
     $this->assertEquals($c->internalFilter2, 0);
     $this->assertEquals($c->internalFilter3, 1);
     $this->assertEquals($c->externalFilter, 1);
     $c->run('internal');
     $this->assertEquals($c->internal, 1);
     $this->assertEquals($c->external, 1);
     $this->assertEquals($c->internalFilter1, 2);
     $this->assertEquals($c->internalFilter2, 1);
     $this->assertEquals($c->internalFilter3, 1);
     $this->assertEquals($c->externalFilter, 2);
     $c->run('external');
     $this->assertEquals($c->internal, 1);
     $this->assertEquals($c->external, 1);
     $this->assertEquals($c->internalFilter1, 3);
     $this->assertEquals($c->internalFilter2, 1);
     $this->assertEquals($c->internalFilter3, 1);
     $this->assertEquals($c->externalFilter, 2);
     $this->setExpectedException('CException');
     $c->run('unknown');
 }
Ejemplo n.º 11
0
 public function testActionClassDiffNameAndParams()
 {
     global $testquery, $testpost;
     $testquery = array();
     $testpost = array();
     $testpost['userid'] = 'johnsmith';
     $testpost['user_Name'] = 'john';
     $testpost['user_Age'] = '22';
     $testpost['user_Hcp'] = '10,7';
     $tc = new TestController();
     $tc->init();
     $tc->executeAction('paramsClassAndParam2');
     $this->assertInstanceOf('Person', $tc->person);
     $this->assertEquals('john', $tc->person->Name);
     $this->assertEquals('johnsmith', $tc->userid);
 }
 public function test_post_reauthenticate_returns_redirect()
 {
     $user = new TestUser();
     $user->password = bcrypt('test');
     Auth::shouldReceive('user')->once()->andReturn($user);
     Session::set('url.intended', 'http://reauthenticate.app/auth/reauthenticate');
     $request = \Illuminate\Http\Request::create('http://reauthenticate.app/auth/reauthenticate', 'POST', ['password' => 'test']);
     $request->setSession(app('session.store'));
     $controller = new TestController();
     /** @var Illuminate\Http\RedirectResponse $response */
     $response = $controller->postReauthenticate($request);
     $this->assertInstanceOf(Illuminate\Http\RedirectResponse::class, $response);
     $this->assertEquals('http://reauthenticate.app/auth/reauthenticate', $response->getTargetUrl());
     $this->assertTrue(Session::has('reauthenticate.life'));
     $this->assertTrue(Session::has('reauthenticate.authenticated'));
     $this->assertTrue(Session::get('reauthenticate.authenticated'));
 }
Ejemplo n.º 13
0
 static function addRoutes($app, $authenticateForRole)
 {
     //* /test/ routes - publicly accessable test route
     $app->group('/api-test', $authenticateForRole('public'), function () use($app) {
         $app->map("/get/status/", function () use($app) {
             TestController::getApiStatus($app);
         })->via('GET', 'POST');
     });
 }
 public function testARBGetSubscriptionList()
 {
     $this->markTestSkipped('Ignoring for Travis. Will fix after release.');
     //TODO
     $name = defined('AUTHORIZENET_API_LOGIN_ID') && '' != AUTHORIZENET_API_LOGIN_ID ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
     $transactionKey = defined('AUTHORIZENET_TRANSACTION_KEY') && '' != AUTHORIZENET_TRANSACTION_KEY ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");
     $merchantAuthentication = new net\authorize\api\contract\v1\MerchantAuthenticationType();
     $merchantAuthentication->setName($name);
     $merchantAuthentication->setTransactionKey($transactionKey);
     //$merchantAuthentication->setMobileDeviceId()
     $refId = 'ref' . time();
     $sorting = new net\authorize\api\contract\v1\ARBGetSubscriptionListSortingType();
     $sorting->setOrderBy('firstName');
     $sorting->setOrderDescending(false);
     $paging = new net\authorize\api\contract\v1\PagingType();
     $paging->setLimit(10);
     $paging->setOffset(1);
     $request = new net\authorize\api\contract\v1\ARBGetSubscriptionListRequest();
     $request->setSearchType('subscriptionActive');
     $request->setRefId($refId);
     $request->setSorting($sorting);
     $request->setPaging($paging);
     $request->setMerchantAuthentication($merchantAuthentication);
     //$controller = new ApiOperationBase($request, 'net\authorize\api\contract\v1\ARBGetSubscriptionListResponse');
     $controller = new TestController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     // Handle the response.
     $this->assertNotNull($response, "null response");
     $this->assertNotNull($response->getMessages());
     $this->assertEquals("Ok", $response->getMessages()->getResultCode());
     $this->assertEquals($response->getRefId(), $refId);
     $this->assertTrue(0 < count($response->getMessages()));
     foreach ($response->getMessages() as $message) {
         $this->assertEquals("I00001", $message->getCode());
         $this->assertEquals("Successful.", $response->getText());
     }
 }
Ejemplo n.º 15
0
 public static function initController()
 {
     TestController::$control = new TestController();
 }
Ejemplo n.º 16
0
 /**
  * Test JController::getTasks
  *
  * @covers  JController::getTasks
  */
 public function testGetTasks()
 {
     $class = new TestController();
     // The available tasks should be the public tasks in the derived controller plus "display".
     $this->assertEquals(array('task1', 'task2', 'display'), $class->getTasks());
 }
Ejemplo n.º 17
0
	/**
	 * Test JController::getTasks
	 */
	public function testGetTasks()
	{
		$controller = new TestController;

		$this->assertThat(
			$controller->getTasks(),
			$this->equalTo(
				array(
					'task1', 'task2', 'display'
				)
			),
			'Line:'.__LINE__.' The available tasks should be the public tasks in the derived controller plus "display".'
		);
	}
Ejemplo n.º 18
0
 public function testCalcCategoriesScore()
 {
     $questions = array('1' => array('category' => '1', 'score' => 1.5, 'weight' => 3), '2' => array('category' => '2', 'score' => 0.5, 'weight' => 1), '3' => array('category' => '1', 'score' => 1.0, 'weight' => 1), '4' => array('category' => '2', 'score' => 1.0, 'weight' => 2));
     $category = array('1' => 'category1', '2' => 'category2');
     $expectation = array('category1' => 75, 'category2' => 50);
     $this->assertEquals($expectation, TestController::calcCategoriesScore($questions, $category));
 }
Ejemplo n.º 19
0
<?php

/**
 * This is a Anax frontcontroller.
 *
 */
// Get environment & autoloader.
require __DIR__ . '/../config.php';
// Create services and inject into the app.
$di = new \Anax\DI\CDIFactoryTest();
$app = new \Anax\Kernel\CAnax($di);
$di->set('TestController', function () use($di) {
    $controller = new TestController();
    $controller->setDI($di);
    return $controller;
});
class TestController
{
    use \Anax\DI\TInjectable;
    public function indexAction()
    {
        $this->theme->setTitle("How verbose is the error reporting");
        $this->views->add('default/page', ['title' => "Testing error reporting from Anax MVC", 'content' => "Trying out some missusage of Anax MVC to see if the errors are easy to understand.", 'links' => [['href' => $this->url->create('t1'), 'text' => "Using not defined service as property of \$app"], ['href' => $this->url->create('t2'), 'text' => "Using not defined service as method of \$app"], ['href' => $this->url->create('t3'), 'text' => "Forward to non-existing controller"], ['href' => $this->url->create('t4'), 'text' => "Forward to non-existing action"], ['href' => $this->url->create('test/no-di-call'), 'text' => "Using TInjectable forgot to set \$di, accessing session() via __call()"], ['href' => $this->url->create('test/no-di-get'), 'text' => "Using TInjectable forgot to set \$di, accessing session via __get()"], ['href' => $this->url->create('test/no-such-service-property'), 'text' => "Using TInjectable forgot to set \$di, accessing session() via __call()"], ['href' => $this->url->create('test/no-such-service-method'), 'text' => "Using TInjectable forgot to set \$di, accessing session via __get()"]]]);
    }
    public function noDiCallAction()
    {
        $this->di = null;
        $this->session();
    }
    public function noDiGetAction()
    {
Ejemplo n.º 20
0
 /**
  * test invoking controller methods.
  *
  * @return void
  */
 public function testInvokeActionReturnValue()
 {
     $url = new CakeRequest('test/returner/');
     $url->addParams(array('controller' => 'test_controller', 'action' => 'returner', 'pass' => array()));
     $response = $this->getMock('CakeResponse');
     $Controller = new TestController($url, $response);
     $result = $Controller->invokeAction($url);
     $this->assertEquals('I am from the controller.', $result);
 }
Ejemplo n.º 21
0
 public function testActionParamsInvalid()
 {
     $app = new TestApplication();
     $c = new TestController('test');
     $_GET = array('a' => 1);
     $this->setExpectedException('CException');
     $c->run('create');
 }
Ejemplo n.º 22
0
 protected function createController()
 {
     $c = new TestController();
     $c->setResponse(new Sabel_Response_Object());
     return $c;
 }
Ejemplo n.º 23
0
 /**
  * Test exception handling
  */
 public function testExceptionHandling()
 {
     $_GET['throwexception'] = 'yesindeedy';
     $controller = new TestController(true);
     $results = $controller->go();
     $v_mgr = $controller->getViewManager();
     $config = Config::getInstance();
     $this->assertEqual('Testing exception handling!', $v_mgr->getTemplateDataItem('error_msg'));
     $this->assertPattern('/<html/', $results);
     $_GET['json'] = true;
     $results = $controller->go();
     $this->debug($results);
     $this->assertFalse(strpos($results, '<html'));
     $this->assertPattern('/{/', $results);
     $this->assertPattern('/Testing exception handling/', $results);
     $this->assertEqual('Exception', $v_mgr->getTemplateDataItem('error_type'));
     unset($_GET['json']);
     $_GET['text'] = true;
     $results = $controller->go();
     $this->assertFalse(strpos($results, '<html'));
     $this->assertFalse(strpos($results, '{'));
     $this->assertPattern('/Testing exception handling/', $results);
     $this->assertEqual('Exception', $v_mgr->getTemplateDataItem('error_type'));
     unset($_GET['text']);
 }
 /**
  * @testdox  The available tasks should be the public tasks in the derived controller plus "display".
  *
  * @covers   JControllerLegacy::getTasks
  */
 public function testGetTasks()
 {
     $class = new TestController();
     $this->assertEquals(array('task1', 'task2', 'display'), $class->getTasks());
 }
Ejemplo n.º 25
0
    {
        return $this->echoAction('delete', $id);
    }
    public function actionProd($prod_id, $id)
    {
        print_r(['$prod_id' => $prod_id, '$id' => $id]);
        return $this->echoAction('prod', [$prod_id, $id]);
    }
    private function echoAction($actionName, $opts = null)
    {
        $json = ['action' => $actionName, 'options' => $opts];
        return $json;
    }
}
echo '<pre>';
TestController::register(['GET test' => "default", 'POST test' => "create", 'GET test/{id}' => "read", 'PUT test/{id}' => "update", 'DELETE test/{id}' => "delete", 'GET test/{id}/prod/{prod_id}' => "prod"], ['id' => '\\d+', 'prod_id' => '\\d+']);
function test($name, $route, $method, $action)
{
    $res = Router::dispatch($route, $method);
    if ($action == $res['action']) {
        echo "Test '{$name}' [{$method} {$route}] passed\n";
    } else {
        echo "Test '{$name}' [{$method} {$route}] NOT passed\n";
    }
}
test('', 'test', 'GET', 'default');
test('when route does not exist', 'test', 'PUT', null);
test('', 'test', 'POST', 'create');
test('', 'test/1', 'GET', 'read');
test('', 'test/1', 'PUT', 'update');
test('', 'test/1', 'DELETE', 'delete');
Ejemplo n.º 26
0
 /**
  * testValidateErrors method
  *
  * @access public
  * @return void
  */
 function testValidateErrors()
 {
     $TestController = new TestController();
     $TestController->constructClasses();
     $this->assertFalse($TestController->validateErrors());
     $this->assertEqual($TestController->validate(), 0);
     $TestController->ControllerComment->invalidate('some_field', 'error_message');
     $TestController->ControllerComment->invalidate('some_field2', 'error_message2');
     $comment = new ControllerComment();
     $comment->set('someVar', 'data');
     $result = $TestController->validateErrors($comment);
     $expected = array('some_field' => 'error_message', 'some_field2' => 'error_message2');
     $this->assertIdentical($result, $expected);
     $this->assertEqual($TestController->validate($comment), 2);
 }
Ejemplo n.º 27
0
 function testControllerName()
 {
     $Controller = new TestController();
     $this->assertEquals('Test', $Controller->getControllerName());
 }
Ejemplo n.º 28
0
 /**
  *
  */
 public static function __init($app, array $config = array())
 {
     self::$app = $app;
 }
Ejemplo n.º 29
0
 /**
  * testRender method
  *
  * @access public
  * @return void
  */
 function testRender()
 {
     Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS));
     $Controller =& new Controller();
     $Controller->viewPath = 'posts';
     $result = $Controller->render('index');
     $this->assertPattern('/posts index/', $result);
     $result = $Controller->render('/elements/test_element');
     $this->assertPattern('/this is the test element/', $result);
     $Controller = new TestController();
     $Controller->constructClasses();
     $Controller->ControllerComment->validationErrors = array('title' => 'tooShort');
     $expected = $Controller->ControllerComment->validationErrors;
     ClassRegistry::flush();
     $Controller->viewPath = 'posts';
     $result = $Controller->render('index');
     $View = ClassRegistry::getObject('view');
     $this->assertTrue(isset($View->validationErrors['ControllerComment']));
     $this->assertEqual($expected, $View->validationErrors['ControllerComment']);
     $Controller->ControllerComment->validationErrors = array();
     ClassRegistry::flush();
 }
Ejemplo n.º 30
0
<?php

require_once __DIR__ . '/../common.php';
class TestController extends Controller
{
    function __construct()
    {
        parent::__construct();
    }
    function __destruct()
    {
        parent::__destruct();
    }
    function checkProcess()
    {
        try {
            $pdo_master = pdo_factory($this->db->master);
            $model = new Model($pdo_master);
            $model->setTableName('test');
            print_r($Model->findAll('stdClass'));
            // 結果を取得し表示
        } catch (Exception $e) {
            print_r($e);
        }
    }
}
$testController = new TestController();
$testController->checkProcess();
// Processテーブルを確認