/** * Ensures that fromGlobals does not set the parsed body when the HTTP method * is GET. * */ public function testNoParsedDataIfHttpMethodIsGet() { $server = ['CONTENT_TYPE' => 'application/json']; $content = new Stream('data://text/plain,{"test":"testing"}'); $request = ServerRequestFactory::fromGlobals($server, null, null, null, null, $content); $this->assertEquals([], $request->getParsedBody()); }
/** * Constructor * * @param \StdClass $user * The Drupal user to call this resource as. Defaults to the current user. * @param JsonRequest $request * The request to use to set the context for the resource. Defaults to the * current page request. * */ public function __construct(\StdClass $user = NULL, JsonRequest $request = NULL) { if (!$request) { $request = ServerRequestFactory::fromGlobals(); } $this->request = $request; $this->user = $user ?: $GLOBALS['user']; }
public function testToErrorReturnsResponse() { $request = ServerRequestFactory::fromGlobals(); $user = (object) ['uid' => 1]; $args = [$user, $request]; $resource = $this->getMockForAbstractClass('Drupal\\restapi\\AbstractResource', $args); $response = $resource->toError('testdata'); $this->assertInstanceOf('Drupal\\restapi\\JsonResponse', $response); }
/** * Ensures that getRequestId() returns the same value when called twice. * */ public function testRequestIdReturnsSameValueWhenCalledMoreThanOnce() { $request = ServerRequestFactory::fromGlobals(); $id = $request->getRequestId(); $this->assertEquals($id, $request->getRequestId()); }