From ab850d6307e6688b9bc6901d59bedbab27b18244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Sun, 9 Jan 2011 17:35:51 +0100 Subject: [PATCH] Test suite moves to external project on github, see: https://github.com/canni/YiiMongoDbSuite-testingApp --- tests/README.mkd | 4 +- tests/bootstrap.php | 28 -- tests/phpunit.xml | 7 - tests/unit/BaseDBTest.php | 11 - tests/unit/BasicOperationsTest.php | 116 ----- tests/unit/CollectionOperationsTest.php | 19 - tests/unit/EMongoCriteriaTest.php | 474 ------------------ tests/unit/EMongoDBTest.php | 36 -- tests/unit/NamedScopesTest.php | 64 --- .../unit/testModels/BasicOperationsModel.php | 14 - .../testModels/BasicTestEmbeddedModel.php | 9 - tests/unit/testModels/BasicTestModel.php | 14 - tests/unit/testModels/NamedScopesModel.php | 35 -- 13 files changed, 3 insertions(+), 828 deletions(-) delete mode 100644 tests/bootstrap.php delete mode 100644 tests/phpunit.xml delete mode 100644 tests/unit/BaseDBTest.php delete mode 100644 tests/unit/BasicOperationsTest.php delete mode 100644 tests/unit/CollectionOperationsTest.php delete mode 100644 tests/unit/EMongoCriteriaTest.php delete mode 100644 tests/unit/EMongoDBTest.php delete mode 100644 tests/unit/NamedScopesTest.php delete mode 100644 tests/unit/testModels/BasicOperationsModel.php delete mode 100644 tests/unit/testModels/BasicTestEmbeddedModel.php delete mode 100644 tests/unit/testModels/BasicTestModel.php delete mode 100644 tests/unit/testModels/NamedScopesModel.php diff --git a/tests/README.mkd b/tests/README.mkd index 70941b60..a312180a 100644 --- a/tests/README.mkd +++ b/tests/README.mkd @@ -1,3 +1,5 @@ +This project testing suite is located in project [canni/YiiMongoDbSuite-testingApp](https://github.com/canni/YiiMongoDbSuite-testingApp) +on Github These tests are designed to be executed inside of an testing application, you may use the [provided one](https://github.com/canni/YiiMongoDbSuite-testingApp) to run tests. @@ -6,4 +8,4 @@ The canni/YiiMongoDbSuite-testingApp project on github, is dedicated to execute use them inside Yours Yii application instance. You may do `git clone git://github.com/canni/YiiMongoDbSuite-testingApp.git` to pull pre-configured -testing app and try on Your own. \ No newline at end of file +testing app with test suite, and try on Your own. \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 4ecd1697..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @author Invenzzia Group, open-source division of CleverIT company http://www.invenzzia.org - * @copyright 2010 CleverIT http://www.cleverit.com.pl - * @license http://www.yiiframework.com/license/ BSD license - * @version 1.3 - * @category ext - * @package ext.YiiMongoDbSuite - * - */ - -$appDir=dirname(__FILE__).'/../../..'; - -$yiit=$appDir.'/vendor/yii/framework/yiit.php'; -$config=$appDir.'/config/test.php'; - -require_once($yiit); - -Yii::setPathOfAlias('testDir', dirname(__FILE__)); -Yii::import('testDir.unit.*'); -Yii::import('testDir.unit.testModels.*'); - -Yii::createWebApplication($config); diff --git a/tests/phpunit.xml b/tests/phpunit.xml deleted file mode 100644 index 40ef6612..00000000 --- a/tests/phpunit.xml +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/tests/unit/BaseDBTest.php b/tests/unit/BaseDBTest.php deleted file mode 100644 index 3dc2bc38..00000000 --- a/tests/unit/BaseDBTest.php +++ /dev/null @@ -1,11 +0,0 @@ -mongodb->dropDb(); - } -} \ No newline at end of file diff --git a/tests/unit/BasicOperationsTest.php b/tests/unit/BasicOperationsTest.php deleted file mode 100644 index 29d2f68d..00000000 --- a/tests/unit/BasicOperationsTest.php +++ /dev/null @@ -1,116 +0,0 @@ -assertEquals( - array('_id'=>null, 'field1'=>null, 'field2'=>null), - $model->toArray() - ); - - $model->_id = 1; - $model->field1 = 'test'; - - $this->assertEquals( - array('_id'=>1, 'field1'=>'test', 'field2'=>null), - $model->toArray() - ); - - $model->_id = 'id'; - $model->field2 = 2; - - $this->assertEquals( - array('_id'=>'id', 'field1'=>'test', 'field2'=>2), - $model->toArray() - ); - } - - public function testInsert() - { - $model = new BasicOperationsModel(); - - $model->field1 = 'val1'; - $model->field2 = 1234; - - $this->assertEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - null - ); - - $this->assertEquals(null, $model->_id); - $this->assertTrue($model->getIsNewRecord()); - - $this->assertTrue($model->save()); - $this->assertTrue($model->_id !== null); - - $this->assertFalse($model->getIsNewRecord()); - - $this->assertEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - $model->toArray() - ); - } - - public function testUpdate() - { - $model = new BasicOperationsModel(); - - $model->field1 = 'val1'; - $model->field2 = 1234; - - $this->assertEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - null - ); - - $this->assertTrue($model->save()); - - $model->field1 = 1234; - $model->field2 = 'val2'; - - $this->assertFalse($model->getIsNewRecord()); - - $this->assertNotEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - $model->toArray() - ); - - $this->assertTrue($model->save()); - $this->assertFalse($model->getIsNewRecord()); - - $this->assertEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - $model->toArray() - ); - } - - public function testDelete() - { - $model = new BasicOperationsModel(); - - $model->field1 = 'val1'; - $model->field2 = 1234; - - $this->assertEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - null - ); - - $this->assertTrue($model->save()); - - $this->assertEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - $model->toArray() - ); - - $this->assertTrue($model->delete()); - - $this->assertEquals( - BasicOperationsModel::model()->getCollection()->findOne(), - null - ); - } -} \ No newline at end of file diff --git a/tests/unit/CollectionOperationsTest.php b/tests/unit/CollectionOperationsTest.php deleted file mode 100644 index f0a6d7f4..00000000 --- a/tests/unit/CollectionOperationsTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(BasicOperationsModel::model()->getCollection() instanceof MongoCollection); - $this->assertEquals('testCollection', BasicOperationsModel::model()->getCollection()->getName()); - - $newCollection = Yii::app()->getComponent('mongodb')->getDbInstance()->newCollection; - - BasicOperationsModel::model()->setCollection($newCollection); - - $this->assertTrue(BasicOperationsModel::model()->getCollection() instanceof MongoCollection); - $this->assertEquals('newCollection', BasicOperationsModel::model()->getCollection()->getName()); - } - - -} \ No newline at end of file diff --git a/tests/unit/EMongoCriteriaTest.php b/tests/unit/EMongoCriteriaTest.php deleted file mode 100644 index d5e0a73e..00000000 --- a/tests/unit/EMongoCriteriaTest.php +++ /dev/null @@ -1,474 +0,0 @@ - - * @author Invenzzia Group, open-source division of CleverIT company http://www.invenzzia.org - * @copyright 2010 CleverIT http://www.cleverit.com.pl - * @license http://www.yiiframework.com/license/ BSD license - * @version 1.3 - * @category ext - * @package ext.YiiMongoDbSuite - * - */ - -class EMongoCriteriaTest extends CTestCase -{ - public $criteria; - - public static $TEST_ARRAY = array( - 'conditions'=>array( - 'testField1'=>array('==' => 10), - 'testField2'=>array( - '>=' => 10, - '%' => array(10, 0) - ), - 'testField3.testField1'=>array( - 'lesseq'=>100, - 'greater'=>10, - ), - 'testField4.testField1'=>array('==' => 20) - ), - 'sort'=>array( - 'testField1'=>EMongoCriteria::SORT_ASC, - 'testField2'=>EMongoCriteria::SORT_DESC - ), - 'limit'=>10, - 'offset'=>25, - 'select'=>array('testField1', 'testField2'), - ); - - public function setUp() - { - parent::setUp(); - - $this->criteria = new EMongoCriteria; - } - - public function testCriteriaObjectCreaction() - { - $this->assertTrue($this->criteria instanceof EMongoCriteria, 'Test criteria object creation'); - } - - public function testGetSetFields() - { - // conditions array - - $this->assertTrue($this->criteria->getConditions() === array()); - - $this->criteria->setConditions(array('testArray')); - - $this->assertTrue($this->criteria->getConditions() === array('testArray')); - - // Limit field - - $this->assertTrue($this->criteria->getLimit() === null); - - $this->criteria->setLimit(10); - - $this->assertTrue($this->criteria->getLimit() === 10); - - // offset field - - $this->assertTrue($this->criteria->getOffset() === null); - - $this->criteria->setOffset(10); - - $this->assertTrue($this->criteria->getOffset() === 10); - - // sort array - - $this->assertTrue($this->criteria->getSort() === array()); - - $this->criteria->setSort(array('testArray')); - - $this->assertTrue($this->criteria->getSort() === array('testArray')); - - // select array - - $this->assertTrue($this->criteria->getSelect() === array()); - - $this->criteria->setSelect(array('testArray')); - - $this->assertTrue($this->criteria->getSelect() === array('testArray')); - - // working fields array - - $this->assertTrue($this->criteria->getWorkingFields() === array()); - - $this->criteria->setWorkingFields(array('testArray')); - - $this->assertTrue($this->criteria->getWorkingFields() === array('testArray')); - } - - public function testEqualsOperator() - { - // magic __set method - - $this->criteria->testField = 'testValue1'; - - $this->assertTrue($this->criteria->getConditions() === array( - 'testField'=>'testValue1' - ), 'Test magic __set method propagation to equals operator'); - - $this->criteria->setConditions(array()); - - // normal method, by magic __call - - $this->criteria->testField('==', 'testValue2'); - - $this->assertTrue($this->criteria->getConditions() === array( - 'testField'=>'testValue2' - ), 'Test magic __call method propagation == to equals operator'); - - $this->criteria->setConditions(array()); - - $this->criteria->testField('equals', 'testValue3'); - - $this->assertTrue($this->criteria->getConditions() === array( - 'testField'=>'testValue3' - ), 'Test magic __call method propagation "equals" to equals operator'); - - $this->criteria->setConditions(array()); - - $this->criteria->testField('eq', 'testValue4'); - - $this->assertTrue($this->criteria->getConditions() === array( - 'testField'=>'testValue4' - ), 'Test magic __call method propagation "equals" to equals operator'); - - $this->criteria->setConditions(array()); - } - - public function testBasicOperators() - { - $i = 1; - foreach(EMongoCriteria::$operators as $opName => $opValue) - { - if(in_array($opValue, array( - '$gt', '$gte', '$lt', '$lte', '$ne', '$size', '$type', '$mod', - '$in', '$nin', '$all', '$ememMatch' - ))) - { - // clear conditions - $this->criteria->setConditions(array()); - - $this->criteria->testField($opName, 'testValue'.$i); - - $this->assertEquals( - array( - 'testField'=>array( - $opValue => 'testValue'.$i - ), - ), - $this->criteria->getConditions(), - 'Test operator: '.$opName.' with value: testValue'.$i - ); - - $i++; - } - } - } - - public function testExistsOperators() - { - $this->criteria->testField('exists'); - - $this->assertEquals( - array( - 'testField'=>array( - '$exists' => true - ), - ), - $this->criteria->getConditions(), - 'Test operator: exists' - ); - - $this->criteria->testField('notexists'); - - $this->assertEquals( - array( - 'testField'=>array( - '$exists' => false - ), - ), - $this->criteria->getConditions(), - 'Test operator: exists' - ); - } - - public function testEmbeddedFieldsConditions() - { - $this->assertEquals( - array( - 'testField1.testField2' => array('$gte'=>'testValue1') - ), - $this->criteria->testField1->testField2('>=', 'testValue1')->getConditions() - ); - - $this->assertEquals( - array( - 'testField1.testField2' => 'testValue2' - ), - $this->criteria->testField1->testField2('==', 'testValue2')->getConditions() - ); - - $this->criteria->testField1->testField2 = 'testValue3'; - - $this->assertEquals( - array( - 'testField1.testField2' => 'testValue3' - ), - $this->criteria->getConditions() - ); - - $this->assertEquals( - array('testField1', 'testField2'), - $this->criteria->testField1->testField2->getWorkingFields() - ); - } - - public function testOperatorAggregation() - { - $this->criteria->testField('>=', 10); - - $this->assertEquals( - array( - 'testField'=>array( - '$gte'=>10 - ), - ), - $this->criteria->getConditions() - ); - - $this->criteria->testField('<=', 100); - - $this->assertEquals( - array( - 'testField'=>array( - '$gte'=>10, - '$lte'=>100, - ), - ), - $this->criteria->getConditions() - ); - - $this->criteria->testField('%', array(10, 0)); - - $this->assertEquals( - array( - 'testField'=>array( - '$gte'=>10, - '$lte'=>100, - '$mod'=>array(10, 0), - ), - ), - $this->criteria->getConditions() - ); - - $this->criteria->testField = 20; - - $this->assertEquals( - array( - 'testField'=>20, - ), - $this->criteria->getConditions() - ); - } - - public function testCreationFromArray() - { - $testArray = self::$TEST_ARRAY; - $criteria = new EMongoCriteria($testArray); - - // ensure that var has not been changed by any reference - $testArray = self::$TEST_ARRAY; - - $this->assertEquals( - array( - 'testField1' => 10, - 'testField2' => array( - '$gte' => 10, - '$mod' => array(10, 0), - ), - 'testField3.testField1' => array( - '$lte' => 100, - '$gt' => 10 - ), - 'testField4.testField1' => 20, - ), - $criteria->getConditions() - ); - - $this->assertEquals( - $testArray['sort'], - $criteria->getSort() - ); - - $this->assertEquals( - $testArray['limit'], - $criteria->getLimit() - ); - - $this->assertEquals( - $testArray['select'], - $criteria->getSelect() - ); - - $this->assertEquals( - $testArray['sort'], - $criteria->getSort() - ); - } - - public function testConditionsChaining() - { - $this->criteria-> - testField1->testField2('%', array(10, 0))-> - testField3('==', 12)-> - sort('testField1', EMongoCriteria::SORT_ASC)-> - limit(10)-> - select(array('testField2'))-> - offset(25); - - $this->assertEquals( - array( - 'testField1.testField2'=>array('$mod'=>array(10, 0)), - 'testField3'=>12, - ), - $this->criteria->getConditions() - ); - - $this->assertEquals( - array('testField1'=>EMongoCriteria::SORT_ASC), - $this->criteria->getSort() - ); - - $this->assertEquals( - 10, - $this->criteria->getLimit() - ); - - $this->assertEquals( - array('testField2'), - $this->criteria->getSelect() - ); - - $this->assertEquals( - 25, - $this->criteria->getOffset() - ); - } - - public function testCriteriaMerge() - { - $c1 = new EMongoCriteria; - $c2 = new EMongoCriteria; - - $c1->fieldName1('>', 10)->fieldName1('<', 100); - $c1->fieldName2 = 20; - $c1->fieldName4->fieldName5('<', 100); - $c1->limit(10)->offset(20)->select(array('fieldName1'))->sort('fieldName1', EMongoCriteria::SORT_ASC); - - $c2->fieldName1 = 20; - $c2->fieldName2('%', array(10, 0)); - $c2->fieldName4->fieldName5('>', 10); - $c2->limit(5)->offset(5)->select(array('fieldName2'))->sort('fieldName2', EMongoCriteria::SORT_DESC); - - $c1->mergeWith($c2); - - $this->assertEquals( - array( - 'fieldName1' => 20, - 'fieldName2' => array( - '$mod' => array(10, 0), - ), - 'fieldName4.fieldName5' => array( - '$lt' => 100, - '$gt' => 10, - ), - ), - $c1->getConditions() - ); - - $this->assertEquals( - 5, $c1->getLimit() - ); - - $this->assertEquals( - 5, $c1->getOffset() - ); - - $this->assertEquals( - array( - 'fieldName1', 'fieldName2' - ), - $c1->getSelect() - ); - - $this->assertEquals( - array( - 'fieldName1'=>EMongoCriteria::SORT_ASC, 'fieldName2'=>EMongoCriteria::SORT_DESC - ), - $c1->getSort() - ); - - $c2->mergeWith(array( - 'conditions'=>array( - 'fieldName1' => array( - '>' => 10, - '<' => 100, - ), - 'fieldName2' => array('==' => 20), - 'fieldName4.fieldName5' => array( - '<' => 100, - ), - 'fieldName6' => array('notExists'), - ), - 'limit' => 10, - 'offset' => 20, - 'select' => array('fieldName1'), - 'sort' => array('fieldName1' => EMongoCriteria::SORT_ASC) - )); - - $this->assertEquals( - array( - 'fieldName1' => array( - '$gt' => 10, - '$lt' => 100, - ), - 'fieldName2' => 20, - 'fieldName4.fieldName5' => array( - '$gt' => 10, - '$lt' => 100, - ), - 'fieldName6' => array('$exists' => false) - ), - $c2->getConditions() - ); - - $this->assertEquals( - 10, $c2->getLimit() - ); - - $this->assertEquals( - 20, $c2->getOffset() - ); - - $this->assertEquals( - array( - 'fieldName2', 'fieldName1' - ), - $c2->getSelect() - ); - - $this->assertEquals( - array( - 'fieldName2'=>EMongoCriteria::SORT_DESC, 'fieldName1'=>EMongoCriteria::SORT_ASC - ), - $c2->getSort() - ); - } -} \ No newline at end of file diff --git a/tests/unit/EMongoDBTest.php b/tests/unit/EMongoDBTest.php deleted file mode 100644 index adb8ef45..00000000 --- a/tests/unit/EMongoDBTest.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @author Invenzzia Group, open-source division of CleverIT company http://www.invenzzia.org - * @copyright 2010 CleverIT http://www.cleverit.com.pl - * @license http://www.yiiframework.com/license/ BSD license - * @version 1.3 - * @category ext - * @package ext.YiiMongoDbSuite - * - */ - -class EMongoDBTest extends CTestCase -{ - public function testMongoDbComponentGet() - { - $db = Yii::app()->getComponent('mongodb'); - - $this->assertTrue($db instanceof EMongoDB, 'Get via getComponent method'); - - $db = null; - - $db = Yii::app()->mongodb; - - $this->assertTrue($db instanceof EMongoDB, 'Get via magic __get method'); - } - - public function testGetMongoConnectionObject() - { - $this->assertTrue(Yii::app()->mongodb->connection instanceof Mongo, 'Test connection object'); - } -} \ No newline at end of file diff --git a/tests/unit/NamedScopesTest.php b/tests/unit/NamedScopesTest.php deleted file mode 100644 index 3773e0e2..00000000 --- a/tests/unit/NamedScopesTest.php +++ /dev/null @@ -1,64 +0,0 @@ -assertEquals( - array(), - $modelWithoutDS->getDbCriteria()->getConditions() - ); - $this->assertEquals( - array('field1'=>array('$gt'=>1)), - $modelWithDS->getDbCriteria()->getConditions() - ); - } - - public function testScope() - { - $modelWithoutDS = new BasicOperationsModel(); - $modelWithDS = new NamedScopesModel(); - - try - { - $modelWithoutDS->scope()->getDbCriteria()->getConditions(); - - $this->fail('Exception expected!'); - } - catch(Exception $e) - { - $this->assertEquals( - 'Property "BasicOperationsModel.scope" is not defined.', - $e->getMessage() - ); - } - - $this->assertEquals( - array('field1'=>array('$gt'=>1), 'field2'=>array('$lte'=>2)), - $modelWithDS->scope()->getDbCriteria()->getConditions() - ); - } - - public function testParamScope() - { - $modelWithDS = new NamedScopesModel(); - - $this->assertEquals( - array('field1'=>'testParam'), - $modelWithDS->paramScope('testParam')->getDbCriteria()->getConditions() - ); - } - - public function testChain() - { - $model = new NamedScopesModel(); - - $this->assertEquals( - array('field1'=>'testParam', 'field2'=>array('$lte'=>2)), - $model->paramScope('testParam')->scope()->getDbCriteria()->getConditions() - ); - } -} \ No newline at end of file diff --git a/tests/unit/testModels/BasicOperationsModel.php b/tests/unit/testModels/BasicOperationsModel.php deleted file mode 100644 index 1accfef9..00000000 --- a/tests/unit/testModels/BasicOperationsModel.php +++ /dev/null @@ -1,14 +0,0 @@ -$name; - } -} \ No newline at end of file diff --git a/tests/unit/testModels/BasicTestModel.php b/tests/unit/testModels/BasicTestModel.php deleted file mode 100644 index 11074b81..00000000 --- a/tests/unit/testModels/BasicTestModel.php +++ /dev/null @@ -1,14 +0,0 @@ -$name; - } -} \ No newline at end of file diff --git a/tests/unit/testModels/NamedScopesModel.php b/tests/unit/testModels/NamedScopesModel.php deleted file mode 100644 index c7c5164f..00000000 --- a/tests/unit/testModels/NamedScopesModel.php +++ /dev/null @@ -1,35 +0,0 @@ -getDbCriteria(); - $criteria->field1 = $param; - $this->setDbCriteria($criteria); - - return $this; - } - - public function scopes() - { - return array( - 'scope'=>array( - 'conditions'=>array( - 'field2' => array('<=' => 2) - ), - ), - ); - } - - public function defaultScope() - { - return array( - 'conditions'=>array( - 'field1' => array('>' => 1), - ), - ); - } -} \ No newline at end of file