Bug #24713 ยป 17201.diff

Administrator Admin, 2011-01-21 22:15

View differences:

tests/t3lib/formprotection/t3lib_formprotection_BackendFormProtectionTest.php (working copy)
94 94
		return $className;
95 95
	}
96 96

  
97
	/**
98
	 * Mock session methods in t3lib_beUserAuth
99
	 *
100
	 * @return t3lib_beUserAuth Instance of BE_USER object with mocked session storage methods
101
	 */
102
	private function createBackendUserSessionStorageStub() {
103
		$className = 't3lib_beUserAuthMocked';
104
		if (!class_exists($className)) {
105
			eval(
106
				'class ' . $className . ' extends t3lib_beUserAuth {' .
107
				'  protected $session=array();' .
108
				'  public function getSessionData($key) {' .
109
				'    return $this->session[$key];' .
110
				'  }' .
111
				'  public function setAndSaveSessionData($key,$data) {' .
112
				'    $this->session[$key] = $data;' .
113
				'  }' .
114
				'}'
115
			);
116
		}
117

  
118
		return $this->getMock($className, array('foo'));// $className;
119
	}
97 120

  
98 121
	////////////////////////////////////
99 122
	// Tests for the utility functions
......
110 133
		);
111 134
	}
112 135

  
136
	/**
137
	 * @test
138
	 */
139
	public function createBackendUserSessionStorageStubWorkProperly() {
140
		$GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
141

  
142
		$allTokens = array(
143
			'12345678' => array(
144
					'formName' => 'foo',
145
					'action' => 'edit',
146
					'formInstanceName' => '42'
147
				),
148
		);
149

  
150
		$GLOBALS['BE_USER']->setAndSaveSessionData('tokens', $allTokens);
151

  
152
		$this->assertEquals($GLOBALS['BE_USER']->getSessionData('tokens'), $allTokens);
153
	}
154

  
113 155

  
114 156
	//////////////////////////////////////////////////////////
115 157
	// Tests concerning the reading and saving of the tokens
......
184 226
	 * @test
185 227
	 */
186 228
	public function createValidationErrorMessageAddsErrorFlashMessage() {
229
		$GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
187 230
		$this->fixture->createValidationErrorMessage();
188 231

  
189 232
		$messages = t3lib_FlashMessageQueue::getAllMessagesAndFlush();
    (1-1/1)