@@ 29-62 (lines=34) @@ | ||
26 | /** |
|
27 | * Helper class for testing with mocked datasources |
|
28 | */ |
|
29 | class TestAuthor extends Author { |
|
30 | ||
31 | public $hasMany = array( |
|
32 | 'Post' => array( |
|
33 | 'className' => 'TestPost' |
|
34 | ) |
|
35 | ); |
|
36 | ||
37 | protected $_dataSourceObject; |
|
38 | ||
39 | /** |
|
40 | * Helper method to set a datasource object |
|
41 | * |
|
42 | * @param Object $object The datasource object |
|
43 | * @return void |
|
44 | */ |
|
45 | public function setDataSourceObject($object) { |
|
46 | $this->_dataSourceObject = $object; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * Overwritten in order to return the directly set datasource object if |
|
51 | * available |
|
52 | * |
|
53 | * @return DataSource |
|
54 | */ |
|
55 | public function getDataSource() { |
|
56 | if ($this->_dataSourceObject !== null) { |
|
57 | return $this->_dataSourceObject; |
|
58 | } |
|
59 | return parent::getDataSource(); |
|
60 | } |
|
61 | ||
62 | } |
|
63 | ||
64 | /** |
|
65 | * Helper class for testing with mocked datasources |
|
@@ 67-100 (lines=34) @@ | ||
64 | /** |
|
65 | * Helper class for testing with mocked datasources |
|
66 | */ |
|
67 | class TestPost extends Post { |
|
68 | ||
69 | public $belongsTo = array( |
|
70 | 'Author' => array( |
|
71 | 'className' => 'TestAuthor' |
|
72 | ) |
|
73 | ); |
|
74 | ||
75 | protected $_dataSourceObject; |
|
76 | ||
77 | /** |
|
78 | * Helper method to set a datasource object |
|
79 | * |
|
80 | * @param Object $object The datasource object |
|
81 | * @return void |
|
82 | */ |
|
83 | public function setDataSourceObject($object) { |
|
84 | $this->_dataSourceObject = $object; |
|
85 | } |
|
86 | ||
87 | /** |
|
88 | * Overwritten in order to return the directly set datasource object if |
|
89 | * available |
|
90 | * |
|
91 | * @return DataSource |
|
92 | */ |
|
93 | public function getDataSource() { |
|
94 | if ($this->_dataSourceObject !== null) { |
|
95 | return $this->_dataSourceObject; |
|
96 | } |
|
97 | return parent::getDataSource(); |
|
98 | } |
|
99 | ||
100 | } |
|
101 | ||
102 | /** |
|
103 | * ModelWriteTest |