propel /test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorWithSchemaTest.php

Language PHP Lines 81
MD5 Hash 970b5153ddbd01acf155d7983b846393
Repository https://github.com/mattleff/propel.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

/*
 *	$Id: SoftDeleteBehaviorTest.php 1612 2010-03-16 22:56:21Z francois $
 * This file is part of the Propel package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license    MIT License
 */

require_once dirname(__FILE__) . '/../../../../tools/helpers/schemas/SchemasTestBase.php';

/**
 * Tests for AggregateColumnBehavior class
 *
 * @author		 Franรงois Zaninotto
 * @version		$Revision: 2092 $
 * @package		generator.behavior.aggregate_column
 */
class AggregateColumnBehaviorWithSchemaTest extends SchemasTestBase
{
	protected function setUp()
	{
		parent::setUp();
		$this->con = Propel::getConnection(BookstoreSchemasBookstorePeer::DATABASE_NAME);
		$this->con->beginTransaction();
	}

	protected function tearDown()
	{
		$this->con->commit();
		parent::tearDown();
	}
	
	public function testParametersWithSchema()
	{
		$storeTable = BookstoreSchemasBookstorePeer::getTableMap();
		$this->assertEquals(count($storeTable->getColumns()), 8, 'AggregateColumn adds one column by default');
		$this->assertTrue(method_exists('BookstoreSchemasBookstore', 'getTotalContestEntries'));
	}

	public function testComputeWithSchema()
	{
		ContestBookstoreContestEntryQuery::create()->deleteAll($this->con);
		BookstoreSchemasBookstoreQuery::create()->deleteAll($this->con);
		BookstoreSchemasCustomerQuery::create()->deleteAll($this->con);
		ContestBookstoreContestQuery::create()->deleteAll($this->con);

		$store = new BookstoreSchemasBookstore();
		$store->save($this->con);
		$this->assertEquals(0, $store->computeTotalContestEntries($this->con), 'The compute method returns 0 for objects with no related objects');

		$contest = new ContestBookstoreContest();
		$contest->setBookstoreSchemasBookstore($store);
		$contest->save($this->con);
		$customer1 = new BookstoreSchemasCustomer();
		$customer1->save($this->con);

		$entry1 = new ContestBookstoreContestEntry();
		$entry1->setBookstoreSchemasBookstore($store);
		$entry1->setContestBookstoreContest($contest);
		$entry1->setBookstoreSchemasCustomer($customer1);
		$entry1->save($this->con, true); // skip reload to avoid #1151 for now

		$this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');

		$customer2 = new BookstoreSchemasCustomer();
		$customer2->save($this->con);

		$entry2 = new ContestBookstoreContestEntry();
		$entry2->setBookstoreSchemasBookstore($store);
		$entry2->setContestBookstoreContest($contest);
		$entry2->setBookstoreSchemasCustomer($customer2);
		$entry2->save($this->con, true); // skip reload to avoid #1151 for now

		$this->assertEquals(2, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
		$entry1->delete($this->con);
		$this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
	}
}
Back to Top