class = new MailLastResource($request); $this->classOAuth = new OAuth2StorageUserCredential(); $_SESSION['wallet']['user']['uid'] = $this->user; $_SESSION['wallet']['user']['password'] = $this->pass; $this->cyrusConf = Config::service('Cyrus', 'config'); $this->cyrusOPTS = ($this->cyrusConf['tlsEncryption']) ? '/tls/novalidate-cert' : '/notls/novalidate-cert'; $this->mbox = imap_open( '{'.$this->cyrusConf['host'].":".$this->cyrusConf['port'].$this->cyrusOPTS.'}INBOX' , Config::me('uid') , Config::me('password') ); $messages = imap_sort( $this->mbox , SORTDATE , 1 , null , "UNSEEN" , 'UTF-8'); if (is_array($messages)) foreach ($messages as $msg_number) imap_delete($this->mbox, $msg_number); imap_expunge ( $this->mbox ); //insere access token $this->classOAuth->setAccessToken($this->accessToken, $this->client_id, $this->user_id, (time() + 3600), 'all', $this->refreshToken); //insere refresh token $this->classOAuth->setRefreshToken($this->refreshToken, $this->client_id, $this->user_id, (time() + 3600), 'all'); } //finaliza classe public function tearDown() { $messages = imap_sort( $this->mbox , SORTDATE , 1 , null , "UNSEEN" , 'UTF-8'); if (is_array($messages)) foreach ($messages as $msg_number) imap_delete($this->mbox, $msg_number); imap_expunge ( $this->mbox ); $this->classOAuth->unsetRefreshToken($this->refreshToken); $this->classOAuth->unsetAccessToken($this->accessToken); } /* * * */ //(sem mensagens novas) public function testGet_emptyFolder() { $request = new Request(); $get = $this->class->get($request); $body = json_decode($get->body); $this->assertCount(0, $body); } /* * * */ //(uma mensagem nova) public function testGet() { $msg = (" MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: quoted-printable\r\n" . "Subject: This is the subject\r\n" . "From: =?ISO-8859-1?Q?jo=E3o_Silva?= \r\n" . "To: teste@test\r\n" . "Cc:\r\n" . "Bcc:\r\n" . "\r\n\r\n" . "Corpo\r\n\r\n"); imap_append($this->mbox,'{'.$this->cyrusConf['host'].":".$this->cyrusConf['port'].$this->cyrusOPTS.'}INBOX',$msg); $request = new Request(); $get = $this->class->get($request); $body = json_decode($get->body,true); $this->assertCount(1, $body); $body = $body[0]; $this->assertEquals($body['subject'], 'This is the subject'); $this->assertEquals($body['from']['mail'], 'teste@teste.com.br'); $this->assertEquals($body['from']['name'], 'joão Silva'); $this->assertInternalType('int', $body['date']); } } ?>