Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.7 KiB

5 years ago
  1. <?= "<?php\n" ?>
  2. namespace <?= $namespace; ?>;
  3. <?php
  4. function dashesToCamelCase($string, $capitalizeFirstCharacter = false)
  5. {
  6. if(strpos($string, '_')!==false){
  7. $str = str_replace('_', '', ucwords($string, '_'));
  8. }else{
  9. $str = str_replace('.', '', ucwords($string, '.'));
  10. }
  11. if (!$capitalizeFirstCharacter) {
  12. $str = lcfirst($str);
  13. }
  14. return $str;
  15. }
  16. ?>
  17. <?php if ($panther_is_available): ?>
  18. use Symfony\Component\Panther\PantherTestCase;
  19. use Prometeo\CommandsBundle\TestTraits\PantherTrait;
  20. <?php else: ?>
  21. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  22. <?php endif ?>
  23. use Symfony\Component\BrowserKit\Cookie;
  24. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  25. use Symfony\Component\HttpFoundation\Session\Session;
  26. use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
  27. class <?= $class_name ?> extends <?= $panther_is_available ? 'PantherTestCase' : 'WebTestCase' ?><?= "\n" ?>
  28. {
  29. <?php if ($panther_is_available): ?>
  30. use PantherTrait;
  31. <?php endif ?>
  32. private $client = null;
  33. public function setUp() :void
  34. {
  35. // Boot the AppKernel in the test environment and with the debug.
  36. self::bootKernel();
  37. <?php if ($panther_is_available): ?>
  38. $this->client = static::createPantherClient();
  39. <?php else: ?>
  40. $this->client = static::createClient();
  41. <?php endif ?>
  42. }
  43. public function testLogin()
  44. {
  45. $crawler = $this->client->request('GET', '/admin');
  46. $this->client->takeScreenshot('screenshoots/app_login.png');
  47. $this->assertFileExists('screenshoots/app_login.png');
  48. $form = $crawler->selectButton('Iniciar sesión')->form();
  49. $form['_username'] = '<?= $username ?>';
  50. $form['_password'] = '<?= $password ?>';
  51. $crawler = $this->client->submit($form);
  52. // $link = $crawler->filter('a:contains("Déconnexion")')->link();
  53. // $crawler = $client->click($link);
  54. // $this->assertSame('http://127.0.0.1:9080/es/admin/login', $this->client->getCurrentURL());
  55. $this->client->takeScreenshot('screenshoots/app_dashboard.png');
  56. $this->assertFileExists('screenshoots/app_dashboard.png');
  57. }
  58. <?php foreach($routes['routes']['routes'] as $key=>$route){
  59. $method='';
  60. if(strpos($route, strtolower('list'))!==false){
  61. $method='configureListFields';
  62. }elseif(strpos($route, strtolower('create'))!==false ||strpos($route, strtolower('edit'))!==false){
  63. $method='configureFormFields';
  64. }elseif(strpos($route, strtolower('show'))!==false){
  65. $method='configureShowFields';
  66. }elseif(strpos($route, strtolower('batch'))!==false){
  67. $method='configureBatchActions';
  68. }elseif(strpos($route, strtolower('delete'))!==false){
  69. $method='delete';
  70. }elseif(strpos($route, strtolower('export'))!==false){
  71. $method='configureExportFields';
  72. }
  73. ?>
  74. /**
  75. * @covers App\Admin\<?= str_replace('Test', 'Admin',$class_name) ?>::<?= $method ?>
  76. * @depends testLogin
  77. */
  78. public function test<?= dashesToCamelCase($route, true) ?>()
  79. {
  80. $crawler = $this->client->request('GET', '<?= $routes['routes']['urls'][$key]?>');
  81. <?php if ($web_assertions_are_available): ?>
  82. //$this->assertResponseIsSuccessful();
  83. <?php else: ?>
  84. <?php if ($panther_is_available): ?>
  85. $this->assertEquals(200, $client->getInternalResponse()->getStatusCode());
  86. <?php else: ?>
  87. $this->assertEquals(200, $client->getResponse()->getStatusCode());
  88. <?php endif ?>
  89. <?php endif ?>
  90. <?php if ($panther_is_available): ?>
  91. $this->client->takeScreenshot('screenshoots/<?= $route ?>.png');
  92. $this->assertFileExists('screenshoots/<?= $route ?>.png');
  93. <?php endif ?>
  94. }
  95. <?php } ?>
  96. }