diff options
author | Thomas Davis <thomasalwyndavis@gmail.com> | 2013-08-14 17:32:51 +1000 |
---|---|---|
committer | Thomas Davis <thomasalwyndavis@gmail.com> | 2013-08-14 17:32:51 +1000 |
commit | d20a0fcf66055a6131a12e66f02cf2866f8bce64 (patch) | |
tree | 936b16012cc40c0b3761a7e27f27cb68147b7647 | |
parent | 8bac6fcd491ef38b42db3e642a58d9904d4407f6 (diff) | |
parent | 471dcb636650695ca33c79666da8349daf5c56cd (diff) | |
download | backbonetutorials-d20a0fcf66055a6131a12e66f02cf2866f8bce64.zip backbonetutorials-d20a0fcf66055a6131a12e66f02cf2866f8bce64.tar.gz backbonetutorials-d20a0fcf66055a6131a12e66f02cf2866f8bce64.tar.bz2 |
Merge branch 'gh-pages' of github.com:thomasdavis/backbonetutorials into gh-pages
-rw-r--r-- | videos/beginner/phpversion/client/README.md | 4 | ||||
-rw-r--r-- | videos/beginner/phpversion/client/index.html | 175 | ||||
-rw-r--r-- | videos/beginner/phpversion/server/.htaccess | 3 | ||||
-rw-r--r-- | videos/beginner/phpversion/server/README.md | 4 | ||||
-rw-r--r-- | videos/beginner/phpversion/server/index.php | 138 | ||||
-rw-r--r-- | videos/beginner/phpversion/tests/README.md | 4 | ||||
-rw-r--r-- | videos/beginner/phpversion/tests/mirror.php | 39 | ||||
-rw-r--r-- | videos/beginner/phpversion/tests/mirror_test.js | 84 | ||||
-rw-r--r-- | videos/beginner/phpversion/tests/qunit.html | 17 | ||||
-rw-r--r-- | videos/beginner/phpversion/tests/qunit_mirror.html | 17 | ||||
-rw-r--r-- | videos/beginner/phpversion/tests/server_test.js | 98 |
11 files changed, 583 insertions, 0 deletions
diff --git a/videos/beginner/phpversion/client/README.md b/videos/beginner/phpversion/client/README.md new file mode 100644 index 0000000..abfbe7d --- /dev/null +++ b/videos/beginner/phpversion/client/README.md @@ -0,0 +1,4 @@ +# Version with minimal PHP server + +Option URL change to '../server' + diff --git a/videos/beginner/phpversion/client/index.html b/videos/beginner/phpversion/client/index.html new file mode 100644 index 0000000..1f9102d --- /dev/null +++ b/videos/beginner/phpversion/client/index.html @@ -0,0 +1,175 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>BackboneTutorials.com Beginner Video</title> + <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.1/css/bootstrap.min.css"> +</head> +<body> + + + <div class="container"> + <h1>User Manager</h1> + <hr /> + <div class="page"></div> + </div> + + + <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script> + <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js" type="text/javascript"></script> + <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script> + + <script type="text/template" id="user-list-template"> + <a href="#/new" class="btn btn-primary">New</a> + <hr /> + <table class="table striped"> + <thead> + <tr> + <th>First Name</th><th>Last Name</th><th>Age</th><th></th> + </tr> + </thead> + <tbody> + <% _.each(users, function(user) { %> + <tr> + <td><%= htmlEncode(user.get('firstname')) %></td> + <td><%= htmlEncode(user.get('lastname')) %></td> + <td><%= htmlEncode(user.get('age')) %></td> + <td><a class="btn" href="#/edit/<%= user.id %>">Edit</a></td> + </tr> + <% }); %> + </tbody> + </table> + </script> + + <script type="text/template" id="edit-user-template"> + <form class="edit-user-form"> + <legend><%= user ? 'Edit' : 'New' %> User</legend> + <label>First Name</label> + <input name="firstname" type="text" value="<%= user ? user.get('firstname') : '' %>"> + <label>Last Name</label> + <input name="lastname" type="text" value="<%= user ? user.get('lastname') : '' %>"> + <label>Age</label> + <input name="age" type="text" value="<%= user ? user.get('age') : '' %>"> + <hr /> + <button type="submit" class="btn"><%= user ? 'Update' : 'Create' %></button> + <% if(user) { %> + <input type="hidden" name="id" value="<%= user.id %>" /> + <button data-user-id="<%= user.id %>" class="btn btn-danger delete">Delete</button> + <% }; %> + </form> + </script> + + <script> + function htmlEncode(value){ + return $('<div/>').text(value).html(); + } + $.fn.serializeObject = function() { + var o = {}; + var a = this.serializeArray(); + $.each(a, function() { + if (o[this.name] !== undefined) { + if (!o[this.name].push) { + o[this.name] = [o[this.name]]; + } + o[this.name].push(this.value || ''); + } else { + o[this.name] = this.value || ''; + } + }); + return o; + }; + + $.ajaxPrefilter( function( options, originalOptions, jqXHR ) { + options.url = '../server' + options.url; + }); + + var Users = Backbone.Collection.extend({ + url: '/users' + }); + + var User = Backbone.Model.extend({ + urlRoot: '/users' + }); + + var UserListView = Backbone.View.extend({ + el: '.page', + render: function () { + var that = this; + var users = new Users(); + users.fetch({ + success: function (users) { + var template = _.template($('#user-list-template').html(), {users: users.models}); + that.$el.html(template); + } + }) + } + }); + + var userListView = new UserListView(); + + var UserEditView = Backbone.View.extend({ + el: '.page', + events: { + 'submit .edit-user-form': 'saveUser', + 'click .delete': 'deleteUser' + }, + saveUser: function (ev) { + var userDetails = $(ev.currentTarget).serializeObject(); + var user = new User(); + user.save(userDetails, { + success: function (user) { + router.navigate('', {trigger:true}); + } + }); + return false; + }, + deleteUser: function (ev) { + this.user.destroy({ + success: function () { + //console.log('destroyed'); + router.navigate('', {trigger:true}); + } + }) + }, + render: function (options) { + var that = this; + if(options.id) { + that.user = new User({id: options.id}); + that.user.fetch({ + success: function (user) { + var template = _.template($('#edit-user-template').html(), {user: user}); + that.$el.html(template); + } + }) + } else { + var template = _.template($('#edit-user-template').html(), {user: null}); + that.$el.html(template); + } + } + }); + + var userEditView = new UserEditView(); + + var Router = Backbone.Router.extend({ + routes: { + "": "home", + "edit/:id": "edit", + "new": "edit", + } + }); + + var router = new Router; + router.on('route:home', function() { + // render user list + userListView.render(); + }) + router.on('route:edit', function(id) { + userEditView.render({id: id}); + }) + Backbone.history.start(); + </script> + + +</body> +</html> + diff --git a/videos/beginner/phpversion/server/.htaccess b/videos/beginner/phpversion/server/.htaccess new file mode 100644 index 0000000..eb5dcaf --- /dev/null +++ b/videos/beginner/phpversion/server/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteBase /www/xxxxxxxxxxxxxxx/phpversion/server +RewriteRule ^(.*)$ index.php?route=$1 [QSA,L] diff --git a/videos/beginner/phpversion/server/README.md b/videos/beginner/phpversion/server/README.md new file mode 100644 index 0000000..8b5a815 --- /dev/null +++ b/videos/beginner/phpversion/server/README.md @@ -0,0 +1,4 @@ +# Version with minimal PHP server + +* You need to change RewriteBase URL with the correct one /xxxxxxxxxxxxxxx/phpversion/server +* Absolute needed diff --git a/videos/beginner/phpversion/server/index.php b/videos/beginner/phpversion/server/index.php new file mode 100644 index 0000000..b779749 --- /dev/null +++ b/videos/beginner/phpversion/server/index.php @@ -0,0 +1,138 @@ +<?php +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2013 Raphael BAER +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////// +// decode parameters +/////////////////////////////////////////////////// +// method = GET|POST|PUT|DELETE +// object_name = OBJECT NAME +// object_id = ID (optional if method GET) +$method = $_SERVER['REQUEST_METHOD']; +@list($object_name,$object_id) = explode('/',$_GET['route']); +// echo 'method='.$method.' object_name='.$object_name.' object_id='.$object_id.'<br />'; + +//no object name : cannot do nothing +if ($object_name=='') { + echo "ERROR : no object name"; + exit; +} + +/////////////////////////////////////////////////// +// load data from file +/////////////////////////////////////////////////// +$file_name='data.'.$object_name.'.json'; +$file_data = json_decode(@file_get_contents($file_name)); +// echo 'file_data=';var_dump($file_data); + +/////////////////////////////////////////////////// +// process data +/////////////////////////////////////////////////// + +// create one object ////////////////////////////// +if (($method=='POST')&&($object_id=='')){ + // echo "create one object : "; + $input_data = json_decode(file_get_contents('php://input')); + if ($input_data=="") { + echo "ERROR : no data found"; + exit; + } + $input_data->id=uniqid(); + $file_data->{$object_name}[]=$input_data; + file_put_contents($file_name, json_encode($file_data)); + exit; +} + +//object is empty : cannot list, update or delete +if (!isset($file_data->$object_name)) { + if (($method=='GET')&&($object_id=='')) { + //not an error to ask to list all objects + echo "[]"; + exit; + } + echo "ERROR : no data available"; + exit; +} + +// list all objects /////////////////////////////// +if (($method=='GET')&&($object_id=='')){ + // echo "list all objects : "; + echo json_encode($file_data->$object_name); + exit; +} + +//no object_id : cannot do nothing more than list all objects +if ($object_id=='') { + echo "ERROR : no object id"; + exit; +} + +// list one object //////////////////////////////// +if ($method=='GET'){ + // echo "list one object : "; + foreach($file_data->$object_name as $object_val){ + if (isset($object_val->id)&&($object_val->id==$object_id)) { + echo json_encode($object_val); + exit; + } + } + echo "ERROR : object not found"; + exit; +} + +// update one object ////////////////////////////// +if ($method=='PUT'){ + foreach($file_data->$object_name as $object_key => $object_val){ + if (isset($object_val->id)&&($object_val->id==$object_id)){ + $input_data = json_decode(file_get_contents('php://input')); + if ($input_data=="") { + echo "ERROR : no data found"; + exit; + } + $file_data->{$object_name}[$object_key]=$input_data; + file_put_contents($file_name, json_encode($file_data)); + exit; + } + } + echo "ERROR : object not found"; + exit; +} + +// delete one object ////////////////////////////// +if ($method=='DELETE'){ + foreach($file_data->$object_name as $object_key => $object_val){ + if ($object_val->id==$object_id){ + array_splice($file_data->$object_name,$object_key,1); + file_put_contents($file_name, json_encode($file_data)); + exit; + } + } + echo "ERROR : object not found"; + exit; +} + +echo "ERROR : no method found"; +exit; +?>
\ No newline at end of file diff --git a/videos/beginner/phpversion/tests/README.md b/videos/beginner/phpversion/tests/README.md new file mode 100644 index 0000000..54ae971 --- /dev/null +++ b/videos/beginner/phpversion/tests/README.md @@ -0,0 +1,4 @@ +# Version with minimal PHP server + +* Run first qunit_mirror.html to be sure server works correcly +* Then run qunit.html diff --git a/videos/beginner/phpversion/tests/mirror.php b/videos/beginner/phpversion/tests/mirror.php new file mode 100644 index 0000000..dcce1a9 --- /dev/null +++ b/videos/beginner/phpversion/tests/mirror.php @@ -0,0 +1,39 @@ +<?php +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2013 Raphael BAER +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////// +// decode parameters +/////////////////////////////////////////////////// +// method = GET|POST|PUT|DELETE +// object_name = OBJECT NAME +// object_id = ID (optional if method GET) +// input_data = POST DATA +$method = $_SERVER['REQUEST_METHOD']; +@list($object_name,$object_id) = explode('/',$_GET['route']); +$input_data = file_get_contents('php://input'); +echo 'method='.$method.' object_name='.$object_name.' object_id='.$object_id.' input_data='.$input_data; +exit; +?>
\ No newline at end of file diff --git a/videos/beginner/phpversion/tests/mirror_test.js b/videos/beginner/phpversion/tests/mirror_test.js new file mode 100644 index 0000000..3b3480b --- /dev/null +++ b/videos/beginner/phpversion/tests/mirror_test.js @@ -0,0 +1,84 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2013 Raphael BAER +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// +(function ($) { + + base_url='mirror.php'; + + function api_test(message, url, type, data, expected) { + return $.ajax( + { + url: url, + type: type, + processData: false, + contentType: 'application/json; charset=utf-8', + data: data, + dataType: 'json', + async: false, + complete: function (result) { + if (result.status == 0) { + ok(false, '0 status - browser could be on offline mode'); + } else if (result.status == 404) { + ok(false, '404 error'); + } else { + result=result.responseText; + deepEqual(result,expected,message); + return result; + } + } + }); + } + + test('Test method',function(){ + expect( 4 ); + api_test('GET',base_url+'','GET','','method=GET object_name= object_id= input_data='); + api_test('POST',base_url+'','POST','','method=POST object_name= object_id= input_data='); + api_test('PUT',base_url+'','PUT','','method=PUT object_name= object_id= input_data='); + api_test('DELETE',base_url+'','DELETE','','method=DELETE object_name= object_id= input_data='); + }); + + test('Test 1 param',function(){ + expect( 4 ); + api_test('GET',base_url+'?route=test1','GET','','method=GET object_name=test1 object_id= input_data='); + api_test('POST',base_url+'?route=test2','POST','','method=POST object_name=test2 object_id= input_data='); + api_test('PUT',base_url+'?route=test3','PUT','','method=PUT object_name=test3 object_id= input_data='); + api_test('DELETE',base_url+'?route=test4','DELETE','','method=DELETE object_name=test4 object_id= input_data='); + }); + + test('Test 2 param',function(){ + expect( 4 ); + api_test('GET',base_url+'?route=test1/1234','GET','','method=GET object_name=test1 object_id=1234 input_data='); + api_test('POST',base_url+'?route=test2/12345','POST','','method=POST object_name=test2 object_id=12345 input_data='); + api_test('PUT',base_url+'?route=test3/123456','PUT','','method=PUT object_name=test3 object_id=123456 input_data='); + api_test('DELETE',base_url+'?route=test4/6789','DELETE','','method=DELETE object_name=test4 object_id=6789 input_data='); + }); + + test('Test input data',function(){ + expect( 4 ); + api_test('GET',base_url+'?route=test1/1234','GET','data1','method=GET object_name=test1 object_id=1234 input_data='); + api_test('POST',base_url+'?route=test2/12345','POST','data2','method=POST object_name=test2 object_id=12345 input_data=data2'); + api_test('PUT',base_url+'?route=test3/123456','PUT','data3','method=PUT object_name=test3 object_id=123456 input_data=data3'); + api_test('DELETE',base_url+'?route=test4/6789','DELETE','data4','method=DELETE object_name=test4 object_id=6789 input_data=data4'); + }); + +}( jQuery ));
\ No newline at end of file diff --git a/videos/beginner/phpversion/tests/qunit.html b/videos/beginner/phpversion/tests/qunit.html new file mode 100644 index 0000000..9d7492e --- /dev/null +++ b/videos/beginner/phpversion/tests/qunit.html @@ -0,0 +1,17 @@ +<html> +<head> + <title>QUnit Test Suite</title> + <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min.css" type="text/css" media="screen"> + <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min.js"></script> + <script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script> + <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min.js"></script> + <script type="text/javascript" src="server_test.js"></script> +</head> +<body> + <h1 id="qunit-header">QUnit Test Suite</h1> + <h2 id="qunit-banner"></h2> + <div id="qunit-testrunner-toolbar"></div> + <h2 id="qunit-userAgent"></h2> + <ol id="qunit-tests"></ol> +</body> +</html>
\ No newline at end of file diff --git a/videos/beginner/phpversion/tests/qunit_mirror.html b/videos/beginner/phpversion/tests/qunit_mirror.html new file mode 100644 index 0000000..b1c176c --- /dev/null +++ b/videos/beginner/phpversion/tests/qunit_mirror.html @@ -0,0 +1,17 @@ +<html> +<head> + <title>QUnit Test Suite</title> + <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min.css" type="text/css" media="screen"> + <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min.js"></script> + <script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script> + <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min.js"></script> + <script type="text/javascript" src="mirror_test.js"></script> +</head> +<body> + <h1 id="qunit-header">QUnit Test Suite</h1> + <h2 id="qunit-banner"></h2> + <div id="qunit-testrunner-toolbar"></div> + <h2 id="qunit-userAgent"></h2> + <ol id="qunit-tests"></ol> +</body> +</html>
\ No newline at end of file diff --git a/videos/beginner/phpversion/tests/server_test.js b/videos/beginner/phpversion/tests/server_test.js new file mode 100644 index 0000000..6718ec9 --- /dev/null +++ b/videos/beginner/phpversion/tests/server_test.js @@ -0,0 +1,98 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2013 Raphael BAER +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// +(function ($) { + + base_url="../server/"; + + function api_test(message, url, type, data, expected) { + return $.ajax( + { + url: url, + type: type, + processData: false, + contentType: 'application/json; charset=utf-8', + data: data, + dataType: 'json', + async: false, + complete: function (result) { + if (result.status == 0) { + ok(false, '0 status - browser could be on offline mode'); + } else if (result.status == 404) { + ok(false, '404 error'); + } else { + result=result.responseText; + if (expected!=undefined) deepEqual(result,expected,message); + return result; + } + } + }); + } + + + test('Test server',function(){ + expect( 7 ); + + api_test('GET all',base_url+'test','GET','','[]'); + + api_test('ADD',base_url+'test','POST','{"test1":"ok"}',''); + mock=api_test('GET all',base_url+'test','GET',''); + // console.log(mock.responseJSON[0]['id']); + mock_id=mock.responseJSON[0]['id'] + api_test('GET all',base_url+'test','GET','','[{"test1":"ok","id":"'+mock_id+'"}]'); + api_test('GET one',base_url+'test/'+mock_id,'GET','','{"test1":"ok","id":"'+mock_id+'"}'); + + api_test('PUT',base_url+'test/'+mock_id,'PUT','{"test1":"ok2","id":"'+mock_id+'"}',''); + api_test('GET one',base_url+'test/'+mock_id,'GET','','{"test1":"ok2","id":"'+mock_id+'"}'); + + api_test('DELETE',base_url+'test/'+mock_id,'DELETE','',''); + }); + + + + test('Test ERROR',function(){ + expect( 13 ); + + api_test('GET',base_url+'','GET','','ERROR : no object name'); + api_test('PUT',base_url+'test','PUT','','ERROR : no object id'); + + api_test('POST',base_url+'test/123456789','POST','','ERROR : no method found'); + + api_test('GET one',base_url+'test/123456789','GET','','ERROR : object not found'); + api_test('PUT',base_url+'test/123456789','PUT','','ERROR : object not found'); + api_test('DELETE',base_url+'test/123456789','DELETE','','ERROR : object not found'); + + api_test('ADD',base_url+'test','POST','','ERROR : no data found'); + api_test('ADD',base_url+'test','POST','{"test1":"ok"}',''); + mock=api_test('GET all',base_url+'test','GET',''); + mock_id=mock.responseJSON[0]['id'] + api_test('PUT',base_url+'test/'+mock_id,'PUT','','ERROR : no data found'); + + api_test('GET one',base_url+'test/123456789','GET','','ERROR : object not found'); + api_test('PUT',base_url+'test/123456789','PUT','','ERROR : object not found'); + api_test('DELETE',base_url+'test/123456789','DELETE','','ERROR : object not found'); + + api_test('DELETE',base_url+'test/'+mock_id,'DELETE','',''); + }); + +}( jQuery ));
\ No newline at end of file |