root/trunk/generator/test/classes/bookstore/BookstoreDataPopulator.php

Revision 1024, 7.8 kB (checked in by hans, 4 months ago)

Updating license to version 3 of the LGPL.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Rev Date Author HeadURL Revision
Line 
1 <?php
2 /*
3  *  $Id$
4  *
5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16  *
17  * This software consists of voluntary contributions made by many individuals
18  * and is licensed under version 3 of the LGPL. For more information please see
19  * <http://propel.phpdb.org>.
20  */
21
22 /*
23 require_once 'bookstore/Book.php';
24 require_once 'bookstore/Author.php';
25 require_once 'bookstore/Media.php';
26 require_once 'bookstore/Publisher.php';
27 require_once 'bookstore/Review.php';
28 require_once 'bookstore/BookClubList.php';
29 require_once 'bookstore/BookListRel.php';
30 require_once 'bookstore/BookstoreEmployee.php';
31 require_once 'bookstore/BookstoreManager.php';
32 require_once 'bookstore/BookstoreCashier.php';
33 require_once 'bookstore/BookstoreEmployeeAccount.php';
34 */
35
36 define('_LOB_SAMPLE_FILE_PATH', dirname(__FILE__) . '/../../etc/lob');
37
38 /**
39  * Populates data needed by the bookstore unit tests.
40  *
41  * This classes uses the actual Propel objects to do the population rather than
42  * inserting directly into the database.  This will have a performance hit, but will
43  * benefit from increased flexibility (as does anything using Propel).
44  *
45  * @author     Hans Lellelid <hans@xmpl.org>
46  */
47 class BookstoreDataPopulator {
48
49     public static function populate() {
50
51         // Add publisher records
52         // ---------------------
53
54         //print "\nAdding some new publishers to the list\n";
55         //print "--------------------------------------\n\n";
56
57         $scholastic = new Publisher();
58         $scholastic->setName("Scholastic");
59         // do not save, will do later to test cascade
60         //print "Added publisher \"Scholastic\" [not saved yet].\n";
61
62         $morrow = new Publisher();
63         $morrow->setName("William Morrow");
64         $morrow->save();
65         $morrow_id = $morrow->getId();
66         //print "Added publisher \"William Morrow\" [id = $morrow_id].\n";
67
68         $penguin = new Publisher();
69         $penguin->setName("Penguin");
70         $penguin->save();
71         $penguin_id = $penguin->getId();
72         //print "Added publisher \"Penguin\" [id = $penguin_id].\n";
73
74         $vintage = new Publisher();
75         $vintage->setName("Vintage");
76         $vintage->save();
77         $vintage_id = $vintage->getId();
78         //print "Added publisher \"Vintage\" [id = $vintage_id].\n";
79
80
81         // Add author records
82         // ------------------
83
84         //print "\nAdding some new authors to the list\n";
85         //print "--------------------------------------\n\n";
86
87         $rowling = new Author();
88         $rowling->setFirstName("J.K.");
89         $rowling->setLastName("Rowling");
90         // print "Created author Rowling: " . (string) $rowling . "\n";
91         // no save()
92         //print "Added author \"J.K. Rowling\" [not saved yet].\n";
93
94         $stephenson = new Author();
95         $stephenson->setFirstName("Neal");
96         $stephenson->setLastName("Stephenson");
97         $stephenson->save();
98         $stephenson_id = $stephenson->getId();
99         //print "Added author \"Neal Stephenson\" [id = $stephenson_id].\n";
100
101         $byron = new Author();
102         $byron->setFirstName("George");
103         $byron->setLastName("Byron");
104         $byron->save();
105         $byron_id = $byron->getId();
106         //print "Added author \"George Byron\" [id = $byron_id].\n";
107
108
109         $grass = new Author();
110         $grass->setFirstName("Gunter");
111         $grass->setLastName("Grass");
112         $grass->save();
113         $grass_id = $grass->getId();
114         //print "Added author \"Gunter Grass\" [id = $grass_id].\n";
115
116
117         // Add book records
118         // ----------------
119
120         //print "\nAdding some new books to the list\n";
121         //print "-------------------------------------\n\n";
122
123         $phoenix = new Book();
124         $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
125         $phoenix->setISBN("043935806X");
126         $phoenix->setAuthor($rowling);
127         $phoenix->setPublisher($scholastic);
128         $phoenix->setPrice(10.99);
129         $phoenix->save();
130         $phoenix_id = $phoenix->getId();
131         // print "Created book Phoenix: " . (string) $phoenix . "\n";
132
133         // print "Added book \"Harry Potter and the Order of the Phoenix\" [id = $phoenix_id].\n";
134
135         $qs = new Book();
136         $qs->setISBN("0380977427");
137         $qs->setTitle("Quicksilver");
138         $qs->setPrice(11.99);
139         $qs->setAuthor($stephenson);
140         $qs->setPublisher($morrow);
141         $qs->save();
142         $qs_id = $qs->getId();
143         // print "Added book \"Quicksilver\" [id = $qs_id].\n";
144
145         $dj = new Book();
146         $dj->setISBN("0140422161");
147         $dj->setTitle("Don Juan");
148         $dj->setPrice(12.99);
149         $dj->setAuthor($byron);
150         $dj->setPublisher($penguin);
151         $dj->save();
152         $dj_id = $dj->getId();
153         // print "Added book \"Don Juan\" [id = $dj_id].\n";
154
155         $td = new Book();
156         $td->setISBN("067972575X");
157         $td->setTitle("The Tin Drum");
158         $td->setPrice(13.99);
159         $td->setAuthor($grass);
160         $td->setPublisher($vintage);
161         $td->save();
162         $td_id = $td->getId();
163         // print "Added book \"The Tin Drum\" [id = $td_id].\n";
164
165         // Add review records
166         // ------------------
167
168         //print "\nAdding some book reviews to the list\n";
169         //print "------------------------------------\n\n";
170
171         $r1 = new Review();
172         $r1->setBook($phoenix);
173         $r1->setReviewedBy("Washington Post");
174         $r1->setRecommended(true);
175         $r1->setReviewDate(time());
176         $r1->save();
177         $r1_id = $r1->getId();
178         //print "Added Washington Post book review  [id = $r1_id].\n";
179
180         $r2 = new Review();
181         $r2->setBook($phoenix);
182         $r2->setReviewedBy("New York Times");
183         $r2->setRecommended(false);
184         $r2->setReviewDate(time());
185         $r2->save();
186         $r2_id = $r2->getId();
187         //print "Added New York Times book review  [id = $r2_id].\n";
188
189         $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
190         $clob_path _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
191
192         $m1 = new Media();
193         $m1->setBook($td);
194         $m1->setCoverImage(file_get_contents($blob_path));
195         $m1->setExcerpt(file_get_contents($clob_path));
196         $m1->save();
197
198         // Add book list records
199         // ---------------------
200         // (this is for many-to-many tests)
201
202         $blc1 = new BookClubList();
203         $blc1->setGroupLeader("Crazyleggs");
204         $blc1->setTheme("Happiness");
205
206         $brel1 = new BookListRel();
207         $brel1->setBook($phoenix);
208
209         $brel2 = new BookListRel();
210         $brel2->setBook($dj);
211
212         $blc1->addBookListRel($brel1);
213         $blc1->addBookListRel($brel2);
214
215         $bemp1 = new BookstoreEmployee();
216         $bemp1->setName("John");
217         $bemp1->setJobTitle("Manager");
218
219         $bemp2 = new BookstoreEmployee();
220         $bemp2->setName("Pieter");
221         $bemp2->setJobTitle("Clerk");
222         $bemp2->setSupervisor($bemp1);
223         $bemp2->save();
224
225         $role = new AcctAccessRole();
226         $role->setName("Admin");
227         
228         $bempacct = new BookstoreEmployeeAccount();
229         $bempacct->setBookstoreEmployee($bemp1);
230         $bempacct->setAcctAccessRole($role);
231         $bempacct->setLogin("john");
232         $bempacct->setPassword("johnp4ss");
233         $bempacct->save();
234         
235         // Add bookstores
236
237         $store = new Bookstore();
238         $store->setStoreName("Amazon");
239         $store->setPopulationServed(5000000000); // world population
240         $store->setTotalBooks(300);
241         $store->save();
242
243         $store = new Bookstore();
244         $store->setStoreName("Local Store");
245         $store->setPopulationServed(20);
246         $store->setTotalBooks(500000);
247         $store->save();
248     }
249
250     public static function depopulate() {
251         AuthorPeer::doDeleteAll();
252         BookPeer::doDeleteAll();
253         PublisherPeer::doDeleteAll();
254         ReviewPeer::doDeleteAll();
255         MediaPeer::doDeleteAll();
256         BookClubListPeer::doDeleteAll();
257         BookstoreEmployeePeer::doDeleteAll();
258         BookstoreEmployeeAccountPeer::doDeleteAll();
259         CustomerPeer::doDeleteAll();
260         ContestPeer::doDeleteAll();
261         BookstoreContestPeer::doDeleteAll();
262         BookstoreContestEntryPeer::doDeleteAll();
263         BookstorePeer::doDeleteAll();
264     }
265
266 }
267
Note: See TracBrowser for help on using the browser.