How to use contains method of controller class

Best Atoum code snippet using controller.contains

TestTaskTest.php

Source:TestTaskTest.php Github

copy

Full Screen

1<?php2/**3 * TestTaskTest file4 *5 * Test Case for test generation shell task6 *7 * CakePHP : Rapid Development Framework (http://cakephp.org)8 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)9 *10 * Licensed under The MIT License11 * For full copyright and license information, please see the LICENSE.txt12 * Redistributions of files must retain the above copyright notice.13 *14 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)15 * @link http://cakephp.org CakePHP Project16 * @package Cake.Test.Case.Console.Command.Task17 * @since CakePHP v 1.2.0.772618 * @license http://www.opensource.org/licenses/mit-license.php MIT License19 */20App::uses('ShellDispatcher', 'Console');21App::uses('ConsoleOutput', 'Console');22App::uses('ConsoleInput', 'Console');23App::uses('Shell', 'Console');24App::uses('TestTask', 'Console/Command/Task');25App::uses('TemplateTask', 'Console/Command/Task');26App::uses('Controller', 'Controller');27App::uses('Model', 'Model');28/**29 * Test Article model30 *31 * @package Cake.Test.Case.Console.Command.Task32 */33class TestTaskArticle extends Model {34/**35 * Table name to use36 *37 * @var string38 */39 public $useTable = 'articles';40/**41 * HasMany Associations42 *43 * @var array44 */45 public $hasMany = array(46 'Comment' => array(47 'className' => 'TestTask.TestTaskComment',48 'foreignKey' => 'article_id',49 )50 );51/**52 * Has and Belongs To Many Associations53 *54 * @var array55 */56 public $hasAndBelongsToMany = array(57 'Tag' => array(58 'className' => 'TestTaskTag',59 'joinTable' => 'articles_tags',60 'foreignKey' => 'article_id',61 'associationForeignKey' => 'tag_id'62 )63 );64/**65 * Example public method66 *67 * @return void68 */69 public function doSomething() {70 }71/**72 * Example Secondary public method73 *74 * @return void75 */76 public function doSomethingElse() {77 }78/**79 * Example protected method80 *81 * @return void82 */83 protected function _innerMethod() {84 }85}86/**87 * Tag Testing Model88 *89 * @package Cake.Test.Case.Console.Command.Task90 */91class TestTaskTag extends Model {92/**93 * Table name94 *95 * @var string96 */97 public $useTable = 'tags';98/**99 * Has and Belongs To Many Associations100 *101 * @var array102 */103 public $hasAndBelongsToMany = array(104 'Article' => array(105 'className' => 'TestTaskArticle',106 'joinTable' => 'articles_tags',107 'foreignKey' => 'tag_id',108 'associationForeignKey' => 'article_id'109 )110 );111}112/**113 * Simulated plugin114 *115 * @package Cake.Test.Case.Console.Command.Task116 */117class TestTaskAppModel extends Model {118}119/**120 * Testing AppMode (TaskComment)121 *122 * @package Cake.Test.Case.Console.Command.Task123 */124class TestTaskComment extends TestTaskAppModel {125/**126 * Table name127 *128 * @var string129 */130 public $useTable = 'comments';131/**132 * Belongs To Associations133 *134 * @var array135 */136 public $belongsTo = array(137 'Article' => array(138 'className' => 'TestTaskArticle',139 'foreignKey' => 'article_id',140 )141 );142}143/**144 * Test Task Comments Controller145 *146 * @package Cake.Test.Case.Console.Command.Task147 */148class TestTaskCommentsController extends Controller {149/**150 * Models to use151 *152 * @var array153 */154 public $uses = array('TestTaskComment', 'TestTaskTag');155}156/**157 * TestTaskTest class158 *159 * @package Cake.Test.Case.Console.Command.Task160 */161class TestTaskTest extends CakeTestCase {162/**163 * Fixtures164 *165 * @var string166 */167 public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');168/**169 * setUp method170 *171 * @return void172 */173 public function setUp() {174 parent::setUp();175 $out = $this->getMock('ConsoleOutput', array(), array(), '', false);176 $in = $this->getMock('ConsoleInput', array(), array(), '', false);177 $this->Task = $this->getMock('TestTask',178 array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),179 array($out, $out, $in)180 );181 $this->Task->name = 'Test';182 $this->Task->Template = new TemplateTask($out, $out, $in);183 }184/**185 * tearDown method186 *187 * @return void188 */189 public function tearDown() {190 parent::tearDown();191 unset($this->Task);192 CakePlugin::unload();193 }194/**195 * Test that file path generation doesn't continuously append paths.196 *197 * @return void198 */199 public function testFilePathGenerationModelRepeated() {200 $this->Task->expects($this->never())->method('err');201 $this->Task->expects($this->never())->method('_stop');202 $file = TESTS . 'Case' . DS . 'Model' . DS . 'MyClassTest.php';203 $this->Task->expects($this->at(1))->method('createFile')204 ->with($file, $this->anything());205 $this->Task->expects($this->at(3))->method('createFile')206 ->with($file, $this->anything());207 $file = TESTS . 'Case' . DS . 'Controller' . DS . 'CommentsControllerTest.php';208 $this->Task->expects($this->at(5))->method('createFile')209 ->with($file, $this->anything());210 $this->Task->bake('Model', 'MyClass');211 $this->Task->bake('Model', 'MyClass');212 $this->Task->bake('Controller', 'Comments');213 }214/**215 * Test that method introspection pulls all relevant non parent class216 * methods into the test case.217 *218 * @return void219 */220 public function testMethodIntrospection() {221 $result = $this->Task->getTestableMethods('TestTaskArticle');222 $expected = array('dosomething', 'dosomethingelse');223 $this->assertEquals($expected, array_map('strtolower', $result));224 }225/**226 * test that the generation of fixtures works correctly.227 *228 * @return void229 */230 public function testFixtureArrayGenerationFromModel() {231 $subject = ClassRegistry::init('TestTaskArticle');232 $result = $this->Task->generateFixtureList($subject);233 $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',234 'app.test_task_article', 'app.test_task_tag');235 $this->assertEquals(sort($expected), sort($result));236 }237/**238 * test that the generation of fixtures works correctly.239 *240 * @return void241 */242 public function testFixtureArrayGenerationFromController() {243 $subject = new TestTaskCommentsController();244 $result = $this->Task->generateFixtureList($subject);245 $expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',246 'app.test_task_article', 'app.test_task_tag');247 $this->assertEquals(sort($expected), sort($result));248 }249/**250 * test user interaction to get object type251 *252 * @return void253 */254 public function testGetObjectType() {255 $this->Task->expects($this->once())->method('_stop');256 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));257 $this->Task->expects($this->at(2))->method('in')->will($this->returnValue(2));258 $this->Task->getObjectType();259 $result = $this->Task->getObjectType();260 $this->assertEquals($this->Task->classTypes['Controller'], $result);261 }262/**263 * creating test subjects should clear the registry so the registry is always fresh264 *265 * @return void266 */267 public function testRegistryClearWhenBuildingTestObjects() {268 ClassRegistry::flush();269 $model = ClassRegistry::init('TestTaskComment');270 $model->bindModel(array(271 'belongsTo' => array(272 'Random' => array(273 'className' => 'TestTaskArticle',274 'foreignKey' => 'article_id',275 )276 )277 ));278 $keys = ClassRegistry::keys();279 $this->assertTrue(in_array('test_task_comment', $keys));280 $this->Task->buildTestSubject('Model', 'TestTaskComment');281 $keys = ClassRegistry::keys();282 $this->assertFalse(in_array('random', $keys));283 }284/**285 * test that getClassName returns the user choice as a class name.286 *287 * @return void288 */289 public function testGetClassName() {290 $objects = App::objects('model');291 $this->skipIf(empty($objects), 'No models in app.');292 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));293 $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));294 $result = $this->Task->getClassName('Model');295 $this->assertEquals('MyCustomClass', $result);296 $result = $this->Task->getClassName('Model');297 $options = App::objects('model');298 $this->assertEquals($options[0], $result);299 }300/**301 * Test the user interaction for defining additional fixtures.302 *303 * @return void304 */305 public function testGetUserFixtures() {306 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));307 $this->Task->expects($this->at(1))->method('in')308 ->will($this->returnValue('app.pizza, app.topping, app.side_dish'));309 $result = $this->Task->getUserFixtures();310 $expected = array('app.pizza', 'app.topping', 'app.side_dish');311 $this->assertEquals($expected, $result);312 }313/**314 * test that resolving class names works315 *316 * @return void317 */318 public function testGetRealClassname() {319 $result = $this->Task->getRealClassname('Model', 'Post');320 $this->assertEquals('Post', $result);321 $result = $this->Task->getRealClassname('Controller', 'Posts');322 $this->assertEquals('PostsController', $result);323 $result = $this->Task->getRealClassname('Controller', 'PostsController');324 $this->assertEquals('PostsController', $result);325 $result = $this->Task->getRealClassname('Controller', 'AlertTypes');326 $this->assertEquals('AlertTypesController', $result);327 $result = $this->Task->getRealClassname('Helper', 'Form');328 $this->assertEquals('FormHelper', $result);329 $result = $this->Task->getRealClassname('Helper', 'FormHelper');330 $this->assertEquals('FormHelper', $result);331 $result = $this->Task->getRealClassname('Behavior', 'Containable');332 $this->assertEquals('ContainableBehavior', $result);333 $result = $this->Task->getRealClassname('Behavior', 'ContainableBehavior');334 $this->assertEquals('ContainableBehavior', $result);335 $result = $this->Task->getRealClassname('Component', 'Auth');336 $this->assertEquals('AuthComponent', $result);337 }338/**339 * test baking files. The conditionally run tests are known to fail in PHP4340 * as PHP4 class names are all lower case, breaking the plugin path inflection.341 *342 * @return void343 */344 public function testBakeModelTest() {345 $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));346 $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));347 $result = $this->Task->bake('Model', 'TestTaskArticle');348 $this->assertContains("App::uses('TestTaskArticle', 'Model')", $result);349 $this->assertContains('class TestTaskArticleTest extends CakeTestCase', $result);350 $this->assertContains('function setUp()', $result);351 $this->assertContains("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);352 $this->assertContains('function tearDown()', $result);353 $this->assertContains('unset($this->TestTaskArticle)', $result);354 $this->assertContains('function testDoSomething()', $result);355 $this->assertContains('function testDoSomethingElse()', $result);356 $this->assertContains('$this->markTestIncomplete(\'testDoSomething not implemented.\')', $result);357 $this->assertContains('$this->markTestIncomplete(\'testDoSomethingElse not implemented.\')', $result);358 $this->assertContains("'app.test_task_article'", $result);359 $this->assertContains("'app.test_task_comment'", $result);360 $this->assertContains("'app.test_task_tag'", $result);361 $this->assertContains("'app.articles_tag'", $result);362 }363/**364 * test baking controller test files365 *366 * @return void367 */368 public function testBakeControllerTest() {369 $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));370 $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));371 $result = $this->Task->bake('Controller', 'TestTaskComments');372 $this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);373 $this->assertContains('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);374 $this->assertNotContains('function setUp()', $result);375 $this->assertNotContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);376 $this->assertNotContains("\$this->TestTaskComments->constructClasses()", $result);377 $this->assertNotContains('function tearDown()', $result);378 $this->assertNotContains('unset($this->TestTaskComments)', $result);379 $this->assertContains("'app.test_task_article'", $result);380 $this->assertContains("'app.test_task_comment'", $result);381 $this->assertContains("'app.test_task_tag'", $result);382 $this->assertContains("'app.articles_tag'", $result);383 }384/**385 * test baking component test files,386 *387 * @return void388 */389 public function testBakeComponentTest() {390 $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));391 $result = $this->Task->bake('Component', 'Example');392 $this->assertContains("App::uses('Component', 'Controller')", $result);393 $this->assertContains("App::uses('ComponentCollection', 'Controller')", $result);394 $this->assertContains("App::uses('ExampleComponent', 'Controller/Component')", $result);395 $this->assertContains('class ExampleComponentTest extends CakeTestCase', $result);396 $this->assertContains('function setUp()', $result);397 $this->assertContains("\$Collection = new ComponentCollection()", $result);398 $this->assertContains("\$this->Example = new ExampleComponent(\$Collection)", $result);399 $this->assertContains('function tearDown()', $result);400 $this->assertContains('unset($this->Example)', $result);401 }402/**403 * test baking behavior test files,404 *405 * @return void406 */407 public function testBakeBehaviorTest() {408 $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));409 $result = $this->Task->bake('Behavior', 'Example');410 $this->assertContains("App::uses('ExampleBehavior', 'Model/Behavior')", $result);411 $this->assertContains('class ExampleBehaviorTest extends CakeTestCase', $result);412 $this->assertContains('function setUp()', $result);413 $this->assertContains("\$this->Example = new ExampleBehavior()", $result);414 $this->assertContains('function tearDown()', $result);415 $this->assertContains('unset($this->Example)', $result);416 }417/**418 * test baking helper test files,419 *420 * @return void421 */422 public function testBakeHelperTest() {423 $this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));424 $result = $this->Task->bake('Helper', 'Example');425 $this->assertContains("App::uses('ExampleHelper', 'View/Helper')", $result);426 $this->assertContains('class ExampleHelperTest extends CakeTestCase', $result);427 $this->assertContains('function setUp()', $result);428 $this->assertContains("\$View = new View()", $result);429 $this->assertContains("\$this->Example = new ExampleHelper(\$View)", $result);430 $this->assertContains('function tearDown()', $result);431 $this->assertContains('unset($this->Example)', $result);432 }433/**434 * test Constructor generation ensure that constructClasses is called for controllers435 *436 * @return void437 */438 public function testGenerateConstructor() {439 $result = $this->Task->generateConstructor('controller', 'PostsController', null);440 $expected = array('', '', '');441 $this->assertEquals($expected, $result);442 $result = $this->Task->generateConstructor('model', 'Post', null);443 $expected = array('', "ClassRegistry::init('Post');\n", '');444 $this->assertEquals($expected, $result);445 $result = $this->Task->generateConstructor('helper', 'FormHelper', null);446 $expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');447 $this->assertEquals($expected, $result);448 }449/**450 * Test generateUses()451 *452 * @return void453 */454 public function testGenerateUses() {455 $result = $this->Task->generateUses('model', 'Model', 'Post');456 $expected = array(457 array('Post', 'Model')458 );459 $this->assertEquals($expected, $result);460 $result = $this->Task->generateUses('controller', 'Controller', 'PostsController');461 $expected = array(462 array('PostsController', 'Controller')463 );464 $this->assertEquals($expected, $result);465 $result = $this->Task->generateUses('helper', 'View/Helper', 'FormHelper');466 $expected = array(467 array('View', 'View'),468 array('Helper', 'View'),469 array('FormHelper', 'View/Helper'),470 );471 $this->assertEquals($expected, $result);472 $result = $this->Task->generateUses('component', 'Controller/Component', 'AuthComponent');473 $expected = array(474 array('ComponentCollection', 'Controller'),475 array('Component', 'Controller'),476 array('AuthComponent', 'Controller/Component')477 );478 $this->assertEquals($expected, $result);479 }480/**481 * Test that mock class generation works for the appropriate classes482 *483 * @return void484 */485 public function testMockClassGeneration() {486 $result = $this->Task->hasMockClass('controller');487 $this->assertTrue($result);488 }489/**490 * test bake() with a -plugin param491 *492 * @return void493 */494 public function testBakeWithPlugin() {495 $this->Task->plugin = 'TestTest';496 //fake plugin path497 CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));498 $path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';499 $this->Task->expects($this->once())->method('createFile')500 ->with($path, $this->anything());501 $this->Task->bake('Helper', 'Form');502 CakePlugin::unload();503 }504/**505 * test interactive with plugins lists from the plugin506 *507 * @return void508 */509 public function testInteractiveWithPlugin() {510 $testApp = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;511 App::build(array(512 'Plugin' => array($testApp)513 ), App::RESET);514 CakePlugin::load('TestPlugin');515 $this->Task->plugin = 'TestPlugin';516 $path = $testApp . 'TestPlugin' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'OtherHelperTest.php';517 $this->Task->expects($this->any())518 ->method('in')519 ->will($this->onConsecutiveCalls(520 5, //helper521 1 //OtherHelper522 ));523 $this->Task->expects($this->once())524 ->method('createFile')525 ->with($path, $this->anything());526 $this->Task->stdout->expects($this->at(21))527 ->method('write')528 ->with('1. OtherHelperHelper');529 $this->Task->execute();530 }531 public static function caseFileNameProvider() {532 return array(533 array('Model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),534 array('Helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),535 array('Controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),536 array('Behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),537 array('Component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),538 array('model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),539 array('helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),540 array('controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),541 array('behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),542 array('component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),543 );544 }545/**546 * Test filename generation for each type + plugins547 *548 * @dataProvider caseFileNameProvider549 * @return void550 */551 public function testTestCaseFileName($type, $class, $expected) {552 $this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;553 $result = $this->Task->testCaseFileName($type, $class);554 $expected = $this->Task->path . $expected;555 $this->assertEquals($expected, $result);556 }557/**558 * Test filename generation for plugins.559 *560 * @return void561 */562 public function testTestCaseFileNamePlugin() {563 $this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;564 CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));565 $this->Task->plugin = 'TestTest';566 $result = $this->Task->testCaseFileName('Model', 'Post');567 $expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';568 $this->assertEquals($expected, $result);569 }570/**571 * test execute with a type defined572 *573 * @return void574 */575 public function testExecuteWithOneArg() {576 $this->Task->args[0] = 'Model';577 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));578 $this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));579 $this->Task->expects($this->once())->method('createFile')580 ->with(581 $this->anything(),582 $this->stringContains('class TestTaskTagTest extends CakeTestCase')583 );584 $this->Task->execute();585 }586/**587 * test execute with type and class name defined588 *589 * @return void590 */591 public function testExecuteWithTwoArgs() {592 $this->Task->args = array('Model', 'TestTaskTag');593 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));594 $this->Task->expects($this->once())->method('createFile')595 ->with(596 $this->anything(),597 $this->stringContains('class TestTaskTagTest extends CakeTestCase')598 );599 $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));600 $this->Task->execute();601 }602/**603 * test execute with type and class name defined and lower case.604 *605 * @return void606 */607 public function testExecuteWithTwoArgsLowerCase() {608 $this->Task->args = array('model', 'TestTaskTag');609 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));610 $this->Task->expects($this->once())->method('createFile')611 ->with(612 $this->anything(),613 $this->stringContains('class TestTaskTagTest extends CakeTestCase')614 );615 $this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));616 $this->Task->execute();617 }618/**619 * Data provider for mapType() tests.620 *621 * @return array622 */623 public static function mapTypeProvider() {624 return array(625 array('controller', null, 'Controller'),626 array('Controller', null, 'Controller'),627 array('component', null, 'Controller/Component'),628 array('Component', null, 'Controller/Component'),629 array('model', null, 'Model'),630 array('Model', null, 'Model'),631 array('behavior', null, 'Model/Behavior'),632 array('Behavior', null, 'Model/Behavior'),633 array('helper', null, 'View/Helper'),634 array('Helper', null, 'View/Helper'),635 array('Helper', 'DebugKit', 'DebugKit.View/Helper'),636 );637 }638/**639 * Test that mapType returns the correct package names.640 *641 * @dataProvider mapTypeProvider642 * @return void643 */644 public function testMapType($original, $plugin, $expected) {645 $this->assertEquals($expected, $this->Task->mapType($original, $plugin));646 }647}...

Full Screen

Full Screen

ControllerTaskTest.php

Source:ControllerTaskTest.php Github

copy

Full Screen

1<?php2/**3 * ControllerTask Test Case4 *5 * PHP 56 *7 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)8 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)9 *10 * Licensed under The MIT License11 * For full copyright and license information, please see the LICENSE.txt12 * Redistributions of files must retain the above copyright notice.13 *14 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)15 * @link http://cakephp.org CakePHP(tm) Project16 * @package Cake.Test.Case.Console.Command.Task17 * @since CakePHP(tm) v 1.318 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)19 */20App::uses('ConsoleOutput', 'Console');21App::uses('ConsoleInput', 'Console');22App::uses('ShellDispatcher', 'Console');23App::uses('Shell', 'Console');24App::uses('CakeSchema', 'Model');25App::uses('ClassRegistry', 'Utility');26App::uses('Helper', 'View/Helper');27App::uses('ProjectTask', 'Console/Command/Task');28App::uses('ControllerTask', 'Console/Command/Task');29App::uses('ModelTask', 'Console/Command/Task');30App::uses('TemplateTask', 'Console/Command/Task');31App::uses('TestTask', 'Console/Command/Task');32App::uses('Model', 'Model');33App::uses('BakeArticle', 'Model');34App::uses('BakeComment', 'Model');35App::uses('BakeTags', 'Model');36$imported = class_exists('BakeArticle') || class_exists('BakeComment') || class_exists('BakeTag');37if (!$imported) {38 define('ARTICLE_MODEL_CREATED', true);39 class BakeArticle extends Model {40 public $name = 'BakeArticle';41 public $hasMany = array('BakeComment');42 public $hasAndBelongsToMany = array('BakeTag');43 }44}45/**46 * ControllerTaskTest class47 *48 * @package Cake.Test.Case.Console.Command.Task49 */50class ControllerTaskTest extends CakeTestCase {51/**52 * fixtures53 *54 * @var array55 */56 public $fixtures = array('core.bake_article', 'core.bake_articles_bake_tag', 'core.bake_comment', 'core.bake_tag');57/**58 * setUp method59 *60 * @return void61 */62 public function setUp() {63 parent::setUp();64 $out = $this->getMock('ConsoleOutput', array(), array(), '', false);65 $in = $this->getMock('ConsoleInput', array(), array(), '', false);66 $this->Task = $this->getMock('ControllerTask',67 array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),68 array($out, $out, $in)69 );70 $this->Task->name = 'Controller';71 $this->Task->Template = new TemplateTask($out, $out, $in);72 $this->Task->Template->params['theme'] = 'default';73 $this->Task->Model = $this->getMock('ModelTask',74 array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),75 array($out, $out, $in)76 );77 $this->Task->Project = $this->getMock('ProjectTask',78 array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),79 array($out, $out, $in)80 );81 $this->Task->Test = $this->getMock('TestTask', array(), array($out, $out, $in));82 if (!defined('ARTICLE_MODEL_CREATED')) {83 $this->markTestSkipped('Could not run as an Article, Tag or Comment model was already loaded.');84 }85 }86/**87 * tearDown method88 *89 * @return void90 */91 public function tearDown() {92 unset($this->Task);93 ClassRegistry::flush();94 App::build();95 parent::tearDown();96 }97/**98 * test ListAll99 *100 * @return void101 */102 public function testListAll() {103 $count = count($this->Task->listAll('test'));104 if ($count != count($this->fixtures)) {105 $this->markTestSkipped('Additional tables detected.');106 }107 $this->Task->connection = 'test';108 $this->Task->interactive = true;109 $this->Task->expects($this->at(2))->method('out')->with(' 1. BakeArticles');110 $this->Task->expects($this->at(3))->method('out')->with(' 2. BakeArticlesBakeTags');111 $this->Task->expects($this->at(4))->method('out')->with(' 3. BakeComments');112 $this->Task->expects($this->at(5))->method('out')->with(' 4. BakeTags');113 $expected = array('BakeArticles', 'BakeArticlesBakeTags', 'BakeComments', 'BakeTags');114 $result = $this->Task->listAll('test');115 $this->assertEquals($expected, $result);116 $this->Task->interactive = false;117 $result = $this->Task->listAll();118 $expected = array('bake_articles', 'bake_articles_bake_tags', 'bake_comments', 'bake_tags');119 $this->assertEquals($expected, $result);120 }121/**122 * Test that getName interacts with the user and returns the controller name.123 *124 * @return void125 */126 public function testGetNameValidIndex() {127 $count = count($this->Task->listAll('test'));128 if ($count != count($this->fixtures)) {129 $this->markTestSkipped('Additional tables detected.');130 }131 $this->Task->interactive = true;132 $this->Task->expects($this->any())->method('in')->will(133 $this->onConsecutiveCalls(3, 1)134 );135 $result = $this->Task->getName('test');136 $expected = 'BakeComments';137 $this->assertEquals($expected, $result);138 $result = $this->Task->getName('test');139 $expected = 'BakeArticles';140 $this->assertEquals($expected, $result);141 }142/**143 * test getting invalid indexes.144 *145 * @return void146 */147 public function testGetNameInvalidIndex() {148 $this->Task->interactive = true;149 $this->Task->expects($this->any())->method('in')150 ->will($this->onConsecutiveCalls(50, 'q'));151 $this->Task->expects($this->once())->method('err');152 $this->Task->expects($this->once())->method('_stop');153 $this->Task->getName('test');154 }155/**156 * test helper interactions157 *158 * @return void159 */160 public function testDoHelpersNo() {161 $this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));162 $result = $this->Task->doHelpers();163 $this->assertSame(array(), $result);164 }165/**166 * test getting helper values167 *168 * @return void169 */170 public function testDoHelpersTrailingSpace() {171 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));172 $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne '));173 $result = $this->Task->doHelpers();174 $expected = array('Text', 'Number', 'CustomOne');175 $this->assertEquals($expected, $result);176 }177/**178 * test doHelpers with extra commas179 *180 * @return void181 */182 public function testDoHelpersTrailingCommas() {183 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));184 $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , '));185 $result = $this->Task->doHelpers();186 $expected = array('Text', 'Number', 'CustomOne');187 $this->assertEquals($expected, $result);188 }189/**190 * test component interactions191 *192 * @return void193 */194 public function testDoComponentsNo() {195 $this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));196 $result = $this->Task->doComponents();197 $this->assertSame(array(), $result);198 }199/**200 * test components with spaces201 *202 * @return void203 */204 public function testDoComponentsTrailingSpaces() {205 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));206 $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security '));207 $result = $this->Task->doComponents();208 $expected = array('RequestHandler', 'Security');209 $this->assertEquals($expected, $result);210 }211/**212 * test components with commas213 *214 * @return void215 */216 public function testDoComponentsTrailingCommas() {217 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));218 $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));219 $result = $this->Task->doComponents();220 $expected = array('RequestHandler', 'Security');221 $this->assertEquals($expected, $result);222 }223/**224 * test Confirming controller user interaction225 *226 * @return void227 */228 public function testConfirmController() {229 $controller = 'Posts';230 $scaffold = false;231 $helpers = array('Js', 'Time');232 $components = array('Acl', 'Auth');233 $this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");234 $this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time");235 $this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");236 $this->Task->confirmController($controller, $scaffold, $helpers, $components);237 }238/**239 * test the bake method240 *241 * @return void242 */243 public function testBake() {244 $helpers = array('Js', 'Time');245 $components = array('Acl', 'Auth');246 $this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));247 $result = $this->Task->bake('Articles', '--actions--', $helpers, $components);248 $this->assertContains(' * @property Article $Article', $result);249 $this->assertContains(' * @property AclComponent $Acl', $result);250 $this->assertContains(' * @property AuthComponent $Auth', $result);251 $this->assertContains('class ArticlesController extends AppController', $result);252 $this->assertContains("public \$components = array('Acl', 'Auth')", $result);253 $this->assertContains("public \$helpers = array('Js', 'Time')", $result);254 $this->assertContains("--actions--", $result);255 $result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);256 $this->assertContains("class ArticlesController extends AppController", $result);257 $this->assertContains("public \$scaffold", $result);258 $this->assertNotContains('@property', $result);259 $this->assertNotContains('helpers', $result);260 $this->assertNotContains('components', $result);261 $result = $this->Task->bake('Articles', '--actions--', array(), array());262 $this->assertContains('class ArticlesController extends AppController', $result);263 $this->assertSame(substr_count($result, '@property'), 1);264 $this->assertNotContains('components', $result);265 $this->assertNotContains('helpers', $result);266 $this->assertContains('--actions--', $result);267 }268/**269 * test bake() with a -plugin param270 *271 * @return void272 */273 public function testBakeWithPlugin() {274 $this->Task->plugin = 'ControllerTest';275 //fake plugin path276 CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));277 $path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';278 $this->Task->expects($this->at(1))->method('createFile')->with(279 $path,280 new PHPUnit_Framework_Constraint_IsAnything()281 );282 $this->Task->expects($this->at(3))->method('createFile')->with(283 $path,284 $this->stringContains('ArticlesController extends ControllerTestAppController')285 )->will($this->returnValue(true));286 $this->Task->bake('Articles', '--actions--', array(), array(), array());287 $this->Task->plugin = 'ControllerTest';288 $path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';289 $result = $this->Task->bake('Articles', '--actions--', array(), array(), array());290 $this->assertContains("App::uses('ControllerTestAppController', 'ControllerTest.Controller');", $result);291 $this->assertEquals('ControllerTest', $this->Task->Template->templateVars['plugin']);292 $this->assertEquals('ControllerTest.', $this->Task->Template->templateVars['pluginPath']);293 CakePlugin::unload();294 }295/**296 * test that bakeActions is creating the correct controller Code. (Using sessions)297 *298 * @return void299 */300 public function testBakeActionsUsingSessions() {301 $result = $this->Task->bakeActions('BakeArticles', null, true);302 $this->assertContains('function index() {', $result);303 $this->assertContains('$this->BakeArticle->recursive = 0;', $result);304 $this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);305 $this->assertContains('function view($id = null)', $result);306 $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);307 $this->assertContains("\$options = array('conditions' => array('BakeArticle.' . \$this->BakeArticle->primaryKey => \$id));", $result);308 $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);309 $this->assertContains('function add()', $result);310 $this->assertContains("if (\$this->request->is('post'))", $result);311 $this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);312 $this->assertContains("\$this->Session->setFlash(__('The bake article has been saved'));", $result);313 $this->assertContains('function edit($id = null)', $result);314 $this->assertContains("\$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));", $result);315 $this->assertContains('function delete($id = null)', $result);316 $this->assertContains('if ($this->BakeArticle->delete())', $result);317 $this->assertContains("\$this->Session->setFlash(__('Bake article deleted'));", $result);318 $result = $this->Task->bakeActions('BakeArticles', 'admin_', true);319 $this->assertContains('function admin_index() {', $result);320 $this->assertContains('function admin_add()', $result);321 $this->assertContains('function admin_view($id = null)', $result);322 $this->assertContains('function admin_edit($id = null)', $result);323 $this->assertContains('function admin_delete($id = null)', $result);324 }325/**326 * Test baking with Controller::flash() or no sessions.327 *328 * @return void329 */330 public function testBakeActionsWithNoSessions() {331 $result = $this->Task->bakeActions('BakeArticles', null, false);332 $this->assertContains('function index() {', $result);333 $this->assertContains('$this->BakeArticle->recursive = 0;', $result);334 $this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);335 $this->assertContains('function view($id = null)', $result);336 $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);337 $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);338 $this->assertContains('function add()', $result);339 $this->assertContains("if (\$this->request->is('post'))", $result);340 $this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);341 $this->assertContains("\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))", $result);342 $this->assertContains('function edit($id = null)', $result);343 $this->assertContains("\$this->BakeArticle->BakeTag->find('list')", $result);344 $this->assertContains("\$this->set(compact('bakeTags'))", $result);345 $this->assertContains('function delete($id = null)', $result);346 $this->assertContains("\$this->request->onlyAllow('post', 'delete')", $result);347 $this->assertContains('if ($this->BakeArticle->delete())', $result);348 $this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result);349 }350/**351 * test baking a test352 *353 * @return void354 */355 public function testBakeTest() {356 $this->Task->plugin = 'ControllerTest';357 $this->Task->connection = 'test';358 $this->Task->interactive = false;359 $this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'BakeArticles');360 $this->Task->bakeTest('BakeArticles');361 $this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);362 $this->assertEquals($this->Task->connection, $this->Task->Test->connection);363 $this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);364 }365/**366 * test Interactive mode.367 *368 * @return void369 */370 public function testInteractive() {371 $count = count($this->Task->listAll('test'));372 if ($count != count($this->fixtures)) {373 $this->markTestSkipped('Additional tables detected.');374 }375 $this->Task->connection = 'test';376 $this->Task->path = '/my/path/';377 $this->Task->expects($this->any())->method('in')378 ->will($this->onConsecutiveCalls(379 '1',380 'y', // build interactive381 'n', // build no scaffolds382 'y', // build normal methods383 'n', // build admin methods384 'n', // helpers?385 'n', // components?386 'y', // sessions ?387 'y' // looks good?388 ));389 $filename = '/my/path/BakeArticlesController.php';390 $this->Task->expects($this->once())->method('createFile')->with(391 $filename,392 $this->stringContains('class BakeArticlesController')393 );394 $this->Task->execute();395 }396/**397 * test Interactive mode.398 *399 * @return void400 */401 public function testInteractiveAdminMethodsNotInteractive() {402 $count = count($this->Task->listAll('test'));403 if ($count != count($this->fixtures)) {404 $this->markTestSkipped('Additional tables detected.');405 }406 $this->Task->connection = 'test';407 $this->Task->interactive = true;408 $this->Task->path = '/my/path/';409 $this->Task->expects($this->any())->method('in')410 ->will($this->onConsecutiveCalls(411 '1',412 'y', // build interactive413 'n', // build no scaffolds414 'y', // build normal methods415 'y', // build admin methods416 'n', // helpers?417 'n', // components?418 'y', // sessions ?419 'y' // looks good?420 ));421 $this->Task->Project->expects($this->any())422 ->method('getPrefix')423 ->will($this->returnValue('admin_'));424 $filename = '/my/path/BakeArticlesController.php';425 $this->Task->expects($this->once())->method('createFile')->with(426 $filename,427 $this->stringContains('class BakeArticlesController')428 )->will($this->returnValue(true));429 $result = $this->Task->execute();430 $this->assertRegExp('/admin_index/', $result);431 }432/**433 * test that execute runs all when the first arg == all434 *435 * @return void436 */437 public function testExecuteIntoAll() {438 $count = count($this->Task->listAll('test'));439 if ($count != count($this->fixtures)) {440 $this->markTestSkipped('Additional tables detected.');441 }442 $this->Task->connection = 'test';443 $this->Task->path = '/my/path/';444 $this->Task->args = array('all');445 $this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));446 $this->Task->Test->expects($this->once())->method('bake');447 $filename = '/my/path/BakeArticlesController.php';448 $this->Task->expects($this->once())->method('createFile')->with(449 $filename,450 $this->stringContains('class BakeArticlesController')451 )->will($this->returnValue(true));452 $this->Task->execute();453 }454/**455 * Test execute() with all and --admin456 *457 * @return void458 */459 public function testExecuteIntoAllAdmin() {460 $count = count($this->Task->listAll('test'));461 if ($count != count($this->fixtures)) {462 $this->markTestSkipped('Additional tables detected.');463 }464 $this->Task->connection = 'test';465 $this->Task->path = '/my/path/';466 $this->Task->args = array('all');467 $this->Task->params['admin'] = true;468 $this->Task->Project->expects($this->any())469 ->method('getPrefix')470 ->will($this->returnValue('admin_'));471 $this->Task->expects($this->any())472 ->method('_checkUnitTest')473 ->will($this->returnValue(true));474 $this->Task->Test->expects($this->once())->method('bake');475 $filename = '/my/path/BakeArticlesController.php';476 $this->Task->expects($this->once())->method('createFile')->with(477 $filename,478 $this->stringContains('function admin_index')479 )->will($this->returnValue(true));480 $this->Task->execute();481 }482/**483 * test that `cake bake controller foos` works.484 *485 * @return void486 */487 public function testExecuteWithController() {488 $this->Task->connection = 'test';489 $this->Task->path = '/my/path/';490 $this->Task->args = array('BakeArticles');491 $filename = '/my/path/BakeArticlesController.php';492 $this->Task->expects($this->once())->method('createFile')->with(493 $filename,494 $this->stringContains('$scaffold')495 );496 $this->Task->execute();497 }498/**499 * data provider for testExecuteWithControllerNameVariations500 *501 * @return void502 */503 public static function nameVariations() {504 return array(505 array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')506 );507 }508/**509 * test that both plural and singular forms work for controller baking.510 *511 * @dataProvider nameVariations512 * @return void513 */514 public function testExecuteWithControllerNameVariations($name) {515 $this->Task->connection = 'test';516 $this->Task->path = '/my/path/';517 $this->Task->args = array($name);518 $filename = '/my/path/BakeArticlesController.php';519 $this->Task->expects($this->once())->method('createFile')->with(520 $filename, $this->stringContains('$scaffold')521 );522 $this->Task->execute();523 }524/**525 * test that `cake bake controller foo scaffold` works.526 *527 * @return void528 */529 public function testExecuteWithPublicParam() {530 $this->Task->connection = 'test';531 $this->Task->path = '/my/path/';532 $this->Task->args = array('BakeArticles');533 $this->Task->params = array('public' => true);534 $filename = '/my/path/BakeArticlesController.php';535 $expected = new PHPUnit_Framework_Constraint_Not($this->stringContains('$scaffold'));536 $this->Task->expects($this->once())->method('createFile')->with(537 $filename, $expected538 );539 $this->Task->execute();540 }541/**542 * test that `cake bake controller foos both` works.543 *544 * @return void545 */546 public function testExecuteWithControllerAndBoth() {547 $this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));548 $this->Task->connection = 'test';549 $this->Task->path = '/my/path/';550 $this->Task->args = array('BakeArticles');551 $this->Task->params = array('public' => true, 'admin' => true);552 $filename = '/my/path/BakeArticlesController.php';553 $this->Task->expects($this->once())->method('createFile')->with(554 $filename, $this->stringContains('admin_index')555 );556 $this->Task->execute();557 }558/**559 * test that `cake bake controller foos admin` works.560 *561 * @return void562 */563 public function testExecuteWithControllerAndAdmin() {564 $this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));565 $this->Task->connection = 'test';566 $this->Task->path = '/my/path/';567 $this->Task->args = array('BakeArticles');568 $this->Task->params = array('admin' => true);569 $filename = '/my/path/BakeArticlesController.php';570 $this->Task->expects($this->once())->method('createFile')->with(571 $filename, $this->stringContains('admin_index')572 );573 $this->Task->execute();574 }575}...

Full Screen

Full Screen

EarlyRenderingControllerTest.php

Source:EarlyRenderingControllerTest.php Github

copy

Full Screen

1<?php2namespace Drupal\Tests\system\Functional\Common;3use Drupal\Core\Url;4use Drupal\Tests\BrowserTestBase;5/**6 * Verifies that bubbleable metadata of early rendering is not lost.7 *8 * @group Common9 */10class EarlyRenderingControllerTest extends BrowserTestBase {11 /**12 * {@inheritdoc}13 */14 protected $dumpHeaders = TRUE;15 /**16 * {@inheritdoc}17 */18 protected static $modules = ['system', 'early_rendering_controller_test'];19 /**20 * {@inheritdoc}21 */22 protected $defaultTheme = 'stark';23 /**24 * Tests theme preprocess functions being able to attach assets.25 */26 public function testEarlyRendering() {27 // Render array: non-early & early.28 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array'));29 $this->assertSession()->statusCodeEquals(200);30 $this->assertSession()->pageTextContains('Hello world!');31 $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'foo');32 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array.early'));33 $this->assertSession()->statusCodeEquals(200);34 $this->assertSession()->pageTextContains('Hello world!');35 $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'foo');36 // AjaxResponse: non-early & early.37 // @todo Add cache tags assertion when AjaxResponse is made cacheable in38 // https://www.drupal.org/node/956186.39 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response'));40 $this->assertSession()->statusCodeEquals(200);41 $this->assertSession()->pageTextContains('Hello world!');42 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response.early'));43 $this->assertSession()->statusCodeEquals(200);44 $this->assertSession()->pageTextContains('Hello world!');45 // Basic Response object: non-early & early.46 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response'));47 $this->assertSession()->statusCodeEquals(200);48 $this->assertSession()->pageTextContains('Hello world!');49 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');50 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response.early'));51 $this->assertSession()->statusCodeEquals(200);52 $this->assertSession()->pageTextContains('Hello world!');53 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');54 // Response object with attachments: non-early & early.55 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments'));56 $this->assertSession()->statusCodeEquals(200);57 $this->assertSession()->pageTextContains('Hello world!');58 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');59 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments.early'));60 $this->assertSession()->statusCodeEquals(500);61 $this->assertSession()->pageTextContains('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\AttachmentsTestResponse.');62 // Cacheable Response object: non-early & early.63 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response'));64 $this->assertSession()->statusCodeEquals(200);65 $this->assertSession()->pageTextContains('Hello world!');66 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');67 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response.early'));68 $this->assertSession()->statusCodeEquals(500);69 $this->assertSession()->pageTextContains('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\CacheableTestResponse.');70 // Basic domain object: non-early & early.71 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object'));72 $this->assertSession()->statusCodeEquals(200);73 $this->assertSession()->pageTextContains('TestDomainObject');74 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');75 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object.early'));76 $this->assertSession()->statusCodeEquals(200);77 $this->assertSession()->pageTextContains('TestDomainObject');78 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');79 // Basic domain object with attachments: non-early & early.80 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments'));81 $this->assertSession()->statusCodeEquals(200);82 $this->assertSession()->pageTextContains('AttachmentsTestDomainObject');83 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');84 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments.early'));85 $this->assertSession()->statusCodeEquals(500);86 $this->assertSession()->pageTextContains('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\AttachmentsTestDomainObject.');87 // Cacheable Response object: non-early & early.88 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object'));89 $this->assertSession()->statusCodeEquals(200);90 $this->assertSession()->pageTextContains('CacheableTestDomainObject');91 $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');92 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object.early'));93 $this->assertSession()->statusCodeEquals(500);94 $this->assertSession()->pageTextContains('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\CacheableTestDomainObject.');95 // The exceptions are expected. Do not interpret them as a test failure.96 // Not using File API; a potential error must trigger a PHP warning.97 unlink($this->root . '/' . $this->siteDirectory . '/error.log');98 }99}...

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1$controller->contains('method_name');2$controller->contains('method_name');3$controller->contains('method_name');4$controller->contains('method_name');5$controller->contains('method_name');6$controller->contains('method_name');7$controller->contains('method_name');8$controller->contains('method_name');9$controller->contains('method_name');10$controller->contains('method_name');11$controller->contains('method_name');12$controller->contains('method_name');13$controller->contains('method_name');14$controller->contains('method_name');15$controller->contains('method_name');16$controller->contains('method_name');17$controller->contains('method_name');18$controller->contains('method_name');19$controller->contains('method_name');20$controller->contains('method_name');

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1$controller = new Controller();2$controller->contains('test');3$controller = new Controller();4$controller->contains('test');5$controller = new Controller();6$controller->contains('test');7$controller = new Controller();8$controller->contains('test');9$controller = new Controller();10$controller->contains('test');11$controller = new Controller();12$controller->contains('test');13$controller = new Controller();14$controller->contains('test');15$controller = new Controller();16$controller->contains('test');17$controller = new Controller();18$controller->contains('test');19$controller = new Controller();20$controller->contains('test');21$controller = new Controller();22$controller->contains('test');23$controller = new Controller();24$controller->contains('test');25$controller = new Controller();26$controller->contains('test');27$controller = new Controller();28$controller->contains('test');29$controller = new Controller();30$controller->contains('test');31$controller = new Controller();32$controller->contains('test');33$controller = new Controller();34$controller->contains('test');

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1$controller->contains('name of the function');2$controller->contains('name of the function');3$controller->contains('name of the function');4$controller->contains('name of the function');5$controller->contains('name of the function');6$controller->contains('name of the function');7$controller->contains('name of the function');8$controller->contains('name of the function');9$controller->contains('name of the function');10$controller->contains('name of the function');11$controller->contains('name of the function');12$controller->contains('name of the function');13$controller->contains('name of the function');14$controller->contains('name of the function');15$controller->contains('name of the function');16$controller->contains('name of the function');17$controller->contains('name of the function');18$controller->contains('name of the function');19$controller->contains('name of the function');20$controller->contains('name of the function');21$controller->contains('name of the function');22$controller->contains('name of the function');23$controller->contains('name of the function');24$controller->contains('name of the function');

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1$this->controller->contains('test','test');2$this->controller->contains('test','test');3$this->controller->contains('test','test');4$this->controller->contains('test','test');5$this->controller->contains('test','test');6$this->controller->contains('test','test');7$this->controller->contains('test','test');8$this->controller->contains('test','test');9$this->controller->contains('test','test');10$this->controller->contains('test','test');11$this->controller->contains('test','test');12$this->controller->contains('test','test');13$this->controller->contains('test','test');14$this->controller->contains('test','test');15$this->controller->contains('test','test');16$this->controller->contains('test','test');17$this->controller->contains('test','test');18$this->controller->contains('test','test');19$this->controller->contains('test','test');

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1$controller->contains('name', 'John');2$controller->contains('name', 'John', 'and');3$controller->contains('name', 'John', 'or');4$controller->contains('name', 'John', 'or', 'and');5$controller->contains('name', 'John', 'or', 'or');6$controller->contains('name', 'John', 'and', 'or');7$controller->contains('name', 'John', 'and', 'and');8$controller->contains('name', 'John', 'or', 'and', 'or');9$controller->contains('name', 'John', 'or', 'and', 'and');10$controller->contains('name', 'John', 'and', 'or', 'or');11$controller->contains('name', 'John', 'and', 'or', 'and');12$controller->contains('name', 'John', 'and', 'and', 'or');13$controller->contains('name', 'John', 'and', 'and', 'and');14$controller->contains('name', 'John', 'or', 'or', 'or');15$controller->contains('name', 'John', 'and', 'or', 'or', 'and');

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1class Controller {2 public function contains($string) {3 if (strpos($string, '1') !== false) {4 return true;5 }6 return false;7 }8}9require_once '1.php';10$controller = new Controller();11if($controller->contains('123')) {12 echo 'yes';13} else {14 echo 'no';15}

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1if($this->controller->contains($this->method)){2$this->controller->{$this->method}();3}else{4$this->controller->index();5}6}7private function getController(){8$controller = $this->url[0];9$this->controller = $controller . 'Controller';10if(file_exists(CONTROLLER . $this->controller . '.php')){11require_once CONTROLLER . $this->controller . '.php';12$this->controller = new $this->controller();13}else{14$this->controller = DEFAULT_CONTROLLER . 'Controller';15require_once CONTROLLER . $this->controller . '.php';16$this->controller = new $this->controller();17}18}19private function getMethod(){20if(isset($this->url[1])){21$this->method = $this->url[1];22}23}24private function getParams(){25$this->params = array_values($this->url);26}27}28define('APPLICATION', 'application/');29define('CONTROLLER', APPLICATION . 'controller/');30define('MODEL', APPLICATION . 'model/');31define('VIEW', APPLICATION . 'view/');32define('DEFAULT_CONTROLLER', 'home');33require_once 'bootstrap.php';

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1$controller = new Controller();2if($controller->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }3$model = new Model();4if($model->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }5$view = new View();6if($view->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }7$index = new Index();8if($index->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }9$app = new App();10if($app->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }11$database = new Database();12if($database->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }13$session = new Session();14if($session->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }15$cookie = new Cookie();16if($cookie->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }17$route = new Route();18if($route->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }19$url = new Url();20if($url->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }21$request = new Request();22if($request->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }23$response = new Response();24if($response->contains('some text', 'some text')){ echo 'true'; }else{ echo 'false'; }

Full Screen

Full Screen

contains

Using AI Code Generation

copy

Full Screen

1if($this->controller->contains("view.php"))2{3$this->controller->view();4}5{6}7if($this->controller->contains("view.php"))8{9$this->controller->view();10}11{12}13if($this->controller->contains("view.php"))14{15$this->controller->view();16}17{18}19if($this->controller->contains("view.php"))20{21$this->controller->view();22}23{24}25if($this->controller->contains("view.php"))26{27$this->controller->view();28}29{30}31if($this->controller->contains("view.php"))32{33$this->controller->view();34}35{

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in controller

Trigger contains code on LambdaTest Cloud Grid

Execute automation tests with contains on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful