Browse Source

Merge branch 'master' into master

Maurits van der Schee 7 years ago
parent
commit
052934796a
9 changed files with 352 additions and 139 deletions
  1. 1
    1
      .travis.yml
  2. 1
    1
      tests/Config.php.dist
  3. 1
    1
      tests/Config.php.travis
  4. 78
    33
      tests/MysqlTest.php
  5. 73
    30
      tests/PostgresqlTest.php
  6. 61
    27
      tests/SqlServerTest.php
  7. 60
    19
      tests/SqliteTest.php
  8. 46
    0
      tests/TestBase.php
  9. 31
    27
      tests/Tests.php

+ 1
- 1
.travis.yml View File

@@ -22,7 +22,7 @@ before_install:
22 22
   - psql -c 'create database testing;' -U postgres
23 23
   - psql -U postgres -c "create extension postgis"
24 24
   # - mysql -e 'CREATE DATABASE testing;'
25
-  - cp tests/config.php.travis tests/config.php
25
+  - cp tests/Config.php.travis tests/Config.php
26 26
 
27 27
 script:
28 28
   - curl https://phar.phpunit.de/phpunit-4.8.phar -L -o phpunit.phar && chmod +x phpunit.phar

tests/config.php.dist → tests/Config.php.dist View File

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3
-class PHP_CRUD_API_Config
3
+class Config
4 4
 {
5 5
     /**
6 6
      * Configure one or more database connections as associative arrays.

tests/config.php.travis → tests/Config.php.travis View File

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3
-class PHP_CRUD_API_Config
3
+class Config
4 4
 {
5 5
     /**
6 6
      * Configure one or more database connections as associative arrays.

+ 78
- 33
tests/MysqlTest.php View File

@@ -1,57 +1,102 @@
1 1
 <?php
2 2
 
3
-require_once(__DIR__ . '/tests.php');
3
+require_once(__DIR__ . '/Tests.php');
4 4
 
5
-class MysqlTest extends PHP_CRUD_API_Test
5
+class MysqlTest extends Tests
6 6
 {
7
-    const MYSQL_56 = 50600;
8
-    const MYSQL_57 = 50700;
9
-    public static $mysql_version;
7
+    /**
8
+     * Connects to the Database
9
+     *
10
+     * @return object Database connection
11
+     */
12
+    public function connect($config)
13
+    {
14
+        $db = mysqli_connect(
15
+            $config['hostname'],
16
+            $config['username'],
17
+            $config['password'],
18
+            $config['database']
19
+        );
20
+
21
+        if (mysqli_connect_errno()) {
22
+            die("Connect failed: ".mysqli_connect_error()."\n");
23
+        }
24
+
25
+        mysqli_set_charset($db,'utf8');
10 26
 
11
-    public static function setUpBeforeClass()
27
+        return $db;
28
+    }
29
+
30
+    /**
31
+     * Disconnects from the Database
32
+     *
33
+     * @return boolean Success
34
+     */
35
+    public function disconnect($db)
12 36
     {
13
-        self::setConfig('MySQL');
14
-        self::seedDatabase();
37
+        return mysqli_close($db);
15 38
     }
16 39
 
17 40
     /**
18
-     * Seeds the database for this connection
41
+     * Checks the version of the Database
19 42
      *
20 43
      * @return void
21 44
      */
22
-    public function seedDatabase()
23
-    {
24
-        if (static::$config['database']=='{{test_database}}') {
25
-            die("Configure database in 'config.php' before running tests.\n");
45
+    public function checkVersion($db)
46
+    {
47
+        $major = 5;
48
+        $minor = 5;
49
+        $version = mysqli_get_server_version($db);
50
+        $v = array(floor($version/10000),floor(($version%10000)/100));
51
+        if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
52
+            die("Detected MySQL $v[0].$v[1], but only $major.$minor and up are supported\n");
26 53
         }
54
+    }
27 55
 
28
-        $link = mysqli_connect(
29
-            static::$config['hostname'],
30
-            static::$config['username'],
31
-            static::$config['password'],
32
-            static::$config['database']
33
-        );
34
-
35
-        if (mysqli_connect_errno()) {
36
-            die("Connect failed: ".mysqli_connect_error()."\n");
56
+    /**
57
+     * Gets the capabilities of the Database
58
+     *
59
+     * @return int Capabilites
60
+     */
61
+    public function getCapabilities($db)
62
+    {
63
+        $capabilities = 0;
64
+        $version = mysqli_get_server_version($db);
65
+        if ($version>=50600) {
66
+            $capabilities |= self::GIS;
67
+        }
68
+        if ($version>=50700) {
69
+            $capabilities |= self::JSON;
37 70
         }
71
+        return $capabilities;
72
+    }
38 73
 
39
-        // Note: For some reason this version is formatted:
40
-        // $mysql_version = main_version * 10000 + minor_version * 100 + sub_version
41
-        static::$mysql_version = mysqli_get_server_version($link);
42
-        $seed_file = self::getSeedFile();
74
+    /**
75
+     * Seeds the database for this connection
76
+     *
77
+     * @return void
78
+     */
79
+    public function seedDatabase($db, $capabilities)
80
+    {
81
+        $fixture = __DIR__.'/data/blog_mysql.sql';
82
+        $contents = file_get_contents($fixture);
43 83
 
44
-        mysqli_set_charset($link,'utf8');
84
+        if (!($capabilities & self::GIS)) {
85
+            $contents = preg_replace('/(POINT|POLYGON) NOT NULL/i','text NOT NULL',$contents);
86
+            $contents = preg_replace('/ST_GeomFromText/i','concat',$contents);
87
+        }
88
+        if (!($capabilities & self::JSON)) {
89
+            $contents = preg_replace('/JSON NOT NULL/i','text NOT NULL',$contents);
90
+        }
45 91
 
46 92
         $i=0;
47
-        if (mysqli_multi_query($link, file_get_contents($seed_file))) {
48
-            do { $i++; mysqli_next_result($link); } while (mysqli_more_results($link));
49
-        }
50
-        if (mysqli_errno($link)) {
51
-            die("Loading '$seed_file' failed on statemement #$i with error:\n".mysqli_error($link)."\n");
93
+        if (mysqli_multi_query($db, $contents)) {
94
+            do { $i++; mysqli_next_result($db); } while (mysqli_more_results($db));
52 95
         }
53 96
 
54
-        mysqli_close($link);
97
+        if (mysqli_errno($db)) {
98
+            die("Loading '$fixture' failed on statemement #$i with error:\n".mysqli_error($db)."\n");
99
+        }
55 100
     }
56 101
 
57 102
     /**

+ 73
- 30
tests/PostgresqlTest.php View File

@@ -1,50 +1,95 @@
1 1
 <?php
2 2
 
3
-require_once(__DIR__ . '/tests.php');
3
+require_once(__DIR__ . '/Tests.php');
4 4
 
5
-class PostgresqlTest extends PHP_CRUD_API_Test
5
+class PostgresqlTest extends Tests
6 6
 {
7
-    public static $gis_installed;
8
-    public static $pg_server_version;
7
+    /**
8
+     * Connects to the Database
9
+     *
10
+     * @return object Database connection
11
+     */
12
+    public function connect($config)
13
+    {
14
+        $e = function ($v) { return str_replace(array('\'','\\'),array('\\\'','\\\\'),$v); };
15
+        $hostname = $e($config['hostname']);
16
+        $database = $e($config['database']);
17
+        $username = $e($config['username']);
18
+        $password = $e($config['password']);
19
+        $connectionString = "host='$hostname' dbname='$database' user='$username' password='$password' options='--client_encoding=UTF8'";
20
+
21
+        return pg_connect($connectionString);
22
+    }
9 23
 
10
-    public static function setUpBeforeClass()
24
+    /**
25
+     * Disconnects from the Database
26
+     *
27
+     * @return boolean Success
28
+     */
29
+    public function disconnect($db)
11 30
     {
12
-        static::setConfig('PostgreSQL');
13
-        self::seedDatabase();
31
+        return pg_close($db);
14 32
     }
15 33
 
16 34
     /**
17
-     * Seeds the database for this connection
35
+     * Checks the version of the Database
18 36
      *
19 37
      * @return void
20 38
      */
21
-    public function seedDatabase()
39
+    public function checkVersion($db)
22 40
     {
23
-        if (static::$config['database']=='{{test_database}}') {
24
-            die("Configure database in 'config.php' before running tests.\n");
41
+        $major = 9;
42
+        $minor = 1;
43
+        $version = pg_version();
44
+        $v = explode('.',$version['server']);
45
+        if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
46
+            die("Detected PostgreSQL $v[0].$v[1], but only $major.$minor and up are supported\n");
25 47
         }
48
+    }
26 49
 
27
-        $e = function ($v) { return str_replace(array('\'','\\'),array('\\\'','\\\\'),$v); };
28
-        $hostname = $e(static::$config['hostname']);
29
-        $database = $e(static::$config['database']);
30
-        $username = $e(static::$config['username']);
31
-        $password = $e(static::$config['password']);
32
-        $conn_string = "host='$hostname' dbname='$database' user='$username' password='$password' options='--client_encoding=UTF8'";
50
+    /**
51
+     * Gets the capabilities of the Database
52
+     *
53
+     * @return int Capabilites
54
+     */
55
+    public function getCapabilities($db)
56
+    {
57
+        $capabilities = 0;
58
+        $major = 9;
59
+        $minor = 4;
60
+        $version = pg_version();
61
+        $v = explode('.',$version['server']);
62
+        if ($v[0]>$major || ($v[0]==$major && $v[1]>=$minor)) {
63
+            $capabilities |= self::JSON;
64
+        }
65
+        $extensions = pg_fetch_all(pg_query($db, "SELECT * FROM pg_extension;"));
66
+        foreach ($extensions as $extension) {
67
+          if ($extension['extname'] === 'postgis') {
68
+            $capabilities |= self::GIS;
69
+          }
70
+        }
71
+        return $capabilities;
72
+    }
33 73
 
34
-        $db = pg_connect($conn_string);
74
+    /**
75
+     * Seeds the database for this connection
76
+     *
77
+     * @return void
78
+     */
79
+    public function seedDatabase($db,$capabilities)
80
+    {
81
+        $fixture = __DIR__.'/data/blog_postgresql.sql';
82
+        $contents = file_get_contents($fixture);
35 83
 
36
-        if (!$db) {
37
-            die("Connect failed: ". pg_last_error());
84
+        if (!($capabilities & self::GIS)) {
85
+            $contents = preg_replace('/(geometry) NOT NULL/i','text NOT NULL',$contents);
86
+            $contents = preg_replace('/ST_GeomFromText/i','concat',$contents);
87
+        }
88
+        if (!($capabilities & self::JSON)) {
89
+            $contents = preg_replace('/JSONB? NOT NULL/i','text NOT NULL',$contents);
38 90
         }
39 91
 
40
-        static::$pg_server_version = pg_version()['server'];
41
-        $gisInstalled = self::isGisInstalled(
42
-            pg_fetch_all(
43
-                pg_query($db, "SELECT * FROM pg_extension;")
44
-            )
45
-        );
46
-        $seed_file = self::getSeedFile();
47
-        $queries = preg_split('/;\s*\n/', file_get_contents($seed_file));
92
+        $queries = preg_split('/;\s*\n/', $contents);
48 93
         array_pop($queries);
49 94
 
50 95
         foreach ($queries as $i=>$query) {
@@ -53,8 +98,6 @@ class PostgresqlTest extends PHP_CRUD_API_Test
53 98
                 die("Loading '$seed_file' failed on statemement #$i with error:\n".print_r( pg_last_error($db), true)."\n");
54 99
             }
55 100
         }
56
-
57
-        pg_close($db);
58 101
     }
59 102
 
60 103
     /**

+ 61
- 27
tests/SqlServerTest.php View File

@@ -1,56 +1,90 @@
1 1
 <?php
2 2
 
3
-require_once(__DIR__ . '/tests.php');
3
+require_once(__DIR__ . '/Tests.php');
4 4
 
5
-class SqlServerTest extends PHP_CRUD_API_Test
5
+class SqlServerTest extends Tests
6 6
 {
7
-    public static function setUpBeforeClass()
7
+    /**
8
+     * Connects to the Database
9
+     *
10
+     * @return object Database connection
11
+     */
12
+    public function connect($config)
8 13
     {
9
-        self::setConfig('SQLServer');
14
+        $connectionInfo = array(
15
+            'UID' => $config['username'],
16
+            'PWD' => $config['password'],
17
+            'Database' => $config['database'],
18
+            'CharacterSet' => 'UTF-8',
19
+        );
20
+
21
+        $db = sqlsrv_connect($config['hostname'], $connectionInfo);
10 22
 
11
-        if (static::$config['database']=='{{test_database}}') {
12
-            die("Configure database in 'config.php' before running tests.\n");
23
+        if (!$db) {
24
+            die("Connect failed: ".print_r( sqlsrv_errors(), true));
13 25
         }
14 26
 
15
-        self::seedDatabase();
27
+        return $db;
16 28
     }
17 29
 
18 30
     /**
19
-     * Seeds the database for this connection
31
+     * Disconnects from the Database
32
+     *
33
+     * @return boolean Success
34
+     */
35
+    public function disconnect($db)
36
+    {
37
+        return sqlsrv_close($db);
38
+    }
39
+
40
+    /**
41
+     * Checks the version of the Database
20 42
      *
21 43
      * @return void
22 44
      */
23
-    public function seedDatabase()
45
+    public function checkVersion($db)
24 46
     {
25
-        if (static::$config['database']=='{{test_database}}') {
26
-            die("Configure database in 'config.php' before running tests.\n");
47
+        $major = 11;
48
+        $minor = 0;
49
+        $build = 3000;
50
+        $version = sqlsrv_server_info($db);
51
+        $v = explode('.',$version['SQLServerVersion']);
52
+        if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor) || ($v[0]==$major && $v[1]==$minor && $v[2]<$build)) {
53
+            die("Detected SQL Server $v[0].$v[1].$v[2], but only $major.$minor.$build and up are supported\n");
27 54
         }
55
+    }
28 56
 
29
-        $fixture = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'.sql';
30
-
31
-        $connectionInfo = array(
32
-            'UID' => static::$config['username'],
33
-            'PWD' => static::$config['password'],
34
-            'Database' => static::$config['database'],
35
-            'CharacterSet' => 'UTF-8',
36
-        );
57
+    /**
58
+     * Gets the capabilities of the Database
59
+     *
60
+     * @return int Capabilites
61
+     */
62
+    public function getCapabilities($db)
63
+    {
64
+        $capabilities = 0;
65
+        $capabilities |= self::GIS;
66
+        return $capabilities;
67
+    }
37 68
 
38
-        $conn = sqlsrv_connect(static::$config['hostname'], $connectionInfo);
39 69
 
40
-        if (!$conn) {
41
-            die("Connect failed: ".print_r( sqlsrv_errors(), true));
42
-        }
70
+    /**
71
+     * Seeds the database for this connection
72
+     *
73
+     * @return void
74
+     */
75
+    public function seedDatabase($db, $capabilities)
76
+    {
77
+        $fixture = __DIR__.'/data/blog_sqlserver.sql';
78
+        $contents = file_get_contents($fixture);
43 79
 
44
-        $queries = preg_split('/\n\s*GO\s*\n/', file_get_contents($fixture));
80
+        $queries = preg_split('/\n\s*GO\s*\n/', $contents);
45 81
         array_pop($queries);
46 82
 
47 83
         foreach ($queries as $i=>$query) {
48
-            if (!sqlsrv_query($conn, $query)) {
84
+            if (!sqlsrv_query($db, $query)) {
49 85
                 $i++;
50 86
                 die("Loading '$fixture' failed on statemement #$i with error:\n".print_r( sqlsrv_errors(), true)."\n");
51 87
             }
52 88
         }
53
-
54
-        sqlsrv_close($conn);
55 89
     }
56 90
 }

+ 60
- 19
tests/SqliteTest.php View File

@@ -1,37 +1,80 @@
1 1
 <?php
2 2
 
3
-require_once(__DIR__ . '/tests.php');
3
+require_once(__DIR__ . '/Tests.php');
4 4
 
5
-class SqliteTest extends PHP_CRUD_API_Test
5
+class SqliteTest extends Tests
6 6
 {
7
-    public static function setUpBeforeClass()
7
+    /**
8
+     * Connects to the Database
9
+     *
10
+     * @return object Database connection
11
+     */
12
+    public function connect($config)
13
+    {
14
+        $db = new SQLite3($config['database']);
15
+
16
+        if (!$db) {
17
+            die("Could not open '$database' SQLite database: ".SQLite3::lastErrorMsg().' ('.SQLite3::lastErrorCode().")\n");
18
+        }
19
+
20
+        return $db;
21
+    }
22
+
23
+    /**
24
+     * Disconnects from the Database
25
+     *
26
+     * @return boolean Success
27
+     */
28
+    public function disconnect($db)
8 29
     {
9
-        self::setConfig('SQLite');
10
-        self::seedDatabase();
30
+        return $db->close();
11 31
     }
12 32
 
13 33
     /**
14
-     * Seeds the database for this connection
34
+     * Checks the version of the Database
15 35
      *
16 36
      * @return void
17 37
      */
18
-    public function seedDatabase()
38
+    public function checkVersion($db)
19 39
     {
20
-        if (static::$config['database']=='{{test_database}}') {
21
-            die("Configure database in 'config.php' before running tests.\n");
40
+        $major = 3;
41
+        $minor = 0;
42
+        $version = SQLite3::version();
43
+        $v = explode('.',$version['versionString']);
44
+        if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
45
+            die("Detected SQLite $v[0].$v[1], but only $major.$minor and up are supported\n");
22 46
         }
47
+    }
23 48
 
24
-        $database = static::$config['database'];
25
-
26
-        $fixture = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'.sql';
49
+    /**
50
+     * Gets the capabilities of the Database
51
+     *
52
+     * @return int Capabilites
53
+     */
54
+    public function getCapabilities($db)
55
+    {
56
+        $capabilities = 0;
57
+        return $capabilities;
58
+    }
27 59
 
28
-        $db = new SQLite3($database);
60
+    /**
61
+     * Seeds the database for this connection
62
+     *
63
+     * @return void
64
+     */
65
+    public function seedDatabase($db, $capabilities)
66
+    {
67
+        $fixture = __DIR__.'/data/blog_sqlite.sql';
68
+        $contents = file_get_contents($fixture);
29 69
 
30
-        if (!$db) {
31
-            die("Could not open '$database' SQLite database: ".SQLite3::lastErrorMsg().' ('.SQLite3::lastErrorCode().")\n");
70
+        if (!($capabilities & self::GIS)) {
71
+            $contents = preg_replace('/GEOMETRY NOT NULL/i','text NOT NULL',$contents);
72
+        }
73
+        if (!($capabilities & self::JSON)) {
74
+            $contents = preg_replace('/JSON NOT NULL/i','text NOT NULL',$contents);
32 75
         }
33 76
 
34
-        $queries = preg_split('/;\s*\n/', file_get_contents($fixture));
77
+        $queries = preg_split('/;\s*\n/', $contents);
35 78
         array_pop($queries);
36 79
 
37 80
         foreach ($queries as $i=>$query) {
@@ -40,7 +83,5 @@ class SqliteTest extends PHP_CRUD_API_Test
40 83
                 die("Loading '$fixture' failed on statemement #$i with error:\n".$db->lastErrorCode().': '.$db->lastErrorMsg()."\n");
41 84
             }
42 85
         }
43
-
44
-        $db->close();
45 86
     }
46
-}
87
+}

+ 46
- 0
tests/TestBase.php View File

@@ -0,0 +1,46 @@
1
+<?php
2
+
3
+require_once(__DIR__ . '/Config.php');
4
+
5
+abstract class TestBase extends PHPUnit_Framework_TestCase
6
+{
7
+    protected function getConfig()
8
+    {
9
+        $dbengine = strtolower(substr(get_called_class(),0,-4));
10
+        foreach (Config::$config as $database) {
11
+            if (strtolower($database['dbengine']) == $dbengine) {
12
+                if ($database['database']!='{{test_database}}') {
13
+                    return $database;
14
+                }
15
+            }
16
+        }
17
+        self::markTestSkipped("Configuration for '{$dbengine}' in 'Config.php' not found.");
18
+        return false;
19
+    }
20
+
21
+    public static function setUpBeforeClass()
22
+    {
23
+        $config = self::getConfig();
24
+        $db = static::connect($config);
25
+        static::checkVersion($db);
26
+        $capabilities = static::getCapabilities($db);
27
+        static::seedDatabase($db,$capabilities);
28
+        static::disconnect($db);
29
+        // set params for test
30
+        static::$config = $config;
31
+        static::$capabilities = $capabilities;
32
+    }
33
+
34
+    public static $config;
35
+    public static $capabilities;
36
+
37
+    const GIS = 1;
38
+    const JSON = 2;
39
+
40
+    public abstract function checkVersion($db);
41
+
42
+    public abstract function getCapabilities($db);
43
+
44
+    public abstract function seedDatabase($db,$capabilities);
45
+
46
+}

tests/tests.php → tests/Tests.php View File

@@ -1,7 +1,7 @@
1 1
 <?php
2 2
 
3
-require __DIR__.'/config.php';
4
-require __DIR__.'/../api.php';
3
+require_once(__DIR__ . '/TestBase.php');
4
+require_once(__DIR__ . '/../api.php');
5 5
 
6 6
 class API
7 7
 {
@@ -113,24 +113,8 @@ class API
113 113
     }
114 114
 }
115 115
 
116
-abstract class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
116
+abstract class Tests extends TestBase
117 117
 {
118
-    public static $config;
119
-
120
-    public abstract function seedDatabase();
121
-
122
-    protected function setConfig($dbengine = '')
123
-    {
124
-        foreach (PHP_CRUD_API_Config::$config as $database) {
125
-            if ($database['dbengine'] == $dbengine) {
126
-                static::$config = $database;
127
-                return true;
128
-            }
129
-        }
130
-        self::markTestSkipped("Configuration for {$dbengine} database not found.");
131
-        return false;
132
-    }
133
-
134 118
     public function testListPosts()
135 119
     {
136 120
         $test = new API($this, static::$config);
@@ -584,7 +568,7 @@ abstract class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
584 568
 
585 569
     public function testSpatialFilterWithin()
586 570
     {
587
-        if (static::$config['dbengine']!='SQLite') {
571
+        if (static::$capabilities & self::GIS) {
588 572
             $test = new API($this, static::$config);
589 573
             $test->get('/users?columns=id,username&filter=location,swi,POINT(30 20)');
590 574
             $test->expect('{"users":{"columns":["id","username"],"records":[[1,"user1"]]}}');
@@ -699,32 +683,52 @@ abstract class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
699 683
     {
700 684
         $test = new API($this, static::$config);
701 685
         $test->get('/products?columns=id,properties&transform=1');
702
-        $test->expect('{"products":[{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}]}');
686
+        if (static::$capabilities & self::JSON) {
687
+            $test->expect('{"products":[{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}]}');
688
+        } else {
689
+            $test->expect('{"products":[{"id":1,"properties":"{\"depth\":false,\"model\":\"TRX-120\",\"width\":100,\"height\":null}"}]}');
690
+        }
703 691
     }
704 692
 
705 693
     public function testReadProductProperties()
706 694
     {
707 695
         $test = new API($this, static::$config);
708 696
         $test->get('/products/1?columns=id,properties');
709
-        $test->expect('{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}');
697
+        if (static::$capabilities & self::JSON) {
698
+            $test->expect('{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}');
699
+        } else {
700
+            $test->expect('{"id":1,"properties":"{\"depth\":false,\"model\":\"TRX-120\",\"width\":100,\"height\":null}"}');
701
+        }
710 702
     }
711 703
 
712 704
     public function testWriteProductProperties()
713 705
     {
714 706
         $test = new API($this, static::$config);
715
-        $test->put('/products/1','{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
707
+        if (static::$capabilities & self::JSON) {
708
+            $test->put('/products/1','{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
709
+        } else {
710
+            $test->put('/products/1','{"properties":"{\"depth\":false,\"model\":\"TRX-120\",\"width\":100,\"height\":123}"}');
711
+        }
716 712
         $test->expect('1');
717 713
         $test->get('/products/1?columns=id,properties');
718
-        $test->expect('{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
714
+        if (static::$capabilities & self::JSON) {
715
+            $test->expect('{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
716
+        } else {
717
+            $test->expect('{"id":1,"properties":"{\"depth\":false,\"model\":\"TRX-120\",\"width\":100,\"height\":123}"}');
718
+        }
719 719
     }
720 720
 
721 721
     public function testAddProducts()
722 722
     {
723 723
         $test = new API($this, static::$config);
724
-        $test->post('/products','{"name":"Laptop","price":"1299.99","properties":{}}');
724
+        if (static::$capabilities & self::JSON) {
725
+            $test->post('/products','{"name":"Laptop","price":"1299.99","properties":{}}');
726
+        } else {
727
+            $test->post('/products','{"name":"Laptop","price":"1299.99","properties":"{}"}');
728
+        }
725 729
         $test->expect('2');
726
-        $test->get('/products/2');
727
-        $test->expect('{"id":2,"name":"Laptop","price":"1299.99","properties":{},"created_at":"2013-12-11 10:09:08","deleted_at":null}');
730
+        $test->get('/products/2?columns=id,created_at,deleted_at');
731
+        $test->expect('{"id":2,"created_at":"2013-12-11 10:09:08","deleted_at":null}');
728 732
     }
729 733
 
730 734
     public function testSoftDeleteProducts()

Loading…
Cancel
Save