set.test.php

来自「Cake Framwork , Excellent」· PHP 代码 · 共 1,605 行 · 第 1/5 页

PHP
1,605
字号
						'X-Original-Transfer-Encoding' => "chunked",						'Content-Length' => "50210",					),					'meta' => array(							'keywords' => array('testing','tests'),							'description'=>'describe me',					),					'get_vars' => '',					'post_vars' => array(),					'cookies' => array('PHPSESSID' => "dde9896ad24595998161ffaf9e0dbe2d"),					'redirect' => '',					'created' => "1195055503",					'updated' => "1195055503",				),			)		);		$mapped = Set::map($expected);		$ids = array();		foreach($mapped as $object)	 {			$ids[] = $object->id;		}		$this->assertEqual($ids, array(1, 2));		$this->assertEqual(get_object_vars($mapped[0]->headers), $expected[0]['IndexedPage']['headers']);		$result = Set::reverse($mapped);		$this->assertIdentical($result, $expected);		$data = array(			array(				"IndexedPage" => array(					"id" => 1,					"url" => 'http://blah.com/',					'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',					'get_vars' => '',					'redirect' => '',					'created' => "1195055503",					'updated' => "1195055503",				)			),			array(				"IndexedPage" => array(					"id" => 2,					"url" => 'http://blah.com/',					'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',					'get_vars' => '',					'redirect' => '',					'created' => "1195055503",					'updated' => "1195055503",				),			)		);		$mapped = Set::map($data);		$expected = new stdClass();		$expected->_name_ = 'IndexedPage';		$expected->id = 2;		$expected->url = 'http://blah.com/';		$expected->hash = '68a9f053b19526d08e36c6a9ad150737933816a5';		$expected->get_vars = '';		$expected->redirect = '';		$expected->created = "1195055503";		$expected->updated = "1195055503";		$this->assertIdentical($mapped[1], $expected);		$ids = array();		foreach($mapped as $object)	 {			$ids[] = $object->id;		}		$this->assertEqual($ids, array(1, 2));	}/** * testNestedMappedData method *  * @access public * @return void */	function testNestedMappedData() {		$result = Set::map(array(				array(					'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),					'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'),				)				, array(					'Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'),					'Author' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'test' => 'working'),				)			));		$expected = new stdClass;		$expected->_name_ = 'Post';		$expected->id = '1';		$expected->author_id = '1';		$expected->title = 'First Post';		$expected->body = 'First Post Body';		$expected->published = 'Y';		$expected->created = "2007-03-18 10:39:23";		$expected->updated = "2007-03-18 10:41:31";		$expected->Author = new stdClass;		$expected->Author->id = '1';		$expected->Author->user = 'mariano';		$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';		$expected->Author->created = "2007-03-17 01:16:23";		$expected->Author->updated = "2007-03-17 01:18:31";		$expected->Author->test = "working";		$expected2 = new stdClass;		$expected2->_name_ = 'Post';		$expected2->id = '2';		$expected2->author_id = '3';		$expected2->title = 'Second Post';		$expected2->body = 'Second Post Body';		$expected2->published = 'Y';		$expected2->created = "2007-03-18 10:41:23";		$expected2->updated = "2007-03-18 10:43:31";		$expected2->Author = new stdClass;		$expected2->Author->id = '3';		$expected2->Author->user = 'larry';		$expected2->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';		$expected2->Author->created = "2007-03-17 01:20:23";		$expected2->Author->updated = "2007-03-17 01:22:31";		$expected2->Author->test = "working";		$test = array();		$test[0] = $expected;		$test[1] = $expected2;		$this->assertIdentical($test, $result);		$result = Set::map(				array(					'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),					'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'),				)			);		$expected = new stdClass;		$expected->_name_ = 'Post';		$expected->id = '1';		$expected->author_id = '1';		$expected->title = 'First Post';		$expected->body = 'First Post Body';		$expected->published = 'Y';		$expected->created = "2007-03-18 10:39:23";		$expected->updated = "2007-03-18 10:41:31";		$expected->Author = new stdClass;		$expected->Author->id = '1';		$expected->Author->user = 'mariano';		$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';		$expected->Author->created = "2007-03-17 01:16:23";		$expected->Author->updated = "2007-03-17 01:18:31";		$expected->Author->test = "working";		$this->assertIdentical($expected, $result);	}/** * testPushDiff method *  * @access public * @return void */	function testPushDiff() {		$array1 = array('ModelOne' => array('id'=>1001, 'field_one'=>'a1.m1.f1', 'field_two'=>'a1.m1.f2'));		$array2 = array('ModelTwo' => array('id'=>1002, 'field_one'=>'a2.m2.f1', 'field_two'=>'a2.m2.f2'));		$result = Set::pushDiff($array1, $array2);		$this->assertIdentical($result, $array1 + $array2);		$array3 = array('ModelOne' => array('id'=>1003, 'field_one'=>'a3.m1.f1', 'field_two'=>'a3.m1.f2', 'field_three'=>'a3.m1.f3'));		$result = Set::pushDiff($array1, $array3);		$expected = array('ModelOne' => array('id'=>1001, 'field_one'=>'a1.m1.f1', 'field_two'=>'a1.m1.f2', 'field_three'=>'a3.m1.f3'));		$this->assertIdentical($result, $expected);		$array1 = array(				0 => array('ModelOne' => array('id'=>1001, 'field_one'=>'s1.0.m1.f1', 'field_two'=>'s1.0.m1.f2')),				1 => array('ModelTwo' => array('id'=>1002, 'field_one'=>'s1.1.m2.f2', 'field_two'=>'s1.1.m2.f2')));		$array2 = array(				0 => array('ModelOne' => array('id'=>1001, 'field_one'=>'s2.0.m1.f1', 'field_two'=>'s2.0.m1.f2')),				1 => array('ModelTwo' => array('id'=>1002, 'field_one'=>'s2.1.m2.f2', 'field_two'=>'s2.1.m2.f2')));		$result = Set::pushDiff($array1, $array2);		$this->assertIdentical($result, $array1);		$array3 = array(0 => array('ModelThree' => array('id'=>1003, 'field_one'=>'s3.0.m3.f1', 'field_two'=>'s3.0.m3.f2')));		$result = Set::pushDiff($array1, $array3);		$expected = array(					0 => array('ModelOne' => array('id'=>1001, 'field_one'=>'s1.0.m1.f1', 'field_two'=>'s1.0.m1.f2'),						'ModelThree' => array('id'=>1003, 'field_one'=>'s3.0.m3.f1', 'field_two'=>'s3.0.m3.f2')),					1 => array('ModelTwo' => array('id'=>1002, 'field_one'=>'s1.1.m2.f2', 'field_two'=>'s1.1.m2.f2')));		$this->assertIdentical($result, $expected);		$result = Set::pushDiff($array1);		$this->assertIdentical($result, $array1);		$set =& new Set($array1);		$result = $set->pushDiff($array2);		$this->assertIdentical($result, $array1+$array2);	}/** * testXmlSetReverse method *  * @access public * @return void */	function testXmlSetReverse() {		App::import('Core', 'Xml');		$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>		<rss version="2.0">		  <channel>		  <title>Cake PHP Google Group</title>		  <link>http://groups.google.com/group/cake-php</link>		  <description>Search this group before posting anything. There are over 20,000 posts and it&amp;#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>		  <language>en</language>		  	<item>			  <title>constructng result array when using findall</title>			  <link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>			  <description>i&#39;m using cakephp to construct a logical data model array that will be &lt;br&gt; passed to a flex app. I have the following model association: &lt;br&gt; ServiceDay-&amp;gt;(hasMany)ServiceTi me-&amp;gt;(hasMany)ServiceTimePrice. So what &lt;br&gt; the current output from my findall is something like this example: &lt;br&gt; &lt;p&gt;Array( &lt;br&gt; [0] =&amp;gt; Array(</description>			  <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>			  <author>bmil...@gmail.com(bpscrugs)</author>			  <pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>			  </item>			  <item>			  <title>Re: share views between actions?</title>			  <link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>			  <description>Then perhaps you might do us all a favour and refrain from replying to &lt;br&gt; things you do not understand. That goes especially for asinine comments. &lt;br&gt; Indeed. &lt;br&gt; To sum up: &lt;br&gt; No comment. &lt;br&gt; In my day, a simple &amp;quot;RTFM&amp;quot; would suffice. I&#39;ll keep in mind to ignore any &lt;br&gt; further responses from you. &lt;br&gt; You (and I) were referring to the *online documentation*, not other</description>			  <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>			  <author>subtropolis.z...@gmail.com(subtropolis zijn)</author>			  <pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>			 </item>		</channel>		</rss>';		$xml = new Xml($string);		$result = Set::reverse($xml);		$expected = array('Rss' => array(			'version' => '2.0',			'Channel' => array(				'title' => 'Cake PHP Google Group',				'link' => 'http://groups.google.com/group/cake-php',				'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',				'language' => 'en',				'Item' => array(					array(						'title' => 'constructng result array when using findall',						'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',						'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] =&gt; Array(",						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),						'author' => 'bmil...@gmail.com(bpscrugs)',						'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',					),					array(						'title' => 'Re: share views between actions?',						'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',						'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other',						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),						'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',						'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'					)				)			)		));		$this->assertEqual($result, $expected);		$string ='<data><post title="Title of this post" description="cool" /></data>';		$xml = new Xml($string);		$result = Set::reverse($xml);		$expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));		$this->assertEqual($result, $expected);		$xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');		$result = Set::reverse($xml);		$expected = array('Example' => 			array(				'Item' => array(					'title' => 'An example of a correctly reversed XMLNode',					'Desc' => array(),				)			)		);		$this->assertIdentical($result, $expected);				$xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');		$result = Set::reverse($xml);		$expected = 			array('Example' => array(				'Item' => array(					'attr' => '123', 					'Titles' => array(						array('Title' => 'title1'),						array('Title' => 'title2'),					)									)			)		);		$this->assertIdentical($result, $expected);				$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');		$result = Set::reverse($xml);		$expected = 			array('Example' => array(				'attr' => 'ex_attr',				'Item' => array(					'attr' => '123', 					'titles' => 'list',					'value'  => 'textforitems'				)			)		);		$this->assertIdentical($result, $expected);	}	function testStrictKeyCheck() {		$set = new Set(array('a' =

⌨️ 快捷键说明

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