GeneratePageObjectTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
  3. class GeneratePageObjectTest extends BaseCommandRunner
  4. {
  5. protected function setUp()
  6. {
  7. $this->makeCommand('\Codeception\Command\GeneratePageObject');
  8. $this->config = array(
  9. 'actor' => 'HobbitGuy',
  10. 'path' => 'tests/shire',
  11. 'paths' => array('tests' => 'tests'),
  12. 'settings' => array('bootstrap' => '_bootstrap.php')
  13. );
  14. }
  15. public function testBasic()
  16. {
  17. unset($this->config['actor']);
  18. $this->execute(array('suite' => 'Login'), false);
  19. $this->assertEquals(\Codeception\Configuration::supportDir().'Page/Login.php', $this->filename);
  20. $this->assertContains('class Login', $this->content);
  21. $this->assertContains('public static', $this->content);
  22. $this->assertNotContains('public function __construct', $this->content);
  23. $this->assertIsValidPhp($this->content);
  24. }
  25. public function testNamespace()
  26. {
  27. unset($this->config['actor']);
  28. $this->config['namespace'] = 'MiddleEarth';
  29. $this->execute(array('suite' => 'Login'), false);
  30. $this->assertEquals(\Codeception\Configuration::supportDir().'Page/Login.php', $this->filename);
  31. $this->assertContains('namespace MiddleEarth\Page;', $this->content);
  32. $this->assertContains('class Login', $this->content);
  33. $this->assertContains('public static', $this->content);
  34. $this->assertIsValidPhp($this->content);
  35. }
  36. public function testCreateForSuite()
  37. {
  38. $this->execute(array('suite' => 'shire', 'page' => 'Login'));
  39. $this->assertEquals(\Codeception\Configuration::supportDir().'Page/Shire/Login.php', $this->filename);
  40. $this->assertContains('namespace Page\Shire;', $this->content);
  41. $this->assertContains('class Login', $this->content);
  42. $this->assertContains('protected $hobbitGuy;', $this->content);
  43. $this->assertContains('public function __construct(\HobbitGuy $I)', $this->content);
  44. $this->assertIsValidPhp($this->content);
  45. }
  46. public function testCreateForSuiteWithNamespace()
  47. {
  48. $this->config['namespace'] = 'MiddleEarth';
  49. $this->execute(array('suite' => 'shire', 'page' => 'Login'));
  50. $this->assertEquals(\Codeception\Configuration::supportDir().'Page/Shire/Login.php', $this->filename);
  51. $this->assertContains('namespace MiddleEarth\Page\Shire;', $this->content);
  52. $this->assertContains('class Login', $this->content);
  53. $this->assertContains('protected $hobbitGuy;', $this->content);
  54. $this->assertContains('public function __construct(\MiddleEarth\HobbitGuy $I)', $this->content);
  55. $this->assertIsValidPhp($this->content);
  56. }
  57. public function testCreateInSubpath()
  58. {
  59. $this->execute(array('suite' => 'User/View'));
  60. $this->assertEquals(\Codeception\Configuration::supportDir().'Page/User/View.php', $this->filename);
  61. $this->assertIsValidPhp($this->content);
  62. }
  63. }