How to use setUp method of should class

Best Phake code snippet using should.setUp

SetupTest.php

Source:SetupTest.php Github

copy

Full Screen

1<?php2use org\bovigo\vfs\vfsStream;3use org\bovigo\vfs\vfsStreamFile;4use Symfony\Component\Console\Application;5use Symfony\Component\Console\Tester\CommandTester;6use tad\Codeception\Command\SearchReplace;7use tad\Codeception\Command\Setup;8class SetupTest extends PHPUnit_Framework_TestCase9{10 /**11 * @test12 * it should use the setup.yml file from the cwd if config file is not specified13 */14 public function it_should_use_the_setup_yml_file_from_the_cwd_if_config_file_is_not_specified()15 {16 $application = new Application();17 $application->add(new Setup());18 $command = $application->find('setup');19 $commandTester = new CommandTester($command);20 $commandTester->execute([21 'command' => $command->getName(),22 ]);23 $this->assertContains('setup.yml] does not exist', $commandTester->getDisplay());24 }25 /**26 * @test27 * it should throw if specified configuration file does not exist28 */29 public function it_should_throw_if_specified_configuration_file_does_not_exist()30 {31 $dir = vfsStream::setup();32 $application = new Application();33 $application->add(new Setup());34 $command = $application->find('setup');35 $commandTester = new CommandTester($command);36 $commandTester->execute([37 'command' => $command->getName(),38 'config' => $dir->url() . '/conf.yaml'39 ]);40 $this->assertRegExp('/Configuration file.*does not exist/', $commandTester->getDisplay());41 }42 /**43 * @test44 * it should allow for the .yml extension to be omitted from the configuration file name45 */46 public function it_should_allow_for_the_yml_extension_to_be_omitted_from_the_configuration_file_name()47 {48 $configFile = codecept_root_dir('local.yml');49 $configFileContent = <<< YAML50foo:51 message: Hello world!52YAML;53 file_put_contents($configFile, $configFileContent);54 $application = new Application();55 $application->add(new Setup());56 $command = $application->find('setup');57 $commandTester = new CommandTester($command);58 $commandTester->execute([59 'command' => $command->getName(),60 'config' => 'local'61 ]);62 $display = $commandTester->getDisplay();63 $this->assertContains('Hello world!', $display);64 if (file_exists($configFile)) {65 unlink($configFile);66 }67 }68 /**69 * @test70 * it should allow specifying a variable in the configuration file71 */72 public function it_should_allow_specifying_a_variable_in_the_configuration_file()73 {74 $dir = vfsStream::setup();75 $configFile = new vfsStreamFile('conf.yaml');76 $configFileContent = <<< YAML77foo:78 var:79 name: first80 question: first var value?81 default: 2382 message: Var value is \$first83YAML;84 $configFile->setContent($configFileContent);85 $dir->addChild($configFile);86 $application = new Application();87 $application->add(new Setup());88 $command = $application->find('setup');89 $commandTester = new CommandTester($command);90 $helper = $command->getHelper('question');91 $helper->setInputStream($this->getInputStream("Test\n"));92 $commandTester->execute([93 'command' => $command->getName(),94 'config' => $dir->url() . '/conf.yaml'95 ]);96 $display = $commandTester->getDisplay();97 $this->assertContains('Configuring "foo"', $display);98 $this->assertContains('first var value? (23)', $display);99 $this->assertContains('Var value is Test', $display);100 }101 /**102 * @test103 * it should allow running commands from the configuration file104 */105 public function it_should_allow_running_commands_from_the_configuration_file()106 {107 $dir = vfsStream::setup();108 $sourceFile = new vfsStreamFile('source.txt');109 $outputFile = new vfsStreamFile('out.txt');110 $sourceFile->setContent('foo baz bar');111 $sourceFilePath = $dir->url() . '/source.txt';112 $outputFilePath = $dir->url() . '/out.txt';113 $configFile = new vfsStreamFile('conf.yaml');114 $configFileContent = <<< YAML115foo:116 var:117 name: first118 question: first var value?119 default: 23120 command: search-replace foo \$first $sourceFilePath $outputFilePath121YAML;122 $configFile->setContent($configFileContent);123 $dir->addChild($configFile);124 $dir->addChild($sourceFile);125 $dir->addChild($outputFile);126 $application = new Application();127 $application->add(new Setup());128 $command = $application->find('setup');129 $application->add(new SearchReplace());130 $commandTester = new CommandTester($command);131 $helper = $command->getHelper('question');132 $helper->setInputStream($this->getInputStream("hello\n"));133 $commandTester->execute([134 'command' => $command->getName(),135 'config' => $dir->url() . '/conf.yaml'136 ]);137 $display = $commandTester->getDisplay();138 $this->assertContains('Configuring "foo"', $display);139 $this->assertContains('first var value? (23)', $display);140 $this->assertStringEqualsFile($outputFilePath, 'hello baz bar');141 }142 /**143 * @test144 * it should allow executing scripts145 */146 public function it_should_allow_executing_scripts()147 {148 $dir = vfsStream::setup();149 $configFile = new vfsStreamFile('conf.yaml');150 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';151 $configFileContent = <<< YAML152foo:153 exec: touch {$outputFile}154YAML;155 $configFile->setContent($configFileContent);156 $dir->addChild($configFile);157 $application = new Application();158 $application->add(new Setup());159 $command = $application->find('setup');160 $commandTester = new CommandTester($command);161 $commandTester->execute([162 'command' => $command->getName(),163 'config' => $dir->url() . '/conf.yaml'164 ]);165 $this->assertFileExists($outputFile);166 unlink($outputFile);167 }168 /**169 * @test170 * it should allow for vars in scripts171 */172 public function it_should_allow_for_vars_in_scripts()173 {174 $dir = vfsStream::setup();175 $configFile = new vfsStreamFile('conf.yaml');176 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';177 $configFileContent = <<< YAML178foo:179 var:180 name: first181 question: first var value?182 default: 12183 exec: touch {$outputFile} && echo "\$first" > {$outputFile}184YAML;185 $configFile->setContent($configFileContent);186 $dir->addChild($configFile);187 $application = new Application();188 $application->add(new Setup());189 $command = $application->find('setup');190 $commandTester = new CommandTester($command);191 $helper = $command->getHelper('question');192 $helper->setInputStream($this->getInputStream("hello\n"));193 $commandTester->execute([194 'command' => $command->getName(),195 'config' => $dir->url() . '/conf.yaml'196 ]);197 $this->assertFileExists($outputFile);198 // let's take the simulated input aberration into account199 $this->assertStringEqualsFile($outputFile, "hello\n");200 unlink($outputFile);201 }202 /**203 * @test204 * it should allow displaying messages conditionally205 */206 public function it_should_allow_displaying_messages_conditionally()207 {208 $dir = vfsStream::setup();209 $configFile = new vfsStreamFile('conf.yaml');210 $configFileContent = <<< YAML211foo:212 var:213 name: display214 question: mode?215 default: on216 message:217 if: display is on218 value: Now you see me219YAML;220 $configFile->setContent($configFileContent);221 $dir->addChild($configFile);222 $application = new Application();223 $application->add(new Setup());224 $command = $application->find('setup');225 $commandTester = new CommandTester($command);226 $helper = $command->getHelper('question');227 $helper->setInputStream($this->getInputStream("on\n"));228 $commandTester->execute([229 'command' => $command->getName(),230 'config' => $dir->url() . '/conf.yaml'231 ]);232 $display = $commandTester->getDisplay();233 $this->assertContains('mode?', $display);234 $this->assertContains('Now you see me', $display);235 }236 /**237 * @test238 * it should allow not displaying messages conditionally239 */240 public function it_should_allow_not_displaying_messages_conditionally()241 {242 $dir = vfsStream::setup();243 $configFile = new vfsStreamFile('conf.yaml');244 $configFileContent = <<< YAML245foo:246 var:247 name: display248 question: mode?249 default: on250 message:251 if: display is on252 value: Now you see me253YAML;254 $configFile->setContent($configFileContent);255 $dir->addChild($configFile);256 $application = new Application();257 $application->add(new Setup());258 $command = $application->find('setup');259 $commandTester = new CommandTester($command);260 $helper = $command->getHelper('question');261 $helper->setInputStream($this->getInputStream("off\n"));262 $commandTester->execute([263 'command' => $command->getName(),264 'config' => $dir->url() . '/conf.yaml'265 ]);266 $display = $commandTester->getDisplay();267 $this->assertContains('mode?', $display);268 $this->assertNotContains('Now you see me', $display);269 }270 /**271 * @test272 * it should allow to conditionally request a var273 */274 public function it_should_allow_to_conditionally_request_a_var()275 {276 $dir = vfsStream::setup();277 $configFile = new vfsStreamFile('conf.yaml');278 $configFileContent = <<< YAML279foo:280 var:281 name: display282 question: mode?283 default: on284 var:285 if: display is on286 name: foo287 question: foo var value?288 default: some value289YAML;290 $configFile->setContent($configFileContent);291 $dir->addChild($configFile);292 $application = new Application();293 $application->add(new Setup());294 $command = $application->find('setup');295 $commandTester = new CommandTester($command);296 $helper = $command->getHelper('question');297 $helper->setInputStream($this->getInputStream("on\n23\n"));298 $commandTester->execute([299 'command' => $command->getName(),300 'config' => $dir->url() . '/conf.yaml'301 ]);302 $display = $commandTester->getDisplay();303 $this->assertContains('foo var value?', $display);304 }305 /**306 * @test307 * it should allow to conditionally not ask for a var308 */309 public function it_should_allow_to_conditionally_not_ask_for_a_var()310 {311 $dir = vfsStream::setup();312 $configFile = new vfsStreamFile('conf.yaml');313 $configFileContent = <<< YAML314foo:315 var:316 name: display317 question: mode?318 default: on319 var:320 unless: display is on321 name: foo322 question: foo var value?323 default: some value324YAML;325 $configFile->setContent($configFileContent);326 $dir->addChild($configFile);327 $application = new Application();328 $application->add(new Setup());329 $command = $application->find('setup');330 $commandTester = new CommandTester($command);331 $helper = $command->getHelper('question');332 $helper->setInputStream($this->getInputStream("on\n"));333 $commandTester->execute([334 'command' => $command->getName(),335 'config' => $dir->url() . '/conf.yaml'336 ]);337 $display = $commandTester->getDisplay();338 $this->assertNotContains('foo var value?', $display);339 }340 /**341 * @test342 * it should allow to conditionally run a command343 */344 public function it_should_allow_to_conditionally_run_a_command()345 {346 $dir = vfsStream::setup();347 $sourceFile = new vfsStreamFile('source.txt');348 $outputFile = new vfsStreamFile('out.txt');349 $sourceFile->setContent('foo baz bar');350 $sourceFilePath = $dir->url() . '/source.txt';351 $outputFilePath = $dir->url() . '/out.txt';352 $configFile = new vfsStreamFile('conf.yaml');353 $configFileContent = <<< YAML354foo:355 var:356 name: first357 question: first var value?358 default: 23359 command: 360 if: first is hello361 value: search-replace foo \$first $sourceFilePath $outputFilePath362YAML;363 $configFile->setContent($configFileContent);364 $dir->addChild($configFile);365 $dir->addChild($sourceFile);366 $dir->addChild($outputFile);367 $application = new Application();368 $application->add(new Setup());369 $command = $application->find('setup');370 $application->add(new SearchReplace());371 $commandTester = new CommandTester($command);372 $helper = $command->getHelper('question');373 $helper->setInputStream($this->getInputStream("hello\n"));374 $commandTester->execute([375 'command' => $command->getName(),376 'config' => $dir->url() . '/conf.yaml'377 ]);378 $display = $commandTester->getDisplay();379 $this->assertContains('Configuring "foo"', $display);380 $this->assertContains('first var value? (23)', $display);381 $this->assertStringEqualsFile($outputFilePath, 'hello baz bar');382 }383 /**384 * @test385 * it should allow to conditionally not run a command386 */387 public function it_should_allow_to_conditionally_not_run_a_command()388 {389 $dir = vfsStream::setup();390 $sourceFile = new vfsStreamFile('source.txt');391 $outputFile = new vfsStreamFile('out.txt');392 $sourceFile->setContent('foo baz bar');393 $sourceFilePath = $dir->url() . '/source.txt';394 $outputFilePath = $dir->url() . '/out.txt';395 $configFile = new vfsStreamFile('conf.yaml');396 $configFileContent = <<< YAML397foo:398 var:399 name: first400 question: first var value?401 default: 23402 command: 403 unless: first is hello404 value: search-replace foo \$first $sourceFilePath $outputFilePath405YAML;406 $configFile->setContent($configFileContent);407 $dir->addChild($configFile);408 $dir->addChild($sourceFile);409 $dir->addChild($outputFile);410 $application = new Application();411 $application->add(new Setup());412 $command = $application->find('setup');413 $application->add(new SearchReplace());414 $commandTester = new CommandTester($command);415 $helper = $command->getHelper('question');416 $helper->setInputStream($this->getInputStream("hello\n"));417 $commandTester->execute([418 'command' => $command->getName(),419 'config' => $dir->url() . '/conf.yaml'420 ]);421 $display = $commandTester->getDisplay();422 $this->assertContains('Configuring "foo"', $display);423 $this->assertContains('first var value? (23)', $display);424 $this->assertStringNotEqualsFile($outputFilePath, 'hello baz bar');425 }426 /**427 * @test428 * it should allow to conditionally execute a script429 */430 public function it_should_allow_to_conditionally_execute_a_script()431 {432 $dir = vfsStream::setup();433 $configFile = new vfsStreamFile('conf.yaml');434 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';435 $configFileContent = <<< YAML436foo:437 var:438 name: first439 question: foo var value?440 default: 23441 exec: 442 if: first is hello443 value: touch {$outputFile}444YAML;445 $configFile->setContent($configFileContent);446 $dir->addChild($configFile);447 $application = new Application();448 $application->add(new Setup());449 $command = $application->find('setup');450 $commandTester = new CommandTester($command);451 $helper = $command->getHelper('question');452 $helper->setInputStream($this->getInputStream("hello\n"));453 $commandTester->execute([454 'command' => $command->getName(),455 'config' => $dir->url() . '/conf.yaml'456 ]);457 $this->assertFileExists($outputFile);458 unlink($outputFile);459 }460 /**461 * @test462 * it should allow to conditionally not execute a script463 */464 public function it_should_allow_to_conditionally_not_execute_a_script()465 {466 $dir = vfsStream::setup();467 $configFile = new vfsStreamFile('conf.yaml');468 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';469 $configFileContent = <<< YAML470foo:471 var:472 name: first473 question: foo var value?474 default: 23475 exec: 476 unless: first is hello477 value: touch {$outputFile}478YAML;479 $configFile->setContent($configFileContent);480 $dir->addChild($configFile);481 $application = new Application();482 $application->add(new Setup());483 $command = $application->find('setup');484 $commandTester = new CommandTester($command);485 $helper = $command->getHelper('question');486 $helper->setInputStream($this->getInputStream("hello\n"));487 $commandTester->execute([488 'command' => $command->getName(),489 'config' => $dir->url() . '/conf.yaml'490 ]);491 $this->assertFileNotExists($outputFile);492 }493 /**494 * @test495 * it should allow for int variable validation and ask until var validates496 */497 public function it_should_allow_for_int_variable_validation_and_ask_until_var_validates()498 {499 $dir = vfsStream::setup();500 $configFile = new vfsStreamFile('conf.yaml');501 $configFileContent = <<< YAML502foo:503 var:504 name: first505 question: first var value?506 validate: int507 default: 23508 message: Var value is \$first509YAML;510 $configFile->setContent($configFileContent);511 $dir->addChild($configFile);512 $application = new Application();513 $application->add(new Setup());514 $command = $application->find('setup');515 $commandTester = new CommandTester($command);516 $helper = $command->getHelper('question');517 $helper->setInputStream($this->getInputStream("Test\nfoo\n12\n"));518 $commandTester->execute([519 'command' => $command->getName(),520 'config' => $dir->url() . '/conf.yaml'521 ]);522 $display = $commandTester->getDisplay();523 $this->assertContains('Configuring "foo"', $display);524 $this->assertContains('first var value? (23)', $display);525 $this->assertContains('Var value is 12', $display);526 }527 /**528 * @test529 * it should allow for float variable validation and ask until var validates530 */531 public function it_should_allow_for_float_variable_validation_and_ask_until_var_validates()532 {533 $dir = vfsStream::setup();534 $configFile = new vfsStreamFile('conf.yaml');535 $configFileContent = <<< YAML536foo:537 var:538 name: first539 question: first var value?540 validate: float541 default: 23542 message: Var value is \$first543YAML;544 $configFile->setContent($configFileContent);545 $dir->addChild($configFile);546 $application = new Application();547 $application->add(new Setup());548 $command = $application->find('setup');549 $commandTester = new CommandTester($command);550 $helper = $command->getHelper('question');551 $helper->setInputStream($this->getInputStream("Test\nfoo\n12.5\n"));552 $commandTester->execute([553 'command' => $command->getName(),554 'config' => $dir->url() . '/conf.yaml'555 ]);556 $display = $commandTester->getDisplay();557 $this->assertContains('Configuring "foo"', $display);558 $this->assertContains('first var value? (23)', $display);559 $this->assertContains('Var value is 12.5', $display);560 }561 /**562 * @test563 * it should allow for bool variable validation and ask until var validates564 */565 public function it_should_allow_for_bool_variable_validation_and_ask_until_var_validates()566 {567 $dir = vfsStream::setup();568 $configFile = new vfsStreamFile('conf.yaml');569 $configFileContent = <<< YAML570foo:571 var:572 name: first573 question: first var value?574 validate: bool575 default: 23576 message: Var value is \$first577YAML;578 $configFile->setContent($configFileContent);579 $dir->addChild($configFile);580 $application = new Application();581 $application->add(new Setup());582 $command = $application->find('setup');583 $commandTester = new CommandTester($command);584 $helper = $command->getHelper('question');585 $helper->setInputStream($this->getInputStream("Test\nfoo\ntrue\n"));586 $commandTester->execute([587 'command' => $command->getName(),588 'config' => $dir->url() . '/conf.yaml'589 ]);590 $display = $commandTester->getDisplay();591 $this->assertContains('Configuring "foo"', $display);592 $this->assertContains('first var value? (23)', $display);593 $this->assertContains('Var value is true', $display);594 }595 /**596 * @test597 * it should allow for url variable validation and ask until var validates598 */599 public function it_should_allow_for_url_variable_validation_and_ask_until_var_validates()600 {601 $dir = vfsStream::setup();602 $configFile = new vfsStreamFile('conf.yaml');603 $configFileContent = <<< YAML604foo:605 var:606 name: first607 question: first var value?608 validate: url609 default: 23610 message: Var value is \$first611YAML;612 $configFile->setContent($configFileContent);613 $dir->addChild($configFile);614 $application = new Application();615 $application->add(new Setup());616 $command = $application->find('setup');617 $commandTester = new CommandTester($command);618 $helper = $command->getHelper('question');619 $helper->setInputStream($this->getInputStream("Test\nfoo\nhttp://wp.dev\n"));620 $commandTester->execute([621 'command' => $command->getName(),622 'config' => $dir->url() . '/conf.yaml'623 ]);624 $display = $commandTester->getDisplay();625 $this->assertContains('Configuring "foo"', $display);626 $this->assertContains('first var value? (23)', $display);627 $this->assertContains('Var value is http://wp.dev', $display);628 }629 /**630 * @test631 * it should allow for email variable validation and ask until var validates632 */633 public function it_should_allow_for_email_variable_validation_and_ask_until_var_validates()634 {635 $dir = vfsStream::setup();636 $configFile = new vfsStreamFile('conf.yaml');637 $configFileContent = <<< YAML638foo:639 var:640 name: first641 question: first var value?642 validate: email643 default: 23644 message: Var value is \$first645YAML;646 $configFile->setContent($configFileContent);647 $dir->addChild($configFile);648 $application = new Application();649 $application->add(new Setup());650 $command = $application->find('setup');651 $commandTester = new CommandTester($command);652 $helper = $command->getHelper('question');653 $helper->setInputStream($this->getInputStream("Test\nfoo\nluca@email.com\n"));654 $commandTester->execute([655 'command' => $command->getName(),656 'config' => $dir->url() . '/conf.yaml'657 ]);658 $display = $commandTester->getDisplay();659 $this->assertContains('Configuring "foo"', $display);660 $this->assertContains('first var value? (23)', $display);661 $this->assertContains('Var value is luca@email.com', $display);662 }663 public function yesNoUserInputProvider()664 {665 return [666 ["\n", "showMessage value is yes"],667 ["yes\n", "showMessage value is yes"],668 ["y\n", "showMessage value is yes"],669 ["Y\n", "showMessage value is yes"],670 ["YES\n", "showMessage value is yes"],671 ["Yes\n", "showMessage value is yes"],672 ["no\n", ""],673 ["n\n", ""],674 ["N\n", ""],675 ["NO\n", ""],676 ["nO\n", ""],677 ];678 }679 /**680 * @test681 * it should allow validating yes/no values682 * @dataProvider yesNoUserInputProvider683 */684 public function it_should_allow_validating_yes_no_values($userInput, $expectedMessage)685 {686 $dir = vfsStream::setup();687 $configFile = new vfsStreamFile('conf.yaml');688 $configFileContent = <<< YAML689foo:690 var:691 name: showMessage692 question: show the message?693 default: yes694 validate: yesno695 message:696 unless: showMessage is no697 value: showMessage value is \$showMessage698YAML;699 $configFile->setContent($configFileContent);700 $dir->addChild($configFile);701 $application = new Application();702 $application->add(new Setup());703 $command = $application->find('setup');704 $commandTester = new CommandTester($command);705 $helper = $command->getHelper('question');706 $helper->setInputStream($this->getInputStream($userInput));707 $commandTester->execute([708 'command' => $command->getName(),709 'config' => $dir->url() . '/conf.yaml'710 ]);711 $display = $commandTester->getDisplay();712 $this->assertContains('Configuring "foo"', $display);713 $this->assertContains('show the message? (yes)', $display);714 if (!empty($expectedMessage)) {715 $this->assertContains($expectedMessage, $display);716 } else {717 $this->assertNotContains('showMessage value is', $display);718 }719 }720 /**721 * @test722 * it should support the not condition723 */724 public function it_should_support_the_not_condition()725 {726 $dir = vfsStream::setup();727 $configFile = new vfsStreamFile('conf.yaml');728 $configFileContent = <<< YAML729foo:730 var:731 name: showMessage732 question: show the message?733 default: yes734 validate: yesno735 message:736 if: showMessage not no737 value: showMessage value is \$showMessage738YAML;739 $configFile->setContent($configFileContent);740 $dir->addChild($configFile);741 $application = new Application();742 $application->add(new Setup());743 $command = $application->find('setup');744 $commandTester = new CommandTester($command);745 $helper = $command->getHelper('question');746 $helper->setInputStream($this->getInputStream("yes\n"));747 $commandTester->execute([748 'command' => $command->getName(),749 'config' => $dir->url() . '/conf.yaml'750 ]);751 $display = $commandTester->getDisplay();752 $this->assertContains('Configuring "foo"', $display);753 $this->assertContains('show the message? (yes)', $display);754 $this->assertContains('showMessage value is yes', $display);755 }756 /**757 * @test758 * it should allow checking if existence condition759 */760 public function it_should_allow_checking_if_existence_condition()761 {762 $dir = vfsStream::setup();763 $configFile = new vfsStreamFile('conf.yaml');764 $configFileContent = <<< YAML765foo:766 var:767 name: myName768 question: name?769 message:770 if: myName771 value: Hello \$myName!772YAML;773 $configFile->setContent($configFileContent);774 $dir->addChild($configFile);775 $application = new Application();776 $application->add(new Setup());777 $command = $application->find('setup');778 $commandTester = new CommandTester($command);779 $helper = $command->getHelper('question');780 $helper->setInputStream($this->getInputStream("\n"));781 $commandTester->execute([782 'command' => $command->getName(),783 'config' => $dir->url() . '/conf.yaml'784 ]);785 $display = $commandTester->getDisplay();786 $this->assertContains('Configuring "foo"', $display);787 $this->assertContains('name?', $display);788 $this->assertNotContains('Hello', $display);789 }790 /**791 * @test792 * it should allow checking positive existence condition793 */794 public function it_should_allow_checking_positive_existence_condition()795 {796 $dir = vfsStream::setup();797 $configFile = new vfsStreamFile('conf.yaml');798 $configFileContent = <<< YAML799foo:800 var:801 name: myName802 question: name?803 message:804 if: myName805 value: Hello \$myName!806YAML;807 $configFile->setContent($configFileContent);808 $dir->addChild($configFile);809 $application = new Application();810 $application->add(new Setup());811 $command = $application->find('setup');812 $commandTester = new CommandTester($command);813 $helper = $command->getHelper('question');814 $helper->setInputStream($this->getInputStream("Luca\n"));815 $commandTester->execute([816 'command' => $command->getName(),817 'config' => $dir->url() . '/conf.yaml'818 ]);819 $display = $commandTester->getDisplay();820 $this->assertContains('Configuring "foo"', $display);821 $this->assertContains('name?', $display);822 $this->assertContains('Hello Luca!', $display);823 }824 /**825 * @test826 * it should support loops in messages827 */828 public function it_should_support_loops_in_messages()829 {830 $dir = vfsStream::setup();831 $configFile = new vfsStreamFile('conf.yaml');832 $configFileContent = <<< YAML833foo:834 var:835 name: times836 question: times?837 validate: int838 default: 3839 message:840 if: times841 for: time in times842 value: loop \$time843YAML;844 $configFile->setContent($configFileContent);845 $dir->addChild($configFile);846 $application = new Application();847 $application->add(new Setup());848 $command = $application->find('setup');849 $commandTester = new CommandTester($command);850 $helper = $command->getHelper('question');851 $helper->setInputStream($this->getInputStream("3\n"));852 $commandTester->execute([853 'command' => $command->getName(),854 'config' => $dir->url() . '/conf.yaml'855 ]);856 $display = $commandTester->getDisplay();857 $this->assertContains('times?', $display);858 $this->assertContains('loop 1', $display);859 $this->assertContains('loop 2', $display);860 $this->assertContains('loop 3', $display);861 }862 /**863 * @test864 * it should support looping over user defined array of strings865 */866 public function it_should_support_looping_over_user_defined_array_of_strings()867 {868 $dir = vfsStream::setup();869 $configFile = new vfsStreamFile('conf.yaml');870 $configFileContent = <<< YAML871foo:872 message:873 for: var in foo,baz,bar874 value: var value is \$var875YAML;876 $configFile->setContent($configFileContent);877 $dir->addChild($configFile);878 $application = new Application();879 $application->add(new Setup());880 $command = $application->find('setup');881 $commandTester = new CommandTester($command);882 $commandTester->execute([883 'command' => $command->getName(),884 'config' => $dir->url() . '/conf.yaml'885 ]);886 $display = $commandTester->getDisplay();887 $this->assertContains('var value is foo', $display);888 $this->assertContains('var value is bar', $display);889 $this->assertContains('var value is baz', $display);890 }891 /**892 * @test893 * it should allow looping over user defined array of numbers894 */895 public function it_should_allow_looping_over_user_defined_array_of_numbers()896 {897 $dir = vfsStream::setup();898 $configFile = new vfsStreamFile('conf.yaml');899 $configFileContent = <<< YAML900foo:901 message:902 for: var in 12,23,71903 value: var value is \$var904YAML;905 $configFile->setContent($configFileContent);906 $dir->addChild($configFile);907 $application = new Application();908 $application->add(new Setup());909 $command = $application->find('setup');910 $commandTester = new CommandTester($command);911 $commandTester->execute([912 'command' => $command->getName(),913 'config' => $dir->url() . '/conf.yaml'914 ]);915 $display = $commandTester->getDisplay();916 $this->assertContains('var value is 12', $display);917 $this->assertContains('var value is 23', $display);918 $this->assertContains('var value is 71', $display);919 }920 /**921 * @test922 * it should allow looping over user defined array of strings, ints and vars923 */924 public function it_should_allow_looping_over_user_defined_array_of_strings_ints_and_vars()925 {926 $dir = vfsStream::setup();927 $configFile = new vfsStreamFile('conf.yaml');928 $configFileContent = <<< YAML929foo:930 var:931 name: varOne932 question: var one?933 validate: int934 default: 3935 message:936 for: loopVar in 45,foo,\$varOne 937 value: var value is \$loopVar938YAML;939 $configFile->setContent($configFileContent);940 $dir->addChild($configFile);941 $application = new Application();942 $application->add(new Setup());943 $command = $application->find('setup');944 $commandTester = new CommandTester($command);945 $helper = $command->getHelper('question');946 $helper->setInputStream($this->getInputStream("12\n"));947 $commandTester->execute([948 'command' => $command->getName(),949 'config' => $dir->url() . '/conf.yaml'950 ]);951 $display = $commandTester->getDisplay();952 $this->assertContains('var one?', $display);953 $this->assertContains('var value is 45', $display);954 $this->assertContains('var value is foo', $display);955 $this->assertContains('var value is 12', $display);956 }957 /**958 * @test959 * it should support loops in commands960 */961 public function it_should_support_loops_in_commands()962 {963 $dir = vfsStream::setup();964 $configFile = new vfsStreamFile('conf.yaml');965 $files = [966 codecept_root_dir('one.txt'),967 codecept_root_dir('two.txt'),968 codecept_root_dir('three.txt')969 ];970 $configFileContent = <<< YAML971foo:972 command:973 for: loopVar in one,two,three 974 value: search-replace foo bar \$loopVar.txt \$loopVar.foo.txt975YAML;976 foreach ($files as $file) {977 file_put_contents($file, 'Foo is foo');978 }979 $configFile->setContent($configFileContent);980 $dir->addChild($configFile);981 $application = new Application();982 $application->add(new Setup());983 $application->add(new SearchReplace());984 $command = $application->find('setup');985 $commandTester = new CommandTester($command);986 $helper = $command->getHelper('question');987 $helper->setInputStream($this->getInputStream("12\n"));988 $commandTester->execute([989 'command' => $command->getName(),990 'config' => $dir->url() . '/conf.yaml'991 ]);992 $expectedFiles = [993 codecept_root_dir('one.foo.txt'),994 codecept_root_dir('two.foo.txt'),995 codecept_root_dir('three.foo.txt')996 ];997 foreach ($expectedFiles as $expectedFile) {998 $this->assertFileExists($expectedFile);999 $this->assertStringEqualsFile($expectedFile, 'Foo is bar');1000 }1001 foreach (array_merge($files, $expectedFiles) as $file) {1002 unlink($file);1003 }1004 }1005 /**1006 * @test1007 * it should support loops in execs1008 */1009 public function it_should_support_loops_in_execs()1010 {1011 $dir = vfsStream::setup();1012 $configFile = new vfsStreamFile('conf.yaml');1013 $configFileContent = <<< YAML1014foo:1015 exec:1016 for: loopVar in one,two,three 1017 value: touch \$loopVar.txt1018YAML;1019 $configFile->setContent($configFileContent);1020 $dir->addChild($configFile);1021 $application = new Application();1022 $application->add(new Setup());1023 $command = $application->find('setup');1024 $commandTester = new CommandTester($command);1025 $helper = $command->getHelper('question');1026 $helper->setInputStream($this->getInputStream("12\n"));1027 $commandTester->execute([1028 'command' => $command->getName(),1029 'config' => $dir->url() . '/conf.yaml'1030 ]);1031 $expectedFiles = [1032 codecept_root_dir('one.txt'),1033 codecept_root_dir('two.txt'),1034 codecept_root_dir('three.txt')1035 ];1036 foreach ($expectedFiles as $expectedFile) {1037 $this->assertFileExists($expectedFile);1038 }1039 foreach ($expectedFiles as $file) {1040 unlink($file);1041 }1042 }1043 /**1044 * @test1045 * it should support regex validation of vars1046 */1047 public function it_should_support_regex_validation_of_vars()1048 {1049 $dir = vfsStream::setup();1050 $configFile = new vfsStreamFile('conf.yaml');1051 $configFileContent = <<< YAML1052foo:1053 var:1054 name: varOne1055 question: var one?1056 validate: regexp1057 regexp: /^foo/1058 message:1059 value: varOne value is \$varOne1060YAML;1061 $configFile->setContent($configFileContent);1062 $dir->addChild($configFile);1063 $application = new Application();1064 $application->add(new Setup());1065 $command = $application->find('setup');1066 $commandTester = new CommandTester($command);1067 $helper = $command->getHelper('question');1068 $helper->setInputStream($this->getInputStream("12\nbar\nfoobar"));1069 $commandTester->execute([1070 'command' => $command->getName(),1071 'config' => $dir->url() . '/conf.yaml'1072 ]);1073 $display = $commandTester->getDisplay();1074 $this->assertContains('var one?', $display);1075 $this->assertContains('varOne value is foobar', $display);1076 }1077 /**1078 * @test1079 * it should support the break instruction1080 */1081 public function it_should_support_the_break_instruction()1082 {1083 $dir = vfsStream::setup();1084 $configFile = new vfsStreamFile('conf.yaml');1085 $configFileContent = <<< YAML1086foo:1087 var:1088 name: stop1089 question: stop?1090 validate: yesno1091 break:1092 if: stop1093 value: Stopped.1094 message: Should not see me.1095YAML;1096 $configFile->setContent($configFileContent);1097 $dir->addChild($configFile);1098 $application = new Application();1099 $application->add(new Setup());1100 $command = $application->find('setup');1101 $commandTester = new CommandTester($command);1102 $helper = $command->getHelper('question');1103 $helper->setInputStream($this->getInputStream("yes\n"));1104 $commandTester->execute([1105 'command' => $command->getName(),1106 'config' => $dir->url() . '/conf.yaml'1107 ]);1108 $display = $commandTester->getDisplay();1109 $this->assertContains('stop?', $display);1110 $this->assertContains('Stopped', $display);1111 $this->assertNotContains('Should not see me', $display);1112 }1113 /**1114 * @test1115 * it should allow setting var values1116 */1117 public function it_should_allow_setting_var_values()1118 {1119 $dir = vfsStream::setup();1120 $configFile = new vfsStreamFile('conf.yaml');1121 $configFileContent = <<< YAML1122foo:1123 var:1124 name: one1125 value: 231126 message: One is \$one1127YAML;1128 $configFile->setContent($configFileContent);1129 $dir->addChild($configFile);1130 $application = new Application();1131 $application->add(new Setup());1132 $command = $application->find('setup');1133 $commandTester = new CommandTester($command);1134 $helper = $command->getHelper('question');1135 $helper->setInputStream($this->getInputStream("yes\n"));1136 $commandTester->execute([1137 'command' => $command->getName(),1138 'config' => $dir->url() . '/conf.yaml'1139 ]);1140 $display = $commandTester->getDisplay();1141 $this->assertContains('One is 23', $display);1142 }1143 private function getInputStream($input)1144 {1145 $stream = fopen('php://memory', 'r+', false);1146 fputs($stream, $input);1147 rewind($stream);1148 return $stream;1149 }1150}...

Full Screen

Full Screen

bp-core-dependency.php

Source:bp-core-dependency.php Github

copy

Full Screen

1<?php2/**3 * Plugin Dependency Action Hooks.4 *5 * The purpose of the following hooks is to mimic the behavior of something6 * called 'plugin dependency' which enables a plugin to have plugins of their7 * own in a safe and reliable way.8 *9 * We do this in BuddyPress by mirroring existing WordPress hooks in many places10 * allowing dependent plugins to hook into the BuddyPress specific ones, thus11 * guaranteeing proper code execution only when BuddyPress is active.12 *13 * The following functions are wrappers for hooks, allowing them to be14 * manually called and/or piggy-backed on top of other hooks if needed.15 *16 * @package BuddyPress17 * @subpackage Core18 * @since 1.7.019 */20/**21 * Fire the 'bp_include' action, where plugins should include files.22 *23 * @since 1.2.524 */25function bp_include() {26 /**27 * Fires inside the 'bp_include' function, where plugins should include files.28 *29 * @since 1.2.530 */31 do_action( 'bp_include' );32}33/**34 * Fire the 'bp_late_include' action for loading conditional files.35 *36 * @since 3.0.037 */38function bp_late_include() {39 /**40 * Fires the 'bp_late_include' action.41 *42 * Allow for conditional includes on certain pages.43 *44 * @since 3.0.045 */46 do_action( 'bp_late_include' );47}48/**49 * Fire the 'bp_setup_components' action, where plugins should initialize components.50 *51 * @since 1.6.052 */53function bp_setup_components() {54 /**55 * Fires inside the 'bp_setup_components' function, where plugins should initialize components.56 *57 * @since 1.6.058 */59 do_action( 'bp_setup_components' );60}61/**62 * Fire the 'bp_setup_canonical_stack' action, where plugins should set up their canonical URL.63 *64 * @since 2.1.065 */66function bp_setup_canonical_stack() {67 /**68 * Fires inside the 'bp_setup_canonical_stack' function, where plugins should set up their canonical URL.69 *70 * @since 2.1.071 */72 do_action( 'bp_setup_canonical_stack' );73}74/**75 * Fire the 'bp_register_taxonomies' action, where plugins should register taxonomies.76 *77 * @since 2.2.078 */79function bp_register_taxonomies() {80 /**81 * Fires inside the 'bp_register_taxonomies' function, where plugins should register taxonomies.82 *83 * @since 2.2.084 */85 do_action( 'bp_register_taxonomies' );86}87/**88 * Fire the 'bp_register_type_metadata' action, where plugins should register metadata for their custom BuddyPress types.89 *90 * @since 7.0.091 */92function bp_register_type_metadata() {93 /**94 * Fires inside the 'bp_register_type_metadata' function, where plugins should register metadata for their custom BuddyPress types.95 *96 * @since 7.0.097 */98 do_action( 'bp_register_type_metadata' );99}100/**101 * Fire the 'bp_register_post_types' action, where plugins should register post types.102 *103 * @since 2.5.0104 */105function bp_register_post_types() {106 /**107 * Fires inside the 'bp_register_post_types' function, where plugins should register post types.108 *109 * @since 2.5.0110 */111 do_action( 'bp_register_post_types' );112}113/**114 * Fire the 'bp_setup_globals' action, where plugins should initialize global settings.115 *116 * @since 1.2.0117 */118function bp_setup_globals() {119 /**120 * Fires inside the 'bp_setup_globals' function, where plugins should initialize global settings.121 *122 * @since 1.2.0123 */124 do_action( 'bp_setup_globals' );125}126/**127 * Fire the 'bp_setup_nav' action, where plugins should register their navigation items.128 *129 * @since 1.2.0130 */131function bp_setup_nav() {132 /**133 * Fires inside the 'bp_setup_nav' function, where plugins should register their navigation items.134 *135 * @since 1.2.0136 */137 do_action( 'bp_setup_nav' );138}139/**140 * Fire the 'bp_setup_admin_bar' action, where plugins should add items to the WP admin bar.141 *142 * @since 1.5.0143 */144function bp_setup_admin_bar() {145 if ( bp_use_wp_admin_bar() ) {146 /**147 * Fires inside the 'bp_setup_admin_bar' function, where plugins should add items to the WP admin bar.148 *149 * This hook will only fire if bp_use_wp_admin_bar() returns true.150 *151 * @since 1.5.0152 */153 do_action( 'bp_setup_admin_bar', array() );154 }155}156/**157 * Fire the 'bp_setup_title' action, where plugins should modify the page title.158 *159 * @since 1.5.0160 */161function bp_setup_title() {162 /**163 * Fires inside the 'bp_setup_title' function, where plugins should modify the page title.164 *165 * @since 1.5.0166 */167 do_action( 'bp_setup_title' );168}169/**170 * Fire the 'bp_register_widgets' action, where plugins should register widgets.171 *172 * @since 1.2.0173 */174function bp_setup_widgets() {175 /**176 * Fires inside the 'bp_register_widgets' function, where plugins should register widgets.177 *178 * @since 1.2.0179 */180 do_action( 'bp_register_widgets' );181}182/**183 * Fire the 'bp_register_member_types' action, where plugins should register member types.184 *185 * @since 2.3.0186 */187function bp_register_member_types() {188 /**189 * Fires inside bp_register_member_types(), so plugins can register member types.190 *191 * @since 2.3.0192 */193 do_action( 'bp_register_member_types' );194}195/**196 * Fire the 'bp_setup_cache_groups' action, where cache groups are registered.197 *198 * @since 2.2.0199 */200function bp_setup_cache_groups() {201 /**202 * Fires inside the 'bp_setup_cache_groups' function, where cache groups are registered.203 *204 * @since 2.2.0205 */206 do_action( 'bp_setup_cache_groups' );207}208/**209 * Set up the currently logged-in user.210 *211 * @since 1.7.0212 *213 * @link https://buddypress.trac.wordpress.org/ticket/6046214 * @link https://core.trac.wordpress.org/ticket/24169215 */216function bp_setup_current_user() {217 /**218 * Fires to set up the current user setup process.219 *220 * @since 1.7.0221 */222 do_action( 'bp_setup_current_user' );223}224/**225 * Fire the 'bp_init' action, BuddyPress's main initialization hook.226 *227 * @since 1.2.5228 */229function bp_init() {230 /**231 * Fires inside the 'bp_init' function, BuddyPress' main initialization hook.232 *233 * @since 1.2.0234 */235 do_action( 'bp_init' );236}237/**238 * Fire the 'bp_rest_api_init' action, where BuddyPress registers REST API endpoints.239 *240 * @since 2.6.0241 */242function bp_rest_api_init() {243 /**244 * Fires the 'bp_rest_api_init' function, where BuddyPress registers REST API endpoints.245 *246 * @since 2.6.0247 */248 do_action( 'bp_rest_api_init' );249}250/**251 * BP Blocks Init hook.252 *253 * @since 6.0.0254 */255function bp_blocks_init() {256 /**257 * Hook here to register your BuddyPress blocks.258 *259 * @since 6.0.0260 */261 do_action( 'bp_blocks_init' );262}263/**264 * Fire the 'bp_customize_register' action when the Customizer has loaded,265 * allowing scripts and styles to be initialized.266 *267 * @since 2.5.0268 *269 * @param WP_Customize_Manager $customizer Customizer instance.270 */271function bp_customize_register( WP_Customize_Manager $customizer ) {272 /**273 * Fires once the Customizer has loaded, allow scripts and styles to be initialized.274 *275 * @since 2.5.0276 *277 * @param WP_Customize_Manager $customizer Customizer instance.278 */279 do_action( 'bp_customize_register', $customizer );280}281/**282 * Fire the 'bp_loaded' action, which fires after BP's core plugin files have been loaded.283 *284 * Attached to 'plugins_loaded'.285 *286 * @since 1.2.0287 */288function bp_loaded() {289 /**290 * Fires inside the 'bp_loaded' function, which fires after BP's core plugin files have been loaded.291 *292 * @since 1.2.5293 */294 do_action( 'bp_loaded' );295}296/**297 * Fire the 'bp_ready' action, which runs after BP is set up and the page is about to render.298 *299 * Attached to 'wp'.300 *301 * @since 1.6.0302 */303function bp_ready() {304 /**305 * Fires inside the 'bp_ready' function, which runs after BP is set up and the page is about to render.306 *307 * @since 1.6.0308 */309 do_action( 'bp_ready' );310}311/**312 * Fire the 'bp_actions' action, which runs just before rendering.313 *314 * Attach potential template actions, such as catching form requests or routing315 * custom URLs.316 *317 * @since 1.5.0318 */319function bp_actions() {320 /**321 * Fires inside the 'bp_actions' function, which runs just before rendering.322 *323 * @since 1.5.0324 */325 do_action( 'bp_actions' );326}327/**328 * Fire the 'bp_screens' action, which runs just before rendering.329 *330 * Runs just after 'bp_actions'. Use this hook to attach your template331 * loaders.332 *333 * @since 1.5.0334 */335function bp_screens() {336 /**337 * Fires inside the 'bp_screens' function, which runs just before rendering.338 *339 * Runs just after 'bp_actions'. Use this hook to attach your template loaders.340 *341 * @since 1.5.0342 */343 do_action( 'bp_screens' );344}345/**346 * Fire 'bp_widgets_init', which runs after widgets have been set up.347 *348 * Hooked to 'widgets_init'.349 *350 * @since 1.6.0351 */352function bp_widgets_init() {353 /**354 * Fires inside the 'bp_widgets_init' function, which runs after widgets have been set up.355 *356 * Hooked to 'widgets_init'.357 *358 * @since 1.6.0359 */360 do_action( 'bp_widgets_init' );361}362/**363 * Fire 'bp_head', which is used to hook scripts and styles in the <head>.364 *365 * Hooked to 'wp_head'.366 *367 * @since 1.6.0368 */369function bp_head() {370 /**371 * Fires inside the 'bp_head' function, which runs on 'wp_head'.372 *373 * @since 1.6.0374 */375 do_action( 'bp_head' );376}377/** Theme Permissions *********************************************************/378/**379 * Fire the 'bp_template_redirect' action.380 *381 * Run at 'template_redirect', just before WordPress selects and loads a theme382 * template. The main purpose of this hook in BuddyPress is to redirect users383 * who do not have the proper permission to access certain content.384 *385 * @since 1.6.0386 */387function bp_template_redirect() {388 /**389 * Fires inside the 'bp_template_redirect' function.390 *391 * @since 1.6.0392 */393 do_action( 'bp_template_redirect' );394}395/** Theme Helpers *************************************************************/396/**397 * Fire the 'bp_register_theme_directory' action.398 *399 * The main action used registering theme directories.400 *401 * @since 1.5.0402 */403function bp_register_theme_directory() {404 /**405 * Fires inside the 'bp_register_theme_directory' function.406 *407 * The main action used registering theme directories.408 *409 * @since 1.7.0410 */411 do_action( 'bp_register_theme_directory' );412}413/**414 * Fire the 'bp_register_theme_packages' action.415 *416 * The main action used registering theme packages.417 *418 * @since 1.7.0419 */420function bp_register_theme_packages() {421 /**422 * Fires inside the 'bp_register_theme_packages' function.423 *424 * @since 1.7.0425 */426 do_action( 'bp_register_theme_packages' );427}428/**429 * Fire the 'bp_enqueue_scripts' action, where BP enqueues its CSS and JS.430 *431 * @since 1.6.0432 */433function bp_enqueue_scripts() {434 /**435 * Fires inside the 'bp_enqueue_scripts' function, where BP enqueues its CSS and JS.436 *437 * @since 1.6.0438 */439 do_action( 'bp_enqueue_scripts' );440}441/**442 * Fires the 'bp_enqueue_embed_scripts' action in the <head> for BP oEmbeds.443 *444 * @since 2.6.0445 */446function bp_enqueue_embed_scripts() {447 if ( ! is_buddypress() ) {448 return;449 }450 /**451 * Enqueue CSS and JS files for BuddyPress embeds.452 *453 * @since 2.6.0454 */455 do_action( 'bp_enqueue_embed_scripts' );456}457/**458 * Fire the 'bp_add_rewrite_tag' action, where BP adds its custom rewrite tags.459 *460 * @since 1.8.0461 */462function bp_add_rewrite_tags() {463 /**464 * Fires inside the 'bp_add_rewrite_tags' function, where BP adds its custom rewrite tags.465 *466 * @since 1.8.0467 */468 do_action( 'bp_add_rewrite_tags' );469}470/**471 * Fire the 'bp_add_rewrite_rules' action, where BP adds its custom rewrite rules.472 *473 * @since 1.9.0474 */475function bp_add_rewrite_rules() {476 /**477 * Fires inside the 'bp_add_rewrite_rules' function, where BP adds its custom rewrite rules.478 *479 * @since 1.9.0480 */481 do_action( 'bp_add_rewrite_rules' );482}483/**484 * Fire the 'bp_add_permastructs' action, where BP adds its BP-specific permalink structure.485 *486 * @since 1.9.0487 */488function bp_add_permastructs() {489 /**490 * Fires inside the 'bp_add_permastructs' function, where BP adds its BP-specific permalink structure.491 *492 * @since 1.9.0493 */494 do_action( 'bp_add_permastructs' );495}496/**497 * Fire the 'bp_setup_theme' action.498 *499 * The main purpose of 'bp_setup_theme' is give themes a place to load their500 * BuddyPress-specific functionality.501 *502 * @since 1.6.0503 */504function bp_setup_theme() {505 /**506 * Fires inside the 'bp_setup_theme' function.507 *508 * @since 1.6.0509 */510 do_action( 'bp_setup_theme' );511}512/**513 * Fire the 'bp_after_setup_theme' action.514 *515 * Piggy-back action for BuddyPress-specific theme actions once the theme has516 * been set up and the theme's functions.php has loaded.517 *518 * Hooked to 'after_setup_theme' with a priority of 100. This allows plenty of519 * time for other themes to load their features, such as BuddyPress support,520 * before our theme compatibility layer kicks in.521 *522 * @since 1.6.0523 */524function bp_after_setup_theme() {525 /**526 * Fires inside the 'bp_after_setup_theme' function.527 *528 * @since 1.7.0529 */530 do_action( 'bp_after_setup_theme' );531}532/** Theme Compatibility Filter ************************************************/533/**534 * Fire the 'bp_request' filter, a piggy-back of WP's 'request'.535 *536 * @since 1.7.0537 *538 * @see WP::parse_request() for a description of parameters.539 *540 * @param array $query_vars See {@link WP::parse_request()}.541 * @return array $query_vars See {@link WP::parse_request()}.542 */543function bp_request( $query_vars = array() ) {544 /**545 * Filters the query_vars for the current request.546 *547 * @since 1.7.0548 *549 * @param array $query_vars Array of query variables.550 */551 return apply_filters( 'bp_request', $query_vars );552}553/**554 * Fire the 'bp_login_redirect' filter, a piggy-back of WP's 'login_redirect'.555 *556 * @since 1.7.0557 *558 * @param string $redirect_to See 'login_redirect'.559 * @param string $redirect_to_raw See 'login_redirect'.560 * @param bool $user See 'login_redirect'.561 * @return string562 */563function bp_login_redirect( $redirect_to = '', $redirect_to_raw = '', $user = false ) {564 /**565 * Filters the URL to redirect to after login.566 *567 * @since 1.7.0568 *569 * @param string $redirect_to The redirect destination URL.570 * @param string $redirect_to_raw The requested redirect destination URL passed as a parameter.571 * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise.572 */573 return apply_filters( 'bp_login_redirect', $redirect_to, $redirect_to_raw, $user );574}575/**576 * Fire 'bp_template_include', main filter used for theme compatibility and displaying custom BP theme files.577 *578 * Hooked to 'template_include'.579 *580 * @since 1.6.0581 *582 * @param string $template See 'template_include'.583 * @return string Template file to use.584 */585function bp_template_include( $template = '' ) {586 /**587 * Filters the template to use with template_include.588 *589 * @since 1.6.0590 *591 * @param string $template The path of the template to include.592 */593 return apply_filters( 'bp_template_include', $template );594}595/**596 * Fire the 'bp_generate_rewrite_rules' action, where BP generates its rewrite rules.597 *598 * @since 1.7.0599 *600 * @param WP_Rewrite $wp_rewrite See 'generate_rewrite_rules'.601 */602function bp_generate_rewrite_rules( $wp_rewrite ) {603 /**604 * Fires inside the 'bp_generate_rewrite_rules' function.605 *606 * @since 1.7.0607 *608 * @param WP_Rewrite $wp_rewrite WP_Rewrite object. Passed by reference.609 */610 do_action_ref_array( 'bp_generate_rewrite_rules', array( &$wp_rewrite ) );611}612/**613 * Fire the 'bp_allowed_themes' filter.614 *615 * Filter the allowed themes list for BuddyPress-specific themes.616 *617 * @since 1.7.0618 *619 * @param array $themes The path of the template to include.620 * @return array621 */622function bp_allowed_themes( $themes ) {623 /**624 * Filters the allowed themes list for BuddyPress-specific themes.625 *626 * @since 1.7.0627 *628 * @param string $template The path of the template to include.629 */630 return apply_filters( 'bp_allowed_themes', $themes );631}632/** Requests ******************************************************************/633/**634 * The main action used for handling theme-side POST requests.635 *636 * @since 1.9.0637 */638function bp_post_request() {639 // Bail if not a POST action.640 if ( ! bp_is_post_request() ) {641 return;642 }643 // Bail if no action.644 if ( empty( $_POST['action'] ) ) {645 return;646 }647 // Sanitize the POST action.648 $action = sanitize_key( $_POST['action'] );649 /**650 * Fires at the end of the bp_post_request function.651 *652 * This dynamic action is probably the one you want to use. It narrows down653 * the scope of the 'action' without needing to check it in your function.654 *655 * @since 1.9.0656 */657 do_action( 'bp_post_request_' . $action );658 /**659 * Fires at the end of the bp_post_request function.660 *661 * Use this static action if you don't mind checking the 'action' yourself.662 *663 * @since 1.9.0664 *665 * @param string $action The action being run.666 */667 do_action( 'bp_post_request', $action );668}669/**670 * The main action used for handling theme-side GET requests.671 *672 * @since 1.9.0673 */674function bp_get_request() {675 // Bail if not a POST action.676 if ( ! bp_is_get_request() ) {677 return;678 }679 // Bail if no action.680 if ( empty( $_GET['action'] ) ) {681 return;682 }683 // Sanitize the GET action.684 $action = sanitize_key( $_GET['action'] );685 /**686 * Fires at the end of the bp_get_request function.687 *688 * This dynamic action is probably the one you want to use. It narrows down689 * the scope of the 'action' without needing to check it in your function.690 *691 * @since 1.9.0692 */693 do_action( 'bp_get_request_' . $action );694 /**695 * Fires at the end of the bp_get_request function.696 *697 * Use this static action if you don't mind checking the 'action' yourself.698 *699 * @since 1.9.0700 *701 * @param string $action The action being run.702 */703 do_action( 'bp_get_request', $action );704}...

Full Screen

Full Screen

setUp

Using AI Code Generation

copy

Full Screen

1$test = new should();2$test->setUp();3$test->test1();4$test->test2();5$test->test3();6$test->test4();7$test->test5();8$test->test6();9$test->test7();10$test->test8();11$test->test9();12$test->test10();13$test->test11();14$test->test12();15$test->test13();16$test->test14();17$test->test15();18$test->test16();19$test->test17();20$test->test18();21$test->test19();22$test->test20();23$test->test21();24$test->test22();25$test->test23();26$test->test24();27$test->test25();28$test->test26();29$test->test27();30$test->test28();31$test->test29();32$test->test30();33$test->test31();34$test->test32();35$test->test33();36$test->test34();37$test->test35();38$test->test36();39$test->test37();40$test->test38();41$test->test39();42$test->test40();43$test->test41();44$test->test42();45$test->test43();46$test->test44();47$test->test45();48$test->test46();49$test->test47();50$test->test48();51$test->test49();52$test->test50();53$test->test51();54$test->test52();55$test->test53();56$test->test54();57$test->test55();58$test->test56();59$test->test57();60$test->test58();61$test->test59();62$test->test60();63$test->test61();64$test->test62();65$test->test63();66$test->test64();67$test->test65();68$test->test66();69$test->test67();70$test->test68();71$test->test69();72$test->test70();73$test->test71();74$test->test72();75$test->test73();76$test->test74();77$test->test75();78$test->test76();79$test->test77();80$test->test78();81$test->test79();82$test->test80();83$test->test81();

Full Screen

Full Screen

setUp

Using AI Code Generation

copy

Full Screen

1{2 protected $should;3 protected function setUp()4 {5 $this->should = new should();6 }7 public function testSomething()8 {9 $this->should->something();10 }11}12{13 public function something()14 {15 $this->somethingElse();16 }17 public function somethingElse()18 {19 echo "something else";20 }21}

Full Screen

Full Screen

setUp

Using AI Code Generation

copy

Full Screen

1{2 protected $should;3 protected function setUp()4 {5 $this->should = new should;6 }7 public function testOne()8 {9 $this->should->beTrue(true);10 }11 public function testTwo()12 {13 $this->should->beTrue(false);14 }15}16{17 public function beTrue($value)18 {19 if ($value == true) {20 echo "Test Passed";21 } else {22 echo "Test Failed";23 }24 }25}26{27 protected $should;28 protected function setUp()29 {30 $this->should = new should;31 }32 public function testOne()33 {34 $this->should->beGreaterThan100(50);35 }36}37{38 public function beGreaterThan100($value)39 {40 if ($value > 100) {41 echo "Test Passed";42 } else {43 echo "Test Failed";44 }45 }46}47{48 protected $should;49 protected function setUp()50 {51 $this->should = new should;

Full Screen

Full Screen

setUp

Using AI Code Generation

copy

Full Screen

1{2 public function setUp()3 {4 $this->should = new Should();5 }6 public function testSomething()7 {8 $this->should->beTrue();9 }10}11Fatal error: Call to a member function beTrue() on a non-object in 2.php on line 912Now, the setUp() method will look like this :13public function setUp()14{15 $this->should = new Should();16}17Now, the testSomething() method will look like this :18public function testSomething()19{20 $this->should->beTrue();21}22Error: Call to undefined method Should::beTrue()23{24 public function beTrue()25 {26 return true;27 }28}29OK (1 test, 1 assertion)30The above output is because we have defined the beTrue() method in the Should class and

Full Screen

Full Screen

setUp

Using AI Code Generation

copy

Full Screen

1{2 public function setUp()3 {4 $this->obj = new myClass();5 }6}7{8 public function setUp()9 {10 $this->obj = new myClass();11 }12}13{14 public function setUp()15 {16 $this->obj = new myClass();17 }18}19{20 public function setUp()21 {22 $this->obj = new myClass();23 }24}25{26 public function setUp()27 {28 $this->obj = new myClass();29 }30}31{32 public function setUp()33 {34 $this->obj = new myClass();35 }36}37{38 public function setUp()39 {40 $this->obj = new myClass();41 }42}43{44 public function setUp()45 {46 $this->obj = new myClass();47 }48}49{50 public function setUp()51 {52 $this->obj = new myClass();53 }54}55{56 public function setUp()57 {58 $this->obj = new myClass();59 }60}61{62 public function setUp()63 {64 $this->obj = new myClass();65 }66}

Full Screen

Full Screen

setUp

Using AI Code Generation

copy

Full Screen

1{2 public function setUp()3 {4 $this->test = new test();5 }6 public function testOne()7 {8 $this->assertEquals($this->test->testOne(), 1);9 }10 public function testTwo()11 {12 $this->assertEquals($this->test->testTwo(), 2);13 }14}15{16 public static function setUpBeforeClass()17 {18 $this->test = new test();19 }20 public function testOne()21 {22 $this->assertEquals($this->test->testOne(), 1);23 }24 public function testTwo()25 {26 $this->assertEquals($this->test->testTwo(), 2);27 }28}29{30 public static function setUpBeforeClass()31 {32 $this->test = new test();33 }34 public function testOne()35 {36 $this->assertEquals($this->test->testOne(), 1);37 }38 public function testTwo()39 {40 $this->assertEquals($this->test->testTwo(), 2);41 }42}43{44 public static function setUpBeforeClass()45 {46 $this->test = new test();47 }48 public function testOne()49 {50 $this->assertEquals($this->test->testOne(), 1);51 }52 public function testTwo()53 {54 $this->assertEquals($this->test->testTwo(), 2);55 }56}57{58 public static function setUpBeforeClass()59 {60 $this->test = new test();61 }62 public function testOne()63 {64 $this->assertEquals($this->test->testOne(), 1);65 }66 public function testTwo()67 {68 $this->assertEquals($this->test->testTwo(), 2);69 }70}71{72 public static function setUpBeforeClass()73 {74 $this->test = new test();75 }

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 Phake automation tests on LambdaTest cloud grid

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

Trigger setUp code on LambdaTest Cloud Grid

Execute automation tests with setUp 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