예제 #1
0
 public function testUsers()
 {
     if (!\PHPPE\ClassMap::has("PHPPE\\Users")) {
         $this->markTestSkipped();
     }
     // destroy session user
     $_SESSION['pe_u'] = [];
     $user = new \PHPPE\Users();
     $this->assertNull($user->login("admin", "changeme"), "Bad username or password");
     $this->assertNotNull($user->login("bzt", "changeme"), "Login");
     $this->assertNull($user->login("bzt", "changeme"), "Already logged in");
     $user->logout();
 }
예제 #2
0
 public function testCore()
 {
     $this->assertTrue(ClassMap::has("NotLoaded", "oneMethod"), "ClassMap has");
     @unlink(ClassMap::$file);
     @unlink(ClassMap::$ace);
     $_SERVER['REQUEST_URI'] = "";
     $_SERVER['argv'][1] = "test";
     @($core = new Core(true));
     $_SERVER['REQUEST_URI'] = "/test/something/?arg=1";
     @($core = new Core(true));
     $this->assertFileExists(ClassMap::$file, "New classmap");
     $this->assertNotEmpty($core->base, "Base");
     $this->assertNotEmpty($core->url, "Url");
     $this->assertEquals(Core::$core->output, $core->output, "Output");
     $this->assertGreaterThan(Core::$core->now, Core::started(), "Started");
     $this->assertNotEmpty(ClassMap::ace(), "ClassMap access control entries");
 }
예제 #3
0
 public function testDB()
 {
     if (!\PHPPE\ClassMap::has("PHPPE\\DB")) {
         $this->markTestSkipped();
     }
     $this->assertEquals("%some%thing%", \PHPPE\DB::like("some thing"), "like");
     $this->assertEquals("SELECT * FROM users", \PHPPE\DB::select("users"), "Simple select");
     $this->assertEquals("SELECT id,name FROM users", \PHPPE\DB::select("users")->fields(["id", "name"]), "Select with fields");
     $this->assertEquals("SELECT * FROM users WHERE id=?", \PHPPE\DB::select("users")->where("id=?"), "Select with where #1");
     $this->assertEquals("SELECT * FROM users WHERE (id=? AND name=?)", \PHPPE\DB::select("users")->where(["id=?", "name=?"]), "Select with where #2");
     $this->assertEquals("SELECT * FROM users WHERE (id = 'my id')", \PHPPE\DB::select("users")->where([["id", "=", "my id"]]), "Select with where #3");
     $this->assertEquals("SELECT * FROM users WHERE (id LIKE '%my%id%')", \PHPPE\DB::select("users")->where([["id", "like", "my id"]]), "Select with where #4");
     $this->assertEquals("SELECT * FROM users WHERE (id LIKE '%my%id%' OR name LIKE '%my%name%') AND 1=1", \PHPPE\DB::select("users")->where([["id", "like", "my id"], ["name", "like", "my name"]], "or")->where("1=1"), "Select with where #5");
     $this->assertEquals("SELECT * FROM users u, user_posts p WHERE u.id=p.id", \PHPPE\DB::select("users", "u")->table("user_posts", "p")->where("u.id=p.id"), "Select with where #6");
     $wasExc = false;
     try {
         \PHPPE\DB::update("users")->where("id=id", "NOT");
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "bad where exception");
     $this->assertEquals("SELECT * FROM users HAVING id=?", \PHPPE\DB::select("users")->having("id=?"), "Select with having");
     $this->assertEquals("SELECT * FROM users LIMIT 10", \PHPPE\DB::select("users")->limit(10), "Select with limit #1");
     $wasExc = false;
     try {
         \PHPPE\DB::select("users")->offset(5)->sql();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "Select with limit #2");
     $this->assertEquals("SELECT * FROM users LIMIT 10 OFFSET 5", \PHPPE\DB::select("users")->limit(10)->offset(5), "Select with limit #3");
     $this->assertEquals("SELECT * FROM users GROUP BY name", \PHPPE\DB::select("users")->groupBy("name"), "Select with group by #1");
     $this->assertEquals("SELECT * FROM users GROUP BY name,id", \PHPPE\DB::select("users")->groupBy(["name", "id"]), "Select with group by #2");
     $this->assertEquals("SELECT * FROM users ORDER BY id", \PHPPE\DB::select("users")->orderBy("id"), "Select with order by #1");
     $this->assertEquals("SELECT * FROM users ORDER BY id", \PHPPE\DB::select("users")->orderBy(["id"]), "Select with order by #2");
     $wasExc = false;
     try {
         \PHPPE\DB::update("users")->sql();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "update no fields exception");
     $this->assertNotFalse(strpos(\PHPPE\DB::update("users"), "No fields specified"), "update no field string");
     $this->assertEquals("UPDATE users SET id=?,name=?", \PHPPE\DB::update("users")->fields(['id', 'name']), "update with fields");
     $this->assertEquals("DELETE FROM users", \PHPPE\DB::delete("users"), "delete table");
     $this->assertEquals("DELETE a FROM users a", \PHPPE\DB::delete("users", "a")->sql(), "delete alias");
     $this->assertEquals("DELETE user_posts FROM user_posts LEFT JOIN users ON user_posts.userId=users.id WHERE (users.id IS NULL)", \PHPPE\DB::delete("user_posts")->join("LEFT", "users", "user_posts.userId=users.id")->where([["users.id", "IS NULL"]]), "delete where");
     $this->assertEquals("INSERT INTO users (id,name) VALUES (?,?)", \PHPPE\DB::insert("users")->fields('id,name'), "insert");
     $wasExc = false;
     try {
         \PHPPE\DB::select("users")->join("SIMPLE", "user_posts", "id=id");
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "bad join exception");
     $this->assertEquals("REPLACE INTO users (id,name) VALUES (?,?) WHERE id=''", \PHPPE\DB::replace("users")->fields(['id', 'name'])->where("id=''"), "replace");
     $this->assertEquals("TRUNCATE TABLE users", \PHPPE\DB::truncate("users"), "truncate");
     $wasExc = false;
     try {
         \PHPPE\DB::select("users")->where([["1", "!="]]);
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "bad where exception");
     $wasExc = false;
     try {
         \PHPPE\DB::select("users")->where([["a", "similarto", "b"]]);
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "bad where exception");
     $wasExc = false;
     try {
         \PHPPE\DB::update("")->sql();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "no table exception");
     $wasExc = false;
     try {
         \PHPPE\DB::insert("users")->sql();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "no where exception");
     $wasExc = false;
     try {
         \PHPPE\DB::replace("users")->fields(["id"])->sql();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "no where exception");
     \PHPPE\DS::close();
     $ds = new \PHPPE\DS("sqlite::memory:");
     $this->assertNotEmpty(\PHPPE\DB::select("users")->execute(), "execute");
     \PHPPE\DB::truncate("users")->execute();
     $wasExc = false;
     try {
         \PHPPE\DB::insert("users")->with('');
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "no fields exception");
     $this->assertEquals(1, \PHPPE\DB::insert("users")->with(['id' => 123, 'name' => 'newcomer', 'email' => '*****@*****.**']), "insert with with");
     $wasExc = false;
     try {
         \PHPPE\DB::select("users")->where("id=?")->execute();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "no argument exception");
     $ds = new \PHPPE\DS("sqlite::memory:");
     $this->assertNotEmpty(\PHPPE\DB::select("users")->execute([], 1), "execute on ds");
 }
예제 #4
0
 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("");
 }