public function testGeneratePostActivation()
 {
     // Touch a new "insert.sql" file and copy a "create.sql" file
     /** @var \org\bovigo\vfs\vfsStreamFile $file */
     $configDir = $this->stream->getChild("Config");
     $file = vfsStream::newFile("create.sql")->at($configDir);
     $file->setContent(file_get_contents(__DIR__ . "/../" . static::TEST_MODULE_PATH . "Config" . DS . "thelia.sql"));
     vfsStream::newFile("insert.sql")->at($configDir);
     // Then run the generator
     $generator = new ModulePhpGenerator($this->getSmarty());
     $generator->doGenerate($this->event);
     // Read the class
     include $this->getStreamPath("TheliaStudioTestModule.php");
     $reflection = new \ReflectionClass("TheliaStudioTestModule\\TheliaStudioTestModule");
     $this->assertTrue($reflection->hasConstant("MESSAGE_DOMAIN"));
     $this->assertEquals("theliastudiotestmodule", $reflection->getConstant("MESSAGE_DOMAIN"));
     $this->assertTrue($reflection->hasMethod("postActivation"));
     // get a method closure
     $method = $reflection->getMethod("postActivation");
     $closure = $method->getClosure($reflection->newInstance());
     // Test that the table doesn't exist
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(0, $stmt->count());
     // Execute the method
     $closure($this->con);
     // Now it exists
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(1, $stmt->count());
 }
Esempio n. 2
0
 public function testCreateForm()
 {
     /**
      * Run the module class generator for the form
      */
     $generator = new ModulePhpGenerator($this->getSmarty());
     $generator->doGenerate($this->event);
     $this->loadClassFromVfs("TheliaStudioTestModule", false);
     $this->loadClassFromVfs("Form/ExampleTableCreateForm");
     $reflection = new \ReflectionClass("TheliaStudioTestModule\\Form\\ExampleTableCreateForm");
     $this->assertTrue($reflection->isSubclassOf("TheliaStudioTestModule\\Form\\Base\\ExampleTableCreateForm"));
     $this->assertTrue($reflection->isSubclassOf("Thelia\\Form\\BaseForm"));
     $this->assertTrue($reflection->hasConstant("FORM_NAME"));
     $this->assertEquals("example_table_create", $reflection->getConstant("FORM_NAME"));
     /**
      * Mock the request to build the form
      */
     new Translator(new Container());
     $request = new Request();
     $session = new Session(new MockArraySessionStorage());
     $request->setSession($session);
     $baseForm = $reflection->newInstance($request);
     /** @var \Symfony\Component\Form\Form $form */
     $form = $baseForm->getForm();
     /**
      * Then test it
      */
     $this->assertTrue($form->has("locale"));
     $this->assertTrue($form->has("title"));
     $this->assertTrue($form->has("description"));
     $this->assertTrue($form->has("chapo"));
     $this->assertTrue($form->has("postscriptum"));
     $this->assertTrue($form->has("visible"));
     $this->assertFalse($form->has("position"));
     $this->assertFalse($form->has("id"));
 }