Browse Source

Fix some skipped tests.

mscherer 6 years ago
parent
commit
0c1580762a

+ 8 - 5
src/Model/Table/Table.php

@@ -105,8 +105,6 @@ class Table extends ShimTable {
 	/**
 	 * Get all related entries that have been used so far
 	 *
-	 * @deprecated Must be refactored.
-	 *
 	 * @param string $tableName The related model
 	 * @param string|null $groupField Field to group by
 	 * @param string $type Find type
@@ -115,7 +113,8 @@ class Table extends ShimTable {
 	 */
 	public function getRelatedInUse($tableName, $groupField = null, $type = 'all', $options = []) {
 		if ($groupField === null) {
-			$groupField = $this->belongsTo[$tableName]['foreignKey'];
+			/** @var string $groupField */
+			$groupField = $this->getAssociation($tableName)->getForeignKey();
 		}
 		$defaults = [
 			'contain' => [$tableName],
@@ -123,9 +122,10 @@ class Table extends ShimTable {
 			'order' => isset($this->$tableName->order) ? $this->$tableName->order : [$tableName . '.' . $this->$tableName->getDisplayField() => 'ASC'],
 		];
 		if ($type === 'list') {
+			$propertyName = $this->getAssociation($tableName)->getProperty();
 			$defaults['fields'] = [$tableName . '.' . $this->$tableName->getPrimaryKey(), $tableName . '.' . $this->$tableName->getDisplayField()];
-			$defaults['keyField'] = $tableName . '.' . $this->$tableName->getPrimaryKey();
-			$defaults['valueField'] = $tableName . '.' . $this->$tableName->getDisplayField();
+			$defaults['keyField'] = $propertyName . '.' . $this->$tableName->getPrimaryKey();
+			$defaults['valueField'] = $propertyName . '.' . $this->$tableName->getDisplayField();
 		}
 		$options += $defaults;
 
@@ -147,8 +147,11 @@ class Table extends ShimTable {
 		];
 		if ($type === 'list') {
 			$defaults['fields'] = ['' . $this->getPrimaryKey(), '' . $this->getDisplayField()];
+			$defaults['keyField'] = $this->getPrimaryKey();
+			$defaults['valueField'] = $this->getDisplayField();
 		}
 		$options += $defaults;
+
 		return $this->find($type, $options);
 	}
 

+ 20 - 12
tests/TestCase/Model/Table/TableTest.php

@@ -6,6 +6,7 @@ use Cake\Datasource\ConnectionManager;
 use Cake\I18n\Time;
 use Cake\ORM\Entity;
 use Cake\ORM\TableRegistry;
+use Cake\Utility\Hash;
 use Tools\TestSuite\TestCase;
 
 class TableTest extends TestCase {
@@ -23,7 +24,12 @@ class TableTest extends TestCase {
 	/**
 	 * @var \Tools\Model\Table\Table;
 	 */
-	public $Users;
+	protected $Users;
+
+	/**
+	 * @var \Tools\Model\Table\Table;
+	 */
+	protected $Posts;
 
 	/**
 	 * SetUp method
@@ -173,30 +179,32 @@ class TableTest extends TestCase {
 	}
 
 	/**
-	 * TableTest::testGetRelatedInUse()
-	 *
 	 * @return void
 	 */
 	public function testGetRelatedInUse() {
-		$this->skipIf(true, 'TODO');
 		$results = $this->Posts->getRelatedInUse('Authors', 'author_id', 'list');
 		$expected = [1 => 'mariano', 3 => 'larry'];
 		$this->assertEquals($expected, $results->toArray());
+
+		$results = $this->Posts->getRelatedInUse('Authors', null, 'list');
+		$expected = [1 => 'mariano', 3 => 'larry'];
+		$this->assertEquals($expected, $results->toArray());
 	}
 
 	/**
-	 * TableTest::testGetFieldInUse()
-	 *
 	 * @return void
 	 */
 	public function testGetFieldInUse() {
-		$this->skipIf(true, 'TODO');
-		$this->db = ConnectionManager::get('test');
-		$this->skipIf(!($this->db instanceof Mysql), 'The test is only compatible with Mysql.');
-
-		$results = $this->Posts->getFieldInUse('author_id', 'list');
-		$expected = [1 => 'First Post', 2 => 'Second Post'];
+		$results = $this->Posts->getFieldInUse('author_id', 'list')->toArray();
+		$expected = [2 => 'Second Post', 3 => 'Third Post'];
 		$this->assertEquals($expected, $results);
+
+		$results = $this->Posts->getFieldInUse('author_id')->toArray();
+		$expected = ['Second Post', 'Third Post'];
+		$this->assertEquals($expected, Hash::extract($results, '{n}.title'));
+
+		$expected = [3, 1];
+		$this->assertEquals($expected, Hash::extract($results, '{n}.author_id'));
 	}
 
 	/**

+ 5 - 5
tests/TestCase/Model/Table/TokensTableTest.php

@@ -8,11 +8,6 @@ use Tools\TestSuite\TestCase;
 class TokensTableTest extends TestCase {
 
 	/**
-	 * @var \Tools\Model\Table\TokensTable;
-	 */
-	public $Tokens;
-
-	/**
 	 * @var array
 	 */
 	public $fixtures = [
@@ -20,6 +15,11 @@ class TokensTableTest extends TestCase {
 	];
 
 	/**
+	 * @var \Tools\Model\Table\TokensTable;
+	 */
+	protected $Tokens;
+
+	/**
 	 * @return void
 	 */
 	public function setUp() {

+ 0 - 12
tests/TestCase/Utility/TimeTest.php

@@ -714,18 +714,6 @@ class TimeTest extends TestCase {
 	}
 
 	/**
-	 * TimeTest::testTimezoneByCoordinates()
-	 *
-	 * @return void
-	 */
-	public function testTimezoneByCoordinates() {
-		$this->skipIf(true);
-
-		$result = $this->Time->timezoneByCoordinates(48, 11);
-		$this->assertEquals('Europe/Vaduz', $result);
-	}
-
-	/**
 	 * @return void
 	 */
 	public function testCweeks() {