Last active
June 19, 2016 03:05
-
-
Save markstory/009640880a13c71d9d27df1f4441ea39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('AppModel', 'Model'); | |
/** | |
* Article Model | |
* | |
* @property Comment $Comment | |
*/ | |
class Article extends AppModel { | |
/** | |
* Validation rules | |
* | |
* @var array | |
*/ | |
public $validate = array( | |
); | |
/** | |
* hasMany associations | |
* | |
* @var array | |
*/ | |
public $hasMany = array( | |
'Comment' => array( | |
'className' => 'Management.Comment', | |
'foreignKey' => 'article_id', | |
'dependent' => false, | |
'conditions' => '', | |
'fields' => '', | |
'order' => '', | |
'limit' => '', | |
'offset' => '', | |
'exclusive' => '', | |
'finderQuery' => '', | |
'counterQuery' => '' | |
) | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ArticleFixture | |
* | |
*/ | |
class ArticleFixture extends CakeTestFixture { | |
/** | |
* Fields | |
* | |
* @var array | |
*/ | |
public $fields = array( | |
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), | |
'title' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | |
'body' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | |
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | |
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | |
'indexes' => array( | |
'PRIMARY' => array('column' => 'id', 'unique' => 1) | |
), | |
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') | |
); | |
/** | |
* Records | |
* | |
* @var array | |
*/ | |
public $records = array( | |
array( | |
'id' => 1, | |
'title' => 'Lorem ipsum dolor sit amet', | |
'body' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.', | |
'created' => '2014-10-09 20:34:42', | |
'modified' => '2014-10-09 20:34:42' | |
), | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('AppController', 'Controller'); | |
/** | |
* Articles Controller | |
* | |
*/ | |
class ArticlesController extends AppController { | |
public $components = ['RequestHandler', 'Flash']; | |
public function add() { | |
$resp = []; | |
if ($this->request->is('post')) { | |
$resp = $this->Article->save($this->request->data); | |
} | |
$this->set('article', $resp); | |
$this->set('_serialize', ['article']); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('ArticlesController', 'Controller'); | |
/** | |
* ArticlesController Test Case | |
* | |
*/ | |
class ArticlesControllerTest extends ControllerTestCase { | |
/** | |
* Fixtures | |
* | |
* @var array | |
*/ | |
public $fixtures = array( | |
'app.article', | |
); | |
public function testAdd() | |
{ | |
$url = Router::url(array( | |
'controller' => 'articles', | |
'action' => 'add', | |
'ext' => 'json', | |
)); | |
$options = array( | |
'return' => 'contents', | |
'method' => 'POST', | |
'data' => [ | |
'Article' => [ | |
'title' => 'testing', | |
'body' => 'testing body', | |
] | |
] | |
); | |
$result = $this->testAction($url, $options); | |
debug($result); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Router::parseExtensions('json'); | |
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); | |
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); | |
CakePlugin::routes(); | |
require CAKE . 'Config' . DS . 'routes.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment