⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 model.test.php

📁 Cake Framwork , Excellent
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		$result = $TestModel->read(null, 1);		$expected = array(				'Person' => array('id' => 1, 'name' => 'person', 'mother_id' => 2, 'father_id' => 3),				'Mother' => array('id' => 2, 'name' => 'mother', 'mother_id' => 4, 'father_id' => 5,					'Mother' => array('id' => 4, 'name' => 'mother - grand mother', 'mother_id' => 0, 'father_id' => 0,						'Mother' => array(),						'Father' => array()),					'Father' => array('id' => 5, 'name' => 'mother - grand father', 'mother_id' => 0, 'father_id' => 0,						'Father' => array(),						'Mother' => array())),				'Father' => array('id' => 3, 'name' => 'father', 'mother_id' => 6, 'father_id' => 7,					'Father' => array('id' => 7, 'name' => 'father - grand father', 'mother_id' => 0, 'father_id' => 0,						'Father' => array(),						'Mother' => array()),					'Mother' => array('id' => 6, 'name' => 'father - grand mother', 'mother_id' => 0, 'father_id' => 0,						'Mother' => array(),						'Father' => array())));		$this->assertEqual($result, $expected);	}/** * testIdentity method *  * @access public * @return void */	function testIdentity() {		$TestModel =& new Test();		$result = $TestModel->alias;		$expected = 'Test';		$this->assertEqual($result, $expected);		$TestModel =& new TestAlias();		$result = $TestModel->alias;		$expected = 'TestAlias';		$this->assertEqual($result, $expected);		$TestModel =& new TestAlias(array('alias' => 'AnotherTest'));		$result = $TestModel->alias;		$expected = 'AnotherTest';		$this->assertEqual($result, $expected);	}/** * testCreation method *  * @access public * @return void */	function testCreation() {		$this->loadFixtures('Article');		$TestModel =& new Test();		$result = $TestModel->create();		$expected = array('Test' => array('notes' => 'write some notes here'));		$this->assertEqual($result, $expected);		$TestModel =& new User();		$result = $TestModel->schema();		if (isset($this->db->columns['primary_key']['length'])) {			$intLength = $this->db->columns['primary_key']['length'];		} elseif (isset($this->db->columns['integer']['length'])) {			$intLength = $this->db->columns['integer']['length'];		} else {			$intLength = 11;		}		$expected = array(				'id' => array('type' => 'integer',	'null' => false, 'default' => null,	'length' => $intLength, 'key' => 'primary'),				'user' => array('type' => 'string',		'null' => false, 'default' => '',	'length' => 255),				'password' => array('type' => 'string',		'null' => false, 'default' => '',	'length' => 255),				'created' => array('type' => 'datetime',	'null' => true, 'default' => null,	'length' => null),				'updated'=> array('type' => 'datetime',	'null' => true, 'default' => null,	'length' => null));		$this->assertEqual($result, $expected);		$TestModel =& new Article();		$result = $TestModel->create();		$expected = array('Article' => array('published' => 'N'));		$this->assertEqual($result, $expected);	}/** * testCreationOfEmptyRecord method *  * @access public * @return void */	function testCreationOfEmptyRecord() {		$this->loadFixtures('Author');		$TestModel =& new Author();		$this->assertEqual($TestModel->find('count'), 4);		$TestModel->deleteAll(true, false, false);		$this->assertEqual($TestModel->find('count'), 0);		$result = $TestModel->save();		$this->assertTrue(isset($result['Author']['created']));		$this->assertTrue(isset($result['Author']['updated']));		$this->assertEqual($TestModel->find('count'), 1);	}/** * testCreateWithPKFiltering method *  * @access public * @return void */	function testCreateWithPKFiltering() {		$TestModel =& new Article();		$data = array('id' => 5, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text');		$result = $TestModel->create($data);		$expected = array('Article' => array('published' => 'N', 'id' => 5, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text'));		$this->assertEqual($result, $expected);		$this->assertEqual($TestModel->id, 5);		$result = $TestModel->create($data, true);		$expected = array('Article' => array('published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text'));		$this->assertEqual($result, $expected);		$this->assertFalse($TestModel->id);		$result = $TestModel->create(array('Article' => $data), true);		$expected = array('Article' => array('published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text'));		$this->assertEqual($result, $expected);		$this->assertFalse($TestModel->id);	}/** * testCreationWithMultipleData method *  * @access public * @return void */	function testCreationWithMultipleData() {		$this->loadFixtures('Article', 'Comment');		$Article =& new Article();		$Comment =& new Comment();		$articles = $Article->find('all', array('fields' => array('id','title'), 'recursive' => -1));		$comments = $Comment->find('all', array('fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1));		$this->assertEqual($articles, array(			array('Article' => array('id' => 1, 'title' => 'First Article')),			array('Article' => array('id' => 2, 'title' => 'Second Article')),			array('Article' => array('id' => 3, 'title' => 'Third Article'))));		$this->assertEqual($comments, array(			array('Comment' => array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y')),			array('Comment' => array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y')),			array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y')),			array('Comment' => array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N')),			array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y')),			array('Comment' => array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y'))));		$data = array('Comment' => array('article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N'),				'Article' => array('id' => 2, 'title' => 'Second Article Modified'));		$result = $Comment->create($data);		$this->assertTrue($result);		$result = $Comment->save();		$this->assertTrue($result);		$articles = $Article->find('all', array('fields' => array('id','title'), 'recursive' => -1));		$comments = $Comment->find('all', array('fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1));		$this->assertEqual($articles, array(			array('Article' => array('id' => 1, 'title' => 'First Article')),			array('Article' => array('id' => 2, 'title' => 'Second Article')),			array('Article' => array('id' => 3, 'title' => 'Third Article'))));		$this->assertEqual($comments, array(			array('Comment' => array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y')),			array('Comment' => array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y')),			array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y')),			array('Comment' => array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N')),			array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y')),			array('Comment' => array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y')),			array('Comment' => array('id' => 7, 'article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N'))));	}/** * testCreationWithMultipleDataSameModel method *  * @access public * @return void */	function testCreationWithMultipleDataSameModel() {		$this->loadFixtures('Article');		$Article =& new Article();		$SecondaryArticle =& new Article();		$result = $Article->field('title', array('id' => 1));		$this->assertEqual($result, 'First Article');		$data = array('Article' => array('user_id' => 2, 'title' => 'Brand New Article', 'body' => 'Brand New Article Body', 'published' => 'Y'),			'SecondaryArticle' => array('id' => 1));		$Article->create();		$result = $Article->save($data);		$this->assertTrue($result);		$result = $Article->getInsertID();		$this->assertTrue(!empty($result));		$result = $Article->field('title', array('id' => 1));		$this->assertEqual($result, 'First Article');		$articles = $Article->find('all', array('fields' => array('id','title'), 'recursive' => -1));		$this->assertEqual($articles, array(			array('Article' => array('id' => 1, 'title' => 'First Article')),			array('Article' => array('id' => 2, 'title' => 'Second Article')),			array('Article' => array('id' => 3, 'title' => 'Third Article')),			array('Article' => array('id' => 4, 'title' => 'Brand New Article'))));	}/** * testCreationWithMultipleDataSameModelManualInstances method *  * @access public * @return void */	function testCreationWithMultipleDataSameModelManualInstances() {		$this->loadFixtures('PrimaryModel');		$Primary =& new PrimaryModel();		$Secondary =& new PrimaryModel();		$result = $Primary->field('primary_name', array('id' => 1));		$this->assertEqual($result, 'Primary Name Existing');		$data = array('PrimaryModel' => array('primary_name' => 'Primary Name New'),			'SecondaryModel' => array('id' => array(1)));		$Primary->create();		$result = $Primary->save($data);		$this->assertTrue($result);		$result = $Primary->field('primary_name', array('id' => 1));		$this->assertEqual($result, 'Primary Name Existing');		$result = $Primary->getInsertID();		$this->assertTrue(!empty($result));		$result = $Primary->field('primary_name', array('id' => $result));		$this->assertEqual($result, 'Primary Name New');		$result = $Primary->findCount();		$this->assertEqual($result, 2);	}/** * testReadFakeThread method *  * @access public * @return void */	function testReadFakeThread() {		$this->loadFixtures('CategoryThread');		$TestModel =& new CategoryThread();		$this->db->fullDebug = true;		$TestModel->recursive = 6;		$TestModel->id = 7;		$result = $TestModel->read();		$expected = array(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -