Ejemplo n.º 1
2
 protected function createRequest($method = 'GET')
 {
     $request = LaravelRequest::createFromBase(LaravelRequest::create('/', 'GET'));
     if ($method !== null) {
         $request->headers->set('Access-Control-Request-Method', $method);
     }
     return new Request($request);
 }
Ejemplo n.º 2
1
 protected function createRequest($origin = null)
 {
     $request = LaravelRequest::createFromBase(LaravelRequest::create('/', 'GET'));
     if ($origin !== null) {
         $request->headers->set('Origin', $origin);
     }
     return new Request($request);
 }
Ejemplo n.º 3
0
 /**
  * @param $uri
  * @param $method
  * @param array $parameters
  * @param bool $collection
  *
  * @return mixed|string
  */
 public function call($uri, $method, $parameters = [], $collection = true)
 {
     try {
         $origin_input = $this->request->input();
         $request = $this->request->create($uri, $method, $parameters);
         $this->request->replace($request->input());
         $dispatch = $this->router->dispatch($request);
         $this->request->replace($origin_input);
         return $this->getResponse($dispatch, $dispatch->getContent(), $collection);
     } catch (NotFoundHttpException $e) {
         throw new NotFoundHttpException('Request Not Found.');
     }
 }
Ejemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $inputs = array('des_name', 'des_coors', 'des_instruction', 'related_photos');
         $obj = array('message' => 'succeeded');
         foreach ($inputs as $field) {
             $obj[$field] = $request->input($field, '');
         }
         // TODO: cuối cùng vẫn phải chạy Raw SQL -_-
         $destination = DB::table('Destination')->insertGetId(array('des_name' => $obj['des_name'], 'des_instruction' => $obj['des_instruction'], 'coordinate' => DB::raw("GeomFromText(\"POINT(" . $obj['des_coors']['latitude'] . " " . $obj['des_coors']['longitude'] . ")\")")));
         // upload selected images too
         $images_uploaded = array();
         $relPhotos = $obj['related_photos'];
         if ($relPhotos) {
             foreach ($relPhotos as $photo) {
                 if ($photo['selected']) {
                     $rq = Request::create("/admin/destination/{$destination}/photo", "POST", [], [], [], [], array('photo_url' => $photo['url'], 'photo_like' => rand(0, 100)));
                     array_push($images_uploaded, Route::dispatch($rq)->getContent());
                 }
             }
         }
         return response()->json(array('addedObject' => Destination::find($destination), 'addedPhotos' => $images_uploaded));
     } catch (\Exception $e) {
         return response()->json($e);
     }
 }
Ejemplo n.º 5
0
 /**
  * Setup test environment.
  */
 public function setUp()
 {
     $this->app = new Application();
     $this->app['request'] = Request::create('/');
     $this->app['html'] = new HTML($this->app);
     $this->form = new Form($this->app);
 }
 /**
  * Setup the test environment.
  */
 public function setUp()
 {
     $this->urlGenerator = new UrlGenerator(new RouteCollection(), Request::create('/foo', 'GET'));
     $this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
     $this->siteKey = 'my-site-key';
     $this->recaptchaBuilder = new RecaptchaBuilder($this->siteKey, $this->htmlBuilder);
 }
Ejemplo n.º 7
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     $uri = '/' . ltrim($uri, '/');
     // Parameters for GET, POST
     $parameters = $parameters ? current($parameters) : array();
     try {
         // store the original request data and route
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // create a new request to the API resource
         $request = $this->request->create($uri, strtoupper($method), $parameters);
         // replace the request input...
         $this->request->replace($request->input());
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // replace the request input and route back to the original state
         $this->request->replace($originalInput);
         $this->router->setCurrentRoute($originalRoute);
         return $response;
     } catch (NotFoundHttpException $e) {
     }
 }
 public function testShouldUpdate()
 {
     // create user and logged in (the user who will perform the action)
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create the group that we will be updating
     $blogger = Group::create(array('name' => 'blogger', 'permissions' => array('blog.list' => 1, 'blog.create' => 1, 'blog.edit' => 1, 'blog.delete' => -1)));
     // dummy request
     // we will update the blogger group that it will not be able to create a blog now
     $request = Request::create('', 'POST', array('id' => $blogger->id, 'name' => 'blogger-renamed', 'permissions' => array('blog.list' => 1, 'blog.create' => -1, 'blog.edit' => 1, 'blog.delete' => -1)));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\User\\Commands\\UpdateGroupCommand', array('id' => $request->get('id', null), 'name' => $request->get('name', null), 'permissions' => $request->get('permissions', array())));
     $this->assertTrue($result->isSuccessful(), 'Transaction should be successful.');
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be 200.');
     $this->assertEquals('Group successfully updated.', $result->getMessage());
     // now prove it has been updated
     $updatedGroup = Group::find($result->getData()->id);
     //$this->assertEquals('blogger-renamed', $updatedGroup->name);
     $this->assertArrayHasKey('blog.list', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.list');
     $this->assertArrayHasKey('blog.create', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.create');
     $this->assertArrayHasKey('blog.edit', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.edit');
     $this->assertArrayHasKey('blog.delete', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.delete');
     $this->assertEquals(1, $updatedGroup->getPermissionsAttribute()['blog.list'], 'Permission blog.list should be allow');
     $this->assertEquals(-1, $updatedGroup->getPermissionsAttribute()['blog.create'], 'Permission blog.create should be deny');
     $this->assertEquals(1, $updatedGroup->getPermissionsAttribute()['blog.edit'], 'Permission blog.edit should be allow');
     $this->assertEquals(-1, $updatedGroup->getPermissionsAttribute()['blog.delete'], 'Permission blog.delete should be deny');
 }
 public function index()
 {
     $dataAccess = new ClientMng();
     //$clients = $dataAccess->getClientsFromUsers();
     $request = Request::create('/api/clients', 'GET');
     $response = Route::dispatch($request);
     $obj = json_decode($response->content(), true);
     $clients = $obj["data"];
     if (\Request::has('search')) {
         $query = \Request::get('search');
         $results = $dataAccess->search($query);
         if (count($results) < 1) {
             $results = $dataAccess->searchRaw($query);
         }
         return \View::make('clientlist')->with('clients', $results);
     }
     //$obj2 = $obj["data"];
     //        foreach($obj as $i)
     //        {
     //            //echo $i[1]["firstName"];
     //            //echo print_r($i);
     //            array_push($obj2, $i);
     //        }
     //echo $response;
     //echo print_r($obj2);
     //echo $clients[0]["id"];
     //echo $response->content();
     //echo print_r($obj2);
     return \View::make('clientlist')->with('clients', $clients);
 }
Ejemplo n.º 10
0
 public function testValidCredentialsReturnsUser()
 {
     $request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);
     $this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(null);
     $this->auth->shouldReceive('user')->once()->andReturn('foo');
     $this->assertEquals('foo', $this->provider->authenticate($request, new Route(['GET'], '/', [])));
 }
Ejemplo n.º 11
0
 /** @test */
 public function it_should_return_false_if_no_token_in_request()
 {
     $request = Request::create('foo', 'GET', ['foo' => 'bar']);
     $parser = new TokenParser($request);
     $this->assertFalse($parser->parseToken());
     $this->assertFalse($parser->hasToken());
 }
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function confirmation(Request $request)
 {
     $ticketIds = array_filter(array_unique(preg_split('/(\\s|,)/', $request['tickets'])), 'is_numeric');
     if (empty($ticketIds)) {
         return redirect('/');
     }
     $projectId = $request['project'];
     // no leading zeros
     $ticketIds = array_map(function ($value) {
         return ltrim($value, '0 ');
     }, $ticketIds);
     /** @var \Illuminate\Database\Eloquent\Collection $doubledTickets */
     $doubledTickets = Ticket::whereIn('id', $ticketIds)->where('project_id', $projectId)->get();
     // in case there are no doubled tickets we will directly print all tickets
     if ($doubledTickets->isEmpty()) {
         /** @var Request $request */
         $request = Request::create('/printAction', 'POST', ['tickets' => implode(',', $this->buildTicketNames($ticketIds, $projectId))]);
         return $this->printAction($request);
     } else {
         // to reprint doubled Tickets we need a confirmation
         $freshTicketIds = array_diff($ticketIds, $doubledTickets->lists('id')->toArray());
         $freshTicketIds = $this->buildTicketNames($freshTicketIds, $projectId);
         return view('pages.confirmation')->with('doubledTickets', $doubledTickets)->with('freshTicketIds', implode(',', $freshTicketIds))->with('project', $projectId);
     }
 }
Ejemplo n.º 13
0
 public function testGettingUserWhenNotAuthenticatedAttemptsToAuthenticateAndReturnsNull()
 {
     $this->router->setCurrentRoute($route = new Route(['GET'], 'foo', ['protected' => true]));
     $this->router->setCurrentRequest($request = Request::create('foo', 'GET'));
     $auth = new Authenticator($this->router, $this->container, ['provider' => Mockery::mock('Dingo\\Api\\Auth\\Provider')]);
     $this->assertNull($auth->user());
 }
 /**
  * Setup the test environment.
  */
 public function setUp()
 {
     $this->urlGenerator = new UrlGenerator(new RouteCollection(), Request::create('/foo', 'GET'));
     $this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
     $this->formBuilder = new FoundationFiveFormBuilder($this->htmlBuilder, $this->urlGenerator, 'abc', new ViewErrorBag());
     $this->attributes = ['id' => 'test-input'];
 }
Ejemplo n.º 15
0
 public function testValidationPassesWithDifferentProtocols()
 {
     $validator = new Domain('ftp://foo.bar');
     $this->assertTrue($validator->validate(Request::create('http://foo.bar', 'GET')), 'Validation failed when it should have passed with a valid domain.');
     $validator = new Domain('https://foo.bar');
     $this->assertTrue($validator->validate(Request::create('http://foo.bar', 'GET')), 'Validation failed when it should have passed with a valid domain.');
 }
Ejemplo n.º 16
0
 public function setUp()
 {
     Carbon::setTestNow(Carbon::createFromTimeStampUTC(123));
     $this->claimFactory = Mockery::mock('Tymon\\JWTAuth\\Claims\\Factory');
     $this->validator = Mockery::mock('Tymon\\JWTAuth\\Validators\\PayloadValidator');
     $this->factory = new PayloadFactory($this->claimFactory, Request::create('/foo', 'GET'), $this->validator);
 }
 public function testQuery()
 {
     // create user and logged in (the user who will perform the action)
     $user = User::create(array('first_name' => 'dianne', 'email' => '*****@*****.**', 'password' => 'pass$dianne', 'permissions' => array('user.manage' => 1)));
     // logged in the user
     $this->application['auth']->loginUsingId($user->id);
     // create dummy groups to be evaluated with
     $this->createGroups();
     // -----------------
     // QUERY ALL
     // -----------------
     // dummy request, required first name
     $request = Request::create('', 'GET', array('name' => null, 'with' => array(), 'paginate' => false));
     $results = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\QueryGroupsCommand', $request);
     $this->assertTrue($results->isSuccessful(), 'Transaction should be good');
     $this->assertEquals(200, $results->getStatusCode(), 'Status code should be 200');
     $this->assertEquals('Query groups command successful.', $results->getMessage());
     $this->assertCount(3, $results->getData()->toArray(), 'There should be 3 groups');
     // -----------------
     // QUERY BY NAME
     // -----------------
     // dummy request, required first name
     $request = Request::create('', 'GET', array('name' => 'blogger', 'with' => array(), 'paginate' => false));
     $results = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\QueryGroupsCommand', $request);
     $this->assertTrue($results->isSuccessful(), 'Transaction should be good');
     $this->assertEquals(200, $results->getStatusCode(), 'Status code should be 200');
     $this->assertEquals('Query groups command successful.', $results->getMessage());
     $this->assertCount(1, $results->getData()->toArray(), 'There should be 1 group');
 }
Ejemplo n.º 18
0
 public function testAuthenticatingWithQueryStringSucceedsAndReturnsUserObject()
 {
     $request = Request::create('foo', 'GET', ['token' => 'foo']);
     $this->auth->shouldReceive('setToken')->with('foo')->andReturn(m::self());
     $this->auth->shouldReceive('authenticate')->once()->andReturn((object) ['id' => 1]);
     $this->assertEquals(1, $this->provider->authenticate($request, m::mock('Dingo\\Api\\Routing\\Route'))->id);
 }
Ejemplo n.º 19
0
 public function testNormalResponseIsReturnedIfMethodIsMissing()
 {
     $request = Request::create('/', 'POST', [], [], [], [], json_encode(['type' => 'foo.bar', 'id' => 'event-id']));
     $controller = new WebhookControllerTestStub();
     $response = $controller->handleWebhook($request);
     $this->assertEquals(200, $response->getStatusCode());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $dataAccess = new ClientMng();
     $dataAccess1 = new DataAccess();
     $id = $dataAccess1->currentUserID();
     $patient = $dataAccess->getPatient($id);
     $list = ['userid' => $id, 'firstName' => $patient["firstName"], 'lastName' => $patient["lastName"], 'dob' => "{$request->year}-{$request->month}-{$request->day}", 'email' => $patient["email"], 'gender' => $request->sex, 'height' => $request->height, 'weight' => $request->weight, 'mobileNum' => $request->phone, 'homeNum' => $request->home_phone, 'address' => $request->address, 'city' => $request->city, 'postalCode' => $request->postal_code, 'state' => $request->state, 'country' => $request->country, 'occupation' => $request->occupation, 'maritalStatus' => $request->status, 'nextOfKin' => $request->next_kin];
     $dataAccess->clientInfoSave($list, Auth::user()->email);
     $json = json_encode(array("data" => $list));
     //
     //        $server = ['Content-Type'=>"application/json"];
     //        //"$uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null"
     //
     $postRequest = Request::create('/api/clients', 'POST', [], [], [], [], $json);
     $headers = $postRequest->headers;
     $headers->set('Content-Type', 'application/json');
     $headers->set('Accept', 'application/json');
     //echo print_r($headers);
     $response = Route::dispatch($postRequest);
     //        $postRequest->headers = array('CONTENT_TYPE'=> 'application/json');
     //        $postRequest->attributes = $json;
     //        $response = Route::dispatch($postRequest);
     //echo print_r($postRequest);
     //echo $postRequest;
     ////
     //        $headers = array();
     //        $headers[] = 'Content-Type: application/json';
     //        $username = "******";
     //        $password = "******";
     //
     //        // create a new cURL resource
     //        $ch = curl_init();
     //
     //        // set URL and other appropriate options
     //        curl_setopt($ch, CURLOPT_URL, "http://localhost:8000/api/clients");
     //        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     //        curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
     //        curl_setopt($ch, CURLOPT_POST, 1);
     //        curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
     //        curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
     //        curl_setopt ($ch, CURLOPT_PORT , 8089);
     //
     //        // grab URL and pass it to the browser
     //        $response = curl_exec($ch);
     //        echo print_r($response);
     //        $info = curl_getinfo($ch);
     //        echo print_r($info["http_code"]);
     //
     ////        if ($response === false)
     ////        {
     ////            // throw new Exception('Curl error: ' . curl_error($crl));
     ////            print_r('Curl error: ' . curl_error($response));
     ////        }
     //        //echo $response;
     //
     //        // close cURL resource, and free up system resources
     //        curl_close($ch);
     return redirect('home');
 }
Ejemplo n.º 21
0
 public function setUp()
 {
     $this->request = Request::create('/foo', 'GET', ['__order__' => 'asc', '__sort__' => 'id', 'another' => 1]);
     $this->url = new Illuminate\Routing\UrlGenerator(new Illuminate\Routing\RouteCollection(), $this->request);
     $this->viewFactory = m::mock(Factory::class);
     $this->html = new Collective\Html\HtmlBuilder($this->url, $this->viewFactory);
     $this->sorter = new Sorter($this->url, $this->html, $this->request, '__sort__', '__order__');
 }
Ejemplo n.º 22
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testExceptionIsThrownWhenVerifierIsMissing()
 {
     $server = m::mock('League\\OAuth1\\Client\\Server\\Twitter');
     $request = Request::create('foo');
     $request->setSession($session = m::mock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'));
     $provider = new OAuthOneTestProviderStub($request, $server);
     $user = $provider->user();
 }
Ejemplo n.º 23
0
 /**
  * Setup the test environment.
  */
 public function setUp()
 {
     $this->urlGenerator = new UrlGenerator(new RouteCollection(), Request::create('/foo', 'GET'));
     $this->viewFactory = new ViewFactory(new EngineResolver(), new FileViewFinder($this->getMock('Illuminate\\Filesystem\\Filesystem'), []), $this->getMock('Illuminate\\Events\\Dispatcher'));
     $this->htmlBuilder = new HtmlBuilder($this->urlGenerator, $this->viewFactory);
     $this->formBuilder = new FoundationFiveFormBuilder($this->htmlBuilder, $this->urlGenerator, $this->viewFactory, 'abc', new ViewErrorBag());
     $this->attributes = ['id' => 'test-input'];
 }
Ejemplo n.º 24
0
 public function request($method, $service_name, $uri, $params = [])
 {
     $uri = trim($uri, '/ ');
     $uri = "/service/{$service_name}/{$uri}";
     $request = Request::create($uri, $method, $params);
     $response = app()->handle($request)->getContent();
     return $response;
 }
Ejemplo n.º 25
0
 protected function createRequest($headers = ['X-Test'])
 {
     $request = LaravelRequest::createFromBase(LaravelRequest::create('/', 'GET'));
     if ($headers !== null) {
         $request->headers->set('Access-Control-Request-Headers', implode(', ', $headers));
     }
     return new Request($request);
 }
Ejemplo n.º 26
0
 public function testAuthSucceedsWithSpecificProvidersAndNoResponseIsReturned()
 {
     $request = Request::create('test', 'GET');
     $route = new Route(['GET'], 'test', ['protected' => true, 'providers' => 'foo']);
     $this->auth->shouldReceive('check')->once()->andReturn(false);
     $this->auth->shouldReceive('authenticate')->once()->with(['test', 'foo']);
     $this->assertNull($this->filter->filter($route, $request, 'test'));
 }
Ejemplo n.º 27
0
 public function testRouteHelper()
 {
     set_app($app = new Application());
     $app['request'] = Request::create('http://www.foo.com', 'GET');
     $app['router']->get('foo', array('as' => 'bar', function () {
     }));
     $this->assertEquals('http://www.foo.com/foo', route('bar'));
 }
Ejemplo n.º 28
0
 /**
  * @expectedException Nanuly\Socialize\Two\InvalidStateException
  */
 public function testExceptionIsThrownIfStateIsNotSet()
 {
     $request = Request::create('foo', 'GET', ['state' => 'state', 'code' => 'code']);
     $request->setSession($session = m::mock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'));
     $session->shouldReceive('pull')->once()->with('state');
     $provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect');
     $user = $provider->user();
 }
Ejemplo n.º 29
0
 /**
  * Call the given URI and return a Response.
  *
  * @param  string $uri
  *
  * @return \Illuminate\Http\Response
  */
 protected function call($uri)
 {
     $request = Request::create($uri, 'GET');
     $kernel = $this->app->make(HttpKernel::class);
     $response = $kernel->handle($request);
     $kernel->terminate($request, $response);
     return $response;
 }
Ejemplo n.º 30
-1
 public function info()
 {
     $request = Request::create('api', 'POST', ['command' => 'info']);
     $response = Route::dispatch($request)->getContent();
     $data = json_decode($response);
     return view('client.info', compact('data'));
 }