public function testContent() { Core::$core->nocache = true; include_once __DIR__ . "/../libs/FailFilter.php"; DS::close(); DS::db("sqlite::memory:"); DS::exec("insert into pages (id,name,template,data,dds,filter) values ('test','Test','testview','{\"body\":\"testbody\"}','{\"testdds\":[\"1\",\"\",\"\"]}','fail');"); DS::exec("insert into views (id,ctrl) values ('testview', 'echo(\"OK\");');"); $url = Core::$core->url; $title = Core::$core->title; $contentApp = new Content(); //! no content Core::$core->title = "NONE"; $contentApp = new Content("no/such/content"); $this->assertEquals("NONE", Core::$core->title, "No content"); //! filter $contentApp = new Content("test/"); $this->assertEquals("403", Core::$core->template, "Filtered"); DS::exec("update pages set filter='' where id='test';"); //! is content $contentApp = new Content("test/"); $this->assertEquals("Test", Core::$core->title, "Content"); $contentApp->getDDS($contentApp); $this->assertEquals("testbody", $contentApp->body, "Body"); $this->assertNotEmpty($contentApp->testdds, "DDS"); $old = Core::$core->noctrl; Core::$core->noctrl = false; $contentApp->ctrl = "echo('OK');"; $this->assertEquals("OK", $contentApp->action(), "Content controller #1"); $old = Core::$core->noctrl; Core::$core->noctrl = true; $this->assertNull($contentApp->action(), "Content controller #2"); Core::$core->noctrl = $old; DS::exec("update pages set dds='{\"testdds2\":[\"nosuchcolumn\",\"\",\"\"]}' where id='test';"); $contentApp = new Content("test/"); $contentApp->getDDS($contentApp); $this->assertEmpty(@$contentApp->testdds2, "DDS failed"); Core::$core->title = $title; }
public function testDiag() { \PHPPE\DS::close(); $ds = new \PHPPE\DS(); $this->assertNull($ds->diag(), "Diag no ds"); \PHPPE\DS::db("sqlite::memory:"); ob_start(); $ds->diag(); $this->assertEmpty(ob_get_clean(), "Diag no update"); if (file_put_contents("vendor/phppe/Developer/sql/upd_test.sql", "select 1;")) { ob_start(); $ds->diag(); $this->assertNotEmpty(ob_get_clean(), "Diag update"); $this->assertFileNotExists("vendor/phppe/Developer/sql/upd_test.sql", "Diag file"); } }
public function testEmail() { if (!\PHPPE\ClassMap::has("PHPPE\\Email")) { $this->markTestSkipped(); } \PHPPE\Core::$core->mailer = null; $email = new \PHPPE\Email(); $emailData = $email->get(); $email2 = new \PHPPE\Email($emailData); $this->assertNotEmpty($email2, "Empty Email dump"); $wasExc = false; try { $email3 = new \PHPPE\Email("something"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "Email creating exception"); $wasExc = false; try { $email->send(); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "No backend exception"); $wasExc = false; try { $email->send("db"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "No message exception"); $email->message("Something"); $wasExc = false; try { $email->send("db"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "No subject exception"); $email->subject("Subject"); \PHPPE\DS::close(); $wasExc = false; try { $email->send("db"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "No recipient exception"); $wasExc = false; try { $email->to("me"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "Bad address exception #1"); $wasExc = false; try { $email->to("me@notld"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "Bad address exception #2"); $email->to("me@localhost"); $email->replyTo("me2@localhost"); $email->cc("me3@localhost"); $email->bcc("me4@localhost"); $wasExc = false; try { $email->send("db"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "No db exception"); $wasExc = false; try { $email->send("phpmailer"); } catch (\Exception $e) { $wasExc = true; } $this->assertTrue($wasExc, "No phpmailer exception"); $this->assertNotEquals(0, preg_match("/Message\\-ID/", $email->send("mime")), "Return mime message"); $email->attachFile("images/phppe.png"); $email->attachFile("images/phppe.png", "image/png"); $email2->attachData("something.txt", "text/plain", "something"); $mime = $email2->message("<html><body>html mail<img src='http://localhost/something.jpg'><img src='images/phppe.png'></body></html>")->subject("Subject")->to("me@localhost")->send("mime"); $this->assertTrue($email2->send("log"), "Log backend"); $email2->send("mail"); $email2->send("sendmail"); $email2->send("smtp://*****:*****@localhost")->subject("Subject")->message("message"); \PHPPE\DS::db("sqlite::memory:"); $wasExc = false; try { $email->send("db"); $email3->send("db"); } catch (\Exception $e) { $wasExc = true; echo $e; } $this->assertFalse($wasExc, "To db queue"); \PHPPE\Core::$core->realmailer = "log"; $email->cronMinute(""); \PHPPE\Core::$core->realmailer = "log"; $email->cronMinute(""); }