Commit 5254e7ac authored by Karamel's avatar Karamel
Browse files

Update tests for CORS and Postgresql.

parent f8892298
......@@ -23,6 +23,7 @@ namespace Pasteque\Server;
use \Pasteque\Server\API\CategoryAPI;
use \Pasteque\Server\Model\Category;
use \Pasteque\Server\System\DAO\DAOCondition;
use \Pasteque\Server\System\DAO\DAOFactory;
use \PHPUnit\Framework\TestCase;
......@@ -40,9 +41,16 @@ class CategoryAPITest extends TestCase
}
protected function tearDown() {
$all = $this->dao->search(Category::class, null, null, null, '-parent');
$ids = array();
foreach($all as $record) {
// Explicitely delete children before parents because Doctrine
// cannot handle it. It won't work if there grandchildren.
$children = $this->dao->search(Category::class,
new DAOCondition('parent', '!=', null));
foreach ($children as $record) {
$this->dao->delete($record);
}
$parents = $this->dao->search(Category::class,
new DAOCondition('parent', '=', null));
foreach ($parents as $record) {
$this->dao->delete($record);
}
$this->dao->commit();
......
......@@ -22,6 +22,7 @@
namespace Pasteque\Server;
use \Pasteque\Server\Model\Category;
use \Pasteque\Server\System\DAO\DAOCondition;
use \Pasteque\Server\System\DAO\DAOFactory;
use \PHPUnit\Framework\TestCase;
......@@ -38,8 +39,16 @@ class CategoryTest extends TestCase
}
protected function tearDown() {
$all = $this->dao->search(Category::class, null, null, null, '-parent');
foreach($all as $record) {
// Explicitely delete children before parents because Doctrine
// cannot handle it. It won't work if there grandchildren.
$children = $this->dao->search(Category::class,
new DAOCondition('parent', '!=', null));
foreach ($children as $record) {
$this->dao->delete($record);
}
$parents = $this->dao->search(Category::class,
new DAOCondition('parent', '=', null));
foreach ($parents as $record) {
$this->dao->delete($record);
}
$this->dao->commit();
......
......@@ -21,6 +21,7 @@
// along with Pasteque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque\Server;
use \Pasteque\Server\System\Login;
use \Pasteque\Server\System\API\APICaller;
use \Pasteque\Server\System\API\APIResult;
use \PHPUnit\Framework\TestCase;
......@@ -64,15 +65,23 @@ class APICallerTest extends TestCase {
public function testGetCORSHeaders() {
$headers = APICaller::getCORSHeaders('origin', 'origin', 100);
$this->assertEquals(3, count(array_keys($headers)));
$this->assertEquals(5, count(array_keys($headers)));
$this->assertEquals('origin', $headers['Access-Control-Allow-Origin']);
$this->assertFalse($headers['Access-Control-Allow-Credentials']);
$this->assertEquals(100, $headers['Access-Control-Max-Age']);
$this->assertEquals(Login::TOKEN_HEADER,
$headers['Access-Control-Expose-Headers']);
$this->assertEquals(Login::TOKEN_HEADER,
$headers['Access-Control-Allow-Headers']);
$headers = APICaller::getCORSHeaders('origin', array('allowed', 'origin'), 200);
$this->assertEquals(4, count(array_keys($headers)));
$this->assertEquals(6, count(array_keys($headers)));
$this->assertEquals('origin', $headers['Access-Control-Allow-Origin']);
$this->assertFalse($headers['Access-Control-Allow-Credentials']);
$this->assertEquals(200, $headers['Access-Control-Max-Age']);
$this->assertEquals(Login::TOKEN_HEADER,
$headers['Access-Control-Expose-Headers']);
$this->assertEquals(Login::TOKEN_HEADER,
$headers['Access-Control-Allow-Headers']);
$this->assertEquals('Origin', $headers['Vary']);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment