Best Atoum code snippet using controller.getContents
ActionControllerTest.php
Source:ActionControllerTest.php
...78 */79 public function defaultActionSpecifiedInRouteIsCalledAndResponseIsReturned()80 {81 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta');82 self::assertEquals('First action was called', $response->getBody()->getContents());83 self::assertEquals(200, $response->getStatusCode());84 }85 /**86 * Checks if a simple request is handled correctly if another than the default87 * action is specified.88 *89 * @test90 */91 public function actionSpecifiedInActionRequestIsCalledAndResponseIsReturned()92 {93 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta/second');94 self::assertEquals('Second action was called', $response->getBody()->getContents());95 self::assertEquals(200, $response->getStatusCode());96 }97 /**98 * Checks if query parameters are handled correctly and default arguments are99 * respected / overridden.100 *101 * @test102 */103 public function queryStringOfAGetRequestIsParsedAndPassedToActionAsArguments()104 {105 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta/third?secondArgument=bar&firstArgument=foo&third=baz');106 self::assertEquals('thirdAction-foo-bar-baz-default', $response->getBody()->getContents());107 }108 /**109 * @test110 */111 public function defaultTemplateIsResolvedAndUsedAccordingToConventions()112 {113 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta/fourth?emailAddress=example@neos.io');114 self::assertEquals('Fourth action <b>example@neos.io</b>', $response->getBody()->getContents());115 }116 /**117 * Bug #36913118 *119 * @test120 */121 public function argumentsOfPutRequestArePassedToAction()122 {123 $request = $this->serverRequestFactory->createServerRequest('PUT', new Uri('http://localhost/test/mvc/actioncontrollertesta/put?getArgument=getValue'));124 $request = $request125 ->withBody(ContentStream::fromContents('putArgument=first value'))126 ->withHeader('Content-Type', 'application/x-www-form-urlencoded')127 ->withHeader('Content-Length', 54);128 $response = $this->browser->sendRequest($request);129 self::assertEquals('putAction-first value-getValue', $response->getBody()->getContents());130 }131 /**132 * RFC 2616 / 10.4.5 (404 Not Found)133 *134 * @test135 */136 public function notFoundStatusIsReturnedIfASpecifiedObjectCantBeFound()137 {138 $request = new ServerRequest('GET', new Uri('http://localhost/test/mvc/actioncontrollertestc/non-existing-id'));139 $response = $this->browser->sendRequest($request);140 self::assertSame(404, $response->getStatusCode());141 }142 /**143 * RFC 2616 / 10.4.7 (406 Not Acceptable)144 *145 * @test146 */147 public function notAcceptableStatusIsReturnedIfMediaTypeDoesNotMatchSupportedMediaTypes()148 {149 $request = $this->serverRequestFactory->createServerRequest('GET', new Uri('http://localhost/test/mvc/actioncontrollertesta'))150 ->withHeader('Content-Type', 'application/xml')151 ->withHeader('Accept', 'application/xml')152 ->withBody(ContentStream::fromContents('<xml></xml>'));153 $response = $this->browser->sendRequest($request);154 self::assertSame(406, $response->getStatusCode());155 }156 /**157 * @test158 */159 public function ignoreValidationAnnotationsAreObservedForPost()160 {161 $arguments = [162 'argument' => [163 'name' => 'Foo',164 'emailAddress' => '-invalid-'165 ]166 ];167 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/showobjectargument', 'POST', $arguments);168 $expectedResult = '-invalid-';169 self::assertEquals($expectedResult, $response->getBody()->getContents());170 }171 /**172 * See http://forge.typo3.org/issues/37385173 * @test174 */175 public function ignoreValidationAnnotationIsObservedWithAndWithoutDollarSign()176 {177 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta/ignorevalidation?brokenArgument1=toolong&brokenArgument2=tooshort');178 self::assertEquals('action was called', $response->getBody()->getContents());179 }180 /**181 * @test182 */183 public function argumentsOfPutRequestWithJsonOrXmlTypeAreAlsoPassedToAction()184 {185 $request = $this->serverRequestFactory->createServerRequest('PUT', new Uri('http://localhost/test/mvc/actioncontrollertesta/put?getArgument=getValue'))186 ->withHeader('Content-Type', 'application/json')187 ->withHeader('Content-Length', 29)188 ->withBody(ContentStream::fromContents('{"putArgument":"first value"}'));189 $response = $this->browser->sendRequest($request);190 self::assertEquals('putAction-first value-getValue', $response->getBody()->getContents());191 }192 /**193 * @test194 */195 public function objectArgumentsAreValidatedByDefault()196 {197 $arguments = [198 'argument' => [199 'name' => 'Foo',200 'emailAddress' => '-invalid-'201 ]202 ];203 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/requiredobject', 'POST', $arguments);204 $expectedResult = 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredObjectAction().' . PHP_EOL;205 self::assertEquals($expectedResult, $response->getBody()->getContents());206 }207 /**208 * @test209 */210 public function optionalObjectArgumentsAreValidatedByDefault()211 {212 $arguments = [213 'argument' => [214 'name' => 'Foo',215 'emailAddress' => '-invalid-'216 ]217 ];218 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/optionalobject', 'POST', $arguments);219 $expectedResult = 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalObjectAction().' . PHP_EOL;220 self::assertEquals($expectedResult, $response->getBody()->getContents());221 }222 /**223 * @test224 */225 public function optionalObjectArgumentsCanBeOmitted()226 {227 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/optionalobject');228 $expectedResult = 'null';229 self::assertEquals($expectedResult, $response->getBody()->getContents());230 }231 /**232 * @test233 */234 public function optionalObjectArgumentsCanBeAnnotatedNullable()235 {236 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/optionalannotatedobject');237 $expectedResult = 'null';238 self::assertEquals($expectedResult, $response->getBody()->getContents());239 }240 /**241 * @test242 */243 public function notValidatedGroupObjectArgumentsAreNotValidated()244 {245 $arguments = [246 'argument' => [247 'name' => 'Foo',248 'emailAddress' => '-invalid-'249 ]250 ];251 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/notvalidatedgroupobject', 'POST', $arguments);252 $expectedResult = '-invalid-';253 self::assertEquals($expectedResult, $response->getBody()->getContents());254 }255 /**256 * @test257 */258 public function notValidatedGroupCollectionsAreNotValidated()259 {260 $arguments = [261 'argument' => [262 'name' => 'Foo',263 'collection' => [264 [265 'name' => 'Bar',266 'emailAddress' => '-invalid-'267 ]268 ]269 ]270 ];271 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/notvalidatedgroupcollection', 'POST', $arguments);272 $expectedResult = '-invalid-';273 self::assertEquals($expectedResult, $response->getBody()->getContents());274 }275 /**276 * @test277 */278 public function notValidatedGroupModelRelationIsNotValidated()279 {280 $arguments = [281 'argument' => [282 'name' => 'Foo',283 'emailAddress' => '-invalid-',284 'related' => [285 'name' => 'Bar',286 'emailAddress' => '-invalid-'287 ]288 ]289 ];290 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/notvalidatedgroupobject', 'POST', $arguments);291 $expectedResult = '-invalid-';292 self::assertEquals($expectedResult, $response->getBody()->getContents());293 }294 /**295 * @test296 */297 public function validatedGroupObjectArgumentsAreValidated()298 {299 $arguments = [300 'argument' => [301 'name' => 'Foo',302 'emailAddress' => '-invalid-'303 ]304 ];305 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/validatedgroupobject', 'POST', $arguments);306 $expectedResult = 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->validatedGroupObjectAction().' . PHP_EOL;307 self::assertEquals($expectedResult, $response->getBody()->getContents());308 }309 /**310 * @test311 */312 public function validatedGroupCollectionsAreValidated()313 {314 $arguments = [315 'argument' => [316 'name' => 'Foo',317 'collection' => [318 [319 'name' => 'Bar',320 'emailAddress' => '-invalid-'321 ]322 ]323 ]324 ];325 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/validatedgroupcollection', 'POST', $arguments);326 $expectedResult = 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->validatedGroupCollectionAction().' . PHP_EOL;327 self::assertEquals($expectedResult, $response->getBody()->getContents());328 }329 /**330 * @test331 */332 public function validatedGroupModelRelationIsValidated()333 {334 $arguments = [335 'argument' => [336 'name' => 'Foo',337 'related' => [338 'name' => 'Bar',339 'emailAddress' => '-invalid-'340 ]341 ]342 ];343 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/validatedgroupobject', 'POST', $arguments);344 $expectedResult = 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->validatedGroupObjectAction().' . PHP_EOL;345 self::assertEquals($expectedResult, $response->getBody()->getContents());346 }347 /**348 * Data provider for argumentTests()349 *350 * @return array351 */352 public function argumentTestsDataProvider()353 {354 $requiredArgumentExceptionText = 'Uncaught Exception in Flow #1298012500: Required argument "argument" is not set.';355 $data = [356 'required string ' => ['requiredString', 'some String', '\'some String\''],357 'required string - missing value' => ['requiredString', null, $requiredArgumentExceptionText],358 'optional string' => ['optionalString', '123', '\'123\''],359 'optional string - default' => ['optionalString', null, '\'default\''],360 'optional string - nullable' => ['optionalNullableString', null, 'NULL'],361 'required integer' => ['requiredInteger', '234', 234],362 'required integer - missing value' => ['requiredInteger', null, $requiredArgumentExceptionText],363 'required integer - mapping error' => ['requiredInteger', 'not an integer', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredIntegerAction().'],364 'required integer - empty value' => ['requiredInteger', '', 'NULL'],365 'optional integer' => ['optionalInteger', 456, 456],366 'optional integer - default value' => ['optionalInteger', null, 123],367 'optional integer - mapping error' => ['optionalInteger', 'not an integer', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalIntegerAction().'],368 'optional integer - empty value' => ['optionalInteger', '', 123],369 'optional integer - nullable' => ['optionalNullableInteger', null, 'NULL'],370 'required float' => ['requiredFloat', 34.56, 34.56],371 'required float - integer' => ['requiredFloat', 485, '485'],372 'required float - integer2' => ['requiredFloat', '888', '888'],373 'required float - missing value' => ['requiredFloat', null, $requiredArgumentExceptionText],374 'required float - mapping error' => ['requiredFloat', 'not a float', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredFloatAction().'],375 'required float - empty value' => ['requiredFloat', '', 'NULL'],376 'optional float' => ['optionalFloat', 78.90, 78.9],377 'optional float - default value' => ['optionalFloat', null, 112.34],378 'optional float - mapping error' => ['optionalFloat', 'not a float', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalFloatAction().'],379 'optional float - empty value' => ['optionalFloat', '', 112.34],380 'optional float - nullable' => ['optionalNullableFloat', null, 'NULL'],381 'required date' => ['requiredDate', ['date' => '1980-12-13', 'dateFormat' => 'Y-m-d'], '1980-12-13'],382 'required date string' => ['requiredDate', '1980-12-13T14:22:12+02:00', '1980-12-13'],383 'required date - missing value' => ['requiredDate', null, $requiredArgumentExceptionText],384 'required date - mapping error' => ['requiredDate', 'no date', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredDateAction().'],385 'optional date string' => ['optionalDate', '1980-12-13T14:22:12+02:00', '1980-12-13'],386 'optional date - default value' => ['optionalDate', null, 'null'],387 'optional date - mapping error' => ['optionalDate', 'no date', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalDateAction().'],388 'optional date - missing value' => ['optionalDate', null, 'null'],389 'optional date - empty value' => ['optionalDate', '', 'null'],390 ];391 return $data;392 }393 /**394 * Tut Dinge.395 *396 * @param string $action397 * @param mixed $argument398 * @param string $expectedResult399 * @test400 * @dataProvider argumentTestsDataProvider401 */402 public function argumentTests($action, $argument, $expectedResult)403 {404 $arguments = [405 'argument' => $argument,406 ];407 $uri = str_replace('{@action}', strtolower($action), 'http://localhost/test/mvc/actioncontrollertestb/{@action}');408 $response = $this->browser->request($uri, 'POST', $arguments);409 self::assertTrue(strpos(trim($response->getBody()->getContents()), (string)$expectedResult) === 0, sprintf('The resulting string did not start with the expected string. Expected: "%s", Actual: "%s"', $expectedResult, $response->getBody()->getContents()));410 }411 /**412 * @test413 */414 public function requiredDateNullArgumentTest()415 {416 $arguments = [417 'argument' => '',418 ];419 $uri = str_replace('{@action}', 'requireddate', 'http://localhost/test/mvc/actioncontrollertestb/{@action}');420 $response = $this->browser->request($uri, 'POST', $arguments);421 if (PHP_MAJOR_VERSION < 8) {422 $expectedResult = 'Uncaught Exception in Flow Argument 1 passed to Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController_Original::requiredDateAction() must be an instance of DateTime, null given';423 } else {424 $expectedResult = 'Uncaught Exception in Flow Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController_Original::requiredDateAction(): Argument #1 ($argument) must be of type DateTime, null given';425 }426 self::assertTrue(strpos(trim($response->getBody()->getContents()), (string)$expectedResult) === 0, sprintf('The resulting string did not start with the expected string. Expected: "%s", Actual: "%s"', $expectedResult, $response->getBody()->getContents()));427 }428 /**429 * @test430 */431 public function wholeRequestBodyCanBeMapped()432 {433 $arguments = [434 'name' => 'Foo',435 'emailAddress' => 'foo@bar.org'436 ];437 $body = json_encode($arguments, JSON_PRETTY_PRINT);438 $this->browser->addAutomaticRequestHeader('Content-Type', 'application/json');439 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/mappedrequestbody', 'POST', [], [], [], $body);440 $expectedResult = 'Foo-foo@bar.org';441 self::assertEquals($expectedResult, $response->getBody()->getContents());442 }443 /**444 * @test445 */446 public function wholeRequestBodyCanBeMappedWithoutAnnotation()447 {448 $arguments = [449 'name' => 'Foo',450 'emailAddress' => 'foo@bar.org'451 ];452 $body = json_encode($arguments, JSON_PRETTY_PRINT);453 $this->browser->addAutomaticRequestHeader('Content-Type', 'application/json');454 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertestb/mappedrequestbodywithoutannotation', 'POST', [], [], [], $body);455 $expectedResult = 'Foo-foo@bar.org';456 self::assertEquals($expectedResult, $response->getBody()->getContents());457 }458 /**459 * @test460 */461 public function trustedPropertiesConfigurationDoesNotIgnoreWildcardConfigurationInController()462 {463 $entity = new TestEntity();464 $entity->setName('Foo');465 $this->persistenceManager->add($entity);466 $identifier = $this->persistenceManager->getIdentifierByObject($entity);467 $trustedPropertiesService = new MvcPropertyMappingConfigurationService();468 $trustedProperties = $trustedPropertiesService->generateTrustedPropertiesToken(['entity[__identity]', 'entity[subEntities][0][content]', 'entity[subEntities][0][date]', 'entity[subEntities][1][content]', 'entity[subEntities][1][date]']);469 $form = [470 'entity' => [471 '__identity' => $identifier,472 'subEntities' => [473 [474 'content' => 'Bar',475 'date' => '1.1.2016'476 ],477 [478 'content' => 'Baz',479 'date' => '30.12.2016'480 ]481 ]482 ],483 '__trustedProperties' => $trustedProperties484 ];485 $request = $this->serverRequestFactory->createServerRequest('POST', new Uri('http://localhost/test/mvc/actioncontrollertestc/' . $identifier . '/update'))486 ->withParsedBody($form);487 $response = $this->browser->sendRequest($request);488 self::assertSame('Entity "Foo" updated', $response->getBody()->getContents());489 }490 /**491 * @test492 */493 public function flashMessagesGetRenderedAfterRedirect()494 {495 $request = $this->serverRequestFactory->createServerRequest('GET', new Uri('http://localhost/test/mvc/actioncontrollertest/redirectWithFlashMessage'));496 $response = $this->browser->sendRequest($request);497 $sessionCookies = array_map(static function ($cookie) {498 return Cookie::createFromRawSetCookieHeader($cookie);499 }, $response->getHeader('Set-Cookie'));500 self::assertNotEmpty($sessionCookies);501 $redirect = $response->getHeaderLine('Location');502 self::assertNotEmpty($redirect);503 $this->objectManager->forgetInstance(StandardController::class);504 $cookies = array_reduce($sessionCookies, static function ($out, $cookie) {505 $out[$cookie->getName()] = $cookie->getValue();506 return $out;507 }, []);508 $redirectRequest = $this->serverRequestFactory->createServerRequest('GET', new Uri($redirect))509 ->withCookieParams($cookies);510 $redirectResponse = $this->browser->sendRequest($redirectRequest);511 $expected = json_encode(['Redirect FlashMessage']);512 self::assertSame($expected, $redirectResponse->getBody()->getContents());513 }514 /**515 * @test516 */517 public function nonstandardStatusCodeIsReturnedWithRedirect()518 {519 $this->browser->setFollowRedirects(false);520 $response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta/redirect');521 self::assertSame(302, $response->getStatusCode());522 self::assertSame('http://some.uri', $response->getHeaderLine('Location'));523 }524}...
PromotionControllerTest.php
Source:PromotionControllerTest.php
...17 {18 $entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);19 $entityManager = $entityManagerProphecy->reveal();20 $requestBodyProphecy = $this->prophesize(StreamInterface::class);21 $requestBodyProphecy->getContents()->willReturn('{"discount_code": "testCode", "discount_name": "testName","discount_type": "testType", "discount_start_date": "testStartDate", "discount_end_date": "testEndDate"}');22 $requestBody = $requestBodyProphecy->reveal();23 $requestProphecy = $this->prophesize(ServerRequestInterface::class);24 $requestProphecy->getBody()->willReturn($requestBody);25 $request = $requestProphecy->reveal();26 $expectedData = new JsonResponse(['message' => 'Error while creating discount!',27 'data' => [28 'discount_value' => 'This value is required.',29 ],30 ], 400);31 $promotionController = new PromotionController($entityManager, 'Asia/Singapore');32 $actualData = $promotionController->createAction($request);33 $this->assertEquals($expectedData->getStatusCode(), $actualData->getStatusCode());34 $this->assertEquals($expectedData->getBody()->getContents(), $actualData->getBody()->getContents());35 }36 public function testCreateActionWithExistingPromotion()37 {38 $promotionProphecy = $this->prophesize(Promotion::class);39 $promotion = $promotionProphecy->reveal();40 $promotionRepositoryProphecy = $this->prophesize(ObjectRepository::class);41 $promotionRepositoryProphecy->findOneBy(['promotionNumber' => 'testCode', 'isBasedOn' => null])->willReturn($promotion);42 $promotionRepository = $promotionRepositoryProphecy->reveal();43 $entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);44 $entityManagerProphecy->getRepository(Promotion::class)->willReturn($promotionRepository);45 $entityManager = $entityManagerProphecy->reveal();46 $requestBodyProphecy = $this->prophesize(StreamInterface::class);47 $requestBodyProphecy->getContents()->willReturn('{"discount_code": "testCode", "discount_name": "testName","discount_type": "testType", "discount_start_date": "testStartDate", "discount_end_date": "testEndDate", "discount_value": 123}');48 $requestBody = $requestBodyProphecy->reveal();49 $requestProphecy = $this->prophesize(ServerRequestInterface::class);50 $requestProphecy->getBody()->willReturn($requestBody);51 $request = $requestProphecy->reveal();52 $expectedData = new JsonResponse(['message' => 'Error while creating discount!',53 'data' => [54 'discount_code' => 'Discount code has already been used.',55 ],56 ], 400);57 $promotionController = new PromotionController($entityManager, 'Asia/Singapore');58 $actualData = $promotionController->createAction($request);59 $this->assertEquals($expectedData->getStatusCode(), $actualData->getStatusCode());60 $this->assertEquals($expectedData->getBody()->getContents(), $actualData->getBody()->getContents());61 }62 public function testCreateActionWithNewCategoryWithPercentageAsDiscountType()63 {64 $promotionRepositoryProphecy = $this->prophesize(ObjectRepository::class);65 $promotionRepositoryProphecy->findOneBy(['promotionNumber' => 'testCode', 'isBasedOn' => null])->willReturn(null);66 $promotionRepository = $promotionRepositoryProphecy->reveal();67 $promotionCategoryRepositoryProphecy = $this->prophesize(ObjectRepository::class);68 $promotionCategoryRepositoryProphecy->findOneBy(['name' => 'Percentage'])->willReturn(null);69 $promotionCategoryRepository = $promotionCategoryRepositoryProphecy->reveal();70 $entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);71 $entityManagerProphecy->getRepository(Promotion::class)->willReturn($promotionRepository);72 $entityManagerProphecy->getRepository(PromotionCategory::class)->willReturn($promotionCategoryRepository);73 $entityManager = $entityManagerProphecy->reveal();74 $requestBodyProphecy = $this->prophesize(StreamInterface::class);75 $requestBodyProphecy->getContents()->willReturn('{"discount_code": "testCode", "discount_name": "testName","discount_type": "Percentage", "discount_start_date": "testStartDate", "discount_end_date": "testEndDate", "discount_value": 30, "max_discount_value": 20, "number_of_discount":1 }');76 $requestBody = $requestBodyProphecy->reveal();77 $requestProphecy = $this->prophesize(ServerRequestInterface::class);78 $requestProphecy->getBody()->willReturn($requestBody);79 $request = $requestProphecy->reveal();80 $expectedData = new JsonResponse(['message' => 'Error while creating discount code!',81 'data' => [82 'discount_start_date' => 'Invalid date format.',83 'discount_end_date' => 'Invalid date format.',84 ],85 ], 400);86 $promotionController = new PromotionController($entityManager, 'Asia/Singapore');87 $actualData = $promotionController->createAction($request);88 $this->assertEquals($expectedData->getStatusCode(), $actualData->getStatusCode());89 $this->assertEquals($expectedData->getBody()->getContents(), $actualData->getBody()->getContents());90 }91 public function testCreateActionWithNewCategoryWithPercentageAsDiscountTypeandWithoutMaxDiscountValue()92 {93 $promotionRepositoryProphecy = $this->prophesize(ObjectRepository::class);94 $promotionRepositoryProphecy->findOneBy(['promotionNumber' => 'testCode', 'isBasedOn' => null])->willReturn(null);95 $promotionRepository = $promotionRepositoryProphecy->reveal();96 $promotionCategoryRepositoryProphecy = $this->prophesize(ObjectRepository::class);97 $promotionCategoryRepositoryProphecy->findOneBy(['name' => 'Percentage'])->willReturn(null);98 $promotionCategoryRepository = $promotionCategoryRepositoryProphecy->reveal();99 $entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);100 $entityManagerProphecy->getRepository(Promotion::class)->willReturn($promotionRepository);101 $entityManagerProphecy->getRepository(PromotionCategory::class)->willReturn($promotionCategoryRepository);102 $entityManager = $entityManagerProphecy->reveal();103 $requestBodyProphecy = $this->prophesize(StreamInterface::class);104 $requestBodyProphecy->getContents()->willReturn('{"discount_code": "testCode", "discount_name": "testName","discount_type": "Percentage", "discount_start_date": "testStartDate", "discount_end_date": "testEndDate", "discount_value": 30, "number_of_discount":1}');105 $requestBody = $requestBodyProphecy->reveal();106 $requestProphecy = $this->prophesize(ServerRequestInterface::class);107 $requestProphecy->getBody()->willReturn($requestBody);108 $request = $requestProphecy->reveal();109 $expectedData = new JsonResponse(['message' => 'Error while creating discount code!',110 'data' => [111 'discount_start_date' => 'Invalid date format.',112 'discount_end_date' => 'Invalid date format.',113 ],114 ], 400);115 $promotionController = new PromotionController($entityManager, 'Asia/Singapore');116 $actualData = $promotionController->createAction($request);117 $this->assertEquals($expectedData->getStatusCode(), $actualData->getStatusCode());118 $this->assertEquals($expectedData->getBody()->getContents(), $actualData->getBody()->getContents());119 }120 public function testCreateActionWithNewCategoryWithFixedAmountAsDiscountType()121 {122 $promotionRepositoryProphecy = $this->prophesize(ObjectRepository::class);123 $promotionRepositoryProphecy->findOneBy(['promotionNumber' => 'testCode', 'isBasedOn' => null])->willReturn(null);124 $promotionRepository = $promotionRepositoryProphecy->reveal();125 $promotionCategoryRepositoryProphecy = $this->prophesize(ObjectRepository::class);126 $promotionCategoryRepositoryProphecy->findOneBy(['name' => 'Fixed Amount'])->willReturn(null);127 $promotionCategoryRepository = $promotionCategoryRepositoryProphecy->reveal();128 $entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);129 $entityManagerProphecy->getRepository(Promotion::class)->willReturn($promotionRepository);130 $entityManagerProphecy->getRepository(PromotionCategory::class)->willReturn($promotionCategoryRepository);131 $entityManager = $entityManagerProphecy->reveal();132 $requestBodyProphecy = $this->prophesize(StreamInterface::class);133 $requestBodyProphecy->getContents()->willReturn('{"discount_code": "testCode", "discount_name": "testName","discount_type": "Fixed Amount", "discount_start_date": "testStartDate", "discount_end_date": "testEndDate", "min_discount_month": 1, "discount_value": 30}');134 $requestBody = $requestBodyProphecy->reveal();135 $requestProphecy = $this->prophesize(ServerRequestInterface::class);136 $requestProphecy->getBody()->willReturn($requestBody);137 $request = $requestProphecy->reveal();138 $expectedData = new JsonResponse(['message' => 'Error while creating discount code!',139 'data' => [140 'discount_start_date' => 'Invalid date format.',141 'discount_end_date' => 'Invalid date format.',142 ],143 ], 400);144 $promotionController = new PromotionController($entityManager, 'Asia/Singapore');145 $actualData = $promotionController->createAction($request);146 $this->assertEquals($expectedData->getStatusCode(), $actualData->getStatusCode());147 $this->assertEquals($expectedData->getBody()->getContents(), $actualData->getBody()->getContents());148 }149 public function testUpdateActionWithoutExistingPromotion()150 {151 $promotionRepositoryProphecy = $this->prophesize(ObjectRepository::class);152 $promotionRepositoryProphecy->findOneBy(['promotionNumber' => 'testCode', 'isBasedOn' => null])->willReturn(null);153 $promotionRepository = $promotionRepositoryProphecy->reveal();154 $entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);155 $entityManagerProphecy->getRepository(Promotion::class)->willReturn($promotionRepository);156 $entityManager = $entityManagerProphecy->reveal();157 $requestBodyProphecy = $this->prophesize(StreamInterface::class);158 $requestBodyProphecy->getContents()->willReturn('{"discount_code": "testCode", "discount_name": "testName","discount_type": "testType", "discount_start_date": "testStartDate", "discount_end_date": "testEndDate", "min_discount_month": "1"}');159 $requestBody = $requestBodyProphecy->reveal();160 $requestProphecy = $this->prophesize(ServerRequestInterface::class);161 $requestProphecy->getBody()->willReturn($requestBody);162 $request = $requestProphecy->reveal();163 $expectedData = new JsonResponse(['message' => 'Discount code testCode not found.'], 404);164 $promotionController = new PromotionController($entityManager, 'Asia/Singapore');165 $actualData = $promotionController->updateAction($request, 'testCode');166 $this->assertEquals($expectedData->getStatusCode(), $actualData->getStatusCode());167 $this->assertEquals($expectedData->getBody()->getContents(), $actualData->getBody()->getContents());168 }169 public function testUpdateActionWithInvalidDateFormat()170 {171 $promotionProphecy = $this->prophesize(Promotion::class);172 $promotionProphecy->setName('testName')->shouldBeCalled();173 $promotionProphecy->setCurrency('SGD')->shouldBeCalled();174 $promotionProphecy->setAmount(new QuantitativeValue('30', null, null, null))->shouldBeCalled();175 $promotionProphecy->setRecurringDuration(new QuantitativeValue('1', null, null, 'MON'))->shouldBeCalled();176 $promotion = $promotionProphecy->reveal();177 $promotionRepositoryProphecy = $this->prophesize(ObjectRepository::class);178 $promotionRepositoryProphecy->findOneBy(['promotionNumber' => 'testCode', 'isBasedOn' => null])->willReturn($promotion);179 $promotionRepository = $promotionRepositoryProphecy->reveal();180 $entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);181 $entityManagerProphecy->getRepository(Promotion::class)->willReturn($promotionRepository);182 $entityManager = $entityManagerProphecy->reveal();183 $requestBodyProphecy = $this->prophesize(StreamInterface::class);184 $requestBodyProphecy->getContents()->willReturn('{"discount_code": "testCode", "discount_name": "testName","discount_type": "Fixed Amount", "discount_start_date": "testStartDate", "discount_end_date": "testEndDate", "number_of_discount":1, "discount_value": 30}');185 $requestBody = $requestBodyProphecy->reveal();186 $requestProphecy = $this->prophesize(ServerRequestInterface::class);187 $requestProphecy->getBody()->willReturn($requestBody);188 $request = $requestProphecy->reveal();189 $expectedData = new JsonResponse(['message' => 'Error while creating discount code!',190 'data' => [191 'discount_start_date' => 'Invalid date format.',192 'discount_end_date' => 'Invalid date format.',193 ],194 ], 400);195 $promotionController = new PromotionController($entityManager, 'Asia/Singapore');196 $actualData = $promotionController->updateAction($request, 'testCode');197 $this->assertEquals($expectedData->getStatusCode(), $actualData->getStatusCode());198 $this->assertEquals($expectedData->getBody()->getContents(), $actualData->getBody()->getContents());199 }200}...
DomainController.php
Source:DomainController.php
...36 $title = $this->title ;37 $client = new \GuzzleHttp\Client();38 $url = url('').'/api/domain?api_token='.Auth()->User()->api_token ;39 $res = $client->get($url);40 $json = json_decode($res->getBody()->getContents(), true);41 if (!isset($json['result'])) {42 $json['errors'] = $res->getBody()->getContents() ;43 return redirect('error')44 ->withError($json['errors']);45 }46 if ($json['result']==false) {47 return redirect('error')48 ->withError($json['errors']);49 }50 $user = $json['response']['user'] ;51 //-- à¸à¹à¸² มีà¸à¹à¸à¸¡à¸¹à¸¥ domain ลà¹à¸²à¸ªà¸¸à¸à¹à¸«à¹ à¹à¸¥à¹à¸§ approve à¹à¸à¹à¸² dashboard à¸à¸à¸ domain à¸à¸±à¹à¸à¹à¹à¸¥à¸¢52 53 if ($user['approve_domain']==1) {54 return redirect(Auth()->User()->getDomainName().'/dashboard');55 }56 //--- version 0.1 หลัà¸à¸à¸²à¸ auto join à¹à¸«à¹à¹à¸à¹à¸à¹à¸à¸«à¸à¹à¸²à¸£à¸ approve57 return redirect(Auth()->User()->getDomainName().'/dashboard');58 $domains = $json['response']['domain'] ;59 return view($this->view.'.index', compact('domains', 'title'));60 }61 public function listDomain()62 {63 $title = $this->title ;64 $client = new \GuzzleHttp\Client();65 $url = url('').'/api/domain?api_token='.Auth()->User()->api_token ;66 $res = $client->get($url);67 $json = json_decode($res->getBody()->getContents(), true);68 if (!isset($json['result'])) {69 $json['errors'] = $res->getBody()->getContents() ;70 return redirect('error')71 ->withError($json['errors']);72 }73 if ($json['result']==false) {74 return redirect('error')75 ->withError($json['errors']);76 }77 78 79 $lists = $json['response']['domain'] ;80 return view($this->view.'.list', compact('lists', 'title'));81 }82 public function create()83 {84 $title = $this->title ;85 $route = $this->route;86 $units = Domain::unitslist();87 return view($this->view.'.create', compact('title', 'route', 'units'));88 }89 public function store(Request $request)90 {91 $post = $request->all();92 $client = new \GuzzleHttp\Client();93 $url = url('').'/api/domain?api_token='.Auth()->User()->api_token ;94 $response = $client->post($url, ['form_params'=>$post]);95 $json = json_decode($response->getBody()->getContents(), true);96 if (!isset($json['result'])) {97 $json['errors'] = $response->getBody()->getContents() ;98 return redirect('error')99 ->withError($json['errors']);100 }101 if ($json['result']=="false") {102 return redirect('error')103 ->withError($json['errors']);104 }105 return redirect($json['response']['domain_name'].'/dashboard')->with('success', 'สรà¹à¸²à¸à¹à¸à¸£à¸à¸à¸²à¸£ สำà¹à¸£à¹à¸');106 }107 public function join()108 {109 $title = $this->title ;110 $route = $this->route;111 $domains = [];112 $client = new \GuzzleHttp\Client();113 $url = url('').'/api/domain/list?api_token='.Auth()->User()->api_token ;114 $response = $client->get($url);115 $json = json_decode($response->getBody()->getContents(), true);116 if ($json['result']=="true") {117 $domains = $json['response']['domain'] ;118 }119 return view($this->view.'.join', compact('title', 'route', 'domains'));120 }121 public function search(Request $request)122 {123 $title = $this->title ;124 $route = $this->route;125 $domains = [];126 $client = new \GuzzleHttp\Client();127 $url = url('').'/api/domain/search?api_token='.Auth()->User()->api_token ;128 $response = $client->post($url, ['form_params'=>$request->all()]);129 $json = json_decode($response->getBody()->getContents(), true);130 if ($json['result']=="true") {131 $domains = $json['response'] ;132 }133 return $domains;134 }135 public function joinStore(Request $request)136 {137 $client = new \GuzzleHttp\Client();138 $url = url('').'/api/domain/join?api_token='.Auth()->User()->api_token ;139 $response = $client->post($url, ['form_params'=>$request->all()]);140 $json = json_decode($response->getBody()->getContents(), true);141 if (!isset($json['result'])) {142 $json['errors'] = $response->getBody()->getContents() ;143 return redirect('error')144 ->withError($json['errors']);145 }146 if ($json['result']=="false") {147 return redirect('error')148 ->withError($json['errors']);149 }150 if ($json['response']['approve']) {151 return redirect($json['response']['domain_id'].'dashboard')->with('success', 'à¹à¸à¹à¸²à¸£à¹à¸§à¸¡à¹à¸à¸£à¸à¸à¸²à¸£ สำà¹à¸£à¹à¸');152 }153 return redirect('domain/join')->with('success', 'à¹à¸à¹à¸²à¸£à¹à¸§à¸¡à¹à¸à¸£à¸à¸à¸²à¸£ สำà¹à¸£à¹à¸');154 }155}...
getContents
Using AI Code Generation
1$controller = new controller();2$result = $controller->getContents();3echo $result;4$controller = new controller();5$result = $controller->getContents();6echo $result;7$controller = new controller();8$result = $controller->getContents();9echo $result;10$controller = new controller();11$result = $controller->getContents();12echo $result;13$controller = new controller();14$result = $controller->getContents();15echo $result;16$controller = new controller();17$result = $controller->getContents();18echo $result;19$controller = new controller();20$result = $controller->getContents();21echo $result;22$controller = new controller();23$result = $controller->getContents();24echo $result;25$controller = new controller();26$result = $controller->getContents();27echo $result;28$controller = new controller();29$result = $controller->getContents();30echo $result;31{32 public function getContents()33 {34 $file = fopen('test.txt', 'r');35 $contents = fread($file, filesize('test.txt'));36 fclose($file);37 return $contents;38 }39}40$controller = new controller();41$result = $controller->getContents();42echo $result;
getContents
Using AI Code Generation
1$controller = new Controller();2$controller->getContents();3$controller = new Controller();4$controller->getContents();5$controller = new Controller();6$controller->getContents();7$controller = new Controller();8$controller->getContents();9$controller = new Controller();10$controller->getContents();11$controller = new Controller();12$controller->getContents();13$controller = new Controller();14$controller->getContents();15$controller = new Controller();16$controller->getContents();17$controller = new Controller();18$controller->getContents();19$controller = new Controller();20$controller->getContents();21$controller = new Controller();22$controller->getContents();23$controller = new Controller();24$controller->getContents();25$controller = new Controller();
getContents
Using AI Code Generation
1require_once('controller.php');2$controller = new Controller();3$controller->getContents();4require_once('controller.php');5$controller = new Controller();6$controller->getContents();7require_once('controller.php');8$controller = new Controller();9$controller->getContents();10{11 public function getContents()12 {13 }14}15foreach (glob("*.php") as $filename)16{17 include $filename;18}19foreach (glob("*.php") as $filename)20{21 if ($filename !== 'controller.php') {22 include $filename;23 }24}
getContents
Using AI Code Generation
1$contents = Controller::getContents("file.txt");2echo $contents;3$contents = Controller::getContents("file.txt");4echo $contents;5$contents = Controller::getContents("file.txt");6echo $contents;7$contents = Controller::getContents("file.txt");8echo $contents;9$contents = Controller::getContents("file.txt");10echo $contents;11$contents = Controller::getContents("file.txt");12echo $contents;13$contents = Controller::getContents("file.txt");14echo $contents;15$contents = Controller::getContents("file.txt");16echo $contents;17$contents = Controller::getContents("file.txt");18echo $contents;19$contents = Controller::getContents("file.txt");20echo $contents;21$contents = Controller::getContents("file.txt");22echo $contents;23$contents = Controller::getContents("file.txt");24echo $contents;25$contents = Controller::getContents("file.txt");26echo $contents;
getContents
Using AI Code Generation
1include_once("controller.php");2$controller = new controller;3$controller->getContents();4include_once("controller.php");5$controller = new controller;6$controller->getContents("folder1/2.txt");7include_once("controller.php");8$controller = new controller;9$controller->getContents("folder1/2.txt");10include_once("controller.php");11$controller = new controller;
getContents
Using AI Code Generation
1$controller->getContents();2{3 public function getContents($viewName)4 {5 }6}7$view = new View();8$viewContents = $view->getContents($viewName);9echo $viewContents;10{11 public function getData($tableName)12 {13 }14}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with getContents on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!